Use FlairStore's cache for group naming

Turns out GroupStore doesn't really know much.
pull/21833/head
Travis Ralston 2020-08-28 14:56:59 -06:00
parent e68c4efd0b
commit 90d9d7128d
5 changed files with 34 additions and 10 deletions

View File

@ -76,8 +76,8 @@ export function showCommunityInviteDialog(communityId) {
});
if (!chat) chat = rooms[0];
if (chat) {
const summary = GroupStore.getSummary(communityId);
showCommunityRoomInviteDialog(chat.roomId, summary?.profile?.name || communityId);
const name = CommunityPrototypeInviteDialog.instance.getCommunityName(communityId);
showCommunityRoomInviteDialog(chat.roomId, name);
} else {
throw new Error("Failed to locate appropriate room to start an invite in");
}

View File

@ -26,7 +26,7 @@ import {MatrixClientPeg} from '../../../MatrixClientPeg';
import {Key} from "../../../Keyboard";
import {privateShouldBeEncrypted} from "../../../createRoom";
import TagOrderStore from "../../../stores/TagOrderStore";
import GroupStore from "../../../stores/GroupStore";
import {CommunityPrototypeStore} from "../../../stores/CommunityPrototypeStore";
export default createReactClass({
displayName: 'CreateRoomDialog',
@ -240,8 +240,7 @@ export default createReactClass({
let title = this.state.isPublic ? _t('Create a public room') : _t('Create a private room');
if (TagOrderStore.getSelectedPrototypeTag()) {
const summary = GroupStore.getSummary(TagOrderStore.getSelectedPrototypeTag());
const name = summary?.profile?.name || TagOrderStore.getSelectedPrototypeTag();
const name = CommunityPrototypeStore.instance.getSelectedCommunityName();
title = _t("Create a room in %(communityName)s", {communityName: name});
}
return (

View File

@ -38,7 +38,7 @@ import {Action} from "../../../dispatcher/actions";
import {DefaultTagID} from "../../../stores/room-list/models";
import RoomListStore from "../../../stores/room-list/RoomListStore";
import TagOrderStore from "../../../stores/TagOrderStore";
import GroupStore from "../../../stores/GroupStore";
import {CommunityPrototypeStore} from "../../../stores/CommunityPrototypeStore";
// we have a number of types defined from the Matrix spec which can't reasonably be altered here.
/* eslint-disable camelcase */
@ -925,8 +925,7 @@ export default class InviteDialog extends React.PureComponent {
let sectionSubname = null;
if (kind === 'suggestions' && TagOrderStore.getSelectedPrototypeTag()) {
const summary = GroupStore.getSummary(TagOrderStore.getSelectedPrototypeTag());
const communityName = summary?.profile?.name || TagOrderStore.getSelectedPrototypeTag();
const communityName = CommunityPrototypeStore.instance.getCommunityName(TagOrderStore.getSelectedPrototypeTag());
sectionSubname = _t("May include members not in %(communityName)s", {communityName});
}
@ -1099,8 +1098,7 @@ export default class InviteDialog extends React.PureComponent {
}},
);
if (TagOrderStore.getSelectedPrototypeTag()) {
const communityId = TagOrderStore.getSelectedPrototypeTag();
const communityName = GroupStore.getSummary(communityId)?.profile?.name || communityId;
const communityName = CommunityPrototypeStore.instance.getSelectedCommunityName();
helpText = _t(
"Start a conversation with someone using their name, username (like <userId/>) or email address. " +
"This won't invite them to %(communityName)s. To invite someone to %(communityName)s, click " +

View File

@ -22,6 +22,8 @@ import { EffectiveMembership, getEffectiveMembership } from "../utils/membership
import SettingsStore from "../settings/SettingsStore";
import * as utils from "matrix-js-sdk/src/utils";
import { UPDATE_EVENT } from "./AsyncStore";
import FlairStore from "./FlairStore";
import TagOrderStore from "./TagOrderStore";
interface IState {
// nothing of value - we use account data
@ -43,6 +45,15 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient<IState> {
return CommunityPrototypeStore.internalInstance;
}
public getSelectedCommunityName(): string {
return CommunityPrototypeStore.instance.getCommunityName(TagOrderStore.getSelectedPrototypeTag());
}
public getCommunityName(communityId: string): string {
const profile = FlairStore.getGroupProfileCachedFast(this.matrixClient, communityId);
return profile?.name || communityId;
}
protected async onAction(payload: ActionPayload): Promise<any> {
if (!this.matrixClient || !SettingsStore.getValue("feature_communities_v2_prototypes")) {
return;

View File

@ -148,6 +148,22 @@ class FlairStore extends EventEmitter {
});
}
/**
* Gets the profile for the given group if known, otherwise returns null.
* This triggers `getGroupProfileCached` if needed, though the result of the
* call will not be returned by this function.
* @param matrixClient The matrix client to use to fetch the profile, if needed.
* @param groupId The group ID to get the profile for.
* @returns The profile if known, otherwise null.
*/
getGroupProfileCachedFast(matrixClient, groupId) {
if (this._groupProfiles[groupId]) {
return this._groupProfiles[groupId];
}
this.getGroupProfileCached(matrixClient, groupId);
return null;
}
async getGroupProfileCached(matrixClient, groupId) {
if (this._groupProfiles[groupId]) {
return this._groupProfiles[groupId];