Skip to content

Commit

Permalink
When merging thread summaries take whichever value is highest (#4549)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Oct 10, 2023
1 parent 085f7ea commit 5777409
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions frontend/openchat-client/src/utils/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import type { TypersByKey } from "../stores/typing";
import { tallyKey } from "../stores/proposalTallies";
import { hasOwnerRights, isPermitted } from "./permissions";
import { cryptoLookup } from "../stores/crypto";
import { bigIntMax } from "./bigint";

const MAX_RTC_CONNECTIONS_PER_CHAT = 10;
const MERGE_MESSAGES_SENT_BY_SAME_USER_WITHIN_MILLIS = 60 * 1000; // 1 minute
Expand Down Expand Up @@ -1268,9 +1269,20 @@ function mergeLocalUpdates(
]);

message.thread = {
...current,
...localUpdates.threadSummary,
participantIds,
followedByMe: localUpdates.threadSummary.followedByMe ?? current.followedByMe,
numberOfReplies: Math.max(
localUpdates.threadSummary.numberOfReplies ?? 0,
current.numberOfReplies,
),
latestEventIndex: Math.max(
localUpdates.threadSummary.latestEventIndex ?? 0,
current.latestEventIndex,
),
latestEventTimestamp: bigIntMax(
localUpdates.threadSummary.latestEventTimestamp ?? BigInt(0),
current.latestEventTimestamp,
),
};
}

Expand Down

0 comments on commit 5777409

Please sign in to comment.