From f6bc4dfe253ea4e52cd4854762d63663fde40d7c Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 21 May 2021 10:27:28 -0700 Subject: [PATCH] Enable click on draft quotes, fetch groups from contact modal --- .../conversation/ContactModal.stories.tsx | 1 + ts/components/conversation/ContactModal.tsx | 7 +++++++ ts/models/conversations.ts | 5 +++++ ts/state/smart/ContactModal.tsx | 1 + ts/views/conversation_view.ts | 17 +++++++---------- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ts/components/conversation/ContactModal.stories.tsx b/ts/components/conversation/ContactModal.stories.tsx index 5704d2b60e9a..8c1e59f4266c 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 d716d0b8442a..31e83bf847f3 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 a9295a450b8a..de95fc97cc21 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 42dfab114f78..a6df2d5fdcc2 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 7b4f5d6ee16f..d4d8b1f9672c 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.