Deduplicate message_changed redux actions
This commit is contained in:
parent
8bb355f971
commit
cfe15b929b
2 changed files with 19 additions and 32 deletions
|
@ -132,7 +132,6 @@ import { getMessageIdForLogging } from '../util/idForLogging';
|
|||
import { hasAttachmentDownloads } from '../util/hasAttachmentDownloads';
|
||||
import { queueAttachmentDownloads } from '../util/queueAttachmentDownloads';
|
||||
import { findStoryMessages } from '../util/findStoryMessage';
|
||||
import { getStoryDataFromMessageAttributes } from '../services/storyLoader';
|
||||
import type { ConversationQueueJobData } from '../jobs/conversationJobQueue';
|
||||
import { shouldDownloadStory } from '../util/shouldDownloadStory';
|
||||
import type { EmbeddedContactWithHydratedAvatar } from '../types/EmbeddedContact';
|
||||
|
@ -249,44 +248,15 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
this.CURRENT_PROTOCOL_VERSION = Proto.DataMessage.ProtocolVersion.CURRENT;
|
||||
this.INITIAL_PROTOCOL_VERSION = Proto.DataMessage.ProtocolVersion.INITIAL;
|
||||
|
||||
this.on('change', this.notifyRedux);
|
||||
this.on('change', this.updateMessageCache);
|
||||
}
|
||||
|
||||
notifyRedux(): void {
|
||||
if (!window.reduxActions) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateMessageCache(): void {
|
||||
window.MessageCache.setAttributes({
|
||||
messageId: this.id,
|
||||
messageAttributes: this.attributes,
|
||||
skipSaveToDatabase: true,
|
||||
});
|
||||
|
||||
const { storyChanged } = window.reduxActions.stories;
|
||||
|
||||
if (isStory(this.attributes)) {
|
||||
const storyData = getStoryDataFromMessageAttributes({
|
||||
...this.attributes,
|
||||
});
|
||||
|
||||
if (!storyData) {
|
||||
return;
|
||||
}
|
||||
|
||||
storyChanged(storyData);
|
||||
|
||||
// We don't want messageChanged to run
|
||||
return;
|
||||
}
|
||||
|
||||
const { messageChanged } = window.reduxActions.conversations;
|
||||
|
||||
if (messageChanged) {
|
||||
const conversationId = this.get('conversationId');
|
||||
// Note: The clone is important for triggering a re-run of selectors
|
||||
messageChanged(this.id, conversationId, { ...this.attributes });
|
||||
}
|
||||
}
|
||||
|
||||
getSenderIdentifier(): string {
|
||||
|
|
|
@ -14,6 +14,8 @@ import { getSenderIdentifier } from '../util/getSenderIdentifier';
|
|||
import { isNotNil } from '../util/isNotNil';
|
||||
import { map } from '../util/iterables';
|
||||
import { softAssert, strictAssert } from '../util/assert';
|
||||
import { isStory } from '../messages/helpers';
|
||||
import { getStoryDataFromMessageAttributes } from './storyLoader';
|
||||
|
||||
export class MessageCache {
|
||||
private state = {
|
||||
|
@ -197,6 +199,21 @@ export class MessageCache {
|
|||
this.markModelStale(nextMessageAttributes);
|
||||
|
||||
if (window.reduxActions) {
|
||||
if (isStory(nextMessageAttributes)) {
|
||||
const storyData = getStoryDataFromMessageAttributes({
|
||||
...nextMessageAttributes,
|
||||
});
|
||||
|
||||
if (!storyData) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.reduxActions.stories.storyChanged(storyData);
|
||||
|
||||
// We don't want messageChanged to run
|
||||
return;
|
||||
}
|
||||
|
||||
window.reduxActions.conversations.messageChanged(
|
||||
messageId,
|
||||
nextMessageAttributes.conversationId,
|
||||
|
|
Loading…
Reference in a new issue