diff --git a/ts/components/conversation/ContactModal.stories.tsx b/ts/components/conversation/ContactModal.stories.tsx index 5704d2b60..8c1e59f42 100644 --- a/ts/components/conversation/ContactModal.stories.tsx +++ b/ts/components/conversation/ContactModal.stories.tsx @@ -36,6 +36,7 @@ const createProps = (overrideProps: Partial = {}): PropsType => ({ removeMember: action('removeMember'), showSafetyNumber: action('showSafetyNumber'), toggleAdmin: action('toggleAdmin'), + updateSharedGroups: action('updateSharedGroups'), }); story.add('As non-admin', () => { diff --git a/ts/components/conversation/ContactModal.tsx b/ts/components/conversation/ContactModal.tsx index d716d0b84..31e83bf84 100644 --- a/ts/components/conversation/ContactModal.tsx +++ b/ts/components/conversation/ContactModal.tsx @@ -21,6 +21,7 @@ export type PropsType = { removeMember: (conversationId: string) => void; showSafetyNumber: (conversationId: string) => void; toggleAdmin: (conversationId: string) => void; + updateSharedGroups: () => void; }; export const ContactModal = ({ @@ -34,6 +35,7 @@ export const ContactModal = ({ removeMember, showSafetyNumber, toggleAdmin, + updateSharedGroups, }: PropsType): ReactPortal | null => { if (!contact) { throw new Error('Contact modal opened without a matching contact'); @@ -54,6 +56,11 @@ export const ContactModal = ({ }; }, []); + React.useEffect(() => { + // Kick off the expensive hydration of the current sharedGroupNames + updateSharedGroups(); + }, [updateSharedGroups]); + React.useEffect(() => { if (root !== null && closeButtonRef.current) { closeButtonRef.current.focus(); diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index a9295a450..de95fc97c 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -156,6 +156,8 @@ export class ConversationModel extends window.Backbone lastSuccessfulGroupFetch?: number; + throttledUpdateSharedGroups?: () => Promise; + private cachedLatestGroupCallEraId?: string; private cachedIdenticon?: CachedIdenticon; @@ -229,6 +231,9 @@ export class ConversationModel extends window.Backbone this.updateLastMessage.bind(this), 200 ); + this.throttledUpdateSharedGroups = + this.throttledUpdateSharedGroups || + window._.throttle(this.updateSharedGroups.bind(this), FIVE_MINUTES); this.contactCollection = this.getContactCollection(); this.contactCollection.on( diff --git a/ts/state/smart/ContactModal.tsx b/ts/state/smart/ContactModal.tsx index 42dfab114..a6df2d5fd 100644 --- a/ts/state/smart/ContactModal.tsx +++ b/ts/state/smart/ContactModal.tsx @@ -20,6 +20,7 @@ export type SmartContactModalProps = { readonly removeMember: (conversationId: string) => void; readonly showSafetyNumber: (conversationId: string) => void; readonly toggleAdmin: (conversationId: string) => void; + readonly updateSharedGroups: () => void; }; const mapStateToProps = ( diff --git a/ts/views/conversation_view.ts b/ts/views/conversation_view.ts index 7b4f5d6ee..d4d8b1f96 100644 --- a/ts/views/conversation_view.ts +++ b/ts/views/conversation_view.ts @@ -386,12 +386,6 @@ Whisper.ConversationView = Whisper.View.extend({ this.model.throttledGetProfiles = this.model.throttledGetProfiles || window._.throttle(this.model.getProfiles.bind(this.model), FIVE_MINUTES); - this.model.throttledUpdateSharedGroups = - this.model.throttledUpdateSharedGroups || - window._.throttle( - this.model.updateSharedGroups.bind(this.model), - FIVE_MINUTES - ); this.model.throttledMaybeMigrateV1Group = this.model.throttledMaybeMigrateV1Group || window._.throttle( @@ -3052,6 +3046,12 @@ Whisper.ConversationView = Whisper.View.extend({ resolve: () => this.model.toggleAdmin(conversationId), }); }, + updateSharedGroups: () => { + const conversation = window.ConversationController.get(contactId); + if (conversation && conversation.throttledUpdateSharedGroups) { + conversation.throttledUpdateSharedGroups(); + } + }, }), }); @@ -3625,10 +3625,6 @@ Whisper.ConversationView = Whisper.View.extend({ const props = message.getPropsForQuote(); - this.listenTo(message, 'scroll-to-message', () => { - this.scrollToMessage(message.quotedMessage.id); - }); - const contact = this.quotedMessage.getContact(); if (contact) { this.listenTo(contact, 'change', this.renderQuotedMessage); @@ -3642,6 +3638,7 @@ Whisper.ConversationView = Whisper.View.extend({ props: { ...props, withContentAbove: true, + onClick: () => this.scrollToMessage(message.quotedMessage.id), onClose: () => { // This can't be the normal 'onClose' because that is always run when this // view is removed from the DOM, and would clear the draft quote.