Handle group data from log endpoint with no groupChange

This commit is contained in:
Scott Nonnenberg 2021-02-08 13:55:21 -08:00
parent 24f2363ebe
commit 80871270c6

View file

@ -2648,7 +2648,7 @@ async function integrateGroupChanges({
const { groupChange, groupState } = changeState; const { groupChange, groupState } = changeState;
if (!groupChange || !groupState) { if (!groupChange && !groupState) {
window.log.warn( window.log.warn(
'integrateGroupChanges: item had neither groupState nor groupChange. Skipping.' 'integrateGroupChanges: item had neither groupState nor groupChange. Skipping.'
); );
@ -2721,7 +2721,7 @@ async function integrateGroupChange({
newRevision, newRevision,
}: { }: {
group: ConversationAttributesType; group: ConversationAttributesType;
groupChange: GroupChangeClass; groupChange?: GroupChangeClass;
groupState?: GroupClass; groupState?: GroupClass;
newRevision: number; newRevision: number;
}): Promise<UpdatesResultType> { }): Promise<UpdatesResultType> {
@ -2732,11 +2732,34 @@ async function integrateGroupChange({
); );
} }
const groupChangeActions = window.textsecure.protobuf.GroupChange.Actions.decode( if (!groupChange && !groupState) {
throw new Error(
`integrateGroupChange/${logId}: Neither groupChange nor groupState received!`
);
}
const isFirstFetch = !isNumber(group.revision);
const ourConversationId = window.ConversationController.getOurConversationIdOrThrow();
const weAreAwaitingApproval = (group.pendingAdminApprovalV2 || []).find(
item => item.conversationId === ourConversationId
);
// These need to be populated from the groupChange. But we might not get one!
let isChangeSupported = false;
let isMoreThanOneVersionUp = false;
let groupChangeActions: undefined | GroupChangeClass.Actions;
let decryptedChangeActions: undefined | GroupChangeClass.Actions;
let sourceConversationId: undefined | string;
if (groupChange) {
groupChangeActions = window.textsecure.protobuf.GroupChange.Actions.decode(
groupChange.actions.toArrayBuffer() groupChange.actions.toArrayBuffer()
); );
if (groupChangeActions.version && groupChangeActions.version > newRevision) { if (
groupChangeActions.version &&
groupChangeActions.version > newRevision
) {
return { return {
newAttributes: group, newAttributes: group,
groupChangeMessages: [], groupChangeMessages: [],
@ -2744,7 +2767,7 @@ async function integrateGroupChange({
}; };
} }
const decryptedChangeActions = decryptGroupChange( decryptedChangeActions = decryptGroupChange(
groupChangeActions, groupChangeActions,
group.secretParams, group.secretParams,
logId logId
@ -2755,23 +2778,21 @@ async function integrateGroupChange({
sourceUuid, sourceUuid,
'private' 'private'
); );
const sourceConversationId = sourceConversation.id; sourceConversationId = sourceConversation.id;
const isChangeSupported = isChangeSupported =
!isNumber(groupChange.changeEpoch) || !isNumber(groupChange.changeEpoch) ||
groupChange.changeEpoch <= SUPPORTED_CHANGE_EPOCH; groupChange.changeEpoch <= SUPPORTED_CHANGE_EPOCH;
const isFirstFetch = !isNumber(group.revision);
const isMoreThanOneVersionUp = isMoreThanOneVersionUp = Boolean(
groupChangeActions.version && groupChangeActions.version &&
isNumber(group.revision) && isNumber(group.revision) &&
groupChangeActions.version > group.revision + 1; groupChangeActions.version > group.revision + 1
const ourConversationId = window.ConversationController.getOurConversationIdOrThrow();
const weAreAwaitingApproval = (group.pendingAdminApprovalV2 || []).find(
item => item.conversationId === ourConversationId
); );
}
if ( if (
!groupChange ||
!isChangeSupported || !isChangeSupported ||
isFirstFetch || isFirstFetch ||
(isMoreThanOneVersionUp && !weAreAwaitingApproval) (isMoreThanOneVersionUp && !weAreAwaitingApproval)
@ -2785,7 +2806,11 @@ async function integrateGroupChange({
window.log.info( window.log.info(
`integrateGroupChange/${logId}: Applying full group state, from version ${group.revision} to ${groupState.version}`, `integrateGroupChange/${logId}: Applying full group state, from version ${group.revision} to ${groupState.version}`,
{ {
isChangePresent: Boolean(groupChange),
isChangeSupported, isChangeSupported,
isFirstFetch,
isMoreThanOneVersionUp,
weAreAwaitingApproval,
} }
); );
@ -2812,6 +2837,12 @@ async function integrateGroupChange({
}; };
} }
if (!sourceConversationId || !groupChangeActions || !decryptedChangeActions) {
throw new Error(
`integrateGroupChange/${logId}: Missing necessary information that should have come from group actions`
);
}
window.log.info( window.log.info(
`integrateGroupChange/${logId}: Applying group change actions, from version ${group.revision} to ${groupChangeActions.version}` `integrateGroupChange/${logId}: Applying group change actions, from version ${group.revision} to ${groupChangeActions.version}`
); );