Skip to content

Commit

Permalink
Re-render left pane and timeline items when group members change
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Mar 26, 2021
1 parent b31a44a commit 7a3130a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
3 changes: 3 additions & 0 deletions ts/ConversationController.ts
Expand Up @@ -822,6 +822,9 @@ export class ConversationController {
await Promise.all(
this._conversations.map(async conversation => {
try {
// Hydrate contactCollection, now that initial fetch is complete
conversation.fetchContacts();

const isChanged = await maybeDeriveGroupV2Id(conversation);
if (isChanged) {
updateConversation(conversation.attributes);
Expand Down
20 changes: 14 additions & 6 deletions ts/models/conversations.ts
Expand Up @@ -218,20 +218,26 @@ export class ConversationModel extends window.Backbone.Model<
// our first save to the database. Or first fetch from the database.
this.initialPromise = Promise.resolve();

this.throttledBumpTyping = window._.throttle(this.bumpTyping, 300);
this.debouncedUpdateLastMessage = window._.debounce(
this.updateLastMessage.bind(this),
200
);

this.contactCollection = this.getContactCollection();
this.contactCollection.on(
'change:name change:profileName change:profileFamilyName change:e164',
this.debouncedUpdateLastMessage,
this
);

this.messageCollection = new window.Whisper.MessageCollection([], {
conversation: this,
});

this.messageCollection.on('change:errors', this.handleMessageError, this);
this.messageCollection.on('send-error', this.onMessageError, this);

this.throttledBumpTyping = window._.throttle(this.bumpTyping, 300);
this.debouncedUpdateLastMessage = window._.debounce(
this.updateLastMessage.bind(this),
200
);

this.listenTo(
this.messageCollection,
'add remove destroy content-changed',
Expand All @@ -258,6 +264,8 @@ export class ConversationModel extends window.Backbone.Model<
this.unset('hasFetchedProfile');
this.unset('tokens');

this.on('change:members change:membersV2', this.fetchContacts);

this.typingRefreshTimer = null;
this.typingPauseTimer = null;

Expand Down
27 changes: 3 additions & 24 deletions ts/state/selectors/conversations.ts
Expand Up @@ -559,10 +559,8 @@ export function _messageSelector(
_ourNumber: string,
_regionCode: string,
interactionMode: 'mouse' | 'keyboard',
_getConversationById: GetConversationByIdType,
_callsByConversation: CallsByConversationType,
_conversation?: ConversationType,
_author?: ConversationType,
_quoted?: ConversationType,
selectedMessageId?: string,
selectedMessageCounter?: number
): TimelineItemType {
Expand Down Expand Up @@ -598,10 +596,8 @@ type CachedMessageSelectorType = (
ourNumber: string,
regionCode: string,
interactionMode: 'mouse' | 'keyboard',
getConversationById: GetConversationByIdType,
callsByConversation: CallsByConversationType,
conversation?: ConversationType,
author?: ConversationType,
quoted?: ConversationType,
selectedMessageId?: string,
selectedMessageCounter?: number
) => TimelineItemType;
Expand Down Expand Up @@ -641,30 +637,13 @@ export const getMessageSelector = createSelector(
return undefined;
}

const { conversationId, source, type, quote } = message;
const conversation = conversationSelector(conversationId);
let author: ConversationType | undefined;
let quoted: ConversationType | undefined;

if (type === 'incoming') {
author = conversationSelector(source);
} else if (type === 'outgoing') {
author = conversationSelector(ourNumber);
}

if (quote && (quote.author || quote.authorUuid)) {
quoted = conversationSelector(quote.authorUuid || quote.author);
}

return messageSelector(
message,
ourNumber,
regionCode,
interactionMode,
conversationSelector,
callsByConversation,
conversation,
author,
quoted,
selectedMessage ? selectedMessage.id : undefined,
selectedMessage ? selectedMessage.counter : undefined
);
Expand Down

0 comments on commit 7a3130a

Please sign in to comment.