Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into t3chguy/feat/modal-widgets
This commit is contained in:
commit
fbbba75f81
54 changed files with 1894 additions and 337 deletions
|
@ -24,9 +24,9 @@ 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";
|
||||
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
|
||||
|
||||
interface IState {
|
||||
// nothing of value - we use account data
|
||||
|
@ -77,7 +77,7 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient<IState> {
|
|||
|
||||
public getGeneralChat(communityId: string): Room {
|
||||
const rooms = GroupStore.getGroupRooms(communityId)
|
||||
.map(r => MatrixClientPeg.get().getRoom(r.roomId))
|
||||
.map(r => this.matrixClient.getRoom(r.roomId))
|
||||
.filter(r => !!r);
|
||||
let chat = rooms.find(r => {
|
||||
const idState = r.currentState.getStateEvents("im.vector.general_chat", "");
|
||||
|
@ -88,6 +88,26 @@ export class CommunityPrototypeStore extends AsyncStoreWithClient<IState> {
|
|||
return chat; // can be null
|
||||
}
|
||||
|
||||
public isAdminOf(communityId: string): boolean {
|
||||
const members = GroupStore.getGroupMembers(communityId);
|
||||
const myMember = members.find(m => m.userId === this.matrixClient.getUserId());
|
||||
return myMember?.isPrivileged;
|
||||
}
|
||||
|
||||
public canInviteTo(communityId: string): boolean {
|
||||
const generalChat = this.getGeneralChat(communityId);
|
||||
if (!generalChat) return this.isAdminOf(communityId);
|
||||
|
||||
const myMember = generalChat.getMember(this.matrixClient.getUserId());
|
||||
if (!myMember) return this.isAdminOf(communityId);
|
||||
|
||||
const pl = generalChat.currentState.getStateEvents("m.room.power_levels", "");
|
||||
if (!pl) return this.isAdminOf(communityId);
|
||||
|
||||
const invitePl = isNullOrUndefined(pl.invite) ? 50 : Number(pl.invite);
|
||||
return invitePl <= myMember.powerLevel;
|
||||
}
|
||||
|
||||
protected async onAction(payload: ActionPayload): Promise<any> {
|
||||
if (!this.matrixClient || !SettingsStore.getValue("feature_communities_v2_prototypes")) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue