Create local messages for group join request/cancel events.
This commit is contained in:
parent
e273f914b6
commit
1d14a90ac3
1 changed files with 45 additions and 17 deletions
|
@ -44,6 +44,7 @@ import org.thoughtcrime.securesms.jobs.ProfileUploadJob;
|
|||
import org.thoughtcrime.securesms.jobs.PushGroupSilentUpdateSendJob;
|
||||
import org.thoughtcrime.securesms.jobs.RequestGroupV2InfoJob;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.mms.MmsException;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingGroupUpdateMessage;
|
||||
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
|
@ -854,8 +855,10 @@ final class GroupManagerV2 {
|
|||
} else if (requestToJoin) {
|
||||
Log.i(TAG, "Requested to join, cannot send update");
|
||||
|
||||
RecipientAndThread recipientAndThread = sendGroupUpdate(groupMasterKey, new GroupMutation(null, decryptedChange, decryptedGroup), signedGroupChange, false);
|
||||
|
||||
return new GroupManager.GroupActionResult(groupRecipient,
|
||||
SignalDatabase.threads().getThreadIdIfExistsFor(groupRecipientId),
|
||||
recipientAndThread.threadId,
|
||||
0,
|
||||
Collections.emptyList());
|
||||
} else {
|
||||
|
@ -1075,6 +1078,8 @@ final class GroupManagerV2 {
|
|||
DecryptedGroup newGroup = DecryptedGroupUtil.applyWithoutRevisionCheck(decryptedGroup, decryptedChange);
|
||||
|
||||
groupDatabase.update(groupId, resetRevision(newGroup, decryptedGroup.getRevision()));
|
||||
|
||||
sendGroupUpdate(groupMasterKey, new GroupMutation(decryptedGroup, decryptedChange, newGroup), signedGroupChange, false);
|
||||
} catch (VerificationFailedException | InvalidGroupStateException | NotAbleToApplyGroupV2ChangeException e) {
|
||||
throw new GroupChangeFailedException(e);
|
||||
}
|
||||
|
@ -1131,29 +1136,52 @@ final class GroupManagerV2 {
|
|||
@NonNull GroupMutation groupMutation,
|
||||
@Nullable GroupChange signedGroupChange)
|
||||
{
|
||||
GroupId.V2 groupId = GroupId.v2(masterKey);
|
||||
Recipient groupRecipient = Recipient.externalGroupExact(context, groupId);
|
||||
DecryptedGroupV2Context decryptedGroupV2Context = GroupProtoUtil.createDecryptedGroupV2Context(masterKey, groupMutation, signedGroupChange);
|
||||
OutgoingGroupUpdateMessage outgoingMessage = new OutgoingGroupUpdateMessage(groupRecipient,
|
||||
decryptedGroupV2Context,
|
||||
null,
|
||||
System.currentTimeMillis(),
|
||||
0,
|
||||
false,
|
||||
null,
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
return sendGroupUpdate(masterKey, groupMutation, signedGroupChange, true);
|
||||
}
|
||||
|
||||
private @NonNull RecipientAndThread sendGroupUpdate(@NonNull GroupMasterKey masterKey,
|
||||
@NonNull GroupMutation groupMutation,
|
||||
@Nullable GroupChange signedGroupChange,
|
||||
boolean sendToMembers)
|
||||
{
|
||||
GroupId.V2 groupId = GroupId.v2(masterKey);
|
||||
Recipient groupRecipient = Recipient.externalGroupExact(context, groupId);
|
||||
DecryptedGroupV2Context decryptedGroupV2Context = GroupProtoUtil.createDecryptedGroupV2Context(masterKey, groupMutation, signedGroupChange);
|
||||
OutgoingGroupUpdateMessage outgoingMessage = new OutgoingGroupUpdateMessage(groupRecipient,
|
||||
decryptedGroupV2Context,
|
||||
null,
|
||||
System.currentTimeMillis(),
|
||||
0,
|
||||
false,
|
||||
null,
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
|
||||
DecryptedGroupChange plainGroupChange = groupMutation.getGroupChange();
|
||||
|
||||
if (plainGroupChange != null && DecryptedGroupUtil.changeIsEmptyExceptForProfileKeyChanges(plainGroupChange)) {
|
||||
ApplicationDependencies.getJobManager().add(PushGroupSilentUpdateSendJob.create(context, groupId, groupMutation.getNewGroupState(), outgoingMessage));
|
||||
if (sendToMembers) {
|
||||
ApplicationDependencies.getJobManager().add(PushGroupSilentUpdateSendJob.create(context, groupId, groupMutation.getNewGroupState(), outgoingMessage));
|
||||
}
|
||||
|
||||
return new RecipientAndThread(groupRecipient, -1);
|
||||
} else {
|
||||
long threadId = MessageSender.send(context, outgoingMessage, -1, false, null, null);
|
||||
return new RecipientAndThread(groupRecipient, threadId);
|
||||
if (sendToMembers) {
|
||||
long threadId = MessageSender.send(context, outgoingMessage, -1, false, null, null);
|
||||
return new RecipientAndThread(groupRecipient, threadId);
|
||||
} else {
|
||||
long threadId = SignalDatabase.threads().getOrCreateValidThreadId(outgoingMessage.getRecipient(), -1, outgoingMessage.getDistributionType());
|
||||
try {
|
||||
long messageId = SignalDatabase.mms().insertMessageOutbox(outgoingMessage, threadId, false, null);
|
||||
SignalDatabase.mms().markAsSent(messageId, true);
|
||||
SignalDatabase.threads().update(threadId, true);
|
||||
} catch (MmsException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
return new RecipientAndThread(groupRecipient, threadId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue