2014-11-04 00:16:04 +01:00
|
|
|
package org.thoughtcrime.securesms.groups;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
2015-07-07 02:36:49 +02:00
|
|
|
import android.support.annotation.NonNull;
|
2015-11-25 01:01:21 +01:00
|
|
|
import android.support.annotation.Nullable;
|
2014-11-04 00:16:04 +01:00
|
|
|
|
|
|
|
import com.google.protobuf.ByteString;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.ApplicationContext;
|
2017-07-26 18:59:15 +02:00
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
2014-11-04 00:16:04 +01:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
2017-01-22 22:52:36 +01:00
|
|
|
import org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult;
|
2017-07-26 18:59:15 +02:00
|
|
|
import org.thoughtcrime.securesms.database.MmsDatabase;
|
2018-01-25 04:17:44 +01:00
|
|
|
import org.thoughtcrime.securesms.database.SmsDatabase;
|
2014-11-04 00:16:04 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.AvatarDownloadJob;
|
2016-11-20 23:50:41 +01:00
|
|
|
import org.thoughtcrime.securesms.jobs.PushGroupUpdateJob;
|
2018-05-22 11:13:10 +02:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2020-05-12 08:28:35 +02:00
|
|
|
import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol;
|
2017-07-26 18:59:15 +02:00
|
|
|
import org.thoughtcrime.securesms.mms.MmsException;
|
2015-10-16 02:10:54 +02:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
2014-11-04 00:16:04 +01:00
|
|
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
2017-08-01 17:56:00 +02:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2014-11-04 00:16:04 +01:00
|
|
|
import org.thoughtcrime.securesms.sms.IncomingGroupMessage;
|
|
|
|
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
|
2014-11-12 20:15:05 +01:00
|
|
|
import org.thoughtcrime.securesms.util.Base64;
|
2015-10-16 02:10:54 +02:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2019-12-13 00:25:53 +01:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2016-03-23 18:34:41 +01:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
2018-05-22 11:13:10 +02:00
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
2016-03-23 18:34:41 +01:00
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
2016-11-20 23:50:41 +01:00
|
|
|
import org.whispersystems.signalservice.api.messages.SignalServiceGroup.Type;
|
2020-05-12 08:28:35 +02:00
|
|
|
import org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol;
|
2014-11-04 00:16:04 +01:00
|
|
|
|
2018-04-27 02:03:54 +02:00
|
|
|
import java.util.Collections;
|
2014-11-04 00:16:04 +01:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import static org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
|
2016-03-23 18:34:41 +01:00
|
|
|
import static org.whispersystems.signalservice.internal.push.SignalServiceProtos.AttachmentPointer;
|
|
|
|
import static org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext;
|
2014-11-04 00:16:04 +01:00
|
|
|
|
|
|
|
public class GroupMessageProcessor {
|
|
|
|
|
|
|
|
private static final String TAG = GroupMessageProcessor.class.getSimpleName();
|
|
|
|
|
2015-11-25 01:01:21 +01:00
|
|
|
public static @Nullable Long process(@NonNull Context context,
|
2018-05-22 11:13:10 +02:00
|
|
|
@NonNull SignalServiceContent content,
|
2016-03-23 18:34:41 +01:00
|
|
|
@NonNull SignalServiceDataMessage message,
|
2015-11-25 01:01:21 +01:00
|
|
|
boolean outgoing)
|
2014-11-04 00:16:04 +01:00
|
|
|
{
|
|
|
|
if (!message.getGroupInfo().isPresent() || message.getGroupInfo().get().getGroupId() == null) {
|
|
|
|
Log.w(TAG, "Received group message with no id! Ignoring...");
|
2015-11-25 01:01:21 +01:00
|
|
|
return null;
|
2014-11-04 00:16:04 +01:00
|
|
|
}
|
|
|
|
|
2017-08-08 01:47:38 +02:00
|
|
|
GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
|
|
|
|
SignalServiceGroup group = message.getGroupInfo().get();
|
2019-12-12 00:07:17 +01:00
|
|
|
String id = GroupUtil.getEncodedId(group);
|
2017-08-08 01:47:38 +02:00
|
|
|
Optional<GroupRecord> record = database.getGroup(id);
|
2014-11-04 00:16:04 +01:00
|
|
|
|
2017-08-08 01:47:38 +02:00
|
|
|
if (record.isPresent() && group.getType() == Type.UPDATE) {
|
2018-05-22 11:13:10 +02:00
|
|
|
return handleGroupUpdate(context, content, group, record.get(), outgoing);
|
2017-08-16 04:23:42 +02:00
|
|
|
} else if (!record.isPresent() && group.getType() == Type.UPDATE) {
|
2018-05-22 11:13:10 +02:00
|
|
|
return handleGroupCreate(context, content, group, outgoing);
|
2017-08-08 01:47:38 +02:00
|
|
|
} else if (record.isPresent() && group.getType() == Type.QUIT) {
|
2018-05-22 11:13:10 +02:00
|
|
|
return handleGroupLeave(context, content, group, record.get(), outgoing);
|
2017-08-08 01:47:38 +02:00
|
|
|
} else if (record.isPresent() && group.getType() == Type.REQUEST_INFO) {
|
2018-05-22 11:13:10 +02:00
|
|
|
return handleGroupInfoRequest(context, content, group, record.get());
|
2014-11-04 00:16:04 +01:00
|
|
|
} else {
|
|
|
|
Log.w(TAG, "Received unknown type, ignoring...");
|
2015-11-25 01:01:21 +01:00
|
|
|
return null;
|
2014-11-04 00:16:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-25 01:01:21 +01:00
|
|
|
private static @Nullable Long handleGroupCreate(@NonNull Context context,
|
2018-05-22 11:13:10 +02:00
|
|
|
@NonNull SignalServiceContent content,
|
2016-03-23 18:34:41 +01:00
|
|
|
@NonNull SignalServiceGroup group,
|
2015-11-25 01:01:21 +01:00
|
|
|
boolean outgoing)
|
2014-11-04 00:16:04 +01:00
|
|
|
{
|
|
|
|
GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
|
2019-12-12 00:07:17 +01:00
|
|
|
String id = GroupUtil.getEncodedId(group);
|
2014-11-04 00:16:04 +01:00
|
|
|
GroupContext.Builder builder = createGroupContext(group);
|
|
|
|
builder.setType(GroupContext.Type.UPDATE);
|
|
|
|
|
2017-07-26 18:59:15 +02:00
|
|
|
SignalServiceAttachment avatar = group.getAvatar().orNull();
|
2020-05-22 03:57:26 +02:00
|
|
|
List<Address> members = group.getMembers().isPresent() ? new LinkedList<>() : null;
|
2019-12-13 00:25:53 +01:00
|
|
|
List<Address> admins = group.getAdmins().isPresent() ? new LinkedList<>() : null;
|
2014-11-04 00:16:04 +01:00
|
|
|
|
2017-07-26 18:59:15 +02:00
|
|
|
if (group.getMembers().isPresent()) {
|
|
|
|
for (String member : group.getMembers().get()) {
|
|
|
|
members.add(Address.fromExternal(context, member));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 08:28:35 +02:00
|
|
|
// Loki - Ignore message if needed
|
2020-05-13 04:29:31 +02:00
|
|
|
if (ClosedGroupsProtocol.shouldIgnoreGroupCreatedMessage(context, group)) {
|
2019-12-13 00:25:53 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-05-12 08:28:35 +02:00
|
|
|
// Loki - Parse admins
|
2019-12-13 00:25:53 +01:00
|
|
|
if (group.getAdmins().isPresent()) {
|
|
|
|
for (String admin : group.getAdmins().get()) {
|
|
|
|
admins.add(Address.fromExternal(context, admin));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-26 18:59:15 +02:00
|
|
|
database.create(id, group.getName().orNull(), members,
|
2019-12-13 00:25:53 +01:00
|
|
|
avatar != null && avatar.isPointer() ? avatar.asPointer() : null, null, admins);
|
2014-11-04 00:16:04 +01:00
|
|
|
|
2019-12-13 06:04:24 +01:00
|
|
|
if (group.getMembers().isPresent()) {
|
2020-05-12 08:28:35 +02:00
|
|
|
ClosedGroupsProtocol.establishSessionsWithMembersIfNeeded(context, group.getMembers().get());
|
2019-12-13 06:04:24 +01:00
|
|
|
}
|
|
|
|
|
2018-05-22 11:13:10 +02:00
|
|
|
return storeMessage(context, content, group, builder.build(), outgoing);
|
2014-11-04 00:16:04 +01:00
|
|
|
}
|
|
|
|
|
2015-11-25 01:01:21 +01:00
|
|
|
private static @Nullable Long handleGroupUpdate(@NonNull Context context,
|
2018-05-22 11:13:10 +02:00
|
|
|
@NonNull SignalServiceContent content,
|
2016-03-23 18:34:41 +01:00
|
|
|
@NonNull SignalServiceGroup group,
|
2015-11-25 01:01:21 +01:00
|
|
|
@NonNull GroupRecord groupRecord,
|
|
|
|
boolean outgoing)
|
2014-11-04 00:16:04 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
|
2019-12-12 00:07:17 +01:00
|
|
|
String id = GroupUtil.getEncodedId(group);
|
2014-11-04 00:16:04 +01:00
|
|
|
|
2020-05-12 08:28:35 +02:00
|
|
|
String userMasterDevice = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
|
2020-06-23 04:23:58 +02:00
|
|
|
if (userMasterDevice == null) { userMasterDevice = TextSecurePreferences.getLocalNumber(context); }
|
2020-04-09 05:17:00 +02:00
|
|
|
|
2019-12-13 00:25:53 +01:00
|
|
|
if (group.getGroupType() == SignalServiceGroup.GroupType.SIGNAL) {
|
2020-05-12 08:28:35 +02:00
|
|
|
// Loki - Only update the group if the group admin sent the message
|
|
|
|
String masterDevice = MultiDeviceProtocol.shared.getMasterDevice(content.getSender());
|
2020-06-23 04:23:58 +02:00
|
|
|
if (masterDevice == null) { masterDevice = content.getSender(); }
|
2020-05-12 08:28:35 +02:00
|
|
|
if (!groupRecord.getAdmins().contains(Address.fromSerialized(masterDevice))) {
|
|
|
|
Log.d("Loki", "Received a group update message from a non-admin user for: " + id +"; ignoring.");
|
2019-12-13 00:25:53 +01:00
|
|
|
return null;
|
|
|
|
}
|
2020-04-09 05:17:00 +02:00
|
|
|
|
2020-05-12 08:28:35 +02:00
|
|
|
// Loki - Only process update messages if we're part of the group
|
|
|
|
Address userMasterDeviceAddress = Address.fromSerialized(userMasterDevice);
|
|
|
|
if (!groupRecord.getMembers().contains(userMasterDeviceAddress) &&
|
2020-05-22 01:53:04 +02:00
|
|
|
!group.getMembers().or(Collections.emptyList()).contains(userMasterDevice)) {
|
2020-05-12 08:28:35 +02:00
|
|
|
Log.d("Loki", "Received a group update message from a group we're not a member of: " + id + "; ignoring.");
|
2020-04-09 05:17:00 +02:00
|
|
|
database.setActive(id, false);
|
|
|
|
return null;
|
|
|
|
}
|
2019-12-13 00:25:53 +01:00
|
|
|
}
|
|
|
|
|
2020-04-09 01:41:01 +02:00
|
|
|
Set<Address> currentMembers = new HashSet<>(groupRecord.getMembers());
|
|
|
|
Set<Address> newMembers = new HashSet<>();
|
2017-07-26 18:59:15 +02:00
|
|
|
|
|
|
|
for (String messageMember : group.getMembers().get()) {
|
2020-04-09 01:41:01 +02:00
|
|
|
newMembers.add(Address.fromExternal(context, messageMember));
|
2017-07-26 18:59:15 +02:00
|
|
|
}
|
2014-11-04 00:16:04 +01:00
|
|
|
|
2020-04-09 01:41:01 +02:00
|
|
|
// Added members are the members who are present in newMembers but not in currentMembers
|
|
|
|
Set<Address> addedMembers = new HashSet<>(newMembers);
|
|
|
|
addedMembers.removeAll(currentMembers);
|
2014-11-04 00:16:04 +01:00
|
|
|
|
2020-04-09 01:41:01 +02:00
|
|
|
// Kicked members are members who are present in currentMembers but not in newMembers
|
|
|
|
Set<Address> removedMembers = new HashSet<>(currentMembers);
|
|
|
|
removedMembers.removeAll(newMembers);
|
2014-11-04 00:16:04 +01:00
|
|
|
|
|
|
|
GroupContext.Builder builder = createGroupContext(group);
|
|
|
|
builder.setType(GroupContext.Type.UPDATE);
|
|
|
|
|
2020-04-09 01:41:01 +02:00
|
|
|
// Update our group members if they're different
|
|
|
|
if (!currentMembers.equals(newMembers)) {
|
|
|
|
database.updateMembers(id, new LinkedList<>(newMembers));
|
|
|
|
}
|
2017-07-26 18:59:15 +02:00
|
|
|
|
2020-05-12 08:28:35 +02:00
|
|
|
// Add any new or removed members to the group context.
|
|
|
|
// This will allow us later to iterate over them to check if they left or were added for UI purposes.
|
2020-04-09 01:41:01 +02:00
|
|
|
for (Address addedMember : addedMembers) {
|
2020-04-09 05:17:00 +02:00
|
|
|
builder.addNewMembers(addedMember.serialize());
|
2014-11-04 00:16:04 +01:00
|
|
|
}
|
|
|
|
|
2020-04-09 01:41:01 +02:00
|
|
|
for (Address removedMember : removedMembers) {
|
2020-04-09 05:17:00 +02:00
|
|
|
builder.addRemovedMembers(removedMember.serialize());
|
2014-11-04 00:16:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (group.getName().isPresent() || group.getAvatar().isPresent()) {
|
2016-03-23 18:34:41 +01:00
|
|
|
SignalServiceAttachment avatar = group.getAvatar().orNull();
|
2014-11-04 00:16:04 +01:00
|
|
|
database.update(id, group.getName().orNull(), avatar != null ? avatar.asPointer() : null);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (group.getName().isPresent() && group.getName().get().equals(groupRecord.getTitle())) {
|
|
|
|
builder.clearName();
|
|
|
|
}
|
|
|
|
|
2020-04-09 05:17:00 +02:00
|
|
|
// If we were removed then we need to disable the chat
|
2020-05-12 08:28:35 +02:00
|
|
|
if (removedMembers.contains(Address.fromSerialized(userMasterDevice))) {
|
2020-04-09 05:17:00 +02:00
|
|
|
database.setActive(id, false);
|
|
|
|
} else {
|
|
|
|
if (!groupRecord.isActive()) database.setActive(id, true);
|
2014-11-04 00:16:04 +01:00
|
|
|
|
2020-04-09 05:17:00 +02:00
|
|
|
if (group.getMembers().isPresent()) {
|
2020-05-12 08:28:35 +02:00
|
|
|
ClosedGroupsProtocol.establishSessionsWithMembersIfNeeded(context, group.getMembers().get());
|
2020-04-09 05:17:00 +02:00
|
|
|
}
|
2019-12-13 06:04:24 +01:00
|
|
|
}
|
|
|
|
|
2018-05-22 11:13:10 +02:00
|
|
|
return storeMessage(context, content, group, builder.build(), outgoing);
|
2014-11-04 00:16:04 +01:00
|
|
|
}
|
|
|
|
|
2016-11-20 23:50:41 +01:00
|
|
|
private static Long handleGroupInfoRequest(@NonNull Context context,
|
2018-05-22 11:13:10 +02:00
|
|
|
@NonNull SignalServiceContent content,
|
2016-11-20 23:50:41 +01:00
|
|
|
@NonNull SignalServiceGroup group,
|
|
|
|
@NonNull GroupRecord record)
|
|
|
|
{
|
2020-05-12 08:28:35 +02:00
|
|
|
String masterDevice = MultiDeviceProtocol.shared.getMasterDevice(content.getSender());
|
2020-06-23 04:23:58 +02:00
|
|
|
if (masterDevice == null) { masterDevice = content.getSender(); }
|
2020-05-12 08:28:35 +02:00
|
|
|
if (record.getMembers().contains(Address.fromSerialized(masterDevice))) {
|
2016-11-20 23:50:41 +01:00
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
2019-03-28 16:56:35 +01:00
|
|
|
.add(new PushGroupUpdateJob(content.getSender(), group.getGroupId()));
|
2016-11-20 23:50:41 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-03-23 18:34:41 +01:00
|
|
|
private static Long handleGroupLeave(@NonNull Context context,
|
2018-05-22 11:13:10 +02:00
|
|
|
@NonNull SignalServiceContent content,
|
2016-03-23 18:34:41 +01:00
|
|
|
@NonNull SignalServiceGroup group,
|
|
|
|
@NonNull GroupRecord record,
|
2015-10-16 02:10:54 +02:00
|
|
|
boolean outgoing)
|
2014-11-04 00:16:04 +01:00
|
|
|
{
|
|
|
|
GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
|
2019-12-12 00:07:17 +01:00
|
|
|
String id = GroupUtil.getEncodedId(group);
|
2017-07-26 18:59:15 +02:00
|
|
|
List<Address> members = record.getMembers();
|
2014-11-04 00:16:04 +01:00
|
|
|
|
|
|
|
GroupContext.Builder builder = createGroupContext(group);
|
|
|
|
builder.setType(GroupContext.Type.QUIT);
|
|
|
|
|
2020-05-12 08:28:35 +02:00
|
|
|
String masterDevice = MultiDeviceProtocol.shared.getMasterDevice(content.getSender());
|
2020-06-23 04:23:58 +02:00
|
|
|
if (masterDevice == null) { masterDevice = content.getSender(); }
|
2020-05-12 08:28:35 +02:00
|
|
|
if (members.contains(Address.fromExternal(context, masterDevice))) {
|
|
|
|
database.remove(id, Address.fromExternal(context, masterDevice));
|
2015-10-16 02:10:54 +02:00
|
|
|
if (outgoing) database.setActive(id, false);
|
2014-11-04 00:16:04 +01:00
|
|
|
|
2018-05-22 11:13:10 +02:00
|
|
|
return storeMessage(context, content, group, builder.build(), outgoing);
|
2014-11-04 00:16:04 +01:00
|
|
|
}
|
2015-11-25 01:01:21 +01:00
|
|
|
|
|
|
|
return null;
|
2014-11-04 00:16:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-25 01:01:21 +01:00
|
|
|
private static @Nullable Long storeMessage(@NonNull Context context,
|
2018-05-22 11:13:10 +02:00
|
|
|
@NonNull SignalServiceContent content,
|
2016-03-23 18:34:41 +01:00
|
|
|
@NonNull SignalServiceGroup group,
|
2015-11-25 01:01:21 +01:00
|
|
|
@NonNull GroupContext storage,
|
|
|
|
boolean outgoing)
|
2014-11-04 00:16:04 +01:00
|
|
|
{
|
|
|
|
if (group.getAvatar().isPresent()) {
|
|
|
|
ApplicationContext.getInstance(context).getJobManager()
|
2019-12-12 00:07:17 +01:00
|
|
|
.add(new AvatarDownloadJob(GroupUtil.getEncodedId(group)));
|
2014-11-04 00:16:04 +01:00
|
|
|
}
|
|
|
|
|
2015-10-16 02:10:54 +02:00
|
|
|
try {
|
|
|
|
if (outgoing) {
|
|
|
|
MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context);
|
2020-06-23 04:23:58 +02:00
|
|
|
Address address = Address.fromExternal(context, GroupUtil.getEncodedId(group));
|
2019-12-12 00:07:17 +01:00
|
|
|
Recipient recipient = Recipient.from(context, address, false);
|
2019-01-15 09:41:05 +01:00
|
|
|
OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(recipient, storage, null, content.getTimestamp(), 0, null, Collections.emptyList(), Collections.emptyList());
|
2017-08-01 17:56:00 +02:00
|
|
|
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
|
2018-01-25 04:17:44 +01:00
|
|
|
long messageId = mmsDatabase.insertMessageOutbox(outgoingMessage, threadId, false, null);
|
2015-10-16 02:10:54 +02:00
|
|
|
|
2016-12-21 18:49:01 +01:00
|
|
|
mmsDatabase.markAsSent(messageId, true);
|
2015-11-25 01:01:21 +01:00
|
|
|
|
|
|
|
return threadId;
|
2015-10-16 02:10:54 +02:00
|
|
|
} else {
|
2018-01-25 04:17:44 +01:00
|
|
|
SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
|
|
|
|
String body = Base64.encodeBytes(storage.toByteArray());
|
2018-05-22 11:13:10 +02:00
|
|
|
IncomingTextMessage incoming = new IncomingTextMessage(Address.fromExternal(context, content.getSender()), content.getSenderDevice(), content.getTimestamp(), body, Optional.of(group), 0, content.isNeedsReceipt());
|
2018-01-25 04:17:44 +01:00
|
|
|
IncomingGroupMessage groupMessage = new IncomingGroupMessage(incoming, storage, body);
|
2015-10-16 02:10:54 +02:00
|
|
|
|
2018-01-25 04:17:44 +01:00
|
|
|
Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(groupMessage);
|
2015-11-25 01:01:21 +01:00
|
|
|
|
2017-01-22 22:52:36 +01:00
|
|
|
if (insertResult.isPresent()) {
|
2018-01-25 04:17:44 +01:00
|
|
|
MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
|
2017-01-22 22:52:36 +01:00
|
|
|
return insertResult.get().getThreadId();
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2015-10-16 02:10:54 +02:00
|
|
|
}
|
|
|
|
} catch (MmsException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
}
|
2015-11-25 01:01:21 +01:00
|
|
|
|
|
|
|
return null;
|
2014-11-04 00:16:04 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 18:34:41 +01:00
|
|
|
private static GroupContext.Builder createGroupContext(SignalServiceGroup group) {
|
2014-11-04 00:16:04 +01:00
|
|
|
GroupContext.Builder builder = GroupContext.newBuilder();
|
|
|
|
builder.setId(ByteString.copyFrom(group.getGroupId()));
|
|
|
|
|
|
|
|
if (group.getAvatar().isPresent() && group.getAvatar().get().isPointer()) {
|
|
|
|
builder.setAvatar(AttachmentPointer.newBuilder()
|
|
|
|
.setId(group.getAvatar().get().asPointer().getId())
|
|
|
|
.setKey(ByteString.copyFrom(group.getAvatar().get().asPointer().getKey()))
|
|
|
|
.setContentType(group.getAvatar().get().getContentType()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (group.getName().isPresent()) {
|
|
|
|
builder.setName(group.getName().get());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (group.getMembers().isPresent()) {
|
|
|
|
builder.addAllMembers(group.getMembers().get());
|
|
|
|
}
|
|
|
|
|
2019-12-13 00:25:53 +01:00
|
|
|
if (group.getAdmins().isPresent()) {
|
|
|
|
builder.addAllAdmins(group.getAdmins().get());
|
|
|
|
}
|
|
|
|
|
2014-11-04 00:16:04 +01:00
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
}
|