Sort stories when they were read at

This commit is contained in:
Josh Perez 2022-09-21 19:54:48 -04:00 committed by GitHub
parent b04fbb6d8d
commit af5a496994
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 7 deletions

1
ts/model-types.d.ts vendored
View File

@ -227,6 +227,7 @@ export type MessageAttributesType = {
sendHQImages?: boolean; sendHQImages?: boolean;
// Should only be present for incoming messages and errors // Should only be present for incoming messages and errors
readAt?: number;
readStatus?: ReadStatus; readStatus?: ReadStatus;
// Used for all kinds of notifications, as well as incoming messages // Used for all kinds of notifications, as well as incoming messages
seenStatus?: SeenStatus; seenStatus?: SeenStatus;

View File

@ -17,6 +17,7 @@ function markReadOrViewed(
const nextMessageAttributes: MessageAttributesType = { const nextMessageAttributes: MessageAttributesType = {
...messageAttrs, ...messageAttrs,
readAt: timestamp,
readStatus: newReadStatus, readStatus: newReadStatus,
seenStatus: SeenStatus.Seen, seenStatus: SeenStatus.Seen,
}; };

View File

@ -44,6 +44,7 @@ export function getStoryDataFromMessageAttributes(
'conversationId', 'conversationId',
'deletedForEveryone', 'deletedForEveryone',
'reactions', 'reactions',
'readAt',
'readStatus', 'readStatus',
'sendStateByConversationId', 'sendStateByConversationId',
'source', 'source',

View File

@ -64,6 +64,7 @@ export type StoryDataType = {
| 'conversationId' | 'conversationId'
| 'deletedForEveryone' | 'deletedForEveryone'
| 'reactions' | 'reactions'
| 'readAt'
| 'readStatus' | 'readStatus'
| 'sendStateByConversationId' | 'sendStateByConversationId'
| 'source' | 'source'
@ -140,7 +141,10 @@ type LoadStoryRepliesActionType = {
type MarkStoryReadActionType = { type MarkStoryReadActionType = {
type: typeof MARK_STORY_READ; type: typeof MARK_STORY_READ;
payload: string; payload: {
messageId: string;
readAt: number;
};
}; };
type QueueStoryDownloadActionType = { type QueueStoryDownloadActionType = {
@ -456,7 +460,10 @@ function markStoryRead(
dispatch({ dispatch({
type: MARK_STORY_READ, type: MARK_STORY_READ,
payload: messageId, payload: {
messageId,
readAt: storyReadDate,
},
}); });
}; };
} }
@ -1157,6 +1164,7 @@ export function reducer(
'expireTimer', 'expireTimer',
'messageId', 'messageId',
'reactions', 'reactions',
'readAt',
'readStatus', 'readStatus',
'sendStateByConversationId', 'sendStateByConversationId',
'source', 'source',
@ -1228,12 +1236,15 @@ export function reducer(
} }
if (action.type === MARK_STORY_READ) { if (action.type === MARK_STORY_READ) {
const { messageId, readAt } = action.payload;
return { return {
...state, ...state,
stories: state.stories.map(story => { stories: state.stories.map(story => {
if (story.messageId === action.payload) { if (story.messageId === messageId) {
return { return {
...story, ...story,
readAt,
readStatus: ReadStatus.Viewed, readStatus: ReadStatus.Viewed,
}; };
} }

View File

@ -73,6 +73,10 @@ function sortByRecencyAndUnread(
return -1; return -1;
} }
if (storyA.storyView.readAt && storyB.storyView.readAt) {
return storyA.storyView.readAt > storyB.storyView.readAt ? -1 : 1;
}
return storyA.storyView.timestamp > storyB.storyView.timestamp ? -1 : 1; return storyA.storyView.timestamp > storyB.storyView.timestamp ? -1 : 1;
} }
@ -145,10 +149,19 @@ export function getStoryView(
'title', 'title',
]); ]);
const { attachment, timestamp, expirationStartTimestamp, expireTimer } = pick( const {
story, attachment,
['attachment', 'timestamp', 'expirationStartTimestamp', 'expireTimer'] expirationStartTimestamp,
); expireTimer,
readAt,
timestamp,
} = pick(story, [
'attachment',
'expirationStartTimestamp',
'expireTimer',
'readAt',
'timestamp',
]);
const { sendStateByConversationId } = story; const { sendStateByConversationId } = story;
let sendState: Array<StorySendStateType> | undefined; let sendState: Array<StorySendStateType> | undefined;
@ -182,6 +195,7 @@ export function getStoryView(
isHidden: Boolean(sender.hideStory), isHidden: Boolean(sender.hideStory),
isUnread: story.readStatus === ReadStatus.Unread, isUnread: story.readStatus === ReadStatus.Unread,
messageId: story.messageId, messageId: story.messageId,
readAt,
sender, sender,
sendState, sendState,
timestamp, timestamp,

View File

@ -73,6 +73,7 @@ export type StoryViewType = {
isHidden?: boolean; isHidden?: boolean;
isUnread?: boolean; isUnread?: boolean;
messageId: string; messageId: string;
readAt?: number;
sender: Pick< sender: Pick<
ConversationType, ConversationType,
| 'acceptedMessageRequest' | 'acceptedMessageRequest'