Handle group data from log endpoint with no groupChange
This commit is contained in:
parent
24f2363ebe
commit
80871270c6
1 changed files with 64 additions and 33 deletions
97
ts/groups.ts
97
ts/groups.ts
|
@ -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,46 +2732,67 @@ async function integrateGroupChange({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const groupChangeActions = window.textsecure.protobuf.GroupChange.Actions.decode(
|
if (!groupChange && !groupState) {
|
||||||
groupChange.actions.toArrayBuffer()
|
throw new Error(
|
||||||
);
|
`integrateGroupChange/${logId}: Neither groupChange nor groupState received!`
|
||||||
|
);
|
||||||
if (groupChangeActions.version && groupChangeActions.version > newRevision) {
|
|
||||||
return {
|
|
||||||
newAttributes: group,
|
|
||||||
groupChangeMessages: [],
|
|
||||||
members: [],
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const decryptedChangeActions = decryptGroupChange(
|
|
||||||
groupChangeActions,
|
|
||||||
group.secretParams,
|
|
||||||
logId
|
|
||||||
);
|
|
||||||
|
|
||||||
const { sourceUuid } = decryptedChangeActions;
|
|
||||||
const sourceConversation = window.ConversationController.getOrCreate(
|
|
||||||
sourceUuid,
|
|
||||||
'private'
|
|
||||||
);
|
|
||||||
const sourceConversationId = sourceConversation.id;
|
|
||||||
|
|
||||||
const isChangeSupported =
|
|
||||||
!isNumber(groupChange.changeEpoch) ||
|
|
||||||
groupChange.changeEpoch <= SUPPORTED_CHANGE_EPOCH;
|
|
||||||
const isFirstFetch = !isNumber(group.revision);
|
const isFirstFetch = !isNumber(group.revision);
|
||||||
const isMoreThanOneVersionUp =
|
|
||||||
groupChangeActions.version &&
|
|
||||||
isNumber(group.revision) &&
|
|
||||||
groupChangeActions.version > group.revision + 1;
|
|
||||||
|
|
||||||
const ourConversationId = window.ConversationController.getOurConversationIdOrThrow();
|
const ourConversationId = window.ConversationController.getOurConversationIdOrThrow();
|
||||||
const weAreAwaitingApproval = (group.pendingAdminApprovalV2 || []).find(
|
const weAreAwaitingApproval = (group.pendingAdminApprovalV2 || []).find(
|
||||||
item => item.conversationId === ourConversationId
|
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()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
groupChangeActions.version &&
|
||||||
|
groupChangeActions.version > newRevision
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
newAttributes: group,
|
||||||
|
groupChangeMessages: [],
|
||||||
|
members: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
decryptedChangeActions = decryptGroupChange(
|
||||||
|
groupChangeActions,
|
||||||
|
group.secretParams,
|
||||||
|
logId
|
||||||
|
);
|
||||||
|
|
||||||
|
const { sourceUuid } = decryptedChangeActions;
|
||||||
|
const sourceConversation = window.ConversationController.getOrCreate(
|
||||||
|
sourceUuid,
|
||||||
|
'private'
|
||||||
|
);
|
||||||
|
sourceConversationId = sourceConversation.id;
|
||||||
|
|
||||||
|
isChangeSupported =
|
||||||
|
!isNumber(groupChange.changeEpoch) ||
|
||||||
|
groupChange.changeEpoch <= SUPPORTED_CHANGE_EPOCH;
|
||||||
|
|
||||||
|
isMoreThanOneVersionUp = Boolean(
|
||||||
|
groupChangeActions.version &&
|
||||||
|
isNumber(group.revision) &&
|
||||||
|
groupChangeActions.version > group.revision + 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
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}`
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue