Enable click on draft quotes, fetch groups from contact modal

This commit is contained in:
Scott Nonnenberg 2021-05-21 10:27:28 -07:00 committed by GitHub
parent b878cad625
commit f6bc4dfe25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 10 deletions

View file

@ -36,6 +36,7 @@ const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
removeMember: action('removeMember'), removeMember: action('removeMember'),
showSafetyNumber: action('showSafetyNumber'), showSafetyNumber: action('showSafetyNumber'),
toggleAdmin: action('toggleAdmin'), toggleAdmin: action('toggleAdmin'),
updateSharedGroups: action('updateSharedGroups'),
}); });
story.add('As non-admin', () => { story.add('As non-admin', () => {

View file

@ -21,6 +21,7 @@ export type PropsType = {
removeMember: (conversationId: string) => void; removeMember: (conversationId: string) => void;
showSafetyNumber: (conversationId: string) => void; showSafetyNumber: (conversationId: string) => void;
toggleAdmin: (conversationId: string) => void; toggleAdmin: (conversationId: string) => void;
updateSharedGroups: () => void;
}; };
export const ContactModal = ({ export const ContactModal = ({
@ -34,6 +35,7 @@ export const ContactModal = ({
removeMember, removeMember,
showSafetyNumber, showSafetyNumber,
toggleAdmin, toggleAdmin,
updateSharedGroups,
}: PropsType): ReactPortal | null => { }: PropsType): ReactPortal | null => {
if (!contact) { if (!contact) {
throw new Error('Contact modal opened without a matching 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(() => { React.useEffect(() => {
if (root !== null && closeButtonRef.current) { if (root !== null && closeButtonRef.current) {
closeButtonRef.current.focus(); closeButtonRef.current.focus();

View file

@ -156,6 +156,8 @@ export class ConversationModel extends window.Backbone
lastSuccessfulGroupFetch?: number; lastSuccessfulGroupFetch?: number;
throttledUpdateSharedGroups?: () => Promise<void>;
private cachedLatestGroupCallEraId?: string; private cachedLatestGroupCallEraId?: string;
private cachedIdenticon?: CachedIdenticon; private cachedIdenticon?: CachedIdenticon;
@ -229,6 +231,9 @@ export class ConversationModel extends window.Backbone
this.updateLastMessage.bind(this), this.updateLastMessage.bind(this),
200 200
); );
this.throttledUpdateSharedGroups =
this.throttledUpdateSharedGroups ||
window._.throttle(this.updateSharedGroups.bind(this), FIVE_MINUTES);
this.contactCollection = this.getContactCollection(); this.contactCollection = this.getContactCollection();
this.contactCollection.on( this.contactCollection.on(

View file

@ -20,6 +20,7 @@ export type SmartContactModalProps = {
readonly removeMember: (conversationId: string) => void; readonly removeMember: (conversationId: string) => void;
readonly showSafetyNumber: (conversationId: string) => void; readonly showSafetyNumber: (conversationId: string) => void;
readonly toggleAdmin: (conversationId: string) => void; readonly toggleAdmin: (conversationId: string) => void;
readonly updateSharedGroups: () => void;
}; };
const mapStateToProps = ( const mapStateToProps = (

View file

@ -386,12 +386,6 @@ Whisper.ConversationView = Whisper.View.extend({
this.model.throttledGetProfiles = this.model.throttledGetProfiles =
this.model.throttledGetProfiles || this.model.throttledGetProfiles ||
window._.throttle(this.model.getProfiles.bind(this.model), FIVE_MINUTES); 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 =
this.model.throttledMaybeMigrateV1Group || this.model.throttledMaybeMigrateV1Group ||
window._.throttle( window._.throttle(
@ -3052,6 +3046,12 @@ Whisper.ConversationView = Whisper.View.extend({
resolve: () => this.model.toggleAdmin(conversationId), 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(); const props = message.getPropsForQuote();
this.listenTo(message, 'scroll-to-message', () => {
this.scrollToMessage(message.quotedMessage.id);
});
const contact = this.quotedMessage.getContact(); const contact = this.quotedMessage.getContact();
if (contact) { if (contact) {
this.listenTo(contact, 'change', this.renderQuotedMessage); this.listenTo(contact, 'change', this.renderQuotedMessage);
@ -3642,6 +3638,7 @@ Whisper.ConversationView = Whisper.View.extend({
props: { props: {
...props, ...props,
withContentAbove: true, withContentAbove: true,
onClick: () => this.scrollToMessage(message.quotedMessage.id),
onClose: () => { onClose: () => {
// This can't be the normal 'onClose' because that is always run when this // 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. // view is removed from the DOM, and would clear the draft quote.