Skip to content

Commit

Permalink
Merge pull request #41 from MixinMessenger/feature/super_group
Browse files Browse the repository at this point in the history
Feature/super group
  • Loading branch information
over140 authored Jun 6, 2018
2 parents 9395ab0 + 369dbac commit 8666f4d
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 82 deletions.
4 changes: 0 additions & 4 deletions Mixin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
7B75E6471FE0E20000CD66F1 /* InsetLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B75E6461FE0E20000CD66F1 /* InsetLabel.swift */; };
7B78B2461FF2170400371632 /* InviteLinkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B78B2451FF2170400371632 /* InviteLinkViewController.swift */; };
7B7B2BC51FB15B6A0002BED5 /* AvatarImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B7B2BC41FB15B6A0002BED5 /* AvatarImageView.swift */; };
7B7F759520B53D46006CF698 /* EmbeddedUsernameDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B7F759420B53D46006CF698 /* EmbeddedUsernameDetector.swift */; };
7B7F7E391FD43F2500A1C91F /* DetailInfoMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B7F7E381FD43F2500A1C91F /* DetailInfoMessageCell.swift */; };
7B8144631FDD62B900404431 /* SystemMessageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B8144621FDD62B900404431 /* SystemMessageViewModel.swift */; };
7B836C7E1FD17D6100529754 /* DetailInfoMessageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B836C7D1FD17D6100529754 /* DetailInfoMessageViewModel.swift */; };
Expand Down Expand Up @@ -604,7 +603,6 @@
7B75E6461FE0E20000CD66F1 /* InsetLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InsetLabel.swift; sourceTree = "<group>"; };
7B78B2451FF2170400371632 /* InviteLinkViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InviteLinkViewController.swift; sourceTree = "<group>"; };
7B7B2BC41FB15B6A0002BED5 /* AvatarImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarImageView.swift; sourceTree = "<group>"; };
7B7F759420B53D46006CF698 /* EmbeddedUsernameDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmbeddedUsernameDetector.swift; sourceTree = "<group>"; };
7B7F7E381FD43F2500A1C91F /* DetailInfoMessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailInfoMessageCell.swift; sourceTree = "<group>"; };
7B8144621FDD62B900404431 /* SystemMessageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemMessageViewModel.swift; sourceTree = "<group>"; };
7B836C7D1FD17D6100529754 /* DetailInfoMessageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailInfoMessageViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1174,7 +1172,6 @@
7BA4193F209AFBCD00DFCD39 /* AppCardMessageViewModel.swift */,
7B9F06C520A9858D0095A51B /* VideoMessageViewModel.swift */,
7BBA1CA820692C7600B2F0CE /* GalleryItem.swift */,
7B7F759420B53D46006CF698 /* EmbeddedUsernameDetector.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -2402,7 +2399,6 @@
DF3C47521FA191A600A07C71 /* UserDAO.swift in Sources */,
DF87949C207505F4004A1E55 /* TransactionCell.swift in Sources */,
DF16682220AC3B5D00C45E31 /* ConversationShareContactViewController.swift in Sources */,
7B7F759520B53D46006CF698 /* EmbeddedUsernameDetector.swift in Sources */,
DF8CECE31FC3075B00E40064 /* TransferViewController.swift in Sources */,
DF768569200687010055F3FF /* PreviewView.swift in Sources */,
7B5747411FA08E18005A6BB5 /* MobileNumberViewController.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Mixin/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
}
var ownerUser: UserItem?
if let userId = userInfo["user_id"] as? String, let userFullName = userInfo["userFullName"] as? String, let userAvatarUrl = userInfo["userAvatarUrl"] as? String, let userIdentityNumber = userInfo["userIdentityNumber"] as? String {
ownerUser = UserItem.createUser(userId: userId, fullName: userFullName, identityNumber: userIdentityNumber, avatarUrl: userAvatarUrl)
ownerUser = UserItem.createUser(userId: userId, fullName: userFullName, identityNumber: userIdentityNumber, avatarUrl: userAvatarUrl, appId: userInfo["userAppId"] as? String)
}
var newMsg = Message.createMessage(category: MessageCategory.SIGNAL_TEXT.rawValue, conversationId: conversationId, createdAt: Date().toUTCString(), userId: AccountAPI.shared.accountUserId)
newMsg.content = text
Expand Down
13 changes: 13 additions & 0 deletions Mixin/Core/WebSocket/Model/BlazeMessageData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct BlazeMessageData: Codable {
let createdAt: String
let updatedAt: String
let source: String
let representativeId: String?

enum CodingKeys: String, CodingKey {
case conversationId = "conversation_id"
Expand All @@ -22,5 +23,17 @@ struct BlazeMessageData: Codable {
case createdAt = "created_at"
case updatedAt = "updated_at"
case source
case representativeId = "representative_id"
}
}

extension BlazeMessageData {

func getSenderId() -> String {
guard let rId = representativeId, !rId.isEmpty else {
return userId
}
return rId
}

}
7 changes: 5 additions & 2 deletions Mixin/Core/WebSocket/Service/ReceiveMessageService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class ReceiveMessageService: MixinService {
UIApplication.trackError("ReceiveMessageService", action: "signal key decrypt failed \(errorInfo)", userInfo: userInfo)
}

private func processDecryptSuccess(data: BlazeMessageData, plainText: String) {
private func processDecryptSuccess(data: BlazeMessageData, plainText: String, representativeId: String? = nil) {
if data.category.hasSuffix("_TEXT") {
var content = plainText
if data.category == MessageCategory.PLAIN_TEXT.rawValue {
Expand Down Expand Up @@ -412,7 +412,10 @@ class ReceiveMessageService: MixinService {
break
}
case MessageCategory.PLAIN_TEXT.rawValue, MessageCategory.PLAIN_IMAGE.rawValue, MessageCategory.PLAIN_DATA.rawValue, MessageCategory.PLAIN_VIDEO.rawValue, MessageCategory.PLAIN_STICKER.rawValue, MessageCategory.PLAIN_CONTACT.rawValue:
processDecryptSuccess(data: data, plainText: data.data)
if let representativeId = data.representativeId {
_ = syncUser(userId: representativeId)
}
processDecryptSuccess(data: data, plainText: data.data, representativeId: data.representativeId)
updateRemoteMessageStatus(messageId: data.messageId, status: .DELIVERED, createdAt: data.createdAt)
default:
break
Expand Down
10 changes: 5 additions & 5 deletions Mixin/Database/Model/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,28 @@ extension Message {
}

static func createMessage(textMessage plainText: String, data: BlazeMessageData) -> Message {
return Message(messageId: data.messageId, conversationId: data.conversationId, userId: data.userId, category: data.category, content: plainText, mediaUrl: nil, mediaMimeType: nil, mediaSize: nil, mediaDuration: nil, mediaWidth: nil, mediaHeight: nil, mediaHash: nil, mediaKey: nil, mediaDigest: nil, mediaStatus: nil, thumbImage: nil, status: MessageStatus.DELIVERED.rawValue, action: nil, participantId: nil, snapshotId: nil, name: nil, albumId: nil, sharedUserId: nil, createdAt: data.createdAt)
return Message(messageId: data.messageId, conversationId: data.conversationId, userId: data.getSenderId(), category: data.category, content: plainText, mediaUrl: nil, mediaMimeType: nil, mediaSize: nil, mediaDuration: nil, mediaWidth: nil, mediaHeight: nil, mediaHash: nil, mediaKey: nil, mediaDigest: nil, mediaStatus: nil, thumbImage: nil, status: MessageStatus.DELIVERED.rawValue, action: nil, participantId: nil, snapshotId: nil, name: nil, albumId: nil, sharedUserId: nil, createdAt: data.createdAt)
}

static func createMessage(systemMessage action: String?, participantId: String?, userId: String, data: BlazeMessageData) -> Message {
return Message(messageId: data.messageId, conversationId: data.conversationId, userId: userId, category: data.category, content: nil, mediaUrl: nil, mediaMimeType: nil, mediaSize: nil, mediaDuration: nil, mediaWidth: nil, mediaHeight: nil, mediaHash: nil, mediaKey: nil, mediaDigest: nil, mediaStatus: nil, thumbImage: nil, status: MessageStatus.READ.rawValue, action: action, participantId: participantId, snapshotId: nil, name: nil, albumId: nil, sharedUserId: nil, createdAt: data.createdAt)
}

static func createMessage(appMessage data: BlazeMessageData) -> Message {
return Message(messageId: data.messageId, conversationId: data.conversationId, userId: data.userId, category: data.category, content: data.data, mediaUrl: nil, mediaMimeType: nil, mediaSize: nil, mediaDuration: nil, mediaWidth: nil, mediaHeight: nil, mediaHash: nil, mediaKey: nil, mediaDigest: nil, mediaStatus: nil, thumbImage: nil, status: MessageStatus.DELIVERED.rawValue, action: nil, participantId: nil, snapshotId: nil, name: nil, albumId: nil, sharedUserId: nil, createdAt: data.createdAt)
return Message(messageId: data.messageId, conversationId: data.conversationId, userId: data.getSenderId(), category: data.category, content: data.data, mediaUrl: nil, mediaMimeType: nil, mediaSize: nil, mediaDuration: nil, mediaWidth: nil, mediaHeight: nil, mediaHash: nil, mediaKey: nil, mediaDigest: nil, mediaStatus: nil, thumbImage: nil, status: MessageStatus.DELIVERED.rawValue, action: nil, participantId: nil, snapshotId: nil, name: nil, albumId: nil, sharedUserId: nil, createdAt: data.createdAt)
}

static func createMessage(stickerData: TransferStickerData, data: BlazeMessageData) -> Message {
return Message(messageId: data.messageId, conversationId: data.conversationId, userId: data.userId, category: data.category, content: nil, mediaUrl: nil, mediaMimeType: nil, mediaSize: nil, mediaDuration: nil, mediaWidth: nil, mediaHeight: nil, mediaHash: nil, mediaKey: nil, mediaDigest: nil, mediaStatus: nil, thumbImage: nil, status: MessageStatus.DELIVERED.rawValue, action: nil, participantId: nil, snapshotId: nil, name: stickerData.name, albumId: stickerData.albumId, sharedUserId: nil, createdAt: data.createdAt)
return Message(messageId: data.messageId, conversationId: data.conversationId, userId: data.getSenderId(), category: data.category, content: nil, mediaUrl: nil, mediaMimeType: nil, mediaSize: nil, mediaDuration: nil, mediaWidth: nil, mediaHeight: nil, mediaHash: nil, mediaKey: nil, mediaDigest: nil, mediaStatus: nil, thumbImage: nil, status: MessageStatus.DELIVERED.rawValue, action: nil, participantId: nil, snapshotId: nil, name: stickerData.name, albumId: stickerData.albumId, sharedUserId: nil, createdAt: data.createdAt)
}

static func createMessage(contactData: TransferContactData, data: BlazeMessageData) -> Message {
return Message(messageId: data.messageId, conversationId: data.conversationId, userId: data.userId, category: data.category, content: nil, mediaUrl: nil, mediaMimeType: nil, mediaSize: nil, mediaDuration: nil, mediaWidth: nil, mediaHeight: nil, mediaHash: nil, mediaKey: nil, mediaDigest: nil, mediaStatus: nil, thumbImage: nil, status: MessageStatus.DELIVERED.rawValue, action: nil, participantId: nil, snapshotId: nil, name: nil, albumId: nil, sharedUserId: contactData.userId, createdAt: data.createdAt)
return Message(messageId: data.messageId, conversationId: data.conversationId, userId: data.getSenderId(), category: data.category, content: nil, mediaUrl: nil, mediaMimeType: nil, mediaSize: nil, mediaDuration: nil, mediaWidth: nil, mediaHeight: nil, mediaHash: nil, mediaKey: nil, mediaDigest: nil, mediaStatus: nil, thumbImage: nil, status: MessageStatus.DELIVERED.rawValue, action: nil, participantId: nil, snapshotId: nil, name: nil, albumId: nil, sharedUserId: contactData.userId, createdAt: data.createdAt)
}

static func createMessage(mediaData: TransferAttachmentData, data: BlazeMessageData) -> Message {
let mediaStatus = data.category.hasSuffix("_DATA") || data.category.hasSuffix("_VIDEO") ? MediaStatus.CANCELED.rawValue : MediaStatus.PENDING.rawValue
return Message(messageId: data.messageId, conversationId: data.conversationId, userId: data.userId, category: data.category, content: mediaData.attachmentId, mediaUrl: nil, mediaMimeType: mediaData.mimeType, mediaSize: mediaData.size, mediaDuration: mediaData.duration, mediaWidth: mediaData.width, mediaHeight: mediaData.height, mediaHash: nil, mediaKey: mediaData.key, mediaDigest: mediaData.digest, mediaStatus: mediaStatus, thumbImage: mediaData.thumbnail, status: MessageStatus.DELIVERED.rawValue, action: nil, participantId: nil, snapshotId: nil, name: mediaData.name, albumId: nil, sharedUserId: nil, createdAt: data.createdAt)
return Message(messageId: data.messageId, conversationId: data.conversationId, userId: data.getSenderId(), category: data.category, content: mediaData.attachmentId, mediaUrl: nil, mediaMimeType: mediaData.mimeType, mediaSize: mediaData.size, mediaDuration: mediaData.duration, mediaWidth: mediaData.width, mediaHeight: mediaData.height, mediaHash: nil, mediaKey: mediaData.key, mediaDigest: mediaData.digest, mediaStatus: mediaStatus, thumbImage: mediaData.thumbnail, status: MessageStatus.DELIVERED.rawValue, action: nil, participantId: nil, snapshotId: nil, name: mediaData.name, albumId: nil, sharedUserId: nil, createdAt: data.createdAt)
}

static func createMessage(messageId: String = UUID().uuidString.lowercased(), category: String, conversationId: String, createdAt: String = Date().toUTCString(), userId: String) -> Message {
Expand Down
13 changes: 13 additions & 0 deletions Mixin/Database/Model/MessageItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,16 @@ extension MessageItem {
}

}

extension MessageItem {

func isRepresentativeMessage(conversation: ConversationItem) -> Bool {
guard userId != AccountAPI.shared.accountUserId else {
return false
}
guard conversation.category != ConversationCategory.GROUP.rawValue else {
return true
}
return conversation.ownerId != userId && conversation.category == ConversationCategory.CONTACT.rawValue
}
}
4 changes: 2 additions & 2 deletions Mixin/Database/Model/UserItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ struct UserItem: BaseCodable {

extension UserItem {

static func createUser(userId: String, fullName: String, identityNumber: String, avatarUrl: String) -> UserItem {
return UserItem(userId: userId, fullName: fullName, identityNumber: identityNumber, avatarUrl: avatarUrl, phone: nil, isVerified: false, muteUntil: nil, appId: nil, createdAt: nil, relationship: "", role: "", appDescription: nil, appCreatorId: nil)
static func createUser(userId: String, fullName: String, identityNumber: String, avatarUrl: String, appId: String?) -> UserItem {
return UserItem(userId: userId, fullName: fullName, identityNumber: identityNumber, avatarUrl: avatarUrl, phone: nil, isVerified: false, muteUntil: nil, appId: appId, createdAt: nil, relationship: "", role: "", appDescription: nil, appCreatorId: nil)
}

static func createUser(from user: UserResponse) -> UserItem {
Expand Down
16 changes: 10 additions & 6 deletions Mixin/Extension/UserNotificationExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,44 +49,47 @@ extension UNUserNotificationCenter {

func sendMessageNotification(message: MessageItem, ownerUser: UserItem?, conversation: ConversationItem) {
let notificationContent = UNMutableNotificationContent()
let isRepresentativeMessage = message.isRepresentativeMessage(conversation: conversation)
if conversation.isGroup() {
notificationContent.title = conversation.name
} else if isRepresentativeMessage {
notificationContent.title = conversation.ownerFullName
} else {
notificationContent.title = message.userFullName
}

if message.category.hasSuffix("_TEXT") {
if conversation.isGroup() {
if conversation.isGroup() || isRepresentativeMessage {
notificationContent.body = "\(message.userFullName): \(message.content)"
} else {
notificationContent.body = message.content
}
} else if message.category.hasSuffix("_IMAGE") {
if conversation.isGroup() {
if conversation.isGroup() || isRepresentativeMessage {
notificationContent.body = "\(message.userFullName): \(Localized.NOTIFICATION_CONTENT_PHOTO)"
} else {
notificationContent.body = Localized.NOTIFICATION_CONTENT_PHOTO
}
} else if message.category.hasSuffix("_VIDEO") {
if conversation.isGroup() {
if conversation.isGroup() || isRepresentativeMessage {
notificationContent.body = "\(message.userFullName): \(Localized.NOTIFICATION_CONTENT_VIDEO)"
} else {
notificationContent.body = Localized.NOTIFICATION_CONTENT_VIDEO
}
} else if message.category.hasSuffix("_DATA") {
if conversation.isGroup() {
if conversation.isGroup() || isRepresentativeMessage {
notificationContent.body = "\(message.userFullName): \(Localized.NOTIFICATION_CONTENT_FILE)"
} else {
notificationContent.body = Localized.NOTIFICATION_CONTENT_FILE
}
} else if message.category.hasSuffix("_STICKER") {
if conversation.isGroup() {
if conversation.isGroup() || isRepresentativeMessage {
notificationContent.body = "\(message.userFullName): \(Localized.NOTIFICATION_CONTENT_STICKER)"
} else {
notificationContent.body = Localized.NOTIFICATION_CONTENT_STICKER
}
} else if message.category.hasSuffix("_CONTACT") {
if conversation.isGroup() {
if conversation.isGroup() || isRepresentativeMessage {
notificationContent.body = "\(message.userFullName): \(Localized.NOTIFICATION_CONTENT_CONTACT)"
} else {
notificationContent.body = Localized.NOTIFICATION_CONTENT_CONTACT
Expand Down Expand Up @@ -120,6 +123,7 @@ extension UNUserNotificationCenter {
userInfo["userFullName"] = user.fullName
userInfo["userAvatarUrl"] = user.avatarUrl
userInfo["userIdentityNumber"] = user.identityNumber
userInfo["userAppId"] = user.appId
}
notificationContent.userInfo = userInfo
notificationContent.sound = UNNotificationSound(named: "mixin.caf")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,6 @@ struct ForwardUser {
}

func toUser() -> UserItem {
return UserItem.createUser(userId: userId, fullName: fullName, identityNumber: identityNumber, avatarUrl: ownerAvatarUrl)
return UserItem.createUser(userId: userId, fullName: fullName, identityNumber: identityNumber, avatarUrl: ownerAvatarUrl, appId: ownerAppId)
}
}
Loading

0 comments on commit 8666f4d

Please sign in to comment.