Skip to content

Commit

Permalink
Tweak the priority for recent encrypted messages (#2276)
Browse files Browse the repository at this point in the history
make sure they never override the current high priority channel
  • Loading branch information
texuf authored Feb 6, 2025
1 parent f6e88b9 commit 346310d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
13 changes: 10 additions & 3 deletions packages/encryption/src/decryptionExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ export abstract class BaseDecryptionExtensions {
* upload device keys to the server
*/
public abstract uploadDeviceKeys(): Promise<void>
public abstract getPriorityForStream(streamId: string, highPriorityIds: Set<string>): number
public abstract getPriorityForStream(
streamId: string,
highPriorityIds: Set<string>,
recentStreamIds: Set<string>,
): number

public enqueueNewGroupSessions(
sessions: UserInboxPayload_GroupEncryptionSessions,
Expand Down Expand Up @@ -446,8 +450,11 @@ export abstract class BaseDecryptionExtensions {
}

private compareStreamIds(a: string, b: string): number {
const priorityIds = new Set([...this.highPriorityIds, ...this.recentStreamIds])
return this.getPriorityForStream(a, priorityIds) - this.getPriorityForStream(b, priorityIds)
const recentStreamIds = new Set(this.recentStreamIds)
return (
this.getPriorityForStream(a, this.highPriorityIds, recentStreamIds) -
this.getPriorityForStream(b, this.highPriorityIds, recentStreamIds)
)
}

private lastPrintedAt = 0
Expand Down
6 changes: 5 additions & 1 deletion packages/encryption/src/tests/decryptionExtensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ class MockDecryptionExtensions extends BaseDecryptionExtensions {
return true
}

public getPriorityForStream(_streamId: string, _highPriorityIds: Set<string>): number {
public getPriorityForStream(
_streamId: string,
_highPriorityIds: Set<string>,
_recentStreamIds: Set<string>,
): number {
return 0
}

Expand Down
20 changes: 14 additions & 6 deletions packages/sdk/src/clientDecryptionExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ export class ClientDecryptionExtensions extends BaseDecryptionExtensions {
}
}

public getPriorityForStream(streamId: string, highPriorityIds: Set<string>): number {
public getPriorityForStream(
streamId: string,
highPriorityIds: Set<string>,
recentStreamIds: Set<string>,
): number {
if (
isUserDeviceStreamId(streamId) ||
isUserInboxStreamId(streamId) ||
Expand All @@ -324,26 +328,30 @@ export class ClientDecryptionExtensions extends BaseDecryptionExtensions {
if ((isDmOrGdm || isChannel) && highPriorityIds.has(streamId)) {
return 1
}
// if you're getting updates for this stream, decrypt them so that you see unread messages
if (recentStreamIds.has(streamId)) {
return 2
}
// channels in the space we're currently viewing
if (isChannel) {
const spaceId = spaceIdFromChannelId(streamId)
if (highPriorityIds.has(spaceId)) {
return 2
return 3
}
}
// dms
if (isDmOrGdm) {
return 3
return 4
}
// space that we're currently viewing
if (highPriorityIds.has(streamId)) {
return 4
return 5
}
// then other channels,
if (isChannel) {
return 5
return 6
}
// then other spaces
return 6
return 7
}
}

0 comments on commit 346310d

Please sign in to comment.