Don't expect endorsement response on group leave

Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2024-06-04 10:29:50 -05:00 committed by GitHub
parent bb93a5516f
commit 09b43bb0ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 39 deletions

View file

@ -96,10 +96,7 @@ import { SeenStatus } from './MessageSeenStatus';
import { incrementMessageCounter } from './util/incrementMessageCounter';
import { sleep } from './util/sleep';
import { groupInvitesRoute } from './util/signalRoutes';
import {
decodeGroupSendEndorsementResponse,
isGroupSendEndorsementResponseEmpty,
} from './util/groupSendEndorsements';
import { decodeGroupSendEndorsementResponse } from './util/groupSendEndorsements';
type AccessRequiredEnum = Proto.AccessControl.AccessRequired;
@ -1568,10 +1565,6 @@ export async function modifyGroupV2({
const { groupChange, groupSendEndorsementResponse } =
groupChangeResponse;
strictAssert(groupChange, 'modifyGroupV2: missing groupChange');
strictAssert(
groupSendEndorsementResponse,
'modifyGroupV2: missing groupSendEndorsementResponse'
);
const groupChangeBuffer =
Proto.GroupChange.encode(groupChange).finish();
@ -1606,6 +1599,10 @@ export async function modifyGroupV2({
const { membersV2 } = conversation.attributes;
strictAssert(membersV2, 'modifyGroupV2: missing membersV2');
// If we are no longer a member - endorsement won't be present
if (Bytes.isNotEmpty(groupSendEndorsementResponse)) {
log.info(`modifyGroupV2/${logId}: Saving group endorsements`);
const groupEndorsementData = decodeGroupSendEndorsementResponse({
groupId,
groupSendEndorsementResponse,
@ -1616,6 +1613,7 @@ export async function modifyGroupV2({
await dataInterface.replaceAllEndorsementsForGroup(
groupEndorsementData
);
}
});
// If we've gotten here with no error, we exit!
@ -1920,7 +1918,7 @@ export async function createGroupV2(
const { groupSendEndorsementResponse } = groupResponse;
strictAssert(
groupSendEndorsementResponse,
Bytes.isNotEmpty(groupSendEndorsementResponse),
'missing groupSendEndorsementResponse'
);
@ -2491,7 +2489,7 @@ export async function initiateMigrationToGroupV2(
updateConversation(conversation.attributes);
strictAssert(
groupSendEndorsementResponse,
Bytes.isNotEmpty(groupSendEndorsementResponse),
'missing groupSendEndorsementResponse'
);
@ -2978,7 +2976,7 @@ export async function respondToGroupV2Migration({
sentAt,
});
if (!isGroupSendEndorsementResponseEmpty(groupSendEndorsementResponse)) {
if (Bytes.isNotEmpty(groupSendEndorsementResponse)) {
const { membersV2 } = conversation.attributes;
strictAssert(membersV2, 'missing membersV2');
@ -3748,10 +3746,6 @@ async function updateGroupViaState({
const { group: groupState, groupSendEndorsementResponse } = groupResponse;
strictAssert(groupState, 'updateGroupViaState: Group state must be present');
strictAssert(
groupSendEndorsementResponse,
'updateGroupViaState: Endorsement must be present'
);
const decryptedGroupState = decryptGroupState(
groupState,
@ -3770,15 +3764,14 @@ async function updateGroupViaState({
});
// If we're not in the group, we won't receive endorsements
if (
groupSendEndorsementResponse != null &&
groupSendEndorsementResponse.byteLength > 0
) {
if (Bytes.isNotEmpty(groupSendEndorsementResponse)) {
// Use the latest state of the group after applying changes
const { groupId, membersV2 } = newAttributes;
strictAssert(groupId, 'updateGroupViaState: Group must have groupId');
strictAssert(membersV2, 'updateGroupViaState: Group must have membersV2');
log.info(`getCurrentGroupState/${logId}: Saving group endorsements`);
const groupEndorsementData = decodeGroupSendEndorsementResponse({
groupId,
groupSendEndorsementResponse,
@ -3975,8 +3968,8 @@ async function updateGroupViaLogs({
});
// If we're not in the group, we won't receive endorsements
if (!isGroupSendEndorsementResponseEmpty(groupSendEndorsementResponse)) {
log.info('updateGroupViaLogs: Saving group endorsements');
if (Bytes.isNotEmpty(groupSendEndorsementResponse)) {
log.info(`updateGroupViaLogs/${logId}: Saving group endorsements`);
// Use the latest state of the group after applying changes
const { membersV2 } = updates.newAttributes;
strictAssert(

View file

@ -15,15 +15,6 @@ import { fromAciObject } from '../types/ServiceId';
import * as log from '../logging/log';
import type { GroupV2MemberType } from '../model-types';
/**
* Despite being optional, the protobufs decoding will create an empty uint8array
*/
export function isGroupSendEndorsementResponseEmpty(
value: Uint8Array | null | undefined
): value is null | undefined {
return value == null || value.byteLength === 0;
}
export function decodeGroupSendEndorsementResponse({
groupId,
groupSendEndorsementResponse,