Use FlairStore's cache for group naming

Turns out GroupStore doesn't really know much.
This commit is contained in:
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

@ -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];