Skip to content

Commit

Permalink
Disambiguate between types of receipts when stored in the same map
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-signal committed Nov 20, 2023
1 parent be5ac3a commit 3c12a0a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ts/messageModifiers/MessageReceipts.ts
Expand Up @@ -83,6 +83,7 @@ function remove(receipt: MessageReceiptAttributesType): void {
generateCacheKey({
sender: receipt.sourceServiceId,
timestamp: receipt.messageSentAt,
type: receipt.type,
})
);
receipt.removeFromMessageReceiverCache();
Expand Down Expand Up @@ -351,6 +352,7 @@ export async function onReceipt(
generateCacheKey({
sender: receipt.sourceServiceId,
timestamp: receipt.messageSentAt,
type: receipt.type,
}),
receipt
);
Expand Down
2 changes: 2 additions & 0 deletions ts/messageModifiers/ReadSyncs.ts
Expand Up @@ -33,6 +33,7 @@ function remove(sync: ReadSyncAttributesType): void {
generateCacheKey({
sender: sync.senderId,
timestamp: sync.timestamp,
type: 'readsync',
})
);
sync.removeFromMessageReceiverCache();
Expand Down Expand Up @@ -109,6 +110,7 @@ export async function onSync(sync: ReadSyncAttributesType): Promise<void> {
generateCacheKey({
sender: sync.senderId,
timestamp: sync.timestamp,
type: 'readsync',
}),
sync
);
Expand Down
2 changes: 2 additions & 0 deletions ts/messageModifiers/ViewSyncs.ts
Expand Up @@ -34,6 +34,7 @@ function remove(sync: ViewSyncAttributesType): void {
generateCacheKey({
sender: sync.senderId,
timestamp: sync.timestamp,
type: 'viewsync',
})
);
sync.removeFromMessageReceiverCache();
Expand Down Expand Up @@ -78,6 +79,7 @@ export async function onSync(sync: ViewSyncAttributesType): Promise<void> {
generateCacheKey({
sender: sync.senderId,
timestamp: sync.timestamp,
type: 'viewsync',
}),
sync
);
Expand Down
10 changes: 9 additions & 1 deletion ts/messageModifiers/generateCacheKey.ts
@@ -1,16 +1,24 @@
// Copyright 2016 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

import type { MessageReceiptType } from './MessageReceipts';

// This function is necessary because the only thing we can guarantee will be unique is
// three pieces of data: sender, deviceId, and timestamp.
// Because we don't care which device interacted with our message, we collapse this down
// to: sender + timestamp.
// In some cases, modifiers are stored in the same map, so we also add the modifier type

type ModifierType = MessageReceiptType | 'readsync' | 'viewsync';

export function generateCacheKey({
sender,
timestamp,
type,
}: {
sender: string;
timestamp: number;
type: ModifierType;
}): string {
return `cacheKey-${sender}-${timestamp}`;
return `cacheKey-${sender}-${timestamp}-${type}`;
}

0 comments on commit 3c12a0a

Please sign in to comment.