Skip to content

Commit c5ce9cd

Browse files
Update backup protos
1 parent 63d38ac commit c5ce9cd

File tree

5 files changed

+63
-9
lines changed

5 files changed

+63
-9
lines changed

protos/Backups.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ message SimpleChatUpdate {
751751
PAYMENTS_ACTIVATED = 10;
752752
PAYMENT_ACTIVATION_REQUEST = 11;
753753
UNSUPPORTED_PROTOCOL_MESSAGE = 12;
754+
REPORTED_SPAM = 13;
754755
}
755756

756757
Type type = 1;
@@ -1042,7 +1043,7 @@ message ChatStyle {
10421043
}
10431044

10441045
message CustomChatColor {
1045-
uint32 id = 1;
1046+
uint64 id = 1;
10461047

10471048
oneof color {
10481049
fixed32 solid = 2;
@@ -1116,7 +1117,7 @@ message ChatStyle {
11161117
BubbleColorPreset bubbleColorPreset = 4;
11171118

11181119
// See AccountSettings.customChatColors
1119-
uint32 customColorId = 5;
1120+
uint64 customColorId = 5;
11201121
}
11211122

11221123
bool dimWallpaperInDarkMode = 7;

ts/services/backups/export.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
import type { RawBodyRange } from '../../types/BodyRange';
2828
import { LONG_ATTACHMENT_LIMIT } from '../../types/Message';
2929
import { PaymentEventKind } from '../../types/Payment';
30+
import { MessageRequestResponseEvent } from '../../types/MessageRequestResponseEvent';
3031
import type {
3132
ConversationAttributesType,
3233
MessageAttributesType,
@@ -78,6 +79,7 @@ import {
7879
isChangeNumberNotification,
7980
isJoinedSignalNotification,
8081
isTitleTransitionNotification,
82+
isMessageRequestResponse,
8183
} from '../../state/selectors/message';
8284
import * as Bytes from '../../Bytes';
8385
import { canBeSynced as canPreferredReactionEmojiBeSynced } from '../../reactions/preferredReactionEmoji';
@@ -181,7 +183,7 @@ export class BackupExportStream extends Readable {
181183

182184
// Map from custom color uuid to an index in accountSettings.customColors
183185
// array.
184-
private customColorIdByUuid = new Map<string, number>();
186+
private customColorIdByUuid = new Map<string, Long>();
185187

186188
public run(backupLevel: BackupLevel): void {
187189
drop(
@@ -1328,6 +1330,31 @@ export class BackupExportStream extends Readable {
13281330
return { kind: NonBubbleResultKind.Directionless, patch };
13291331
}
13301332

1333+
if (isMessageRequestResponse(message)) {
1334+
const { messageRequestResponseEvent: event } = message;
1335+
if (event == null) {
1336+
return { kind: NonBubbleResultKind.Drop };
1337+
}
1338+
1339+
let type: Backups.SimpleChatUpdate.Type;
1340+
const { Type } = Backups.SimpleChatUpdate;
1341+
switch (event) {
1342+
case MessageRequestResponseEvent.ACCEPT:
1343+
case MessageRequestResponseEvent.BLOCK:
1344+
case MessageRequestResponseEvent.UNBLOCK:
1345+
return { kind: NonBubbleResultKind.Drop };
1346+
case MessageRequestResponseEvent.SPAM:
1347+
type = Type.REPORTED_SPAM;
1348+
break;
1349+
default:
1350+
throw missingCaseError(event);
1351+
}
1352+
1353+
updateMessage.simpleUpdate = { type };
1354+
1355+
return { kind: NonBubbleResultKind.Directionless, patch };
1356+
}
1357+
13311358
if (isDeliveryIssue(message)) {
13321359
updateMessage.simpleUpdate = {
13331360
type: Backups.SimpleChatUpdate.Type.BAD_DECRYPT,
@@ -2278,7 +2305,7 @@ export class BackupExportStream extends Readable {
22782305

22792306
const result = new Array<Backups.ChatStyle.ICustomChatColor>();
22802307
for (const [uuid, color] of Object.entries(customColors.colors)) {
2281-
const id = result.length;
2308+
const id = Long.fromNumber(result.length);
22822309
this.customColorIdByUuid.set(uuid, id);
22832310

22842311
const start = hslToRGBInt(color.start.hue, color.start.saturation);

ts/services/backups/import.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import { isStoryDistributionId } from '../../types/StoryDistributionId';
2424
import * as Errors from '../../types/errors';
2525
import { PaymentEventKind } from '../../types/Payment';
26+
import { MessageRequestResponseEvent } from '../../types/MessageRequestResponseEvent';
2627
import {
2728
ContactFormType,
2829
AddressType as ContactAddressType,
@@ -2450,6 +2451,7 @@ export class BackupImportStream extends Writable {
24502451
}
24512452
): Promise<Partial<MessageAttributesType> | undefined> {
24522453
const { Type } = Backups.SimpleChatUpdate;
2454+
strictAssert(simpleUpdate.type != null, 'Simple update missing type');
24532455
switch (simpleUpdate.type) {
24542456
case Type.END_SESSION:
24552457
return {
@@ -2493,7 +2495,6 @@ export class BackupImportStream extends Writable {
24932495
case Type.RELEASE_CHANNEL_DONATION_REQUEST:
24942496
log.warn('backups: dropping boost request from release notes');
24952497
return undefined;
2496-
// TODO(indutny): REPORTED_SPAM
24972498
case Type.PAYMENTS_ACTIVATED:
24982499
return {
24992500
payment: {
@@ -2513,8 +2514,13 @@ export class BackupImportStream extends Writable {
25132514
requiredProtocolVersion:
25142515
SignalService.DataMessage.ProtocolVersion.CURRENT - 1,
25152516
};
2517+
case Type.REPORTED_SPAM:
2518+
return {
2519+
type: 'message-request-response-event',
2520+
messageRequestResponseEvent: MessageRequestResponseEvent.SPAM,
2521+
};
25162522
default:
2517-
throw new Error('Not implemented');
2523+
throw new Error(`Unsupported update type: ${simpleUpdate.type}`);
25182524
}
25192525
}
25202526

@@ -2583,7 +2589,7 @@ export class BackupImportStream extends Writable {
25832589
}
25842590

25852591
customColors.colors[uuid] = value;
2586-
this.customColorById.set(color.id || 0, {
2592+
this.customColorById.set(color.id?.toNumber() || 0, {
25872593
id: uuid,
25882594
value,
25892595
});
@@ -2703,7 +2709,9 @@ export class BackupImportStream extends Writable {
27032709
} else {
27042710
strictAssert(chatStyle.customColorId != null, 'Missing custom color id');
27052711

2706-
const entry = this.customColorById.get(chatStyle.customColorId);
2712+
const entry = this.customColorById.get(
2713+
chatStyle.customColorId.toNumber()
2714+
);
27072715
strictAssert(entry != null, 'Missing custom color');
27082716

27092717
color = 'custom';

ts/state/selectors/message.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,8 @@ export function isNormalBubble(message: MessageWithUIFieldsType): boolean {
10221022
!isVerifiedChange(message) &&
10231023
!isChangeNumberNotification(message) &&
10241024
!isJoinedSignalNotification(message) &&
1025-
!isDeliveryIssue(message)
1025+
!isDeliveryIssue(message) &&
1026+
!isMessageRequestResponse(message)
10261027
);
10271028
}
10281029

ts/test-electron/backup/non_bubble_test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { DataWriter } from '../../sql/Client';
1313
import { generateAci } from '../../types/ServiceId';
1414
import { PaymentEventKind } from '../../types/Payment';
1515
import { ContactFormType } from '../../types/EmbeddedContact';
16+
import { MessageRequestResponseEvent } from '../../types/MessageRequestResponseEvent';
1617
import { DurationInSeconds } from '../../util/durations';
1718
import { ReadStatus } from '../../messages/MessageReadStatus';
1819
import { SeenStatus } from '../../MessageSeenStatus';
@@ -542,4 +543,20 @@ describe('backup/non-bubble messages', () => {
542543
]
543544
);
544545
});
546+
547+
it('roundtrips spam report message', async () => {
548+
await symmetricRoundtripHarness([
549+
{
550+
conversationId: contactA.id,
551+
id: generateGuid(),
552+
type: 'message-request-response-event',
553+
received_at: 1,
554+
sourceServiceId: CONTACT_A,
555+
sourceDevice: 1,
556+
sent_at: 1,
557+
timestamp: 1,
558+
messageRequestResponseEvent: MessageRequestResponseEvent.SPAM,
559+
},
560+
]);
561+
});
545562
});

0 commit comments

Comments
 (0)