Skip to content

Commit

Permalink
[lib] Check the timestamps when updating read status
Browse files Browse the repository at this point in the history
Summary:
Check the timestamp before setting the value. We need to use a different update type so that we can update also the timestamps.

https://linear.app/comm/issue/ENG-9120/update-thread-unread-status-spec

Depends on D13241

Test Plan: Process a couple of operations setting to read / unread.

Reviewers: kamil, inka, marcin

Reviewed By: inka

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D13240
  • Loading branch information
palys-swm committed Sep 6, 2024
1 parent 1164b23 commit 694c044
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions lib/shared/dm-ops/change-thread-read-status-spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow

import invariant from 'invariant';
import uuid from 'uuid';

import type {
Expand All @@ -22,15 +23,39 @@ const changeThreadReadStatusSpec: DMOperationSpec<DMChangeThreadReadStatusOperat
},
processDMOperation: async (
dmOperation: DMChangeThreadReadStatusOperation,
viewerID: string,
utilities: ProcessDMOperationUtilities,
) => {
const { threadID, unread, time } = dmOperation;

const threadInfo = utilities.threadInfos[threadID];
invariant(threadInfo.thick, 'Thread should be thick');
if (threadInfo.timestamps.currentUser.unread > time) {
return {
rawMessageInfos: [],
updateInfos: [],
};
}

const updateInfos = [
{
type: updateTypes.UPDATE_THREAD_READ_STATUS,
type: updateTypes.UPDATE_THREAD,
id: uuid.v4(),
time,
threadID,
unread,
threadInfo: {
...threadInfo,
currentUser: {
...threadInfo.currentUser,
unread,
},
timestamps: {
...threadInfo.timestamps,
currentUser: {
...threadInfo.timestamps.currentUser,
unread: time,
},
},
},
},
];
return {
Expand Down

0 comments on commit 694c044

Please sign in to comment.