Merge branch 'develop' of https://github.com/matrix-org/matrix-react-sdk into t3chguy/dpsah/6785.2
This commit is contained in:
commit
368571bcff
31 changed files with 747 additions and 119 deletions
|
@ -22,6 +22,11 @@ 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";
|
||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
import GroupStore from "./GroupStore";
|
||||
import dis from "../dispatcher/dispatcher";
|
||||
|
||||
interface IState {
|
||||
// nothing of value - we use account data
|
||||
|
@ -43,6 +48,46 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient<IState> {
|
|||
return CommunityPrototypeStore.internalInstance;
|
||||
}
|
||||
|
||||
public getSelectedCommunityId(): string {
|
||||
if (SettingsStore.getValue("feature_communities_v2_prototypes")) {
|
||||
return TagOrderStore.getSelectedTags()[0];
|
||||
}
|
||||
return null; // no selection as far as this function is concerned
|
||||
}
|
||||
|
||||
public getSelectedCommunityName(): string {
|
||||
return CommunityPrototypeStore.instance.getCommunityName(this.getSelectedCommunityId());
|
||||
}
|
||||
|
||||
public getSelectedCommunityGeneralChat(): Room {
|
||||
const communityId = this.getSelectedCommunityId();
|
||||
if (communityId) {
|
||||
return this.getGeneralChat(communityId);
|
||||
}
|
||||
}
|
||||
|
||||
public getCommunityName(communityId: string): string {
|
||||
const profile = FlairStore.getGroupProfileCachedFast(this.matrixClient, communityId);
|
||||
return profile?.name || communityId;
|
||||
}
|
||||
|
||||
public getCommunityProfile(communityId: string): { name?: string, avatarUrl?: string } {
|
||||
return FlairStore.getGroupProfileCachedFast(this.matrixClient, communityId);
|
||||
}
|
||||
|
||||
public getGeneralChat(communityId: string): Room {
|
||||
const rooms = GroupStore.getGroupRooms(communityId)
|
||||
.map(r => MatrixClientPeg.get().getRoom(r.roomId))
|
||||
.filter(r => !!r);
|
||||
let chat = rooms.find(r => {
|
||||
const idState = r.currentState.getStateEvents("im.vector.general_chat", "");
|
||||
if (!idState || idState.getContent()['groupId'] !== communityId) return false;
|
||||
return true;
|
||||
});
|
||||
if (!chat) chat = rooms[0];
|
||||
return chat; // can be null
|
||||
}
|
||||
|
||||
protected async onAction(payload: ActionPayload): Promise<any> {
|
||||
if (!this.matrixClient || !SettingsStore.getValue("feature_communities_v2_prototypes")) {
|
||||
return;
|
||||
|
@ -71,6 +116,15 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient<IState> {
|
|||
if (payload.event_type.startsWith("im.vector.group_info.")) {
|
||||
this.emit(UPDATE_EVENT, payload.event_type.substring("im.vector.group_info.".length));
|
||||
}
|
||||
} else if (payload.action === "select_tag") {
|
||||
// Automatically select the general chat when switching communities
|
||||
const chat = this.getGeneralChat(payload.tag);
|
||||
if (chat) {
|
||||
dis.dispatch({
|
||||
action: 'view_room',
|
||||
room_id: chat.roomId,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -148,6 +148,23 @@ 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} matrixClient The matrix client to use to fetch the profile, if needed.
|
||||
* @param {string} groupId The group ID to get the profile for.
|
||||
* @returns {*} The profile if known, otherwise null.
|
||||
*/
|
||||
getGroupProfileCachedFast(matrixClient, groupId) {
|
||||
if (!matrixClient || !groupId) return null;
|
||||
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];
|
||||
|
|
|
@ -166,25 +166,6 @@ class TagOrderStore extends Store {
|
|||
selectedTags: newTags,
|
||||
});
|
||||
|
||||
if (!allowMultiple && newTags.length === 1) {
|
||||
// We're in prototype behaviour: select the general chat for the community
|
||||
const rooms = GroupStore.getGroupRooms(newTags[0])
|
||||
.map(r => MatrixClientPeg.get().getRoom(r.roomId))
|
||||
.filter(r => !!r);
|
||||
let chat = rooms.find(r => {
|
||||
const idState = r.currentState.getStateEvents("im.vector.general_chat", "");
|
||||
if (!idState || idState.getContent()['groupId'] !== newTags[0]) return false;
|
||||
return true;
|
||||
});
|
||||
if (!chat) chat = rooms[0];
|
||||
if (chat) {
|
||||
dis.dispatch({
|
||||
action: 'view_room',
|
||||
room_id: chat.roomId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Analytics.trackEvent('FilterStore', 'select_tag');
|
||||
}
|
||||
break;
|
||||
|
@ -285,13 +266,6 @@ class TagOrderStore extends Store {
|
|||
getSelectedTags() {
|
||||
return this._state.selectedTags;
|
||||
}
|
||||
|
||||
getSelectedPrototypeTag() {
|
||||
if (SettingsStore.getValue("feature_communities_v2_prototypes")) {
|
||||
return this.getSelectedTags()[0];
|
||||
}
|
||||
return null; // no selection as far as this function is concerned
|
||||
}
|
||||
}
|
||||
|
||||
if (global.singletonTagOrderStore === undefined) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue