From db9f26d9df305f8a1cd46c0e9888f2d3ede4e4ba Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 4 Feb 2020 10:25:46 +1100 Subject: [PATCH] Map text & media group messages from secondary deivces to their primary device --- .../groups/GroupMessageProcessor.java | 6 ++++-- .../securesms/jobs/PushDecryptJob.java | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java index af5d0274af..9ba4a0b043 100644 --- a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java +++ b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java @@ -70,6 +70,7 @@ public class GroupMessageProcessor { String id = GroupUtil.getEncodedId(group); Optional record = database.getGroup(id); + // TODO: Allow processing messages from secondary devices if (record.isPresent() && group.getType() == Type.UPDATE) { return handleGroupUpdate(context, content, group, record.get(), outgoing); } else if (!record.isPresent() && group.getType() == Type.UPDATE) { @@ -230,8 +231,9 @@ public class GroupMessageProcessor { GroupContext.Builder builder = createGroupContext(group); builder.setType(GroupContext.Type.QUIT); - if (members.contains(Address.fromExternal(context, content.getSender()))) { - database.remove(id, Address.fromExternal(context, content.getSender())); + String hexEncodedPublicKey = getMasterHexEncodedPublicKey(context, content.getSender()); + if (members.contains(Address.fromExternal(context, hexEncodedPublicKey))) { + database.remove(id, Address.fromExternal(context, hexEncodedPublicKey)); if (outgoing) database.setActive(id, false); return storeMessage(context, content, group, builder.build(), outgoing); diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 980e74020a..cb15f2c4a5 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -851,8 +851,13 @@ public class PushDecryptJob extends BaseJob implements InjectableType { Optional> linkPreviews = getLinkPreviews(message.getPreviews(), message.getBody().or("")); Optional sticker = getStickerAttachment(message.getSticker()); - // If message is from group then we need to map it to the correct sender - Address sender = message.isGroupMessage() ? Address.fromSerialized(content.getSender()) : primaryDeviceRecipient.getAddress(); + Address sender = primaryDeviceRecipient.getAddress(); + + // If message is from group then we need to map it to get the sender of the message + if (message.isGroupMessage()) { + sender = getPrimaryDeviceRecipient(content.getSender()).getAddress(); + } + IncomingMediaMessage mediaMessage = new IncomingMediaMessage(sender, message.getTimestamp(), -1, message.getExpiresInSeconds() * 1000L, false, content.isNeedsReceipt(), message.getBody(), message.getGroupInfo(), message.getAttachments(), quote, sharedContacts, linkPreviews, sticker); @@ -1036,8 +1041,13 @@ public class PushDecryptJob extends BaseJob implements InjectableType { } else { notifyTypingStoppedFromIncomingMessage(primaryDeviceRecipient, content.getSender(), content.getSenderDevice()); - // If message is from group then we need to map it to the correct sender - Address sender = message.isGroupMessage() ? Address.fromSerialized(content.getSender()) : primaryDeviceRecipient.getAddress(); + Address sender = primaryDeviceRecipient.getAddress(); + + // If message is from group then we need to map it to get the sender of the message + if (message.isGroupMessage()) { + sender = getPrimaryDeviceRecipient(content.getSender()).getAddress(); + } + IncomingTextMessage _textMessage = new IncomingTextMessage(sender, content.getSenderDevice(), message.getTimestamp(), body,