Run all selected prototype community logic through one store

This commit is contained in:
Travis Ralston 2020-08-31 10:19:05 -06:00
parent 93d67a6689
commit 724e3f6905
8 changed files with 31 additions and 30 deletions

View file

@ -218,7 +218,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
// way the right panel is structured makes this exceedingly difficult. Instead, we'll
// switch to the general room and open the member list there as it should be in sync
// anyways.
const chat = CommunityPrototypeStore.instance.getGeneralChat(TagOrderStore.getSelectedPrototypeTag());
const chat = CommunityPrototypeStore.instance.getSelectedCommunityGeneralChat();
if (chat) {
dis.dispatch({
action: 'view_room',
@ -239,7 +239,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
ev.preventDefault();
ev.stopPropagation();
showCommunityInviteDialog(TagOrderStore.getSelectedPrototypeTag());
showCommunityInviteDialog(CommunityPrototypeStore.instance.getSelectedCommunityId());
this.setState({contextMenuPosition: null}); // also close the menu
};

View file

@ -25,7 +25,6 @@ import { _t } from '../../../languageHandler';
import {MatrixClientPeg} from '../../../MatrixClientPeg';
import {Key} from "../../../Keyboard";
import {privateShouldBeEncrypted} from "../../../createRoom";
import TagOrderStore from "../../../stores/TagOrderStore";
import {CommunityPrototypeStore} from "../../../stores/CommunityPrototypeStore";
export default createReactClass({
@ -72,8 +71,8 @@ export default createReactClass({
opts.encryption = this.state.isEncrypted;
}
if (TagOrderStore.getSelectedPrototypeTag()) {
opts.associatedWithCommunity = TagOrderStore.getSelectedPrototypeTag();
if (CommunityPrototypeStore.instance.getSelectedCommunityId()) {
opts.associatedWithCommunity = CommunityPrototypeStore.instance.getSelectedCommunityId();
}
return opts;
@ -198,7 +197,7 @@ export default createReactClass({
"Private rooms can be found and joined by invitation only. Public rooms can be " +
"found and joined by anyone.",
)}</p>;
if (TagOrderStore.getSelectedPrototypeTag()) {
if (CommunityPrototypeStore.instance.getSelectedCommunityId()) {
publicPrivateLabel = <p>{_t(
"Private rooms can be found and joined by invitation only. Public rooms can be " +
"found and joined by anyone in this community.",
@ -239,7 +238,7 @@ export default createReactClass({
}
let title = this.state.isPublic ? _t('Create a public room') : _t('Create a private room');
if (TagOrderStore.getSelectedPrototypeTag()) {
if (CommunityPrototypeStore.instance.getSelectedCommunityId()) {
const name = CommunityPrototypeStore.instance.getSelectedCommunityName();
title = _t("Create a room in %(communityName)s", {communityName: name});
}

View file

@ -37,7 +37,6 @@ import {Key} from "../../../Keyboard";
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 {CommunityPrototypeStore} from "../../../stores/CommunityPrototypeStore";
// we have a number of types defined from the Matrix spec which can't reasonably be altered here.
@ -913,7 +912,7 @@ export default class InviteDialog extends React.PureComponent {
_onCommunityInviteClick = (e) => {
this.props.onFinished();
showCommunityInviteDialog(TagOrderStore.getSelectedPrototypeTag());
showCommunityInviteDialog(CommunityPrototypeStore.instance.getSelectedCommunityId());
};
_renderSection(kind: "recents"|"suggestions") {
@ -924,8 +923,8 @@ export default class InviteDialog extends React.PureComponent {
let sectionName = kind === 'recents' ? _t("Recent Conversations") : _t("Suggestions");
let sectionSubname = null;
if (kind === 'suggestions' && TagOrderStore.getSelectedPrototypeTag()) {
const communityName = CommunityPrototypeStore.instance.getCommunityName(TagOrderStore.getSelectedPrototypeTag());
if (kind === 'suggestions' && CommunityPrototypeStore.instance.getSelectedCommunityId()) {
const communityName = CommunityPrototypeStore.instance.getSelectedCommunityName();
sectionSubname = _t("May include members not in %(communityName)s", {communityName});
}
@ -1097,7 +1096,7 @@ export default class InviteDialog extends React.PureComponent {
return <a href={makeUserPermalink(userId)} rel="noreferrer noopener" target="_blank">{userId}</a>;
}},
);
if (TagOrderStore.getSelectedPrototypeTag()) {
if (CommunityPrototypeStore.instance.getSelectedCommunityId()) {
const communityName = CommunityPrototypeStore.instance.getSelectedCommunityName();
helpText = _t(
"Start a conversation with someone using their name, username (like <userId/>) or email address. " +

View file

@ -27,7 +27,6 @@ import rate_limited_func from "../../../ratelimitedfunc";
import {MatrixClientPeg} from "../../../MatrixClientPeg";
import * as sdk from "../../../index";
import CallHandler from "../../../CallHandler";
import TagOrderStore from "../../../stores/TagOrderStore";
import {CommunityPrototypeStore} from "../../../stores/CommunityPrototypeStore";
const INITIAL_LOAD_NUM_MEMBERS = 30;
@ -467,12 +466,9 @@ export default createReactClass({
}
let inviteButtonText = _t("Invite to this room");
const communityId = TagOrderStore.getSelectedPrototypeTag();
if (communityId) {
const chat = CommunityPrototypeStore.instance.getGeneralChat(communityId);
if (chat && chat.roomId === this.props.roomId) {
inviteButtonText = _t("Invite to this community");
}
const chat = CommunityPrototypeStore.instance.getSelectedCommunityGeneralChat();
if (chat && chat.roomId === this.props.roomId) {
inviteButtonText = _t("Invite to this community");
}
const AccessibleButton = sdk.getComponent("elements.AccessibleButton");

View file

@ -45,7 +45,7 @@ import { arrayFastClone, arrayHasDiff } from "../../../utils/arrays";
import { objectShallowClone, objectWithOnly } from "../../../utils/objects";
import { IconizedContextMenuOption, IconizedContextMenuOptionList } from "../context_menus/IconizedContextMenu";
import AccessibleButton from "../elements/AccessibleButton";
import TagOrderStore from "../../../stores/TagOrderStore";
import { CommunityPrototypeStore } from "../../../stores/CommunityPrototypeStore";
interface IProps {
onKeyDown: (ev: React.KeyboardEvent) => void;
@ -130,7 +130,7 @@ const TAG_AESTHETICS: {
}}
/>
<IconizedContextMenuOption
label={TagOrderStore.getSelectedPrototypeTag()
label={CommunityPrototypeStore.instance.getSelectedCommunityId()
? _t("Explore community rooms")
: _t("Explore public rooms")}
iconClassName="mx_RoomList_iconExplore"

View file

@ -1062,6 +1062,7 @@
"and %(count)s others...|other": "and %(count)s others...",
"and %(count)s others...|one": "and one other...",
"Invite to this room": "Invite to this room",
"Invite to this community": "Invite to this community",
"Invited": "Invited",
"Filter room members": "Filter room members",
"%(userName)s (power %(powerLevelNumber)s)": "%(userName)s (power %(powerLevelNumber)s)",
@ -1424,7 +1425,6 @@
"Submit logs": "Submit logs",
"Failed to load group members": "Failed to load group members",
"Filter community members": "Filter community members",
"Invite to this community": "Invite to this community",
"Are you sure you want to remove '%(roomName)s' from %(groupId)s?": "Are you sure you want to remove '%(roomName)s' from %(groupId)s?",
"Removing a room from the community will also remove it from the community page.": "Removing a room from the community will also remove it from the community page.",
"Failed to remove room from community": "Failed to remove room from community",

View file

@ -47,8 +47,22 @@ 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(TagOrderStore.getSelectedPrototypeTag());
return CommunityPrototypeStore.instance.getCommunityName(this.getSelectedCommunityId());
}
public getSelectedCommunityGeneralChat(): Room {
const communityId = this.getSelectedCommunityId();
if (communityId) {
return this.getGeneralChat(communityId);
}
}
public getCommunityName(communityId: string): string {

View file

@ -286,13 +286,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) {