Fetch full group state if last epoch is stale

This commit is contained in:
Fedor Indutny 2022-03-24 10:06:39 -07:00 committed by GitHub
parent e8651afa0b
commit 0f5a01f2b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -3622,6 +3622,7 @@ async function getGroupDelta({
changes,
group,
newRevision: latestRevision,
serverPublicParamsBase64,
});
}
@ -3629,15 +3630,17 @@ async function integrateGroupChanges({
group,
newRevision,
changes,
serverPublicParamsBase64,
}: {
group: ConversationAttributesType;
newRevision: number | undefined;
changes: Array<Proto.IGroupChanges>;
serverPublicParamsBase64: string;
}): Promise<UpdatesResultType> {
const logId = idForLogging(group.groupId);
let attributes = group;
const finalMessages: Array<Array<GroupChangeMessageType>> = [];
const finalMembers: Array<Array<MemberType>> = [];
let finalMembers: Array<Array<MemberType>> = [];
const imax = changes.length;
for (let i = 0; i < imax; i += 1) {
@ -3721,6 +3724,24 @@ async function integrateGroupChanges({
Errors.toLogFormat(error)
);
}
} else if (attributes.lastFetchedEpoch !== SUPPORTED_CHANGE_EPOCH) {
log.info(
`integrateGroupChanges(${logId}): last fetched epoch ` +
`${group.lastFetchedEpoch ?? '?'} is stale. ` +
'Refreshing group state'
);
const {
newAttributes: updatedAttributes,
groupChangeMessages: extraChanges,
members: updatedMembers,
} = await updateGroupViaState({
group: attributes,
serverPublicParamsBase64,
});
attributes = updatedAttributes;
finalMessages.push(extraChanges);
finalMembers = [updatedMembers];
}
// If this is our first fetch, we will collapse this down to one set of messages
@ -3839,6 +3860,7 @@ async function integrateGroupChange({
!groupChange ||
!isChangeSupported ||
isFirstFetch ||
(groupState && group.lastFetchedEpoch !== SUPPORTED_CHANGE_EPOCH) ||
(isMoreThanOneVersionUp && !weAreAwaitingApproval)
) {
if (!groupState) {
@ -4993,6 +5015,7 @@ async function applyGroupState({
// version
result.revision = version;
result.lastFetchedEpoch = SUPPORTED_CHANGE_EPOCH;
// title
// Note: During decryption, title becomes a GroupAttributeBlob

1
ts/model-types.d.ts vendored
View File

@ -331,6 +331,7 @@ export type ConversationAttributesType = {
secretParams?: string;
publicParams?: string;
revision?: number;
lastFetchedEpoch?: number;
senderKeyInfo?: SenderKeyInfoType;
// GroupV2 other fields