Sync story read status from primary
This commit is contained in:
parent
da45f26d37
commit
4896ce32c3
3 changed files with 24 additions and 24 deletions
|
@ -9,7 +9,7 @@ import { Collection, Model } from 'backbone';
|
||||||
import type { ConversationModel } from '../models/conversations';
|
import type { ConversationModel } from '../models/conversations';
|
||||||
import type { MessageModel } from '../models/messages';
|
import type { MessageModel } from '../models/messages';
|
||||||
import type { MessageAttributesType } from '../model-types.d';
|
import type { MessageAttributesType } from '../model-types.d';
|
||||||
import { isOutgoing } from '../state/selectors/message';
|
import { isOutgoing, isStory } from '../state/selectors/message';
|
||||||
import { isDirectConversation } from '../util/whatTypeOfConversation';
|
import { isDirectConversation } from '../util/whatTypeOfConversation';
|
||||||
import { getOwn } from '../util/getOwn';
|
import { getOwn } from '../util/getOwn';
|
||||||
import { missingCaseError } from '../util/missingCaseError';
|
import { missingCaseError } from '../util/missingCaseError';
|
||||||
|
@ -66,7 +66,8 @@ async function getTargetMessage(
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const message = messages.find(
|
const message = messages.find(
|
||||||
item => isOutgoing(item) && sourceId === item.conversationId
|
item =>
|
||||||
|
(isOutgoing(item) || isStory(item)) && sourceId === item.conversationId
|
||||||
);
|
);
|
||||||
if (message) {
|
if (message) {
|
||||||
return window.MessageController.register(message.id, message);
|
return window.MessageController.register(message.id, message);
|
||||||
|
@ -78,7 +79,8 @@ async function getTargetMessage(
|
||||||
ids.push(sourceId);
|
ids.push(sourceId);
|
||||||
|
|
||||||
const target = messages.find(
|
const target = messages.find(
|
||||||
item => isOutgoing(item) && ids.includes(item.conversationId)
|
item =>
|
||||||
|
(isOutgoing(item) || isStory(item)) && ids.includes(item.conversationId)
|
||||||
);
|
);
|
||||||
if (!target) {
|
if (!target) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { Collection, Model } from 'backbone';
|
||||||
import type { MessageModel } from '../models/messages';
|
import type { MessageModel } from '../models/messages';
|
||||||
import { ReadStatus } from '../messages/MessageReadStatus';
|
import { ReadStatus } from '../messages/MessageReadStatus';
|
||||||
import { markViewed } from '../services/MessageUpdater';
|
import { markViewed } from '../services/MessageUpdater';
|
||||||
import { isIncoming } from '../state/selectors/message';
|
import { isIncoming, isStory } from '../state/selectors/message';
|
||||||
import { notificationService } from '../services/notifications';
|
import { notificationService } from '../services/notifications';
|
||||||
import * as log from '../logging/log';
|
import * as log from '../logging/log';
|
||||||
|
|
||||||
|
@ -67,7 +67,10 @@ export class ViewSyncs extends Collection {
|
||||||
uuid: item.sourceUuid,
|
uuid: item.sourceUuid,
|
||||||
});
|
});
|
||||||
|
|
||||||
return isIncoming(item) && senderId === sync.get('senderId');
|
return (
|
||||||
|
(isIncoming(item) || isStory(item)) &&
|
||||||
|
senderId === sync.get('senderId')
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
|
|
@ -374,37 +374,32 @@ export function reducer(
|
||||||
'type',
|
'type',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Stories don't really need to change except for when we don't have the
|
const prevStoryIndex = state.stories.findIndex(
|
||||||
// attachment downloaded and we queue a download. Then the story's message
|
|
||||||
// will have the new attachment information. This is an optimization so
|
|
||||||
// we don't needlessly re-render.
|
|
||||||
const prevStory = state.stories.find(
|
|
||||||
existingStory => existingStory.messageId === newStory.messageId
|
existingStory => existingStory.messageId === newStory.messageId
|
||||||
);
|
);
|
||||||
if (prevStory) {
|
if (prevStoryIndex >= 0) {
|
||||||
|
const prevStory = state.stories[prevStoryIndex];
|
||||||
|
|
||||||
|
// Stories rarely need to change, here are the following exceptions:
|
||||||
|
const isDownloadingAttachment = isDownloading(newStory.attachment);
|
||||||
|
const hasAttachmentDownloaded =
|
||||||
|
!isDownloaded(prevStory.attachment) &&
|
||||||
|
isDownloaded(newStory.attachment);
|
||||||
|
const readStatusChanged = prevStory.readStatus !== newStory.readStatus;
|
||||||
|
|
||||||
const shouldReplace =
|
const shouldReplace =
|
||||||
(!isDownloaded(prevStory.attachment) &&
|
isDownloadingAttachment || hasAttachmentDownloaded || readStatusChanged;
|
||||||
isDownloaded(newStory.attachment)) ||
|
|
||||||
isDownloading(newStory.attachment);
|
|
||||||
|
|
||||||
if (!shouldReplace) {
|
if (!shouldReplace) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
const storyIndex = state.stories.findIndex(
|
|
||||||
existingStory => existingStory.messageId === newStory.messageId
|
|
||||||
);
|
|
||||||
|
|
||||||
if (storyIndex < 0) {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
stories: replaceIndex(state.stories, storyIndex, newStory),
|
stories: replaceIndex(state.stories, prevStoryIndex, newStory),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adding a new story
|
||||||
const stories = [...state.stories, newStory].sort((a, b) =>
|
const stories = [...state.stories, newStory].sort((a, b) =>
|
||||||
a.timestamp > b.timestamp ? 1 : -1
|
a.timestamp > b.timestamp ? 1 : -1
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue