Sort stories when they were read at
This commit is contained in:
parent
b04fbb6d8d
commit
af5a496994
|
@ -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;
|
||||||
|
|
|
@ -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,
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,6 +44,7 @@ export function getStoryDataFromMessageAttributes(
|
||||||
'conversationId',
|
'conversationId',
|
||||||
'deletedForEveryone',
|
'deletedForEveryone',
|
||||||
'reactions',
|
'reactions',
|
||||||
|
'readAt',
|
||||||
'readStatus',
|
'readStatus',
|
||||||
'sendStateByConversationId',
|
'sendStateByConversationId',
|
||||||
'source',
|
'source',
|
||||||
|
|
|
@ -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,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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'
|
||||||
|
|
Loading…
Reference in New Issue