mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-03 23:15:44 +01:00
Improve group change defensive checks and update logic.
This commit is contained in:
committed by
jeffrey-signal
parent
fa19ed7ffc
commit
f427f31303
@@ -591,26 +591,7 @@ class GroupsV2StateProcessor private constructor(
|
||||
Log.i(TAG, "$logPrefix Local state (revision: ${currentLocalState?.revision}) does not match, updating to ${updatedGroupState.revision}")
|
||||
}
|
||||
|
||||
val wasTerminated = updatedGroupState.terminated && (currentLocalState == null || !currentLocalState.terminated)
|
||||
val terminatorRecipientId: RecipientId? = if (wasTerminated) {
|
||||
groupStateDiff.serverHistory
|
||||
.mapNotNull { it.change }
|
||||
.firstOrNull { it.terminateGroup }
|
||||
?.let { ServiceId.parseOrNull(it.editorServiceIdBytes) }
|
||||
?.let { RecipientId.from(it) }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
saveGroupState(groupStateDiff, updatedGroupState, groupSendEndorsements, terminatorRecipientId)
|
||||
|
||||
if (terminatorRecipientId != null) {
|
||||
profileAndMessageHelper.stopAllTypingForGroup()
|
||||
}
|
||||
|
||||
if (wasTerminated) {
|
||||
ConversationShortcutUpdateJob.enqueue()
|
||||
}
|
||||
saveGroupState(groupStateDiff, updatedGroupState, groupSendEndorsements)
|
||||
|
||||
if (currentLocalState == null || currentLocalState.revision == RESTORE_PLACEHOLDER_REVISION) {
|
||||
if (!updatedGroupState.terminated) {
|
||||
@@ -639,13 +620,29 @@ class GroupsV2StateProcessor private constructor(
|
||||
return InternalUpdateResult.Updated(updatedGroupState)
|
||||
}
|
||||
|
||||
private fun saveGroupState(groupStateDiff: GroupStateDiff, updatedGroupState: DecryptedGroup, groupSendEndorsements: ReceivedGroupSendEndorsements?, terminatorRecipientId: RecipientId? = null) {
|
||||
private fun saveGroupState(
|
||||
groupStateDiff: GroupStateDiff,
|
||||
updatedGroupState: DecryptedGroup,
|
||||
groupSendEndorsements: ReceivedGroupSendEndorsements?
|
||||
) {
|
||||
val previousGroupState = groupStateDiff.previousGroupState
|
||||
|
||||
if (groupSendEndorsements != null) {
|
||||
Log.i(TAG, "$logPrefix Updating send endorsements")
|
||||
}
|
||||
|
||||
val wasTerminated = updatedGroupState.terminated && (previousGroupState == null || !previousGroupState.terminated)
|
||||
val terminatorRecipientId: RecipientId? = if (wasTerminated) {
|
||||
groupStateDiff
|
||||
.serverHistory
|
||||
.mapNotNull { it.change }
|
||||
.firstOrNull { it.terminateGroup }
|
||||
?.let { ServiceId.parseOrNull(it.editorServiceIdBytes) }
|
||||
?.let { RecipientId.from(it) }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val needsAvatarFetch = if (previousGroupState == null) {
|
||||
val groupId = SignalDatabase.groups.create(groupMasterKey, updatedGroupState, groupSendEndorsements)
|
||||
|
||||
@@ -661,6 +658,11 @@ class GroupsV2StateProcessor private constructor(
|
||||
updatedGroupState.avatar != previousGroupState.avatar
|
||||
}
|
||||
|
||||
if (wasTerminated) {
|
||||
profileAndMessageHelper.stopAllTypingForGroup()
|
||||
ConversationShortcutUpdateJob.enqueue()
|
||||
}
|
||||
|
||||
if (needsAvatarFetch) {
|
||||
AppDependencies.jobManager.add(AvatarGroupsV2DownloadJob(groupId, updatedGroupState.avatar))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user