mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 09:49:30 +01:00
GroupsV2 update sending and local context storage.
This commit is contained in:
committed by
Greyson Parrelli
parent
f5e6fd6340
commit
78055e3ccb
@@ -132,6 +132,21 @@ public final class GroupDatabase extends Database {
|
||||
return Optional.fromNullable(reader.getCurrent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Call if you are sure this group should exist.
|
||||
* <p>
|
||||
* Finds group and throws if it cannot.
|
||||
*/
|
||||
public @NonNull GroupRecord requireGroup(@NonNull GroupId groupId) {
|
||||
Optional<GroupRecord> group = getGroup(groupId);
|
||||
|
||||
if (!group.isPresent()) {
|
||||
throw new AssertionError("Group not found");
|
||||
}
|
||||
|
||||
return group.get();
|
||||
}
|
||||
|
||||
public boolean isUnknownGroup(@NonNull GroupId groupId) {
|
||||
Optional<GroupRecord> group = getGroup(groupId);
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ import org.thoughtcrime.securesms.jobs.TrimThreadJob;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.mms.IncomingMediaMessage;
|
||||
import org.thoughtcrime.securesms.mms.MessageGroupContext;
|
||||
import org.thoughtcrime.securesms.mms.MmsException;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
||||
@@ -791,7 +792,7 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
}
|
||||
|
||||
if (body != null && (Types.isGroupQuit(outboxType) || Types.isGroupUpdate(outboxType))) {
|
||||
return new OutgoingGroupMediaMessage(recipient, body, attachments, timestamp, 0, false, quote, contacts, previews);
|
||||
return new OutgoingGroupMediaMessage(recipient, new MessageGroupContext(body, Types.isGroupV2(outboxType)), attachments, timestamp, 0, false, quote, contacts, previews);
|
||||
} else if (Types.isExpirationTimerUpdate(outboxType)) {
|
||||
return new OutgoingExpirationUpdateMessage(recipient, timestamp, expiresIn);
|
||||
}
|
||||
@@ -1050,8 +1051,16 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
if (forceSms) type |= Types.MESSAGE_FORCE_SMS_BIT;
|
||||
|
||||
if (message.isGroup()) {
|
||||
if (((OutgoingGroupMediaMessage)message).isGroupUpdate()) type |= Types.GROUP_UPDATE_BIT;
|
||||
else if (((OutgoingGroupMediaMessage)message).isGroupQuit()) type |= Types.GROUP_QUIT_BIT;
|
||||
OutgoingGroupMediaMessage outgoingGroupMediaMessage = (OutgoingGroupMediaMessage) message;
|
||||
if (outgoingGroupMediaMessage.isV2Group()) {
|
||||
MessageGroupContext.GroupV2Properties groupV2Properties = outgoingGroupMediaMessage.requireGroupV2Properties();
|
||||
type |= Types.GROUP_V2_BIT;
|
||||
if (groupV2Properties.isUpdate()) type |= Types.GROUP_UPDATE_BIT;
|
||||
} else {
|
||||
MessageGroupContext.GroupV1Properties properties = outgoingGroupMediaMessage.requireGroupV1Properties();
|
||||
if (properties.isUpdate()) type |= Types.GROUP_UPDATE_BIT;
|
||||
else if (properties.isQuit()) type |= Types.GROUP_QUIT_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
if (message.isExpirationUpdate()) {
|
||||
@@ -1090,11 +1099,24 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
long messageId = insertMediaMessage(message.getBody(), message.getAttachments(), quoteAttachments, message.getSharedContacts(), message.getLinkPreviews(), contentValues, insertListener);
|
||||
|
||||
if (message.getRecipient().isGroup()) {
|
||||
GroupReceiptDatabase receiptDatabase = DatabaseFactory.getGroupReceiptDatabase(context);
|
||||
List<Recipient> members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(message.getRecipient().requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF);
|
||||
OutgoingGroupMediaMessage outgoingGroupMediaMessage = (message instanceof OutgoingGroupMediaMessage) ? (OutgoingGroupMediaMessage) message : null;
|
||||
|
||||
receiptDatabase.insert(Stream.of(members).map(Recipient::getId).toList(),
|
||||
messageId, defaultReceiptStatus, message.getSentTimeMillis());
|
||||
GroupReceiptDatabase receiptDatabase = DatabaseFactory.getGroupReceiptDatabase(context);
|
||||
RecipientDatabase recipientDatabase = DatabaseFactory.getRecipientDatabase(context);
|
||||
Set<RecipientId> members = new HashSet<>();
|
||||
|
||||
if (outgoingGroupMediaMessage != null && outgoingGroupMediaMessage.isV2Group()) {
|
||||
MessageGroupContext.GroupV2Properties groupV2Properties = outgoingGroupMediaMessage.requireGroupV2Properties();
|
||||
members.addAll(Stream.of(groupV2Properties.getActiveMembers()).map(recipientDatabase::getOrInsertFromUuid).toList());
|
||||
if (groupV2Properties.isUpdate()) {
|
||||
members.addAll(Stream.of(groupV2Properties.getPendingMembers()).map(recipientDatabase::getOrInsertFromUuid).toList());
|
||||
}
|
||||
members.remove(Recipient.self().getId());
|
||||
} else {
|
||||
members.addAll(Stream.of(DatabaseFactory.getGroupDatabase(context).getGroupMembers(message.getRecipient().requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_EXCLUDING_SELF)).map(Recipient::getId).toList());
|
||||
}
|
||||
|
||||
receiptDatabase.insert(members, messageId, defaultReceiptStatus, message.getSentTimeMillis());
|
||||
|
||||
for (RecipientId recipientId : earlyDeliveryReceipts.keySet()) receiptDatabase.update(recipientId, messageId, GroupReceiptDatabase.STATUS_DELIVERED, -1);
|
||||
for (RecipientId recipientId : earlyReadReceipts.keySet()) receiptDatabase.update(recipientId, messageId, GroupReceiptDatabase.STATUS_READ, -1);
|
||||
|
||||
@@ -76,6 +76,7 @@ public interface MmsSmsColumns {
|
||||
protected static final long GROUP_UPDATE_BIT = 0x10000;
|
||||
protected static final long GROUP_QUIT_BIT = 0x20000;
|
||||
protected static final long EXPIRATION_TIMER_UPDATE_BIT = 0x40000;
|
||||
protected static final long GROUP_V2_BIT = 0x80000;
|
||||
|
||||
// Encrypted Storage Information XXX
|
||||
public static final long ENCRYPTION_MASK = 0xFF000000;
|
||||
@@ -223,6 +224,10 @@ public interface MmsSmsColumns {
|
||||
return (type & GROUP_UPDATE_BIT) != 0;
|
||||
}
|
||||
|
||||
public static boolean isGroupV2(long type) {
|
||||
return (type & GROUP_V2_BIT) != 0;
|
||||
}
|
||||
|
||||
public static boolean isGroupQuit(long type) {
|
||||
return (type & GROUP_QUIT_BIT) != 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user