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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue