Merge pull request #12336 from matrix-org/andybalaam/stas-demydiuk-membership-type3
Introduce Membership type (take 2)
This commit is contained in:
commit
8f22550f19
113 changed files with 711 additions and 517 deletions
|
@ -15,9 +15,9 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import jsQR from "jsqr";
|
||||
import { type Preset, type Visibility } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import type { JSHandle, Locator, Page } from "@playwright/test";
|
||||
import type { Preset, Visibility } from "matrix-js-sdk/src/matrix";
|
||||
import type { VerificationRequest, Verifier } from "matrix-js-sdk/src/crypto-api";
|
||||
import { test, expect } from "../../element-web-test";
|
||||
import {
|
||||
|
|
|
@ -16,7 +16,8 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import type { Visibility } from "matrix-js-sdk/src/matrix";
|
||||
import { type Visibility } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { test, expect } from "../../element-web-test";
|
||||
import { waitForRoom } from "../utils";
|
||||
import { Filter } from "../../pages/Spotlight";
|
||||
|
|
|
@ -16,8 +16,8 @@ limitations under the License.
|
|||
|
||||
import { JSHandle, Page } from "@playwright/test";
|
||||
import { uniqueId } from "lodash";
|
||||
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import type { Logger } from "matrix-js-sdk/src/logger";
|
||||
import type { SecretStorageKeyDescription } from "matrix-js-sdk/src/secret-storage";
|
||||
import type { Credentials, HomeserverInstance } from "../plugins/homeserver";
|
||||
|
|
|
@ -292,6 +292,7 @@ Response:
|
|||
*/
|
||||
|
||||
import { IContent, MatrixEvent, IEvent, StateEvents } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import { MatrixClientPeg } from "./MatrixClientPeg";
|
||||
|
@ -357,7 +358,10 @@ function inviteUser(event: MessageEvent<any>, roomId: string, userId: string): v
|
|||
if (room) {
|
||||
// if they are already invited or joined we can resolve immediately.
|
||||
const member = room.getMember(userId);
|
||||
if (member && ["join", "invite"].includes(member.membership!)) {
|
||||
if (
|
||||
member &&
|
||||
([KnownMembership.Join, KnownMembership.Invite] as Array<string | undefined>).includes(member.membership)
|
||||
) {
|
||||
sendResponse(event, {
|
||||
success: true,
|
||||
});
|
||||
|
@ -669,7 +673,7 @@ function canSendEvent(event: MessageEvent<any>, roomId: string): void {
|
|||
sendError(event, _t("scalar|error_room_unknown"));
|
||||
return;
|
||||
}
|
||||
if (room.getMyMembership() !== "join") {
|
||||
if (room.getMyMembership() !== KnownMembership.Join) {
|
||||
sendError(event, _t("scalar|error_membership"));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ limitations under the License.
|
|||
import * as React from "react";
|
||||
import { ContentHelpers, Direction, EventType, IContent, MRoomTopicEventContent, User } from "matrix-js-sdk/src/matrix";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { RoomMemberEventContent } from "matrix-js-sdk/src/types";
|
||||
import { KnownMembership, RoomMemberEventContent } from "matrix-js-sdk/src/types";
|
||||
|
||||
import dis from "./dispatcher/dispatcher";
|
||||
import { _t, _td, UserFriendlyError } from "./languageHandler";
|
||||
|
@ -242,7 +242,7 @@ export const Commands = [
|
|||
if (args) {
|
||||
const ev = cli.getRoom(roomId)?.currentState.getStateEvents(EventType.RoomMember, cli.getSafeUserId());
|
||||
const content: RoomMemberEventContent = {
|
||||
...(ev ? ev.getContent() : { membership: "join" }),
|
||||
...(ev ? ev.getContent() : { membership: KnownMembership.Join }),
|
||||
displayname: args,
|
||||
};
|
||||
return success(cli.sendStateEvent(roomId, EventType.RoomMember, content, cli.getSafeUserId()));
|
||||
|
@ -292,7 +292,7 @@ export const Commands = [
|
|||
if (!url) return;
|
||||
const ev = room?.currentState.getStateEvents(EventType.RoomMember, userId);
|
||||
const content: RoomMemberEventContent = {
|
||||
...(ev ? ev.getContent() : { membership: "join" }),
|
||||
...(ev ? ev.getContent() : { membership: KnownMembership.Join }),
|
||||
avatar_url: url,
|
||||
};
|
||||
return cli.sendStateEvent(roomId, EventType.RoomMember, content, userId);
|
||||
|
|
|
@ -26,6 +26,7 @@ import {
|
|||
M_POLL_START,
|
||||
M_POLL_END,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { removeDirectionOverrideChars } from "matrix-js-sdk/src/utils";
|
||||
import { PollStartEvent } from "matrix-js-sdk/src/extensible_events_v1/PollStartEvent";
|
||||
|
@ -122,7 +123,7 @@ function textForMemberEvent(
|
|||
const reason = content.reason;
|
||||
|
||||
switch (content.membership) {
|
||||
case "invite": {
|
||||
case KnownMembership.Invite: {
|
||||
const threePidContent = content.third_party_invite;
|
||||
if (threePidContent) {
|
||||
if (threePidContent.display_name) {
|
||||
|
@ -138,13 +139,13 @@ function textForMemberEvent(
|
|||
return () => _t("timeline|m.room.member|invite", { senderName, targetName });
|
||||
}
|
||||
}
|
||||
case "ban":
|
||||
case KnownMembership.Ban:
|
||||
return () =>
|
||||
reason
|
||||
? _t("timeline|m.room.member|ban_reason", { senderName, targetName, reason })
|
||||
: _t("timeline|m.room.member|ban", { senderName, targetName });
|
||||
case "join":
|
||||
if (prevContent && prevContent.membership === "join") {
|
||||
case KnownMembership.Join:
|
||||
if (prevContent && prevContent.membership === KnownMembership.Join) {
|
||||
const modDisplayname = getModification(prevContent.displayname, content.displayname);
|
||||
const modAvatarUrl = getModification(prevContent.avatar_url, content.avatar_url);
|
||||
|
||||
|
@ -194,9 +195,9 @@ function textForMemberEvent(
|
|||
if (!ev.target) logger.warn("Join message has no target! -- " + ev.getContent().state_key);
|
||||
return () => _t("timeline|m.room.member|join", { targetName });
|
||||
}
|
||||
case "leave":
|
||||
case KnownMembership.Leave:
|
||||
if (ev.getSender() === ev.getStateKey()) {
|
||||
if (prevContent.membership === "invite") {
|
||||
if (prevContent.membership === KnownMembership.Invite) {
|
||||
return () => _t("timeline|m.room.member|reject_invite", { targetName });
|
||||
} else {
|
||||
return () =>
|
||||
|
@ -204,9 +205,9 @@ function textForMemberEvent(
|
|||
? _t("timeline|m.room.member|left_reason", { targetName, reason })
|
||||
: _t("timeline|m.room.member|left", { targetName });
|
||||
}
|
||||
} else if (prevContent.membership === "ban") {
|
||||
} else if (prevContent.membership === KnownMembership.Ban) {
|
||||
return () => _t("timeline|m.room.member|unban", { senderName, targetName });
|
||||
} else if (prevContent.membership === "invite") {
|
||||
} else if (prevContent.membership === KnownMembership.Invite) {
|
||||
return () =>
|
||||
reason
|
||||
? _t("timeline|m.room.member|withdrew_invite_reason", {
|
||||
|
@ -215,7 +216,7 @@ function textForMemberEvent(
|
|||
reason,
|
||||
})
|
||||
: _t("timeline|m.room.member|withdrew_invite", { senderName, targetName });
|
||||
} else if (prevContent.membership === "join") {
|
||||
} else if (prevContent.membership === KnownMembership.Join) {
|
||||
return () =>
|
||||
reason
|
||||
? _t("timeline|m.room.member|kick_reason", {
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { Room, EventType } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import { ensureVirtualRoomExists } from "./createRoom";
|
||||
|
@ -95,7 +96,7 @@ export default class VoipUserMapper {
|
|||
if (!virtualRoomEvent || !virtualRoomEvent.getContent()) return null;
|
||||
const nativeRoomID = virtualRoomEvent.getContent()["native_room"];
|
||||
const nativeRoom = cli.getRoom(nativeRoomID);
|
||||
if (!nativeRoom || nativeRoom.getMyMembership() !== "join") return null;
|
||||
if (!nativeRoom || nativeRoom.getMyMembership() !== KnownMembership.Join) return null;
|
||||
|
||||
return nativeRoomID;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import {
|
|||
RoomStateEvent,
|
||||
IRoomTimelineData,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
import QueryMatcher from "./QueryMatcher";
|
||||
|
@ -159,7 +160,7 @@ export default class UserProvider extends AutocompleteProvider {
|
|||
|
||||
const currentUserId = MatrixClientPeg.safeGet().credentials.userId;
|
||||
this.users = this.room.getJoinedMembers().filter(({ userId }) => userId !== currentUserId);
|
||||
this.users = this.users.concat(this.room.getMembersWithMembership("invite"));
|
||||
this.users = this.users.concat(this.room.getMembersWithMembership(KnownMembership.Invite));
|
||||
|
||||
this.users = sortBy(this.users, (member) => 1e20 - lastSpoken[member.userId] || 1e20);
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ import {
|
|||
ISearchResults,
|
||||
THREAD_RELATION_TYPE,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { CallState, MatrixCall } from "matrix-js-sdk/src/webrtc/call";
|
||||
import { throttle } from "lodash";
|
||||
|
@ -1454,7 +1455,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
private async loadMembersIfJoined(room: Room): Promise<void> {
|
||||
// lazy load members if enabled
|
||||
if (this.context.client?.hasLazyLoadMembersEnabled()) {
|
||||
if (room && room.getMyMembership() === "join") {
|
||||
if (room && room.getMyMembership() === KnownMembership.Join) {
|
||||
try {
|
||||
await room.loadMembersIfNeeded();
|
||||
if (!this.unmounted) {
|
||||
|
@ -1588,7 +1589,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
if (room && this.context.client) {
|
||||
const me = this.context.client.getSafeUserId();
|
||||
const canReact =
|
||||
room.getMyMembership() === "join" && room.currentState.maySendEvent(EventType.Reaction, me);
|
||||
room.getMyMembership() === KnownMembership.Join &&
|
||||
room.currentState.maySendEvent(EventType.Reaction, me);
|
||||
const canSendMessages = room.maySendMessage();
|
||||
const canSelfRedact = room.currentState.maySendEvent(EventType.RoomRedaction, me);
|
||||
|
||||
|
@ -1622,10 +1624,10 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
|
||||
private updateDMState(): void {
|
||||
const room = this.state.room;
|
||||
if (room?.getMyMembership() !== "join") {
|
||||
if (room?.getMyMembership() != KnownMembership.Join) {
|
||||
return;
|
||||
}
|
||||
const dmInviter = room.getDMInviter();
|
||||
const dmInviter = room?.getDMInviter();
|
||||
if (dmInviter) {
|
||||
Rooms.setDMRoom(room.client, room.roomId, dmInviter);
|
||||
}
|
||||
|
@ -1662,7 +1664,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
action: Action.JoinRoom,
|
||||
roomId,
|
||||
opts: { inviteSignUrl: signUrl },
|
||||
metricsTrigger: this.state.room?.getMyMembership() === "invite" ? "Invite" : "RoomPreview",
|
||||
metricsTrigger:
|
||||
this.state.room?.getMyMembership() === KnownMembership.Invite ? "Invite" : "RoomPreview",
|
||||
canAskToJoin: this.state.canAskToJoin,
|
||||
});
|
||||
}
|
||||
|
@ -2183,7 +2186,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
const myMembership = this.state.room.getMyMembership();
|
||||
if (
|
||||
isVideoRoom(this.state.room) &&
|
||||
!(SettingsStore.getValue("feature_video_rooms") && myMembership === "join")
|
||||
!(SettingsStore.getValue("feature_video_rooms") && myMembership === KnownMembership.Join)
|
||||
) {
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
|
@ -2200,7 +2203,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
}
|
||||
|
||||
// SpaceRoomView handles invites itself
|
||||
if (myMembership === "invite" && !this.state.room.isSpaceRoom()) {
|
||||
if (myMembership === KnownMembership.Invite && !this.state.room.isSpaceRoom()) {
|
||||
if (this.state.joining || this.state.rejecting) {
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
|
@ -2247,16 +2250,19 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
}
|
||||
}
|
||||
|
||||
if (this.state.canAskToJoin && ["knock", "leave"].includes(myMembership)) {
|
||||
if (
|
||||
this.state.canAskToJoin &&
|
||||
([KnownMembership.Knock, KnownMembership.Leave] as Array<string>).includes(myMembership)
|
||||
) {
|
||||
return (
|
||||
<div className="mx_RoomView" data-room-header={roomHeaderType}>
|
||||
<ErrorBoundary>
|
||||
<RoomPreviewBar
|
||||
onJoinClick={this.onJoinButtonClicked}
|
||||
room={this.state.room}
|
||||
canAskToJoinAndMembershipIsLeave={myMembership === "leave"}
|
||||
canAskToJoinAndMembershipIsLeave={myMembership === KnownMembership.Leave}
|
||||
promptAskToJoin={this.state.promptAskToJoin}
|
||||
knocked={myMembership === "knock"}
|
||||
knocked={myMembership === KnownMembership.Knock}
|
||||
onSubmitAskToJoin={this.onSubmitAskToJoin}
|
||||
onCancelAskToJoin={this.onCancelAskToJoin}
|
||||
onForgetClick={this.onForgetClick}
|
||||
|
@ -2288,7 +2294,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
statusBar = (
|
||||
<RoomStatusBar
|
||||
room={this.state.room}
|
||||
isPeeking={myMembership !== "join"}
|
||||
isPeeking={myMembership !== KnownMembership.Join}
|
||||
onInviteClick={this.onInviteClick}
|
||||
onVisible={this.onStatusBarVisible}
|
||||
onHidden={this.onStatusBarHidden}
|
||||
|
@ -2332,7 +2338,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
);
|
||||
} else if (showRoomUpgradeBar) {
|
||||
aux = <RoomUpgradeWarningBar room={this.state.room} />;
|
||||
} else if (myMembership !== "join") {
|
||||
} else if (myMembership !== KnownMembership.Join) {
|
||||
// We do have a room object for this room, but we're not currently in it.
|
||||
// We may have a 3rd party invite to it.
|
||||
let inviterName: string | undefined;
|
||||
|
@ -2406,7 +2412,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
let messageComposer;
|
||||
const showComposer =
|
||||
// joined and not showing search results
|
||||
myMembership === "join" && !this.state.search;
|
||||
myMembership === KnownMembership.Join && !this.state.search;
|
||||
if (showComposer) {
|
||||
messageComposer = (
|
||||
<MessageComposer
|
||||
|
@ -2603,7 +2609,9 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
|
||||
const myMember = this.state.room!.getMember(this.context.client!.getSafeUserId());
|
||||
const showForgetButton =
|
||||
!this.context.client.isGuest() && (["leave", "ban"].includes(myMembership) || myMember?.isKicked());
|
||||
!this.context.client.isGuest() &&
|
||||
(([KnownMembership.Leave, KnownMembership.Ban] as Array<string>).includes(myMembership) ||
|
||||
myMember?.isKicked());
|
||||
|
||||
return (
|
||||
<RoomContext.Provider value={this.state}>
|
||||
|
@ -2640,7 +2648,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
|||
room={this.state.room}
|
||||
searchInfo={this.state.search}
|
||||
oobData={this.props.oobData}
|
||||
inRoom={myMembership === "join"}
|
||||
inRoom={myMembership === KnownMembership.Join}
|
||||
onSearchClick={onSearchClick}
|
||||
onInviteClick={onInviteClick}
|
||||
onForgetClick={showForgetButton ? onForgetClick : null}
|
||||
|
|
|
@ -46,7 +46,7 @@ import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy";
|
|||
import classNames from "classnames";
|
||||
import { sortBy, uniqBy } from "lodash";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { SpaceChildEventContent } from "matrix-js-sdk/src/types";
|
||||
import { KnownMembership, SpaceChildEventContent } from "matrix-js-sdk/src/types";
|
||||
|
||||
import defaultDispatcher from "../../dispatcher/dispatcher";
|
||||
import { _t } from "../../languageHandler";
|
||||
|
@ -113,7 +113,7 @@ const Tile: React.FC<ITileProps> = ({
|
|||
const cli = useContext(MatrixClientContext);
|
||||
const joinedRoom = useTypedEventEmitterState(cli, ClientEvent.Room, () => {
|
||||
const cliRoom = cli?.getRoom(room.room_id);
|
||||
return cliRoom?.getMyMembership() === "join" ? cliRoom : undefined;
|
||||
return cliRoom?.getMyMembership() === KnownMembership.Join ? cliRoom : undefined;
|
||||
});
|
||||
const joinedRoomName = useTypedEventEmitterState(joinedRoom, RoomEvent.Name, (room) => room?.name);
|
||||
const name =
|
||||
|
@ -829,7 +829,7 @@ const SpaceHierarchy: React.FC<IProps> = ({ space, initialText = "", showRoom, a
|
|||
content = <Spinner />;
|
||||
} else {
|
||||
const hasPermissions =
|
||||
space?.getMyMembership() === "join" &&
|
||||
space?.getMyMembership() === KnownMembership.Join &&
|
||||
space.currentState.maySendStateEvent(EventType.SpaceChild, cli.getSafeUserId());
|
||||
|
||||
const root = hierarchy.roomMap.get(space.roomId);
|
||||
|
@ -847,7 +847,7 @@ const SpaceHierarchy: React.FC<IProps> = ({ space, initialText = "", showRoom, a
|
|||
onViewRoomClick={(roomId, roomType) => showRoom(cli, hierarchy, roomId, roomType)}
|
||||
onJoinRoomClick={async (roomId, parents) => {
|
||||
for (const parent of parents) {
|
||||
if (cli.getRoom(parent)?.getMyMembership() !== "join") {
|
||||
if (cli.getRoom(parent)?.getMyMembership() !== KnownMembership.Join) {
|
||||
await joinRoom(cli, hierarchy, parent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { EventType, RoomType, JoinRule, Preset, Room, RoomEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import React, { useCallback, useContext, useRef, useState } from "react";
|
||||
|
||||
|
@ -237,7 +238,7 @@ const SpaceLanding: React.FC<{ space: Room }> = ({ space }) => {
|
|||
}
|
||||
|
||||
const hasAddRoomPermissions =
|
||||
myMembership === "join" && space.currentState.maySendStateEvent(EventType.SpaceChild, userId);
|
||||
myMembership === KnownMembership.Join && space.currentState.maySendStateEvent(EventType.SpaceChild, userId);
|
||||
|
||||
let addRoomButton;
|
||||
if (hasAddRoomPermissions) {
|
||||
|
@ -678,7 +679,7 @@ export default class SpaceRoomView extends React.PureComponent<IProps, IState> {
|
|||
private renderBody(): JSX.Element {
|
||||
switch (this.state.phase) {
|
||||
case Phase.Landing:
|
||||
if (this.state.myMembership === "join") {
|
||||
if (this.state.myMembership === KnownMembership.Join) {
|
||||
return <SpaceLanding space={this.props.space} />;
|
||||
} else {
|
||||
return (
|
||||
|
|
|
@ -39,6 +39,7 @@ import {
|
|||
ThreadEvent,
|
||||
ReceiptType,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership, Membership } from "matrix-js-sdk/src/types";
|
||||
import { debounce, findLastIndex, throttle } from "lodash";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
|
@ -1824,7 +1825,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
|||
// that the event belongs to, and traversing the timeline looking for
|
||||
// that event, while keeping track of the user's membership
|
||||
let i = events.length - 1;
|
||||
let userMembership = "leave";
|
||||
let userMembership: Membership = KnownMembership.Leave;
|
||||
for (; i >= 0; i--) {
|
||||
const timeline = this.props.timelineSet.getTimelineForEvent(events[i].getId()!);
|
||||
if (!timeline) {
|
||||
|
@ -1837,14 +1838,15 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
|||
continue;
|
||||
}
|
||||
|
||||
userMembership = timeline.getState(EventTimeline.FORWARDS)?.getMember(userId)?.membership ?? "leave";
|
||||
userMembership =
|
||||
timeline.getState(EventTimeline.FORWARDS)?.getMember(userId)?.membership ?? KnownMembership.Leave;
|
||||
const timelineEvents = timeline.getEvents();
|
||||
for (let j = timelineEvents.length - 1; j >= 0; j--) {
|
||||
const event = timelineEvents[j];
|
||||
if (event.getId() === events[i].getId()) {
|
||||
break;
|
||||
} else if (event.getStateKey() === userId && event.getType() === EventType.RoomMember) {
|
||||
userMembership = event.getPrevContent().membership || "leave";
|
||||
userMembership = event.getPrevContent().membership || KnownMembership.Leave;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -1855,8 +1857,11 @@ class TimelinePanel extends React.Component<IProps, IState> {
|
|||
for (; i >= 0; i--) {
|
||||
const event = events[i];
|
||||
if (event.getStateKey() === userId && event.getType() === EventType.RoomMember) {
|
||||
userMembership = event.getPrevContent().membership || "leave";
|
||||
} else if (userMembership === "leave" && (event.isDecryptionFailure() || event.isBeingDecrypted())) {
|
||||
userMembership = event.getPrevContent().membership || KnownMembership.Leave;
|
||||
} else if (
|
||||
userMembership === KnownMembership.Leave &&
|
||||
(event.isDecryptionFailure() || event.isBeingDecrypted())
|
||||
) {
|
||||
// reached an undecryptable message when the user wasn't in the room -- don't try to load any more
|
||||
// Note: for now, we assume that events that are being decrypted are
|
||||
// not decryptable - we will be called once more when it is decrypted.
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import React, { ReactNode } from "react";
|
||||
import { EventType, M_BEACON_INFO, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { BaseGrouper } from "./BaseGrouper";
|
||||
import MessagePanel, { WrappedEvent } from "../MessagePanel";
|
||||
|
@ -48,7 +49,8 @@ export class CreationGrouper extends BaseGrouper {
|
|||
const eventType = event.getType();
|
||||
if (
|
||||
eventType === EventType.RoomMember &&
|
||||
(event.getStateKey() !== createEvent.getSender() || event.getContent()["membership"] !== "join")
|
||||
(event.getStateKey() !== createEvent.getSender() ||
|
||||
event.getContent()["membership"] !== KnownMembership.Join)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import React, { useContext } from "react";
|
||||
import { Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { IProps as IContextMenuProps } from "../../structures/ContextMenu";
|
||||
import IconizedContextMenu, {
|
||||
|
@ -144,7 +145,7 @@ const RoomContextMenu: React.FC<IProps> = ({ room, onFinished, ...props }) => {
|
|||
let favouriteOption: JSX.Element | undefined;
|
||||
let lowPriorityOption: JSX.Element | undefined;
|
||||
let notificationOption: JSX.Element | undefined;
|
||||
if (room.getMyMembership() === "join") {
|
||||
if (room.getMyMembership() === KnownMembership.Join) {
|
||||
const isFavorite = roomTags.includes(DefaultTagID.Favourite);
|
||||
favouriteOption = (
|
||||
<IconizedContextMenuCheckbox
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
import React, { ReactElement, ReactNode, useContext, useMemo, useRef, useState } from "react";
|
||||
import classNames from "classnames";
|
||||
import { Room, EventType } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { sleep } from "matrix-js-sdk/src/utils";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
|
@ -140,7 +141,9 @@ export const AddExistingToSpace: React.FC<IAddExistingToSpaceProps> = ({
|
|||
const msc3946ProcessDynamicPredecessor = useSettingValue<boolean>("feature_dynamic_room_predecessors");
|
||||
const visibleRooms = useMemo(
|
||||
() =>
|
||||
cli?.getVisibleRooms(msc3946ProcessDynamicPredecessor).filter((r) => r.getMyMembership() === "join") ?? [],
|
||||
cli
|
||||
?.getVisibleRooms(msc3946ProcessDynamicPredecessor)
|
||||
.filter((r) => r.getMyMembership() === KnownMembership.Join) ?? [],
|
||||
[cli, msc3946ProcessDynamicPredecessor],
|
||||
);
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import {
|
|||
M_TIMESTAMP,
|
||||
M_BEACON,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { _t } from "../../../languageHandler";
|
||||
import dis from "../../../dispatcher/dispatcher";
|
||||
|
@ -267,7 +268,7 @@ const ForwardDialog: React.FC<IProps> = ({ matrixClient: cli, event, permalinkCr
|
|||
sortRooms(
|
||||
cli
|
||||
.getVisibleRooms(msc3946DynamicRoomPredecessors)
|
||||
.filter((room) => room.getMyMembership() === "join" && !room.isSpaceRoom()),
|
||||
.filter((room) => room.getMyMembership() === KnownMembership.Join && !room.isSpaceRoom()),
|
||||
),
|
||||
[cli, msc3946DynamicRoomPredecessors],
|
||||
);
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
import React, { createRef, ReactNode, SyntheticEvent } from "react";
|
||||
import classNames from "classnames";
|
||||
import { RoomMember, Room, MatrixError, EventType } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { MatrixCall } from "matrix-js-sdk/src/webrtc/call";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { uniqBy } from "lodash";
|
||||
|
@ -372,10 +373,10 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
|
|||
const room = MatrixClientPeg.safeGet().getRoom(props.roomId);
|
||||
const isFederated = room?.currentState.getStateEvents(EventType.RoomCreate, "")?.getContent()["m.federate"];
|
||||
if (!room) throw new Error("Room ID given to InviteDialog does not look like a room");
|
||||
room.getMembersWithMembership("invite").forEach((m) => excludedIds.add(m.userId));
|
||||
room.getMembersWithMembership("join").forEach((m) => excludedIds.add(m.userId));
|
||||
room.getMembersWithMembership(KnownMembership.Invite).forEach((m) => excludedIds.add(m.userId));
|
||||
room.getMembersWithMembership(KnownMembership.Join).forEach((m) => excludedIds.add(m.userId));
|
||||
// add banned users, so we don't try to invite them
|
||||
room.getMembersWithMembership("ban").forEach((m) => excludedIds.add(m.userId));
|
||||
room.getMembersWithMembership(KnownMembership.Ban).forEach((m) => excludedIds.add(m.userId));
|
||||
if (isFederated === false) {
|
||||
// exclude users from external servers
|
||||
const homeserver = props.roomId.split(":")[1];
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { _t } from "../../../languageHandler";
|
||||
import BaseDialog from "./BaseDialog";
|
||||
|
@ -102,7 +103,7 @@ const ManageRestrictedJoinRuleDialog: React.FC<IProps> = ({ room, selected = [],
|
|||
if (!room) {
|
||||
return { roomId, name: roomId } as Room;
|
||||
}
|
||||
if (room.getMyMembership() !== "join" || !room.isSpaceRoom()) {
|
||||
if (room.getMyMembership() !== KnownMembership.Join || !room.isSpaceRoom()) {
|
||||
return room;
|
||||
}
|
||||
}),
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
|
||||
import React, { useContext, useMemo } from "react";
|
||||
import { EventType } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import BaseTool, { DevtoolsContext, IDevtoolsProps } from "./BaseTool";
|
||||
import { _t } from "../../../../languageHandler";
|
||||
|
@ -27,7 +28,7 @@ const ServersInRoom: React.FC<IDevtoolsProps> = ({ onBack }) => {
|
|||
const servers = useMemo<Record<string, number>>(() => {
|
||||
const servers: Record<string, number> = {};
|
||||
context.room.currentState.getStateEvents(EventType.RoomMember).forEach((ev) => {
|
||||
if (ev.getContent().membership !== "join") return; // only count joined users
|
||||
if (ev.getContent().membership !== KnownMembership.Join) return; // only count joined users
|
||||
const server = ev.getSender()!.split(":")[1];
|
||||
servers[server] = (servers[server] ?? 0) + 1;
|
||||
});
|
||||
|
|
|
@ -26,6 +26,7 @@ import {
|
|||
HierarchyRoom,
|
||||
JoinRule,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { normalize } from "matrix-js-sdk/src/utils";
|
||||
import React, { ChangeEvent, RefObject, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
|
@ -244,7 +245,7 @@ const findVisibleRooms = (cli: MatrixClient, msc3946ProcessDynamicPredecessor: b
|
|||
if (isLocalRoom(room)) return false;
|
||||
|
||||
// TODO we may want to put invites in their own list
|
||||
return room.getMyMembership() === "join" || room.getMyMembership() == "invite";
|
||||
return room.getMyMembership() === KnownMembership.Join || room.getMyMembership() == KnownMembership.Invite;
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -675,7 +676,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
|
|||
// world readable, a modal will appear asking you to register first. If
|
||||
// it is readable, the preview appears as normal.
|
||||
const showViewButton =
|
||||
clientRoom?.getMyMembership() === "join" ||
|
||||
clientRoom?.getMyMembership() === KnownMembership.Join ||
|
||||
(result.publicRoom.world_readable && !canAskToJoin(joinRule)) ||
|
||||
cli.isGuest();
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import React, { ContextType, createRef, CSSProperties, MutableRefObject, ReactNo
|
|||
import classNames from "classnames";
|
||||
import { IWidget, MatrixCapabilities } from "matrix-widget-api";
|
||||
import { Room, RoomEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { ApprovalOpts, WidgetLifecycle } from "@matrix-org/react-sdk-module-api/lib/lifecycles/WidgetLifecycle";
|
||||
|
||||
|
@ -219,7 +220,10 @@ export default class AppTile extends React.Component<IProps, IState> {
|
|||
}
|
||||
|
||||
private onMyMembership = (room: Room, membership: string): void => {
|
||||
if ((membership === "leave" || membership === "ban") && room.roomId === this.props.room?.roomId) {
|
||||
if (
|
||||
(membership === KnownMembership.Leave || membership === KnownMembership.Ban) &&
|
||||
room.roomId === this.props.room?.roomId
|
||||
) {
|
||||
this.onUserLeftRoom();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -18,6 +18,7 @@ limitations under the License.
|
|||
|
||||
import React, { ComponentProps, ReactNode } from "react";
|
||||
import { MatrixEvent, RoomMember, EventType } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { _t } from "../../../languageHandler";
|
||||
import { formatList } from "../../../utils/FormattingUtils";
|
||||
|
@ -416,12 +417,12 @@ export default class EventListSummary extends React.Component<
|
|||
|
||||
case EventType.RoomMember:
|
||||
switch (e.mxEvent.getContent().membership) {
|
||||
case "invite":
|
||||
case KnownMembership.Invite:
|
||||
return TransitionType.Invited;
|
||||
case "ban":
|
||||
case KnownMembership.Ban:
|
||||
return TransitionType.Banned;
|
||||
case "join":
|
||||
if (e.mxEvent.getPrevContent().membership === "join") {
|
||||
case KnownMembership.Join:
|
||||
if (e.mxEvent.getPrevContent().membership === KnownMembership.Join) {
|
||||
if (e.mxEvent.getContent().displayname !== e.mxEvent.getPrevContent().displayname) {
|
||||
return TransitionType.ChangedName;
|
||||
} else if (e.mxEvent.getContent().avatar_url !== e.mxEvent.getPrevContent().avatar_url) {
|
||||
|
@ -431,17 +432,17 @@ export default class EventListSummary extends React.Component<
|
|||
} else {
|
||||
return TransitionType.Joined;
|
||||
}
|
||||
case "leave":
|
||||
case KnownMembership.Leave:
|
||||
if (e.mxEvent.getSender() === e.mxEvent.getStateKey()) {
|
||||
if (e.mxEvent.getPrevContent().membership === "invite") {
|
||||
if (e.mxEvent.getPrevContent().membership === KnownMembership.Invite) {
|
||||
return TransitionType.InviteReject;
|
||||
}
|
||||
return TransitionType.Left;
|
||||
}
|
||||
switch (e.mxEvent.getPrevContent().membership) {
|
||||
case "invite":
|
||||
case KnownMembership.Invite:
|
||||
return TransitionType.InviteWithdrawal;
|
||||
case "ban":
|
||||
case KnownMembership.Ban:
|
||||
return TransitionType.Unbanned;
|
||||
// sender is not target and made the target leave, if not from invite/ban then this is a kick
|
||||
default:
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import React, { FC, HTMLAttributes, useContext } from "react";
|
||||
import { Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { sortBy } from "lodash";
|
||||
|
||||
import { _t } from "../../../languageHandler";
|
||||
|
@ -38,7 +39,7 @@ interface IProps extends HTMLAttributes<HTMLSpanElement> {
|
|||
|
||||
const RoomFacePile: FC<IProps> = ({ room, onlyKnownUsers = true, numShown = DEFAULT_NUM_FACES, ...props }) => {
|
||||
const cli = useContext(MatrixClientContext);
|
||||
const isJoined = room.getMyMembership() === "join";
|
||||
const isJoined = room.getMyMembership() === KnownMembership.Join;
|
||||
let members = useRoomMembers(room);
|
||||
const count = members.length;
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import {
|
|||
EventTimelineSet,
|
||||
Thread,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import BaseCard from "./BaseCard";
|
||||
import ResizeNotifier from "../../../utils/ResizeNotifier";
|
||||
|
@ -217,7 +218,7 @@ export default class TimelineCard extends React.Component<IProps, IState> {
|
|||
const isUploading = ContentMessages.sharedInstance().getCurrentUploads(this.props.composerRelation).length > 0;
|
||||
|
||||
const myMembership = this.props.room.getMyMembership();
|
||||
const showComposer = myMembership === "join";
|
||||
const showComposer = myMembership === KnownMembership.Join;
|
||||
|
||||
return (
|
||||
<RoomContext.Provider
|
||||
|
|
|
@ -30,6 +30,7 @@ import {
|
|||
Device,
|
||||
EventType,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { UserVerificationStatus, VerificationRequest } from "matrix-js-sdk/src/crypto-api";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
|
||||
|
@ -473,7 +474,7 @@ export const UserOptionsSection: React.FC<{
|
|||
if (
|
||||
member instanceof RoomMember &&
|
||||
canInvite &&
|
||||
(member?.membership ?? "leave") === "leave" &&
|
||||
(member?.membership ?? KnownMembership.Leave) === KnownMembership.Leave &&
|
||||
shouldShowComponent(UIComponent.InviteUsers)
|
||||
) {
|
||||
const roomId = member && member.roomId ? member.roomId : SdkContextClass.instance.roomViewStore.getRoomId();
|
||||
|
@ -638,7 +639,7 @@ export const RoomKickButton = ({
|
|||
const cli = useContext(MatrixClientContext);
|
||||
|
||||
// check if user can be kicked/disinvited
|
||||
if (member.membership !== "invite" && member.membership !== "join") return <></>;
|
||||
if (member.membership !== KnownMembership.Invite && member.membership !== KnownMembership.Join) return <></>;
|
||||
|
||||
const onKick = async (): Promise<void> => {
|
||||
if (isUpdating) return; // only allow one operation at a time
|
||||
|
@ -647,17 +648,17 @@ export const RoomKickButton = ({
|
|||
const commonProps = {
|
||||
member,
|
||||
action: room.isSpaceRoom()
|
||||
? member.membership === "invite"
|
||||
? member.membership === KnownMembership.Invite
|
||||
? _t("user_info|disinvite_button_space")
|
||||
: _t("user_info|kick_button_space")
|
||||
: member.membership === "invite"
|
||||
: member.membership === KnownMembership.Invite
|
||||
? _t("user_info|disinvite_button_room")
|
||||
: _t("user_info|kick_button_room"),
|
||||
title:
|
||||
member.membership === "invite"
|
||||
member.membership === KnownMembership.Invite
|
||||
? _t("user_info|disinvite_button_room_name", { roomName: room.name })
|
||||
: _t("user_info|kick_button_room_name", { roomName: room.name }),
|
||||
askReason: member.membership === "join",
|
||||
askReason: member.membership === KnownMembership.Join,
|
||||
danger: true,
|
||||
};
|
||||
|
||||
|
@ -718,10 +719,10 @@ export const RoomKickButton = ({
|
|||
};
|
||||
|
||||
const kickLabel = room.isSpaceRoom()
|
||||
? member.membership === "invite"
|
||||
? member.membership === KnownMembership.Invite
|
||||
? _t("user_info|disinvite_button_space")
|
||||
: _t("user_info|kick_button_space")
|
||||
: member.membership === "invite"
|
||||
: member.membership === KnownMembership.Invite
|
||||
? _t("user_info|disinvite_button_room")
|
||||
: _t("user_info|kick_button_room");
|
||||
|
||||
|
@ -771,7 +772,7 @@ export const BanToggleButton = ({
|
|||
}: Omit<IBaseRoomProps, "powerLevels">): JSX.Element => {
|
||||
const cli = useContext(MatrixClientContext);
|
||||
|
||||
const isBanned = member.membership === "ban";
|
||||
const isBanned = member.membership === KnownMembership.Ban;
|
||||
const onBanOrUnban = async (): Promise<void> => {
|
||||
if (isUpdating) return; // only allow one operation at a time
|
||||
startUpdating();
|
||||
|
@ -808,7 +809,7 @@ export const BanToggleButton = ({
|
|||
return (
|
||||
!!myMember &&
|
||||
!!theirMember &&
|
||||
theirMember.membership === "ban" &&
|
||||
theirMember.membership === KnownMembership.Ban &&
|
||||
myMember.powerLevel > theirMember.powerLevel &&
|
||||
child.currentState.hasSufficientPowerLevelFor("ban", myMember.powerLevel)
|
||||
);
|
||||
|
@ -820,7 +821,7 @@ export const BanToggleButton = ({
|
|||
return (
|
||||
!!myMember &&
|
||||
!!theirMember &&
|
||||
theirMember.membership !== "ban" &&
|
||||
theirMember.membership !== KnownMembership.Ban &&
|
||||
myMember.powerLevel > theirMember.powerLevel &&
|
||||
child.currentState.hasSufficientPowerLevelFor("ban", myMember.powerLevel)
|
||||
);
|
||||
|
@ -903,7 +904,7 @@ const MuteToggleButton: React.FC<IBaseRoomProps> = ({
|
|||
const cli = useContext(MatrixClientContext);
|
||||
|
||||
// Don't show the mute/unmute option if the user is not in the room
|
||||
if (member.membership !== "join") return null;
|
||||
if (member.membership !== KnownMembership.Join) return null;
|
||||
|
||||
const muted = isMuted(member, powerLevels);
|
||||
const onMuteToggle = async (): Promise<void> => {
|
||||
|
|
|
@ -31,6 +31,7 @@ import {
|
|||
EventType,
|
||||
ClientEvent,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { throttle } from "lodash";
|
||||
import { Button, Tooltip } from "@vector-im/compound-web";
|
||||
import { Icon as UserAddIcon } from "@vector-im/compound-design-tokens/icons/user-add-solid.svg";
|
||||
|
@ -171,7 +172,11 @@ export default class MemberList extends React.Component<IProps, IState> {
|
|||
};
|
||||
|
||||
private onMyMembership = (room: Room, membership: string, oldMembership?: string): void => {
|
||||
if (room.roomId === this.props.roomId && membership === "join" && oldMembership !== "join") {
|
||||
if (
|
||||
room.roomId === this.props.roomId &&
|
||||
membership === KnownMembership.Join &&
|
||||
oldMembership !== KnownMembership.Join
|
||||
) {
|
||||
// we just joined the room, load the member list
|
||||
this.updateListNow(true);
|
||||
}
|
||||
|
@ -363,7 +368,7 @@ export default class MemberList extends React.Component<IProps, IState> {
|
|||
const room = cli.getRoom(this.props.roomId);
|
||||
let inviteButton: JSX.Element | undefined;
|
||||
|
||||
if (room?.getMyMembership() === "join" && shouldShowComponent(UIComponent.InviteUsers)) {
|
||||
if (room?.getMyMembership() === KnownMembership.Join && shouldShowComponent(UIComponent.InviteUsers)) {
|
||||
const inviteButtonText = room.isSpaceRoom() ? _t("space|invite_this_space") : _t("room|invite_this_room");
|
||||
|
||||
const button = (
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import React, { useContext } from "react";
|
||||
import { EventType, Room, User, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
||||
import RoomContext from "../../../contexts/RoomContext";
|
||||
|
@ -112,7 +113,7 @@ const NewRoomIntro: React.FC = () => {
|
|||
</React.Fragment>
|
||||
);
|
||||
} else {
|
||||
const inRoom = room && room.getMyMembership() === "join";
|
||||
const inRoom = room && room.getMyMembership() === KnownMembership.Join;
|
||||
const topic = room.currentState.getStateEvents(EventType.RoomTopic, "")?.getContent()?.topic;
|
||||
const canAddTopic = inRoom && room.currentState.maySendStateEvent(EventType.RoomTopic, cli.getSafeUserId());
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import React, { FC } from "react";
|
||||
import { Room, JoinRule, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { _t } from "../../../languageHandler";
|
||||
import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
|
||||
|
@ -33,7 +34,7 @@ interface IProps {
|
|||
const RoomInfoLine: FC<IProps> = ({ room }) => {
|
||||
// summary will begin as undefined whilst loading and go null if it fails to load or we are not invited.
|
||||
const summary = useAsyncMemo(async (): Promise<Awaited<ReturnType<MatrixClient["getRoomSummary"]>> | null> => {
|
||||
if (room.getMyMembership() !== "invite") return null;
|
||||
if (room.getMyMembership() !== KnownMembership.Invite) return null;
|
||||
try {
|
||||
return await room.client.getRoomSummary(room.roomId);
|
||||
} catch (e) {
|
||||
|
@ -61,7 +62,7 @@ const RoomInfoLine: FC<IProps> = ({ room }) => {
|
|||
}
|
||||
|
||||
let members: JSX.Element | undefined;
|
||||
if (membership === "invite" && summary) {
|
||||
if (membership === KnownMembership.Invite && summary) {
|
||||
// Don't trust local state and instead use the summary API
|
||||
members = (
|
||||
<span className="mx_RoomInfoLine_members">
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { EventTimeline, JoinRule, MatrixError, Room, RoomStateEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import React, { ReactElement, ReactNode, useCallback, useState, VFC } from "react";
|
||||
|
||||
import { Icon as CheckIcon } from "../../../../res/img/feather-customised/check.svg";
|
||||
|
@ -35,7 +36,7 @@ export const RoomKnocksBar: VFC<{ room: Room }> = ({ room }) => {
|
|||
const knockMembers = useTypedEventEmitterState(
|
||||
room,
|
||||
RoomStateEvent.Update,
|
||||
useCallback(() => room.getMembersWithMembership("knock"), [room]),
|
||||
useCallback(() => room.getMembersWithMembership(KnownMembership.Knock), [room]),
|
||||
);
|
||||
const knockMembersCount = knockMembers.length;
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import {
|
|||
JoinRule,
|
||||
MatrixError,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import classNames from "classnames";
|
||||
import { RoomPreviewOpts, RoomViewLifecycle } from "@matrix-org/react-sdk-module-api/lib/lifecycles/RoomViewLifecycle";
|
||||
|
||||
|
@ -192,13 +193,13 @@ export default class RoomPreviewBar extends React.Component<IProps, IState> {
|
|||
if (myMember) {
|
||||
const previousMembership = myMember.events.member?.getPrevContent().membership;
|
||||
if (myMember.isKicked()) {
|
||||
if (previousMembership === "knock") {
|
||||
if (previousMembership === KnownMembership.Knock) {
|
||||
return MessageCase.RequestDenied;
|
||||
} else if (this.props.promptAskToJoin) {
|
||||
return MessageCase.PromptAskToJoin;
|
||||
}
|
||||
return MessageCase.Kicked;
|
||||
} else if (myMember.membership === "ban") {
|
||||
} else if (myMember.membership === KnownMembership.Ban) {
|
||||
return MessageCase.Banned;
|
||||
}
|
||||
}
|
||||
|
@ -284,7 +285,7 @@ export default class RoomPreviewBar extends React.Component<IProps, IState> {
|
|||
return false;
|
||||
}
|
||||
const memberContent = myMember.events.member?.getContent();
|
||||
return memberContent?.membership === "invite" && memberContent.is_direct;
|
||||
return memberContent?.membership === KnownMembership.Invite && memberContent.is_direct;
|
||||
}
|
||||
|
||||
private makeScreenAfterLogin(): { screen: string; params: Record<string, any> } {
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import React, { FC, useContext, useState } from "react";
|
||||
import { Room, JoinRule } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { _t } from "../../../languageHandler";
|
||||
import defaultDispatcher from "../../../dispatcher/dispatcher";
|
||||
|
@ -73,7 +74,7 @@ const RoomPreviewCard: FC<IProps> = ({ room, onJoinButtonClicked, onRejectButton
|
|||
|
||||
let inviterSection: JSX.Element | null = null;
|
||||
let joinButtons: JSX.Element;
|
||||
if (myMembership === "join") {
|
||||
if (myMembership === KnownMembership.Join) {
|
||||
joinButtons = (
|
||||
<AccessibleButton
|
||||
kind="danger_outline"
|
||||
|
@ -87,7 +88,7 @@ const RoomPreviewCard: FC<IProps> = ({ room, onJoinButtonClicked, onRejectButton
|
|||
{_t("action|leave")}
|
||||
</AccessibleButton>
|
||||
);
|
||||
} else if (myMembership === "invite") {
|
||||
} else if (myMembership === KnownMembership.Invite) {
|
||||
const inviteSender = room.getMember(cli.getUserId()!)?.events.member?.getSender();
|
||||
|
||||
if (inviteSender) {
|
||||
|
@ -178,7 +179,7 @@ const RoomPreviewCard: FC<IProps> = ({ room, onJoinButtonClicked, onRejectButton
|
|||
});
|
||||
} else if (isVideoRoom && !videoRoomsEnabled) {
|
||||
notice =
|
||||
myMembership === "join"
|
||||
myMembership === KnownMembership.Join
|
||||
? _t("room|view_failed_enable_video_rooms")
|
||||
: _t("room|join_failed_enable_video_rooms");
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
|
||||
import React, { createRef } from "react";
|
||||
import { Room, RoomEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import classNames from "classnames";
|
||||
|
||||
import type { Call } from "../../../models/Call";
|
||||
|
@ -124,7 +125,7 @@ export class RoomTile extends React.PureComponent<ClassProps, State> {
|
|||
private get showContextMenu(): boolean {
|
||||
return (
|
||||
this.props.tag !== DefaultTagID.Invite &&
|
||||
this.props.room.getMyMembership() !== "knock" &&
|
||||
this.props.room.getMyMembership() !== KnownMembership.Knock &&
|
||||
!isKnockDenied(this.props.room) &&
|
||||
shouldShowComponent(UIComponent.RoomOptionsMenu)
|
||||
);
|
||||
|
@ -393,7 +394,7 @@ export class RoomTile extends React.PureComponent<ClassProps, State> {
|
|||
mx_RoomTile: true,
|
||||
mx_RoomTile_sticky:
|
||||
SettingsStore.getValue("feature_ask_to_join") &&
|
||||
(this.props.room.getMyMembership() === "knock" || isKnockDenied(this.props.room)),
|
||||
(this.props.room.getMyMembership() === KnownMembership.Knock || isKnockDenied(this.props.room)),
|
||||
mx_RoomTile_selected: this.state.selected,
|
||||
mx_RoomTile_hasMenuOpen: !!(this.state.generalMenuPosition || this.state.notificationsMenuPosition),
|
||||
mx_RoomTile_minimized: this.props.isMinimized,
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import React, { ContextType } from "react";
|
||||
import { Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { _t } from "../../../../../languageHandler";
|
||||
import RoomProfileSettings from "../../../room_settings/RoomProfileSettings";
|
||||
|
@ -73,7 +74,7 @@ export default class GeneralRoomSettingsTab extends React.Component<IProps, ISta
|
|||
) : null;
|
||||
|
||||
let leaveSection;
|
||||
if (room.getMyMembership() === "join") {
|
||||
if (room.getMyMembership() === KnownMembership.Join) {
|
||||
leaveSection = (
|
||||
<SettingsSubsection heading={_t("action|leave_room")}>
|
||||
<AccessibleButton kind="danger" onClick={this.onLeaveClick}>
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { EventTimeline, MatrixError, Room, RoomMember, RoomStateEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import React, { useCallback, useState, VFC } from "react";
|
||||
|
||||
import { Icon as CheckIcon } from "../../../../../../res/img/feather-customised/check.svg";
|
||||
|
@ -145,7 +146,7 @@ export const PeopleRoomSettingsTab: VFC<{ room: Room }> = ({ room }) => {
|
|||
const knockMembers = useTypedEventEmitterState(
|
||||
room,
|
||||
RoomStateEvent.Update,
|
||||
useCallback(() => room.getMembersWithMembership("knock"), [room]),
|
||||
useCallback(() => room.getMembersWithMembership(KnownMembership.Knock), [room]),
|
||||
);
|
||||
|
||||
return (
|
||||
|
|
|
@ -18,7 +18,7 @@ import React from "react";
|
|||
import { EventType, RoomMember, RoomState, RoomStateEvent, Room, IContent } from "matrix-js-sdk/src/matrix";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { throttle, get } from "lodash";
|
||||
import { RoomPowerLevelsEventContent } from "matrix-js-sdk/src/types";
|
||||
import { KnownMembership, RoomPowerLevelsEventContent } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { _t, _td, TranslationKey } from "../../../../../languageHandler";
|
||||
import AccessibleButton from "../../../elements/AccessibleButton";
|
||||
|
@ -375,7 +375,7 @@ export default class RolesRoomSettingsTab extends React.Component<IProps> {
|
|||
);
|
||||
}
|
||||
|
||||
const banned = room.getMembersWithMembership("ban");
|
||||
const banned = room.getMembersWithMembership(KnownMembership.Ban);
|
||||
let bannedUsersSection: JSX.Element | undefined;
|
||||
if (banned?.length) {
|
||||
const canBanUsers = currentUserLevel >= banLevel;
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
import React, { ReactNode } from "react";
|
||||
import { sleep } from "matrix-js-sdk/src/utils";
|
||||
import { Room, RoomEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership, Membership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import { _t } from "../../../../../languageHandler";
|
||||
|
@ -121,12 +122,12 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt
|
|||
MatrixClientPeg.safeGet().removeListener(RoomEvent.MyMembership, this.onMyMembership);
|
||||
}
|
||||
|
||||
private onMyMembership = (room: Room, membership: string): void => {
|
||||
private onMyMembership = (room: Room, membership: Membership): void => {
|
||||
if (room.isSpaceRoom()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (membership === "invite") {
|
||||
if (membership === KnownMembership.Invite) {
|
||||
this.addInvitedRoom(room);
|
||||
} else if (this.state.invitedRoomIds.has(room.roomId)) {
|
||||
// The user isn't invited anymore
|
||||
|
@ -167,7 +168,7 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt
|
|||
return MatrixClientPeg.safeGet()
|
||||
.getRooms()
|
||||
.filter((r) => {
|
||||
return r.hasMembershipState(MatrixClientPeg.safeGet().getUserId()!, "invite");
|
||||
return r.hasMembershipState(MatrixClientPeg.safeGet().getUserId()!, KnownMembership.Invite);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import React, {
|
|||
} from "react";
|
||||
import classNames from "classnames";
|
||||
import { Room, RoomEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { DraggableProvidedDragHandleProps } from "react-beautiful-dnd";
|
||||
|
||||
import RoomAvatar from "../avatars/RoomAvatar";
|
||||
|
@ -99,7 +100,7 @@ export const SpaceButton = <T extends keyof JSX.IntrinsicElements>({
|
|||
let notifBadge;
|
||||
if (spaceKey && notificationState) {
|
||||
let ariaLabel = _t("a11y_jump_first_unread_room");
|
||||
if (space?.getMyMembership() === "invite") {
|
||||
if (space?.getMyMembership() === KnownMembership.Invite) {
|
||||
ariaLabel = _t("a11y|jump_first_invite");
|
||||
}
|
||||
|
||||
|
@ -325,7 +326,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
|
|||
hasSubSpaces: this.state.childSpaces?.length,
|
||||
});
|
||||
|
||||
const isInvite = space.getMyMembership() === "invite";
|
||||
const isInvite = space.getMyMembership() === KnownMembership.Invite;
|
||||
|
||||
const notificationState = isInvite
|
||||
? StaticNotificationState.forSymbol("!", NotificationLevel.Highlight)
|
||||
|
@ -378,7 +379,9 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
|
|||
isNarrow={isPanelCollapsed}
|
||||
size={isNested ? "24px" : "32px"}
|
||||
onKeyDown={this.onKeyDown}
|
||||
ContextMenuComponent={this.props.space.getMyMembership() === "join" ? SpaceContextMenu : undefined}
|
||||
ContextMenuComponent={
|
||||
this.props.space.getMyMembership() === KnownMembership.Join ? SpaceContextMenu : undefined
|
||||
}
|
||||
>
|
||||
{toggleCollapseButton}
|
||||
</SpaceButton>
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import { useMemo, useState } from "react";
|
||||
import { Room, RoomEvent, RoomMember, RoomStateEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { Membership } from "matrix-js-sdk/src/types";
|
||||
import { throttle } from "lodash";
|
||||
|
||||
import { useTypedEventEmitter } from "./useEventEmitter";
|
||||
|
@ -81,8 +82,8 @@ export const useRoomMemberCount = (
|
|||
};
|
||||
|
||||
// Hook to simplify watching the local user's membership in a room
|
||||
export const useMyRoomMembership = (room: Room): string => {
|
||||
const [membership, setMembership] = useState<string>(room.getMyMembership());
|
||||
export const useMyRoomMembership = (room: Room): Membership => {
|
||||
const [membership, setMembership] = useState<Membership>(room.getMyMembership());
|
||||
useTypedEventEmitter(room, RoomEvent.MyMembership, () => {
|
||||
setMembership(room.getMyMembership());
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { Room, RoomType, HierarchyRoom } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy";
|
||||
import { normalize } from "matrix-js-sdk/src/utils";
|
||||
|
||||
|
@ -57,7 +58,7 @@ export const useSpaceResults = (space: Room | undefined, query: string): [Hierar
|
|||
return rooms?.filter((r) => {
|
||||
return (
|
||||
r.room_type !== RoomType.Space &&
|
||||
cli.getRoom(r.room_id)?.getMyMembership() !== "join" &&
|
||||
cli.getRoom(r.room_id)?.getMyMembership() !== KnownMembership.Join &&
|
||||
(normalize(r.name || "").includes(normalizedQuery) || (r.canonical_alias || "").includes(lcQuery))
|
||||
);
|
||||
});
|
||||
|
|
|
@ -38,6 +38,7 @@ import {
|
|||
TimelineIndex,
|
||||
TimelineWindow,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { sleep } from "matrix-js-sdk/src/utils";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
|
@ -533,7 +534,7 @@ export default class EventIndex extends EventEmitter {
|
|||
const profiles: Record<string, IMatrixProfile> = {};
|
||||
|
||||
stateEvents.forEach((ev) => {
|
||||
if (ev.getContent().membership === "join") {
|
||||
if (ev.getContent().membership === KnownMembership.Join) {
|
||||
profiles[ev.getSender()!] = {
|
||||
displayname: ev.getContent().displayname,
|
||||
avatar_url: ev.getContent().avatar_url,
|
||||
|
@ -754,7 +755,7 @@ export default class EventIndex extends EventEmitter {
|
|||
// This is sets the avatar URL.
|
||||
const memberEvent = eventMapper({
|
||||
content: {
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
avatar_url: e.profile.avatar_url,
|
||||
displayname: e.profile.displayname,
|
||||
},
|
||||
|
|
|
@ -24,6 +24,7 @@ import {
|
|||
Room,
|
||||
RoomMember,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership, Membership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { randomString } from "matrix-js-sdk/src/randomstring";
|
||||
import { CallType } from "matrix-js-sdk/src/webrtc/call";
|
||||
|
@ -308,8 +309,8 @@ export abstract class Call extends TypedEventEmitter<CallEvent, CallEventHandler
|
|||
this.emit(CallEvent.Destroy);
|
||||
}
|
||||
|
||||
private onMyMembership = async (_room: Room, membership: string): Promise<void> => {
|
||||
if (membership !== "join") this.setDisconnected();
|
||||
private onMyMembership = async (_room: Room, membership: Membership): Promise<void> => {
|
||||
if (membership !== KnownMembership.Join) this.setDisconnected();
|
||||
};
|
||||
|
||||
private onStopMessaging = (uid: string): void => {
|
||||
|
@ -382,7 +383,7 @@ export class JitsiCall extends Call {
|
|||
devices = devices.filter((d) => d !== this.client.getDeviceId());
|
||||
}
|
||||
// Must have a connected device and still be joined to the room
|
||||
if (devices.length > 0 && member?.membership === "join") {
|
||||
if (devices.length > 0 && member?.membership === KnownMembership.Join) {
|
||||
participants.set(member, new Set(devices));
|
||||
if (expiresAt < allExpireAt) allExpireAt = expiresAt;
|
||||
}
|
||||
|
@ -412,7 +413,7 @@ export class JitsiCall extends Call {
|
|||
* returns null, the update is skipped.
|
||||
*/
|
||||
private async updateDevices(fn: (devices: string[]) => string[] | null): Promise<void> {
|
||||
if (this.room.getMyMembership() !== "join") return;
|
||||
if (this.room.getMyMembership() !== KnownMembership.Join) return;
|
||||
|
||||
const event = this.room.currentState.getStateEvents(JitsiCall.MEMBER_EVENT_TYPE, this.client.getUserId()!);
|
||||
const content = event?.getContent<JitsiCallMemberContent>();
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
import { MatrixEvent, EventType, RelationType } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import SettingsStore from "./settings/SettingsStore";
|
||||
import { IRoomState } from "./components/structures/RoomView";
|
||||
|
@ -39,10 +40,11 @@ function memberEventDiff(ev: MatrixEvent): IDiff {
|
|||
const prevContent = ev.getPrevContent();
|
||||
|
||||
const isMembershipChanged = content.membership !== prevContent.membership;
|
||||
diff.isJoin = isMembershipChanged && content.membership === "join";
|
||||
diff.isPart = isMembershipChanged && content.membership === "leave" && ev.getStateKey() === ev.getSender();
|
||||
diff.isJoin = isMembershipChanged && content.membership === KnownMembership.Join;
|
||||
diff.isPart =
|
||||
isMembershipChanged && content.membership === KnownMembership.Leave && ev.getStateKey() === ev.getSender();
|
||||
|
||||
const isJoinToJoin = !isMembershipChanged && content.membership === "join";
|
||||
const isJoinToJoin = !isMembershipChanged && content.membership === KnownMembership.Join;
|
||||
diff.isDisplaynameChange = isJoinToJoin && content.displayname !== prevContent.displayname;
|
||||
diff.isAvatarChange = isJoinToJoin && content.avatar_url !== prevContent.avatar_url;
|
||||
return diff;
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { Room, RoomEvent, ClientEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
|
||||
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
|
@ -91,7 +92,7 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
|
|||
// The tests might not result in a valid room object.
|
||||
const room = this.matrixClient.getRoom(payload.room_id);
|
||||
const membership = room?.getMyMembership();
|
||||
if (room && membership === "join") await this.appendRoom(room);
|
||||
if (room && membership === KnownMembership.Join) await this.appendRoom(room);
|
||||
}
|
||||
} else if (payload.action === Action.JoinRoom) {
|
||||
const room = this.matrixClient.getRoom(payload.roomId);
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
import { SdkContextClass } from "../contexts/SDKContext";
|
||||
|
@ -90,7 +91,7 @@ export class MemberListStore {
|
|||
// pull straight from the server. Don't use a since token as we don't have earlier deltas
|
||||
// accumulated.
|
||||
room.currentState.markOutOfBandMembersStarted();
|
||||
const response = await this.stores.client!.members(roomId, undefined, "leave");
|
||||
const response = await this.stores.client!.members(roomId, undefined, KnownMembership.Leave);
|
||||
const memberEvents = response.chunk.map(this.stores.client!.getEventMapper());
|
||||
room.currentState.setOutOfBandMembers(memberEvents);
|
||||
} else {
|
||||
|
@ -167,7 +168,7 @@ export class MemberListStore {
|
|||
invited: [],
|
||||
};
|
||||
members.forEach((m) => {
|
||||
if (m.membership !== "join" && m.membership !== "invite") {
|
||||
if (m.membership !== KnownMembership.Join && m.membership !== KnownMembership.Invite) {
|
||||
return; // bail early for left/banned users
|
||||
}
|
||||
if (query) {
|
||||
|
@ -179,10 +180,10 @@ export class MemberListStore {
|
|||
}
|
||||
}
|
||||
switch (m.membership) {
|
||||
case "join":
|
||||
case KnownMembership.Join:
|
||||
result.joined.push(m);
|
||||
break;
|
||||
case "invite":
|
||||
case KnownMembership.Invite:
|
||||
result.invited.push(m);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import {
|
|||
MBeaconInfoEventContent,
|
||||
M_BEACON,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import defaultDispatcher from "../dispatcher/dispatcher";
|
||||
|
@ -313,7 +314,7 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
|
|||
// in PSF-797
|
||||
|
||||
// stop watching beacons in rooms where user is no longer a member
|
||||
if (member.membership === "leave" || member.membership === "ban") {
|
||||
if (member.membership === KnownMembership.Leave || member.membership === KnownMembership.Ban) {
|
||||
this.beaconsByRoomId.get(roomState.roomId)?.forEach(this.removeBeacon);
|
||||
this.beaconsByRoomId.delete(roomState.roomId);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ limitations under the License.
|
|||
import React, { ReactNode } from "react";
|
||||
import * as utils from "matrix-js-sdk/src/utils";
|
||||
import { MatrixError, JoinRule, Room, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { ViewRoom as ViewRoomEvent } from "@matrix-org/analytics-events/types/typescript/ViewRoom";
|
||||
import { JoinedRoom as JoinedRoomEvent } from "@matrix-org/analytics-events/types/typescript/JoinedRoom";
|
||||
|
@ -610,7 +611,7 @@ export class RoomViewStore extends EventEmitter {
|
|||
private getInvitingUserId(roomId: string): string | undefined {
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
const room = cli.getRoom(roomId);
|
||||
if (room?.getMyMembership() === "invite") {
|
||||
if (room?.getMyMembership() === KnownMembership.Invite) {
|
||||
const myMember = room.getMember(cli.getSafeUserId());
|
||||
const inviteEvent = myMember ? myMember.events.member : null;
|
||||
return inviteEvent?.getSender();
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { MatrixEventEvent, RoomEvent, ClientEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import type { Room, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import type { IDestroyable } from "../../utils/IDestroyable";
|
||||
|
@ -105,7 +106,8 @@ export class RoomNotificationState extends NotificationState implements IDestroy
|
|||
const { level, symbol, count } = RoomNotifs.determineUnreadState(this.room, undefined, this.includeThreads);
|
||||
const muted =
|
||||
RoomNotifs.getRoomNotifsState(this.room.client, this.room.roomId) === RoomNotifs.RoomNotifState.Mute;
|
||||
const knocked = SettingsStore.getValue("feature_ask_to_join") && this.room.getMyMembership() === "knock";
|
||||
const knocked =
|
||||
SettingsStore.getValue("feature_ask_to_join") && this.room.getMyMembership() === KnownMembership.Knock;
|
||||
this._level = level;
|
||||
this._symbol = symbol;
|
||||
this._count = count;
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { MatrixClient, Room, RoomState, EventType } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import SettingsStore from "../../settings/SettingsStore";
|
||||
|
@ -350,7 +351,7 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> implements
|
|||
}
|
||||
|
||||
private async handleRoomUpdate(room: Room, cause: RoomUpdateCause): Promise<any> {
|
||||
if (cause === RoomUpdateCause.NewRoom && room.getMyMembership() === "invite") {
|
||||
if (cause === RoomUpdateCause.NewRoom && room.getMyMembership() === KnownMembership.Invite) {
|
||||
// Let the visibility provider know that there is a new invited room. It would be nice
|
||||
// if this could just be an event that things listen for but the point of this is that
|
||||
// we delay doing anything about this room until the VoipUserMapper had had a chance
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
|
||||
import { EventEmitter } from "events";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
@ -172,7 +173,7 @@ export class Algorithm extends EventEmitter {
|
|||
}
|
||||
|
||||
private doUpdateStickyRoom(val: Room | null): void {
|
||||
if (val?.isSpaceRoom() && val.getMyMembership() !== "invite") {
|
||||
if (val?.isSpaceRoom() && val.getMyMembership() !== KnownMembership.Invite) {
|
||||
// no-op sticky rooms for spaces - they're effectively virtual rooms
|
||||
val = null;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import {
|
|||
ClientEvent,
|
||||
ISendEventResponse,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import { AsyncStoreWithClient } from "../AsyncStoreWithClient";
|
||||
|
@ -255,8 +256,8 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
// else view space home or home depending on what is being clicked on
|
||||
if (
|
||||
roomId &&
|
||||
cliSpace?.getMyMembership() !== "invite" &&
|
||||
this.matrixClient.getRoom(roomId)?.getMyMembership() === "join" &&
|
||||
cliSpace?.getMyMembership() !== KnownMembership.Invite &&
|
||||
this.matrixClient.getRoom(roomId)?.getMyMembership() === KnownMembership.Join &&
|
||||
this.isRoomInSpace(space, roomId)
|
||||
) {
|
||||
defaultDispatcher.dispatch<ViewRoomPayload>({
|
||||
|
@ -325,7 +326,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
.filter((roomInfo) => {
|
||||
return (
|
||||
roomInfo.room_type !== RoomType.Space &&
|
||||
this.matrixClient?.getRoom(roomInfo.room_id)?.getMyMembership() !== "join"
|
||||
this.matrixClient?.getRoom(roomInfo.room_id)?.getMyMembership() !== KnownMembership.Join
|
||||
);
|
||||
})
|
||||
.map((roomInfo) => ({
|
||||
|
@ -368,7 +369,10 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
return history[history.length - 1];
|
||||
})
|
||||
.filter((room) => {
|
||||
return room?.getMyMembership() === "join" || room?.getMyMembership() === "invite";
|
||||
return (
|
||||
room?.getMyMembership() === KnownMembership.Join ||
|
||||
room?.getMyMembership() === KnownMembership.Invite
|
||||
);
|
||||
}) || []
|
||||
);
|
||||
}
|
||||
|
@ -379,7 +383,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
|
||||
public getChildSpaces(spaceId: string): Room[] {
|
||||
// don't show invited subspaces as they surface at the top level for better visibility
|
||||
return this.getChildren(spaceId).filter((r) => r.isSpaceRoom() && r.getMyMembership() === "join");
|
||||
return this.getChildren(spaceId).filter((r) => r.isSpaceRoom() && r.getMyMembership() === KnownMembership.Join);
|
||||
}
|
||||
|
||||
public getParents(roomId: string, canonicalOnly = false): Room[] {
|
||||
|
@ -593,7 +597,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
private rebuildParentMap = (): void => {
|
||||
if (!this.matrixClient) return;
|
||||
const joinedSpaces = this.matrixClient.getVisibleRooms(this._msc3946ProcessDynamicPredecessor).filter((r) => {
|
||||
return r.isSpaceRoom() && r.getMyMembership() === "join";
|
||||
return r.isSpaceRoom() && r.getMyMembership() === KnownMembership.Join;
|
||||
});
|
||||
|
||||
this.parentMap = new EnhancedMap<string, Set<string>>();
|
||||
|
@ -717,12 +721,12 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
return (
|
||||
!this.parentMap.get(room.roomId)?.size || // put all orphaned rooms in the Home Space
|
||||
!!DMRoomMap.shared().getUserIdForRoomId(room.roomId) || // put all DMs in the Home Space
|
||||
room.getMyMembership() === "invite"
|
||||
room.getMyMembership() === KnownMembership.Invite
|
||||
); // put all invites in the Home Space
|
||||
};
|
||||
|
||||
private static isInSpace(member?: RoomMember | null): boolean {
|
||||
return member?.membership === "join" || member?.membership === "invite";
|
||||
return member?.membership === KnownMembership.Join || member?.membership === KnownMembership.Invite;
|
||||
}
|
||||
|
||||
// Method for resolving the impact of a single user's membership change in the given Space and its hierarchy
|
||||
|
@ -766,7 +770,8 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
|
||||
const hiddenChildren = new EnhancedMap<string, Set<string>>();
|
||||
visibleRooms.forEach((room) => {
|
||||
if (!["join", "invite"].includes(room.getMyMembership())) return;
|
||||
if (!([KnownMembership.Join, KnownMembership.Invite] as Array<string>).includes(room.getMyMembership()))
|
||||
return;
|
||||
this.getParents(room.roomId).forEach((parent) => {
|
||||
hiddenChildren.getOrCreate(parent.roomId, new Set()).add(room.roomId);
|
||||
});
|
||||
|
@ -796,7 +801,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
space
|
||||
?.getMembers()
|
||||
.filter((m) => {
|
||||
return m.membership === "join" || m.membership === "invite";
|
||||
return m.membership === KnownMembership.Join || m.membership === KnownMembership.Invite;
|
||||
})
|
||||
.map((m) => m.userId),
|
||||
);
|
||||
|
@ -924,7 +929,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
if (!room.isSpaceRoom()) {
|
||||
this.onRoomsUpdate();
|
||||
|
||||
if (membership === "join") {
|
||||
if (membership === KnownMembership.Join) {
|
||||
// the user just joined a room, remove it from the suggested list if it was there
|
||||
const numSuggestedRooms = this._suggestedRooms.length;
|
||||
this._suggestedRooms = this._suggestedRooms.filter((r) => r.room_id !== room.roomId);
|
||||
|
@ -935,7 +940,10 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
}
|
||||
|
||||
// if the room currently being viewed was just joined then switch to its related space
|
||||
if (newMembership === "join" && room.roomId === SdkContextClass.instance.roomViewStore.getRoomId()) {
|
||||
if (
|
||||
newMembership === KnownMembership.Join &&
|
||||
room.roomId === SdkContextClass.instance.roomViewStore.getRoomId()
|
||||
) {
|
||||
this.switchSpaceIfNeeded(room.roomId);
|
||||
}
|
||||
}
|
||||
|
@ -943,13 +951,13 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
}
|
||||
|
||||
// Space
|
||||
if (membership === "invite") {
|
||||
if (membership === KnownMembership.Invite) {
|
||||
const len = this._invitedSpaces.size;
|
||||
this._invitedSpaces.add(room);
|
||||
if (len !== this._invitedSpaces.size) {
|
||||
this.emit(UPDATE_INVITED_SPACES, this.invitedSpaces);
|
||||
}
|
||||
} else if (oldMembership === "invite" && membership !== "join") {
|
||||
} else if (oldMembership === KnownMembership.Invite && membership !== KnownMembership.Join) {
|
||||
if (this._invitedSpaces.delete(room)) {
|
||||
this.emit(UPDATE_INVITED_SPACES, this.invitedSpaces);
|
||||
}
|
||||
|
@ -962,10 +970,10 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
this.emit(room.roomId);
|
||||
}
|
||||
|
||||
if (membership === "join" && room.roomId === SdkContextClass.instance.roomViewStore.getRoomId()) {
|
||||
if (membership === KnownMembership.Join && room.roomId === SdkContextClass.instance.roomViewStore.getRoomId()) {
|
||||
// if the user was looking at the space and then joined: select that space
|
||||
this.setActiveSpace(room.roomId, false);
|
||||
} else if (membership === "leave" && room.roomId === this.activeSpace) {
|
||||
} else if (membership === KnownMembership.Leave && room.roomId === this.activeSpace) {
|
||||
// user's active space has gone away, go back to home
|
||||
this.goToFirstSpace(true);
|
||||
}
|
||||
|
@ -1000,7 +1008,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
|
||||
if (
|
||||
room.roomId === this.activeSpace && // current space
|
||||
target?.getMyMembership() !== "join" && // target not joined
|
||||
target?.getMyMembership() !== KnownMembership.Join && // target not joined
|
||||
ev.getPrevContent().suggested !== ev.getContent().suggested // suggested flag changed
|
||||
) {
|
||||
this.loadSuggestedRooms(room);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
import { Room, MatrixEvent, MatrixEventEvent, MatrixClient, ClientEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import {
|
||||
ClientWidgetApi,
|
||||
IModalWidgetOpenRequest,
|
||||
|
@ -550,7 +551,7 @@ export class StopGapWidget extends EventEmitter {
|
|||
const evId = ev.getId();
|
||||
if (evRoomId && evId) {
|
||||
const room = this.client.getRoom(evRoomId);
|
||||
if (room && room.getMyMembership() === "join" && !isRelationToUnknown) {
|
||||
if (room && room.getMyMembership() === KnownMembership.Join && !isRelationToUnknown) {
|
||||
this.readUpToMap[evRoomId] = evId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import { uniq } from "lodash";
|
||||
import { Room, MatrixEvent, EventType, ClientEvent, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { Optional } from "matrix-events-sdk";
|
||||
|
||||
|
@ -172,7 +173,7 @@ export default class DMRoomMap {
|
|||
|
||||
const joinedRooms = commonRooms
|
||||
.map((r) => this.matrixClient.getRoom(r))
|
||||
.filter((r) => r && r.getMyMembership() === "join");
|
||||
.filter((r) => r && r.getMyMembership() === KnownMembership.Join);
|
||||
|
||||
return joinedRooms[0];
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { MatrixError, MatrixClient, EventType, HistoryVisibility } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { defer, IDeferred } from "matrix-js-sdk/src/utils";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
|
@ -159,17 +160,17 @@ export default class MultiInviter {
|
|||
if (!room) throw new Error("Room not found");
|
||||
|
||||
const member = room.getMember(addr);
|
||||
if (member?.membership === "join") {
|
||||
if (member?.membership === KnownMembership.Join) {
|
||||
throw new MatrixError({
|
||||
errcode: USER_ALREADY_JOINED,
|
||||
error: "Member already joined",
|
||||
});
|
||||
} else if (member?.membership === "invite") {
|
||||
} else if (member?.membership === KnownMembership.Invite) {
|
||||
throw new MatrixError({
|
||||
errcode: USER_ALREADY_INVITED,
|
||||
error: "Member already invited",
|
||||
});
|
||||
} else if (member?.membership === "ban") {
|
||||
} else if (member?.membership === KnownMembership.Ban) {
|
||||
let proceed = false;
|
||||
// Check if we can unban the invitee.
|
||||
// See https://spec.matrix.org/v1.7/rooms/v10/#authorization-rules, particularly 4.5.3 and 4.5.4.
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { Room, EventType, ClientEvent, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import { inviteUsersToRoom } from "../RoomInvite";
|
||||
|
@ -67,7 +68,10 @@ export async function upgradeRoom(
|
|||
|
||||
let toInvite: string[] = [];
|
||||
if (inviteUsers) {
|
||||
toInvite = [...room.getMembersWithMembership("join"), ...room.getMembersWithMembership("invite")]
|
||||
toInvite = [
|
||||
...room.getMembersWithMembership(KnownMembership.Join),
|
||||
...room.getMembersWithMembership(KnownMembership.Invite),
|
||||
]
|
||||
.map((m) => m.userId)
|
||||
.filter((m) => m !== cli.getUserId());
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import { groupBy, mapValues, maxBy, minBy, sumBy, takeRight } from "lodash";
|
||||
import { MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { Member } from "./direct-messages";
|
||||
import DMRoomMap from "./DMRoomMap";
|
||||
|
@ -52,7 +53,7 @@ function joinedRooms(cli: MatrixClient): Room[] {
|
|||
return (
|
||||
cli
|
||||
.getRooms()
|
||||
.filter((r) => r.getMyMembership() === "join")
|
||||
.filter((r) => r.getMyMembership() === KnownMembership.Join)
|
||||
// Skip low priority rooms and DMs
|
||||
.filter((r) => !DMRoomMap.shared().getUserIdForRoomId(r.roomId))
|
||||
.filter((r) => !Object.keys(r.tags).includes("m.lowpriority"))
|
||||
|
|
|
@ -18,6 +18,7 @@ limitations under the License.
|
|||
import { base32 } from "rfc4648";
|
||||
import { IWidget, IWidgetData } from "matrix-widget-api";
|
||||
import { Room, ClientEvent, MatrixClient, RoomStateEvent, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { CallType } from "matrix-js-sdk/src/webrtc/call";
|
||||
import { randomString, randomLowercaseString, randomUppercaseString } from "matrix-js-sdk/src/randomstring";
|
||||
|
@ -83,7 +84,7 @@ export default class WidgetUtils {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (room.getMyMembership() !== "join") {
|
||||
if (room.getMyMembership() !== KnownMembership.Join) {
|
||||
logger.warn(`User ${me} is not in room ${roomId}`);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import { MEGOLM_ALGORITHM } from "matrix-js-sdk/src/crypto/olmlib";
|
||||
import { EventType, KNOWN_SAFE_ROOM_VERSION, MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { LocalRoom, LOCAL_ROOM_ID_PREFIX } from "../../../src/models/LocalRoom";
|
||||
import { determineCreateRoomEncryptionOption, Member } from "../../../src/utils/direct-messages";
|
||||
|
@ -76,7 +77,7 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
|
|||
type: EventType.RoomMember,
|
||||
content: {
|
||||
displayname: userId,
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
},
|
||||
state_key: userId,
|
||||
user_id: userId,
|
||||
|
@ -93,7 +94,7 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
|
|||
content: {
|
||||
displayname: target.name,
|
||||
avatar_url: target.getMxcAvatarUrl() ?? undefined,
|
||||
membership: "invite",
|
||||
membership: KnownMembership.Invite,
|
||||
isDirect: true,
|
||||
},
|
||||
state_key: target.userId,
|
||||
|
@ -108,7 +109,7 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
|
|||
content: {
|
||||
displayname: target.name,
|
||||
avatar_url: target.getMxcAvatarUrl() ?? undefined,
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
},
|
||||
state_key: target.userId,
|
||||
sender: target.userId,
|
||||
|
@ -118,7 +119,7 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
|
|||
});
|
||||
|
||||
localRoom.targets = targets;
|
||||
localRoom.updateMyMembership("join");
|
||||
localRoom.updateMyMembership(KnownMembership.Join);
|
||||
localRoom.addLiveEvents(events);
|
||||
localRoom.currentState.setStateEvents(events);
|
||||
localRoom.name = localRoom.getDefaultRoomName(client.getUserId()!);
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { MatrixClient, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import DMRoomMap from "../DMRoomMap";
|
||||
import { isLocalRoom } from "../localRoom/isLocalRoom";
|
||||
|
@ -42,7 +43,7 @@ function extractSuitableRoom(rooms: Room[], userId: string, findRoomWithThirdpar
|
|||
// a DM is a room of two people that contains those two people exactly. This does mean
|
||||
// that bots, assistants, etc will ruin a room's DM-ness, though this is a problem for
|
||||
// canonical DMs to solve.
|
||||
if (r && r.getMyMembership() === "join") {
|
||||
if (r && r.getMyMembership() === KnownMembership.Join) {
|
||||
if (isLocalRoom(r)) return false;
|
||||
|
||||
const functionalUsers = getFunctionalMembers(r);
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { Room, RoomMember, RoomState, RoomStateEvent, MatrixEvent, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership, Membership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
|
@ -65,10 +66,13 @@ export function splitRoomsByMembership(rooms: Room[]): MembershipSplit {
|
|||
return split;
|
||||
}
|
||||
|
||||
export function getEffectiveMembership(membership: string): EffectiveMembership {
|
||||
if (membership === "invite") {
|
||||
export function getEffectiveMembership(membership: Membership): EffectiveMembership {
|
||||
if (membership === KnownMembership.Invite) {
|
||||
return EffectiveMembership.Invite;
|
||||
} else if (membership === "join" || (SettingsStore.getValue("feature_ask_to_join") && membership === "knock")) {
|
||||
} else if (
|
||||
membership === KnownMembership.Join ||
|
||||
(SettingsStore.getValue("feature_ask_to_join") && membership === KnownMembership.Knock)
|
||||
) {
|
||||
return EffectiveMembership.Join;
|
||||
} else {
|
||||
// Probably a leave, kick, or ban
|
||||
|
@ -81,7 +85,7 @@ export function isKnockDenied(room: Room): boolean | undefined {
|
|||
const member = memberId ? room.getMember(memberId) : null;
|
||||
const previousMembership = member?.events.member?.getPrevContent().membership;
|
||||
|
||||
return member?.isKicked() && previousMembership === "knock";
|
||||
return member?.isKicked() && previousMembership === KnownMembership.Knock;
|
||||
}
|
||||
|
||||
export function getEffectiveMembershipTag(room: Room, membership?: string): EffectiveMembership {
|
||||
|
@ -90,7 +94,7 @@ export function getEffectiveMembershipTag(room: Room, membership?: string): Effe
|
|||
: getEffectiveMembership(membership ?? room.getMyMembership());
|
||||
}
|
||||
|
||||
export function isJoinedOrNearlyJoined(membership: string): boolean {
|
||||
export function isJoinedOrNearlyJoined(membership: Membership): boolean {
|
||||
const effective = getEffectiveMembership(membership);
|
||||
return effective === EffectiveMembership.Join || effective === EffectiveMembership.Invite;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
import isIp from "is-ip";
|
||||
import * as utils from "matrix-js-sdk/src/utils";
|
||||
import { Room, MatrixClient, RoomStateEvent, EventType } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import MatrixToPermalinkConstructor, {
|
||||
|
@ -178,7 +179,7 @@ export class RoomPermalinkCreator {
|
|||
const entries = Object.entries(users);
|
||||
const allowedEntries = entries.filter(([userId]) => {
|
||||
const member = this.room?.getMember(userId);
|
||||
if (!member || member.membership !== "join") {
|
||||
if (!member || member.membership !== KnownMembership.Join) {
|
||||
return false;
|
||||
}
|
||||
const serverName = getServerName(userId);
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { JoinRule, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { shouldShowComponent } from "../../customisations/helpers/UIComponents";
|
||||
import { UIComponent } from "../../settings/UIFeature";
|
||||
|
@ -29,5 +30,5 @@ export function canInviteTo(room: Room): boolean {
|
|||
const canInvite =
|
||||
!!room.canInvite(client.getSafeUserId()) || !!(room.isSpaceRoom() && room.getJoinRule() === JoinRule.Public);
|
||||
|
||||
return canInvite && room.getMyMembership() === "join" && shouldShowComponent(UIComponent.InviteUsers);
|
||||
return canInvite && room.getMyMembership() === KnownMembership.Join && shouldShowComponent(UIComponent.InviteUsers);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import React from "react";
|
||||
import { Room, ICreateRoomStateEvent, RoomType, EventType, JoinRule } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { calculateRoomVia } from "./permalinks/Permalinks";
|
||||
import Modal from "../Modal";
|
||||
|
@ -40,7 +41,7 @@ import { SdkContextClass } from "../contexts/SDKContext";
|
|||
export const shouldShowSpaceSettings = (space: Room): boolean => {
|
||||
const userId = space.client.getUserId()!;
|
||||
return (
|
||||
space.getMyMembership() === "join" &&
|
||||
space.getMyMembership() === KnownMembership.Join &&
|
||||
(space.currentState.maySendStateEvent(EventType.RoomAvatar, userId) ||
|
||||
space.currentState.maySendStateEvent(EventType.RoomName, userId) ||
|
||||
space.currentState.maySendStateEvent(EventType.RoomTopic, userId) ||
|
||||
|
@ -85,7 +86,7 @@ export const showCreateNewRoom = async (space: Room, type?: RoomType): Promise<b
|
|||
};
|
||||
|
||||
export const shouldShowSpaceInvite = (space: Room): boolean =>
|
||||
((space?.getMyMembership() === "join" && space.canInvite(space.client.getUserId()!)) ||
|
||||
((space?.getMyMembership() === KnownMembership.Join && space.canInvite(space.client.getUserId()!)) ||
|
||||
space.getJoinRule() === JoinRule.Public) &&
|
||||
shouldShowComponent(UIComponent.InviteUsers);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import {
|
|||
RuleId,
|
||||
TweakName,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { CallEvent, CallState, CallType, MatrixCall } from "matrix-js-sdk/src/webrtc/call";
|
||||
import EventEmitter from "events";
|
||||
import { mocked } from "jest-mock";
|
||||
|
@ -102,7 +103,7 @@ function mkStubDM(roomId: string, userId: string) {
|
|||
name: "Member",
|
||||
rawDisplayName: "Member",
|
||||
roomId: roomId,
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
},
|
||||
|
@ -111,7 +112,7 @@ function mkStubDM(roomId: string, userId: string) {
|
|||
name: "Member",
|
||||
rawDisplayName: "Member",
|
||||
roomId: roomId,
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
},
|
||||
|
@ -120,7 +121,7 @@ function mkStubDM(roomId: string, userId: string) {
|
|||
name: "Bot user",
|
||||
rawDisplayName: "Bot user",
|
||||
roomId: roomId,
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
},
|
||||
|
|
|
@ -25,6 +25,7 @@ import {
|
|||
MatrixEvent,
|
||||
PendingEventOrdering,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { mkEvent, mkRoom, mkRoomMember, muteRoom, stubClient, upsertRoomStateEvents } from "./test-utils";
|
||||
|
@ -277,7 +278,7 @@ describe("RoomNotifs test", () => {
|
|||
});
|
||||
|
||||
it("indicates the user has been invited to a channel", async () => {
|
||||
room.updateMyMembership("invite");
|
||||
room.updateMyMembership(KnownMembership.Invite);
|
||||
|
||||
const { level, symbol, count } = determineUnreadState(room);
|
||||
|
||||
|
@ -290,9 +291,15 @@ describe("RoomNotifs test", () => {
|
|||
jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => {
|
||||
return name === "feature_ask_to_join";
|
||||
});
|
||||
const roomMember = mkRoomMember(room.roomId, MatrixClientPeg.get()!.getSafeUserId(), "leave", true, {
|
||||
membership: "knock",
|
||||
});
|
||||
const roomMember = mkRoomMember(
|
||||
room.roomId,
|
||||
MatrixClientPeg.get()!.getSafeUserId(),
|
||||
KnownMembership.Leave,
|
||||
true,
|
||||
{
|
||||
membership: KnownMembership.Knock,
|
||||
},
|
||||
);
|
||||
jest.spyOn(room, "getMember").mockReturnValue(roomMember);
|
||||
const { level, symbol, count } = determineUnreadState(room);
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { mocked } from "jest-mock";
|
||||
|
||||
import { Command, Commands, getCommand } from "../src/SlashCommands";
|
||||
|
@ -162,7 +163,7 @@ describe("SlashCommands", () => {
|
|||
it("should warn about self demotion", async () => {
|
||||
setCurrentRoom();
|
||||
const member = new RoomMember(roomId, client.getSafeUserId());
|
||||
member.membership = "join";
|
||||
member.membership = KnownMembership.Join;
|
||||
member.powerLevel = 100;
|
||||
room.getMember = () => member;
|
||||
command.run(client, roomId, null, `${client.getUserId()} 0`);
|
||||
|
@ -172,7 +173,7 @@ describe("SlashCommands", () => {
|
|||
it("should default to 50 if no powerlevel specified", async () => {
|
||||
setCurrentRoom();
|
||||
const member = new RoomMember(roomId, "@user:server");
|
||||
member.membership = "join";
|
||||
member.membership = KnownMembership.Join;
|
||||
room.getMember = () => member;
|
||||
command.run(client, roomId, null, member.userId);
|
||||
expect(client.setPowerLevel).toHaveBeenCalledWith(roomId, member.userId, 50);
|
||||
|
@ -191,7 +192,7 @@ describe("SlashCommands", () => {
|
|||
it("should warn about self demotion", async () => {
|
||||
setCurrentRoom();
|
||||
const member = new RoomMember(roomId, client.getSafeUserId());
|
||||
member.membership = "join";
|
||||
member.membership = KnownMembership.Join;
|
||||
member.powerLevel = 100;
|
||||
room.getMember = () => member;
|
||||
command.run(client, roomId, null, client.getSafeUserId());
|
||||
|
@ -366,7 +367,7 @@ describe("SlashCommands", () => {
|
|||
describe("/join", () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(dispatcher, "dispatch");
|
||||
command = findCommand("join")!;
|
||||
command = findCommand(KnownMembership.Join)!;
|
||||
});
|
||||
|
||||
it("should return usage if no args", () => {
|
||||
|
|
|
@ -23,6 +23,7 @@ import {
|
|||
Room,
|
||||
RoomMember,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { render } from "@testing-library/react";
|
||||
import { ReactElement } from "react";
|
||||
import { Mocked, mocked } from "jest-mock";
|
||||
|
@ -504,12 +505,12 @@ describe("TextForEvent", () => {
|
|||
type: "m.room.member",
|
||||
sender: "@a:foo",
|
||||
content: {
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
avatar_url: "b",
|
||||
displayname: "Bob",
|
||||
},
|
||||
prev_content: {
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
avatar_url: "a",
|
||||
displayname: "Andy",
|
||||
},
|
||||
|
|
|
@ -18,6 +18,7 @@ limitations under the License.
|
|||
import React from "react";
|
||||
import { EventEmitter } from "events";
|
||||
import { MatrixEvent, Room, RoomMember, Thread, ReceiptType } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { render } from "@testing-library/react";
|
||||
import { TooltipProvider } from "@vector-im/compound-web";
|
||||
|
||||
|
@ -171,8 +172,8 @@ describe("MessagePanel", function () {
|
|||
user: "@user:id",
|
||||
target: bobMember,
|
||||
ts: ts0 + i * 1000,
|
||||
mship: "join",
|
||||
prevMship: "join",
|
||||
mship: KnownMembership.Join,
|
||||
prevMship: KnownMembership.Join,
|
||||
name: "A user",
|
||||
}),
|
||||
);
|
||||
|
@ -205,8 +206,8 @@ describe("MessagePanel", function () {
|
|||
user: "@user:id",
|
||||
target: bobMember,
|
||||
ts: ts0 + i * 1000,
|
||||
mship: "join",
|
||||
prevMship: "join",
|
||||
mship: KnownMembership.Join,
|
||||
prevMship: KnownMembership.Join,
|
||||
name: "A user",
|
||||
}),
|
||||
);
|
||||
|
@ -245,7 +246,7 @@ describe("MessagePanel", function () {
|
|||
user: alice,
|
||||
target: aliceMember,
|
||||
ts: ts0 + 1,
|
||||
mship: "join",
|
||||
mship: KnownMembership.Join,
|
||||
name: "Alice",
|
||||
}),
|
||||
mkEvent({
|
||||
|
@ -285,7 +286,7 @@ describe("MessagePanel", function () {
|
|||
skey: "@bob:example.org",
|
||||
target: bobMember,
|
||||
ts: ts0 + 5,
|
||||
mship: "invite",
|
||||
mship: KnownMembership.Invite,
|
||||
name: "Bob",
|
||||
}),
|
||||
];
|
||||
|
@ -542,8 +543,8 @@ describe("MessagePanel", function () {
|
|||
user: "@user:id",
|
||||
target: bobMember,
|
||||
ts: Date.now(),
|
||||
mship: "join",
|
||||
prevMship: "join",
|
||||
mship: KnownMembership.Join,
|
||||
prevMship: KnownMembership.Join,
|
||||
name: "A user",
|
||||
}),
|
||||
];
|
||||
|
@ -571,8 +572,8 @@ describe("MessagePanel", function () {
|
|||
user: "@user:id",
|
||||
target: bobMember,
|
||||
ts: Date.now(),
|
||||
mship: "join",
|
||||
prevMship: "join",
|
||||
mship: KnownMembership.Join,
|
||||
prevMship: KnownMembership.Join,
|
||||
name: "A user",
|
||||
}),
|
||||
...events,
|
||||
|
@ -695,8 +696,8 @@ describe("MessagePanel", function () {
|
|||
for (let i = 0; i < 100; i++) {
|
||||
events.push(
|
||||
TestUtilsMatrix.mkMembership({
|
||||
mship: "join",
|
||||
prevMship: "join",
|
||||
mship: KnownMembership.Join,
|
||||
prevMship: KnownMembership.Join,
|
||||
room: "!room:id",
|
||||
user: "@user:id",
|
||||
event: true,
|
||||
|
@ -716,8 +717,8 @@ describe("MessagePanel", function () {
|
|||
for (let i = 0; i < 100; i++) {
|
||||
events.push(
|
||||
TestUtilsMatrix.mkMembership({
|
||||
mship: "join",
|
||||
prevMship: "join",
|
||||
mship: KnownMembership.Join,
|
||||
prevMship: KnownMembership.Join,
|
||||
room: "!room:id",
|
||||
user: "@user:id",
|
||||
event: true,
|
||||
|
|
|
@ -29,6 +29,7 @@ import {
|
|||
SearchResult,
|
||||
IEvent,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { MEGOLM_ALGORITHM } from "matrix-js-sdk/src/crypto/olmlib";
|
||||
import { fireEvent, render, screen, RenderResult, waitForElementToBeRemoved, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
@ -238,7 +239,7 @@ describe("RoomView", () => {
|
|||
});
|
||||
|
||||
it("updates url preview visibility on encryption state change", async () => {
|
||||
room.getMyMembership = jest.fn().mockReturnValue("join");
|
||||
room.getMyMembership = jest.fn().mockReturnValue(KnownMembership.Join);
|
||||
// we should be starting unencrypted
|
||||
expect(cli.isCryptoEnabled()).toEqual(false);
|
||||
expect(cli.isRoomEncrypted(room.roomId)).toEqual(false);
|
||||
|
@ -583,7 +584,7 @@ describe("RoomView", () => {
|
|||
it("allows to cancel a join request", async () => {
|
||||
jest.spyOn(MatrixClientPeg, "safeGet").mockReturnValue(client);
|
||||
jest.spyOn(client, "leave").mockResolvedValue({});
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("knock");
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Knock);
|
||||
|
||||
await mountRoomView();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel request" }));
|
||||
|
@ -594,7 +595,7 @@ describe("RoomView", () => {
|
|||
});
|
||||
|
||||
it("should close search results when edit is clicked", async () => {
|
||||
room.getMyMembership = jest.fn().mockReturnValue("join");
|
||||
room.getMyMembership = jest.fn().mockReturnValue(KnownMembership.Join);
|
||||
|
||||
const eventMapper = (obj: Partial<IEvent>) => new MatrixEvent(obj);
|
||||
|
||||
|
@ -655,7 +656,7 @@ describe("RoomView", () => {
|
|||
const room2 = new Room(`!${roomCount++}:example.org`, cli, "@alice:example.org");
|
||||
rooms.set(room2.roomId, room2);
|
||||
|
||||
room.getMyMembership = jest.fn().mockReturnValue("join");
|
||||
room.getMyMembership = jest.fn().mockReturnValue(KnownMembership.Join);
|
||||
|
||||
const eventMapper = (obj: Partial<IEvent>) => new MatrixEvent(obj);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import React from "react";
|
|||
import { mocked } from "jest-mock";
|
||||
import { fireEvent, render, screen, waitFor, waitForElementToBeRemoved } from "@testing-library/react";
|
||||
import { MatrixClient, Room, HierarchyRoom } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy";
|
||||
import { TooltipProvider } from "@vector-im/compound-web";
|
||||
|
||||
|
@ -181,7 +182,7 @@ describe("SpaceHierarchy", () => {
|
|||
mocked(client.getRoom).mockImplementation(
|
||||
(roomId) => client.getRooms().find((room) => room.roomId === roomId) ?? null,
|
||||
);
|
||||
[room1, room2, space1, room3].forEach((r) => mocked(r.getMyMembership).mockReturnValue("leave"));
|
||||
[room1, room2, space1, room3].forEach((r) => mocked(r.getMyMembership).mockReturnValue(KnownMembership.Leave));
|
||||
|
||||
const hierarchyRoot: HierarchyRoom = {
|
||||
room_id: root.roomId,
|
||||
|
|
|
@ -35,6 +35,7 @@ import {
|
|||
ThreadEvent,
|
||||
ThreadFilterType,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import React, { createRef } from "react";
|
||||
import { Mocked, mocked } from "jest-mock";
|
||||
import { forEachRight } from "lodash";
|
||||
|
@ -988,8 +989,8 @@ describe("TimelinePanel", () => {
|
|||
events.forEach((event) => timelineSet.getLiveTimeline().addEvent(event, { toStartOfTimeline: true }));
|
||||
|
||||
const roomMembership = mkMembership({
|
||||
mship: "join",
|
||||
prevMship: "join",
|
||||
mship: KnownMembership.Join,
|
||||
prevMship: KnownMembership.Join,
|
||||
user: authorId,
|
||||
room: room.roomId,
|
||||
event: true,
|
||||
|
@ -999,7 +1000,7 @@ describe("TimelinePanel", () => {
|
|||
events.push(roomMembership);
|
||||
|
||||
const member = new RoomMember(room.roomId, authorId);
|
||||
member.membership = "join";
|
||||
member.membership = KnownMembership.Join;
|
||||
|
||||
const roomState = new RoomState(room.roomId);
|
||||
jest.spyOn(roomState, "getMember").mockReturnValue(member);
|
||||
|
|
|
@ -20,6 +20,7 @@ import { render, screen } from "@testing-library/react";
|
|||
import React, { ComponentProps } from "react";
|
||||
import { mocked } from "jest-mock";
|
||||
import { MatrixClient, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
|
||||
import RoomContextMenu from "../../../../src/components/views/context_menus/RoomContextMenu";
|
||||
|
@ -106,7 +107,7 @@ describe("RoomContextMenu", () => {
|
|||
it("should render notification option for joined rooms", () => {
|
||||
const chamber = EchoChamber.forRoom(room);
|
||||
chamber.notificationVolume = RoomNotifState.Mute;
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("join");
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
|
||||
renderComponent();
|
||||
|
||||
expect(
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
import { fireEvent, getByLabelText, render, screen } from "@testing-library/react";
|
||||
import { mocked } from "jest-mock";
|
||||
import { ReceiptType, MatrixClient, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import React from "react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
||||
|
@ -105,7 +106,7 @@ describe("RoomGeneralContextMenu", () => {
|
|||
});
|
||||
|
||||
it("does not render invite menu item when UIComponent customisations disable room invite", () => {
|
||||
room.updateMyMembership("join");
|
||||
room.updateMyMembership(KnownMembership.Join);
|
||||
jest.spyOn(room, "canInvite").mockReturnValue(true);
|
||||
mocked(shouldShowComponent).mockReturnValue(false);
|
||||
|
||||
|
@ -116,7 +117,7 @@ describe("RoomGeneralContextMenu", () => {
|
|||
});
|
||||
|
||||
it("renders invite menu item when UIComponent customisations enables room invite", () => {
|
||||
room.updateMyMembership("join");
|
||||
room.updateMyMembership(KnownMembership.Join);
|
||||
jest.spyOn(room, "canInvite").mockReturnValue(true);
|
||||
mocked(shouldShowComponent).mockReturnValue(true);
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import React from "react";
|
||||
import { render } from "@testing-library/react";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import ConfirmUserActionDialog from "../../../../src/components/views/dialogs/ConfirmUserActionDialog";
|
||||
import { mkRoomMember } from "../../../test-utils";
|
||||
|
@ -25,7 +26,7 @@ describe("ConfirmUserActionDialog", () => {
|
|||
const { asFragment } = render(
|
||||
<ConfirmUserActionDialog
|
||||
onFinished={jest.fn()}
|
||||
member={mkRoomMember("123", "@user:test.com", "join")}
|
||||
member={mkRoomMember("123", "@user:test.com", KnownMembership.Join)}
|
||||
action="Ban"
|
||||
title="Ban this " // eg. 'Ban this user?'
|
||||
/>,
|
||||
|
|
|
@ -18,6 +18,7 @@ import React from "react";
|
|||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { RoomType, MatrixClient, MatrixError, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { sleep } from "matrix-js-sdk/src/utils";
|
||||
import { mocked, Mocked } from "jest-mock";
|
||||
|
||||
|
@ -163,7 +164,7 @@ describe("InviteDialog", () => {
|
|||
mkMembership({
|
||||
event: true,
|
||||
room: roomId,
|
||||
mship: "join",
|
||||
mship: KnownMembership.Join,
|
||||
user: aliceId,
|
||||
skey: aliceId,
|
||||
}),
|
||||
|
|
|
@ -25,6 +25,7 @@ import {
|
|||
Room,
|
||||
RoomMember,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
|
||||
|
@ -158,9 +159,9 @@ describe("Spotlight Dialog", () => {
|
|||
beforeEach(() => {
|
||||
mockedClient = mockClient({ rooms: [testPublicRoom], users: [testPerson] });
|
||||
testRoom = mkRoom(mockedClient, "!test23:example.com");
|
||||
mocked(testRoom.getMyMembership).mockReturnValue("join");
|
||||
mocked(testRoom.getMyMembership).mockReturnValue(KnownMembership.Join);
|
||||
testLocalRoom = new LocalRoom(LOCAL_ROOM_ID_PREFIX + "test23", mockedClient, mockedClient.getUserId()!);
|
||||
testLocalRoom.updateMyMembership("join");
|
||||
testLocalRoom.updateMyMembership(KnownMembership.Join);
|
||||
mocked(mockedClient.getVisibleRooms).mockReturnValue([testRoom, testLocalRoom]);
|
||||
|
||||
jest.spyOn(DMRoomMap, "shared").mockReturnValue({
|
||||
|
@ -169,7 +170,7 @@ describe("Spotlight Dialog", () => {
|
|||
|
||||
testDM = mkRoom(mockedClient, testDMRoomId);
|
||||
testDM.name = "Chat with Alice";
|
||||
mocked(testDM.getMyMembership).mockReturnValue("join");
|
||||
mocked(testDM.getMyMembership).mockReturnValue(KnownMembership.Join);
|
||||
|
||||
mocked(DMRoomMap.shared().getUserIdForRoomId).mockImplementation((roomId: string) => {
|
||||
if (roomId === testDMRoomId) {
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
import React, { ComponentProps } from "react";
|
||||
import { render, RenderResult } from "@testing-library/react";
|
||||
import { MatrixEvent, RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership, Membership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import {
|
||||
getMockClientWithEventEmitter,
|
||||
|
@ -61,8 +62,8 @@ describe("EventListSummary", function () {
|
|||
interface MembershipEventParams {
|
||||
senderId?: string;
|
||||
userId?: string;
|
||||
membership: string;
|
||||
prevMembership?: string;
|
||||
membership: Membership;
|
||||
prevMembership?: Membership;
|
||||
}
|
||||
const generateMembershipEvent = (
|
||||
eventId: string,
|
||||
|
@ -145,7 +146,9 @@ describe("EventListSummary", function () {
|
|||
});
|
||||
|
||||
it("renders expanded events if there are less than props.threshold", function () {
|
||||
const events = generateEvents([{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" }]);
|
||||
const events = generateEvents([
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
]);
|
||||
const props = {
|
||||
events: events,
|
||||
children: generateTiles(events),
|
||||
|
@ -163,8 +166,8 @@ describe("EventListSummary", function () {
|
|||
|
||||
it("renders expanded events if there are less than props.threshold for join and leave", function () {
|
||||
const events = generateEvents([
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
]);
|
||||
const props = {
|
||||
events: events,
|
||||
|
@ -184,9 +187,9 @@ describe("EventListSummary", function () {
|
|||
|
||||
it("renders collapsed events if events.length = props.threshold", function () {
|
||||
const events = generateEvents([
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
]);
|
||||
const props = {
|
||||
events: events,
|
||||
|
@ -203,20 +206,20 @@ describe("EventListSummary", function () {
|
|||
|
||||
it("truncates long join,leave repetitions", function () {
|
||||
const events = generateEvents([
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
]);
|
||||
const props = {
|
||||
events: events,
|
||||
|
@ -235,28 +238,28 @@ describe("EventListSummary", function () {
|
|||
const events = generateEvents([
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "ban",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Ban,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "leave",
|
||||
membership: "invite",
|
||||
prevMembership: KnownMembership.Leave,
|
||||
membership: KnownMembership.Invite,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
]);
|
||||
|
@ -277,30 +280,30 @@ describe("EventListSummary", function () {
|
|||
const events = generateEvents([
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "ban",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Ban,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "leave",
|
||||
membership: "ban",
|
||||
prevMembership: KnownMembership.Leave,
|
||||
membership: KnownMembership.Ban,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
{ userId: "@user_1:some.domain", prevMembership: "ban", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Ban, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "leave",
|
||||
membership: "invite",
|
||||
prevMembership: KnownMembership.Leave,
|
||||
membership: KnownMembership.Invite,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
]);
|
||||
|
@ -324,35 +327,35 @@ describe("EventListSummary", function () {
|
|||
// user_1
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "ban",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Ban,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "leave",
|
||||
membership: "ban",
|
||||
prevMembership: KnownMembership.Leave,
|
||||
membership: KnownMembership.Ban,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
// user_2
|
||||
{
|
||||
userId: "@user_2:some.domain",
|
||||
prevMembership: "ban",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Ban,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
{ userId: "@user_2:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_2:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_2:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_2:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_2:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_2:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_2:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_2:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{
|
||||
userId: "@user_2:some.domain",
|
||||
prevMembership: "leave",
|
||||
membership: "ban",
|
||||
prevMembership: KnownMembership.Leave,
|
||||
membership: KnownMembership.Ban,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
]);
|
||||
|
@ -374,17 +377,17 @@ describe("EventListSummary", function () {
|
|||
it("handles many users following the same sequence of memberships", function () {
|
||||
const events = generateEventsForUsers("@user_$:some.domain", 20, [
|
||||
{
|
||||
prevMembership: "ban",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Ban,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
{ prevMembership: "leave", membership: "join" },
|
||||
{ prevMembership: "join", membership: "leave" },
|
||||
{ prevMembership: "leave", membership: "join" },
|
||||
{ prevMembership: "join", membership: "leave" },
|
||||
{ prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{
|
||||
prevMembership: "leave",
|
||||
membership: "ban",
|
||||
prevMembership: KnownMembership.Leave,
|
||||
membership: KnownMembership.Ban,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
]);
|
||||
|
@ -407,30 +410,30 @@ describe("EventListSummary", function () {
|
|||
const events = generateEvents([
|
||||
{
|
||||
userId: "@user_2:some.domain",
|
||||
prevMembership: "ban",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Ban,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "ban",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Ban,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "leave",
|
||||
membership: "ban",
|
||||
prevMembership: KnownMembership.Leave,
|
||||
membership: KnownMembership.Ban,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
{ userId: "@user_2:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_2:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_2:some.domain", prevMembership: "leave", membership: "join" },
|
||||
{ userId: "@user_2:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_2:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_2:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
{ userId: "@user_2:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
|
||||
{ userId: "@user_2:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
]);
|
||||
const props = {
|
||||
events: events,
|
||||
|
@ -451,52 +454,52 @@ describe("EventListSummary", function () {
|
|||
it("correctly identifies transitions", function () {
|
||||
const events = generateEvents([
|
||||
// invited
|
||||
{ userId: "@user_1:some.domain", membership: "invite" },
|
||||
{ userId: "@user_1:some.domain", membership: KnownMembership.Invite },
|
||||
// banned
|
||||
{ userId: "@user_1:some.domain", membership: "ban" },
|
||||
{ userId: "@user_1:some.domain", membership: KnownMembership.Ban },
|
||||
// joined
|
||||
{ userId: "@user_1:some.domain", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", membership: KnownMembership.Join },
|
||||
// invite_reject
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "invite",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Invite,
|
||||
membership: KnownMembership.Leave,
|
||||
},
|
||||
// left
|
||||
{ userId: "@user_1:some.domain", prevMembership: "join", membership: "leave" },
|
||||
{ userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
|
||||
// invite_withdrawal
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "invite",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Invite,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
// unbanned
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "ban",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Ban,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
// kicked
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "join",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Join,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
// default for sender=target (leave)
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "????",
|
||||
membership: "leave",
|
||||
prevMembership: "????" as Membership,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@user_1:some.domain",
|
||||
},
|
||||
// default for sender<>target (kicked)
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "????",
|
||||
membership: "leave",
|
||||
prevMembership: "????" as Membership,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
]);
|
||||
|
@ -520,24 +523,24 @@ describe("EventListSummary", function () {
|
|||
const events = generateEvents([
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "invite",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Invite,
|
||||
membership: KnownMembership.Leave,
|
||||
},
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "invite",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Invite,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
{
|
||||
userId: "@user_2:some.domain",
|
||||
prevMembership: "invite",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Invite,
|
||||
membership: KnownMembership.Leave,
|
||||
},
|
||||
{
|
||||
userId: "@user_2:some.domain",
|
||||
prevMembership: "invite",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Invite,
|
||||
membership: KnownMembership.Leave,
|
||||
senderId: "@some_other_user:some.domain",
|
||||
},
|
||||
]);
|
||||
|
@ -560,13 +563,13 @@ describe("EventListSummary", function () {
|
|||
const events = generateEvents([
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "invite",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Invite,
|
||||
membership: KnownMembership.Leave,
|
||||
},
|
||||
{
|
||||
userId: "@user_1:some.domain",
|
||||
prevMembership: "invite",
|
||||
membership: "leave",
|
||||
prevMembership: KnownMembership.Invite,
|
||||
membership: KnownMembership.Leave,
|
||||
},
|
||||
]);
|
||||
const props = {
|
||||
|
@ -584,10 +587,10 @@ describe("EventListSummary", function () {
|
|||
|
||||
it('handles a summary length = 2, with no "others"', function () {
|
||||
const events = generateEvents([
|
||||
{ userId: "@user_1:some.domain", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", membership: "join" },
|
||||
{ userId: "@user_2:some.domain", membership: "join" },
|
||||
{ userId: "@user_2:some.domain", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", membership: KnownMembership.Join },
|
||||
{ userId: "@user_1:some.domain", membership: KnownMembership.Join },
|
||||
{ userId: "@user_2:some.domain", membership: KnownMembership.Join },
|
||||
{ userId: "@user_2:some.domain", membership: KnownMembership.Join },
|
||||
]);
|
||||
const props = {
|
||||
events: events,
|
||||
|
@ -604,9 +607,9 @@ describe("EventListSummary", function () {
|
|||
|
||||
it('handles a summary length = 2, with 1 "other"', function () {
|
||||
const events = generateEvents([
|
||||
{ userId: "@user_1:some.domain", membership: "join" },
|
||||
{ userId: "@user_2:some.domain", membership: "join" },
|
||||
{ userId: "@user_3:some.domain", membership: "join" },
|
||||
{ userId: "@user_1:some.domain", membership: KnownMembership.Join },
|
||||
{ userId: "@user_2:some.domain", membership: KnownMembership.Join },
|
||||
{ userId: "@user_3:some.domain", membership: KnownMembership.Join },
|
||||
]);
|
||||
const props = {
|
||||
events: events,
|
||||
|
@ -622,7 +625,7 @@ describe("EventListSummary", function () {
|
|||
});
|
||||
|
||||
it('handles a summary length = 2, with many "others"', function () {
|
||||
const events = generateEventsForUsers("@user_$:some.domain", 20, [{ membership: "join" }]);
|
||||
const events = generateEventsForUsers("@user_$:some.domain", 20, [{ membership: KnownMembership.Join }]);
|
||||
const props = {
|
||||
events: events,
|
||||
children: generateTiles(events),
|
||||
|
|
|
@ -15,13 +15,14 @@ limitations under the License.
|
|||
import { render } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import { TooltipProvider } from "@vector-im/compound-web";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import FacePile from "../../../../src/components/views/elements/FacePile";
|
||||
import { mkRoomMember } from "../../../test-utils";
|
||||
|
||||
describe("<FacePile />", () => {
|
||||
it("renders with a tooltip", () => {
|
||||
const member = mkRoomMember("123", "456", "join");
|
||||
const member = mkRoomMember("123", "456", KnownMembership.Join);
|
||||
|
||||
const { asFragment } = render(
|
||||
<FacePile members={[member]} size="36px" overflow={false} tooltipLabel="tooltip" />,
|
||||
|
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
import { render } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import { TooltipProvider } from "@vector-im/compound-web";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { mkRoom, mkRoomMember, stubClient, withClientContextRenderOptions } from "../../../test-utils";
|
||||
import RoomFacePile from "../../../../src/components/views/elements/RoomFacePile";
|
||||
|
@ -27,7 +28,9 @@ describe("<RoomFacePile />", () => {
|
|||
DMRoomMap.makeShared(cli);
|
||||
const room = mkRoom(cli, "!123");
|
||||
|
||||
jest.spyOn(room, "getJoinedMembers").mockReturnValue([mkRoomMember(room.roomId, "@bob:example.org", "join")]);
|
||||
jest.spyOn(room, "getJoinedMembers").mockReturnValue([
|
||||
mkRoomMember(room.roomId, "@bob:example.org", KnownMembership.Join),
|
||||
]);
|
||||
|
||||
const { asFragment } = render(
|
||||
<TooltipProvider>
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
import React from "react";
|
||||
import { render, fireEvent, screen } from "@testing-library/react";
|
||||
import { EventType, MatrixEvent, Room, MatrixClient, JoinRule } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { mocked, MockedObject } from "jest-mock";
|
||||
import { TooltipProvider } from "@vector-im/compound-web";
|
||||
|
||||
|
@ -86,7 +87,7 @@ describe("<RoomSummaryCard />", () => {
|
|||
state_key: "",
|
||||
});
|
||||
room.currentState.setStateEvents([roomCreateEvent]);
|
||||
room.updateMyMembership("join");
|
||||
room.updateMyMembership(KnownMembership.Join);
|
||||
|
||||
jest.spyOn(Modal, "createDialog");
|
||||
jest.spyOn(RightPanelStore.instance, "pushCard");
|
||||
|
|
|
@ -29,6 +29,7 @@ import {
|
|||
DeviceVerificationStatus,
|
||||
Device,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import {
|
||||
Phase,
|
||||
VerificationRequest,
|
||||
|
@ -943,8 +944,8 @@ describe("<PowerLevelEditor />", () => {
|
|||
|
||||
describe("<RoomKickButton />", () => {
|
||||
const defaultMember = new RoomMember(defaultRoomId, defaultUserId);
|
||||
const memberWithInviteMembership = { ...defaultMember, membership: "invite" };
|
||||
const memberWithJoinMembership = { ...defaultMember, membership: "join" };
|
||||
const memberWithInviteMembership = { ...defaultMember, membership: KnownMembership.Invite };
|
||||
const memberWithJoinMembership = { ...defaultMember, membership: KnownMembership.Join };
|
||||
|
||||
let defaultProps: Parameters<typeof RoomKickButton>[0];
|
||||
beforeEach(() => {
|
||||
|
@ -1031,7 +1032,7 @@ describe("<RoomKickButton />", () => {
|
|||
// null vs their member followed by
|
||||
// my member vs their member
|
||||
const mockMyMember = { powerLevel: 1 };
|
||||
const mockTheirMember = { membership: "invite", powerLevel: 0 };
|
||||
const mockTheirMember = { membership: KnownMembership.Invite, powerLevel: 0 };
|
||||
|
||||
const mockRoom = {
|
||||
getMember: jest
|
||||
|
@ -1052,7 +1053,7 @@ describe("<RoomKickButton />", () => {
|
|||
|
||||
describe("<BanToggleButton />", () => {
|
||||
const defaultMember = new RoomMember(defaultRoomId, defaultUserId);
|
||||
const memberWithBanMembership = { ...defaultMember, membership: "ban" };
|
||||
const memberWithBanMembership = { ...defaultMember, membership: KnownMembership.Ban };
|
||||
let defaultProps: Parameters<typeof BanToggleButton>[0];
|
||||
beforeEach(() => {
|
||||
defaultProps = {
|
||||
|
@ -1161,7 +1162,7 @@ describe("<BanToggleButton />", () => {
|
|||
// null vs their member followed by
|
||||
// my member vs their member
|
||||
const mockMyMember = { powerLevel: 1 };
|
||||
const mockTheirMember = { membership: "ban", powerLevel: 0 };
|
||||
const mockTheirMember = { membership: KnownMembership.Ban, powerLevel: 0 };
|
||||
|
||||
const mockRoom = {
|
||||
getMember: jest
|
||||
|
@ -1182,7 +1183,7 @@ describe("<BanToggleButton />", () => {
|
|||
|
||||
describe("<RoomAdminToolsContainer />", () => {
|
||||
const defaultMember = new RoomMember(defaultRoomId, defaultUserId);
|
||||
defaultMember.membership = "invite";
|
||||
defaultMember.membership = KnownMembership.Invite;
|
||||
|
||||
let defaultProps: Parameters<typeof RoomAdminToolsContainer>[0];
|
||||
beforeEach(() => {
|
||||
|
@ -1245,7 +1246,11 @@ describe("<RoomAdminToolsContainer />", () => {
|
|||
mockMeMember.powerLevel = 51; // defaults to 50
|
||||
mockRoom.getMember.mockReturnValueOnce(mockMeMember);
|
||||
|
||||
const defaultMemberWithPowerLevelAndJoinMembership = { ...defaultMember, powerLevel: 0, membership: "join" };
|
||||
const defaultMemberWithPowerLevelAndJoinMembership = {
|
||||
...defaultMember,
|
||||
powerLevel: 0,
|
||||
membership: KnownMembership.Join,
|
||||
};
|
||||
|
||||
renderComponent({
|
||||
member: defaultMemberWithPowerLevelAndJoinMembership,
|
||||
|
@ -1263,7 +1268,11 @@ describe("<RoomAdminToolsContainer />", () => {
|
|||
mockMeMember.powerLevel = 51; // defaults to 50
|
||||
mockRoom.getMember.mockReturnValueOnce(mockMeMember);
|
||||
|
||||
const defaultMemberWithPowerLevelAndJoinMembership = { ...defaultMember, powerLevel: 0, membership: "join" };
|
||||
const defaultMemberWithPowerLevelAndJoinMembership = {
|
||||
...defaultMember,
|
||||
powerLevel: 0,
|
||||
membership: KnownMembership.Join,
|
||||
};
|
||||
|
||||
renderComponent({
|
||||
member: defaultMemberWithPowerLevelAndJoinMembership,
|
||||
|
|
|
@ -26,6 +26,7 @@ import {
|
|||
ISearchResults,
|
||||
IContent,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { CallType } from "matrix-js-sdk/src/webrtc/call";
|
||||
import { ClientWidgetApi, Widget } from "matrix-widget-api";
|
||||
import EventEmitter from "events";
|
||||
|
@ -907,7 +908,7 @@ function mkJoinEvent(roomId: string, userId: string) {
|
|||
room: roomId,
|
||||
user: userId,
|
||||
content: {
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
avatar_url: "mxc://example.org/" + userId,
|
||||
},
|
||||
});
|
||||
|
|
|
@ -18,6 +18,7 @@ limitations under the License.
|
|||
import React from "react";
|
||||
import { act, fireEvent, render, RenderResult, screen } from "@testing-library/react";
|
||||
import { Room, MatrixClient, RoomState, RoomMember, User, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { compare } from "matrix-js-sdk/src/utils";
|
||||
import { mocked, MockedObject } from "jest-mock";
|
||||
import { TooltipProvider } from "@vector-im/compound-web";
|
||||
|
@ -170,7 +171,7 @@ describe("MemberList", () => {
|
|||
const usersPerLevel = 2;
|
||||
for (let i = 0; i < usersPerLevel; i++) {
|
||||
const adminUser = new RoomMember(memberListRoom.roomId, `@admin${i}:localhost`);
|
||||
adminUser.membership = "join";
|
||||
adminUser.membership = KnownMembership.Join;
|
||||
adminUser.powerLevel = 100;
|
||||
adminUser.user = User.createUser(adminUser.userId, client);
|
||||
adminUser.user.currentlyActive = true;
|
||||
|
@ -180,7 +181,7 @@ describe("MemberList", () => {
|
|||
adminUsers.push(adminUser);
|
||||
|
||||
const moderatorUser = new RoomMember(memberListRoom.roomId, `@moderator${i}:localhost`);
|
||||
moderatorUser.membership = "join";
|
||||
moderatorUser.membership = KnownMembership.Join;
|
||||
moderatorUser.powerLevel = 50;
|
||||
moderatorUser.user = User.createUser(moderatorUser.userId, client);
|
||||
moderatorUser.user.currentlyActive = true;
|
||||
|
@ -190,7 +191,7 @@ describe("MemberList", () => {
|
|||
moderatorUsers.push(moderatorUser);
|
||||
|
||||
const defaultUser = new RoomMember(memberListRoom.roomId, `@default${i}:localhost`);
|
||||
defaultUser.membership = "join";
|
||||
defaultUser.membership = KnownMembership.Join;
|
||||
defaultUser.powerLevel = 0;
|
||||
defaultUser.user = User.createUser(defaultUser.userId, client);
|
||||
defaultUser.user.currentlyActive = true;
|
||||
|
@ -402,7 +403,7 @@ describe("MemberList", () => {
|
|||
});
|
||||
|
||||
it("renders disabled invite button when current user is a member but does not have rights to invite", async () => {
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("join");
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
|
||||
jest.spyOn(room, "canInvite").mockReturnValue(false);
|
||||
|
||||
renderComponent();
|
||||
|
@ -413,7 +414,7 @@ describe("MemberList", () => {
|
|||
});
|
||||
|
||||
it("renders enabled invite button when current user is a member and has rights to invite", async () => {
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("join");
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
|
||||
jest.spyOn(room, "canInvite").mockReturnValue(true);
|
||||
|
||||
renderComponent();
|
||||
|
@ -424,7 +425,7 @@ describe("MemberList", () => {
|
|||
|
||||
it("opens room inviter on button click", async () => {
|
||||
jest.spyOn(defaultDispatcher, "dispatch");
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("join");
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
|
||||
jest.spyOn(room, "canInvite").mockReturnValue(true);
|
||||
|
||||
renderComponent();
|
||||
|
|
|
@ -27,6 +27,7 @@ import {
|
|||
PendingEventOrdering,
|
||||
ReceiptType,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { mkThread } from "../../../../test-utils/threads";
|
||||
|
@ -140,7 +141,7 @@ describe("UnreadNotificationBadge", () => {
|
|||
});
|
||||
|
||||
it("adds a warning for invites", () => {
|
||||
room.updateMyMembership("invite");
|
||||
room.updateMyMembership(KnownMembership.Invite);
|
||||
render(getComponent());
|
||||
expect(screen.queryByText("!")).not.toBeNull();
|
||||
});
|
||||
|
|
|
@ -25,6 +25,7 @@ import {
|
|||
Room,
|
||||
RoomMember,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import {
|
||||
createEvent,
|
||||
fireEvent,
|
||||
|
@ -154,7 +155,7 @@ describe("RoomHeader", () => {
|
|||
name: "Member",
|
||||
rawDisplayName: "Member",
|
||||
roomId: room.roomId,
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
},
|
||||
|
@ -172,7 +173,7 @@ describe("RoomHeader", () => {
|
|||
name: "Member",
|
||||
rawDisplayName: "Member",
|
||||
roomId: room.roomId,
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
},
|
||||
|
@ -181,7 +182,7 @@ describe("RoomHeader", () => {
|
|||
name: "Member",
|
||||
rawDisplayName: "Member",
|
||||
roomId: room.roomId,
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
},
|
||||
|
@ -190,7 +191,7 @@ describe("RoomHeader", () => {
|
|||
name: "Member",
|
||||
rawDisplayName: "Member",
|
||||
roomId: room.roomId,
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
},
|
||||
|
@ -199,7 +200,7 @@ describe("RoomHeader", () => {
|
|||
name: "Bot user",
|
||||
rawDisplayName: "Bot user",
|
||||
roomId: room.roomId,
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
getAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
|
||||
},
|
||||
|
@ -703,7 +704,7 @@ function mockRoomMembers(room: Room, count: number) {
|
|||
name: `Member ${index}`,
|
||||
rawDisplayName: `Member ${index}`,
|
||||
roomId: room.roomId,
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
getAvatarUrl: () => `mxc://avatar.url/user-${index}.png`,
|
||||
getMxcAvatarUrl: () => `mxc://avatar.url/user-${index}.png`,
|
||||
}));
|
||||
|
|
|
@ -25,6 +25,7 @@ import {
|
|||
RoomMember,
|
||||
RoomStateEvent,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import React from "react";
|
||||
|
||||
import ErrorDialog from "../../../../src/components/views/dialogs/ErrorDialog";
|
||||
|
@ -111,15 +112,26 @@ describe("RoomKnocksBar", () => {
|
|||
const other = new RoomMember(roomId, "@doe:example.org");
|
||||
|
||||
bob.setMembershipEvent(
|
||||
new MatrixEvent({ content: { displayname: "Bob", membership: "knock" }, type: EventType.RoomMember }),
|
||||
new MatrixEvent({
|
||||
content: { displayname: "Bob", membership: KnownMembership.Knock },
|
||||
type: EventType.RoomMember,
|
||||
}),
|
||||
);
|
||||
jane.setMembershipEvent(
|
||||
new MatrixEvent({ content: { displayname: "Jane", membership: "knock" }, type: EventType.RoomMember }),
|
||||
new MatrixEvent({
|
||||
content: { displayname: "Jane", membership: KnownMembership.Knock },
|
||||
type: EventType.RoomMember,
|
||||
}),
|
||||
);
|
||||
john.setMembershipEvent(
|
||||
new MatrixEvent({ content: { displayname: "John", membership: "knock" }, type: EventType.RoomMember }),
|
||||
new MatrixEvent({
|
||||
content: { displayname: "John", membership: KnownMembership.Knock },
|
||||
type: EventType.RoomMember,
|
||||
}),
|
||||
);
|
||||
other.setMembershipEvent(
|
||||
new MatrixEvent({ content: { membership: KnownMembership.Knock }, type: EventType.RoomMember }),
|
||||
);
|
||||
other.setMembershipEvent(new MatrixEvent({ content: { membership: "knock" }, type: EventType.RoomMember }));
|
||||
|
||||
beforeEach(async () => {
|
||||
await clearAllModals();
|
||||
|
@ -178,7 +190,7 @@ describe("RoomKnocksBar", () => {
|
|||
it("renders a link to open the room settings people tab", () => {
|
||||
bob.setMembershipEvent(
|
||||
new MatrixEvent({
|
||||
content: { displayname: "Bob", membership: "knock", reason: "some reason" },
|
||||
content: { displayname: "Bob", membership: KnownMembership.Knock, reason: "some reason" },
|
||||
type: EventType.RoomMember,
|
||||
}),
|
||||
);
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
import React, { ComponentProps } from "react";
|
||||
import { render, fireEvent, RenderResult, waitFor } from "@testing-library/react";
|
||||
import { Room, RoomMember, MatrixError, IContent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { withClientContextRenderOptions, stubClient } from "../../../test-utils";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
|
@ -49,10 +50,10 @@ const makeMockRoomMember = ({
|
|||
}: {
|
||||
userId?: string;
|
||||
isKicked?: boolean;
|
||||
membership?: "invite" | "ban" | "leave";
|
||||
membership?: KnownMembership.Invite | KnownMembership.Ban | KnownMembership.Leave;
|
||||
content?: Partial<IContent>;
|
||||
memberContent?: Partial<IContent>;
|
||||
oldMembership?: "join" | "knock";
|
||||
oldMembership?: KnownMembership.Join | KnownMembership.Knock;
|
||||
}) =>
|
||||
({
|
||||
userId,
|
||||
|
@ -180,7 +181,11 @@ describe("<RoomPreviewBar />", () => {
|
|||
it("renders denied request message", () => {
|
||||
const room = createRoom(roomId, otherUserId);
|
||||
jest.spyOn(room, "getMember").mockReturnValue(
|
||||
makeMockRoomMember({ isKicked: true, membership: "leave", oldMembership: "knock" }),
|
||||
makeMockRoomMember({
|
||||
isKicked: true,
|
||||
membership: KnownMembership.Leave,
|
||||
oldMembership: KnownMembership.Knock,
|
||||
}),
|
||||
);
|
||||
const component = getComponent({ room, promptAskToJoin: true });
|
||||
|
||||
|
@ -191,7 +196,11 @@ describe("<RoomPreviewBar />", () => {
|
|||
const onForgetClick = jest.fn();
|
||||
const room = createRoom(roomId, otherUserId);
|
||||
jest.spyOn(room, "getMember").mockReturnValue(
|
||||
makeMockRoomMember({ isKicked: true, membership: "leave", oldMembership: "knock" }),
|
||||
makeMockRoomMember({
|
||||
isKicked: true,
|
||||
membership: KnownMembership.Leave,
|
||||
oldMembership: KnownMembership.Knock,
|
||||
}),
|
||||
);
|
||||
const component = getComponent({ room, promptAskToJoin: true, onForgetClick });
|
||||
|
||||
|
@ -201,7 +210,7 @@ describe("<RoomPreviewBar />", () => {
|
|||
|
||||
it("renders banned message", () => {
|
||||
const room = createRoom(roomId, otherUserId);
|
||||
jest.spyOn(room, "getMember").mockReturnValue(makeMockRoomMember({ membership: "ban" }));
|
||||
jest.spyOn(room, "getMember").mockReturnValue(makeMockRoomMember({ membership: KnownMembership.Ban }));
|
||||
const component = getComponent({ loading: true, room });
|
||||
|
||||
expect(getMessage(component)).toMatchSnapshot();
|
||||
|
@ -244,8 +253,8 @@ describe("<RoomPreviewBar />", () => {
|
|||
const userMember = makeMockRoomMember({ userId });
|
||||
const userMemberWithDmInvite = makeMockRoomMember({
|
||||
userId,
|
||||
membership: "invite",
|
||||
memberContent: { is_direct: true, membership: "invite" },
|
||||
membership: KnownMembership.Invite,
|
||||
memberContent: { is_direct: true, membership: KnownMembership.Invite },
|
||||
});
|
||||
const inviterMember = makeMockRoomMember({
|
||||
userId: inviterUserId,
|
||||
|
|
|
@ -18,6 +18,7 @@ import React from "react";
|
|||
import { mocked, Mocked } from "jest-mock";
|
||||
import { render, screen, act } from "@testing-library/react";
|
||||
import { PendingEventOrdering, Room, RoomStateEvent, RoomType } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import type { MatrixClient, RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
import { stubClient, wrapInMatrixClientContext, mkRoomMember } from "../../../test-utils";
|
||||
|
@ -68,7 +69,7 @@ describe("RoomPreviewCard", () => {
|
|||
|
||||
it("shows a beta pill on Jitsi video room invites", async () => {
|
||||
jest.spyOn(room, "getType").mockReturnValue(RoomType.ElementVideo);
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("invite");
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Invite);
|
||||
enabledFeatures = ["feature_video_rooms"];
|
||||
|
||||
await renderPreview();
|
||||
|
@ -77,7 +78,7 @@ describe("RoomPreviewCard", () => {
|
|||
|
||||
it("shows a beta pill on Element video room invites", async () => {
|
||||
jest.spyOn(room, "getType").mockReturnValue(RoomType.UnstableCall);
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("invite");
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Invite);
|
||||
enabledFeatures = ["feature_video_rooms", "feature_element_call_video_rooms"];
|
||||
|
||||
await renderPreview();
|
||||
|
@ -85,7 +86,7 @@ describe("RoomPreviewCard", () => {
|
|||
});
|
||||
|
||||
it("doesn't show a beta pill on normal invites", async () => {
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("invite");
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Invite);
|
||||
|
||||
await renderPreview();
|
||||
expect(screen.queryByRole("button", { name: /beta/i })).toBeNull();
|
||||
|
@ -93,7 +94,7 @@ describe("RoomPreviewCard", () => {
|
|||
|
||||
it("shows instructions on Jitsi video rooms invites if video rooms are disabled", async () => {
|
||||
jest.spyOn(room, "getType").mockReturnValue(RoomType.ElementVideo);
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("invite");
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Invite);
|
||||
|
||||
await renderPreview();
|
||||
screen.getByText(/enable video rooms in labs/i);
|
||||
|
@ -101,7 +102,7 @@ describe("RoomPreviewCard", () => {
|
|||
|
||||
it("shows instructions on Element video rooms invites if video rooms are disabled", async () => {
|
||||
jest.spyOn(room, "getType").mockReturnValue(RoomType.UnstableCall);
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("invite");
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Invite);
|
||||
enabledFeatures = ["feature_element_call_video_rooms"];
|
||||
|
||||
await renderPreview();
|
||||
|
|
|
@ -25,6 +25,7 @@ import {
|
|||
RoomStateEvent,
|
||||
Thread,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { Widget } from "matrix-widget-api";
|
||||
|
||||
import type { RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
|
@ -187,7 +188,7 @@ describe("RoomTile", () => {
|
|||
return name === "feature_ask_to_join";
|
||||
});
|
||||
mocked(shouldShowComponent).mockReturnValue(true);
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("knock");
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Knock);
|
||||
const { container } = renderRoomTile();
|
||||
expect(container.querySelector(".mx_RoomTile_sticky")).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Room options" })).not.toBeInTheDocument();
|
||||
|
@ -198,9 +199,15 @@ describe("RoomTile", () => {
|
|||
return name === "feature_ask_to_join";
|
||||
});
|
||||
mocked(shouldShowComponent).mockReturnValue(true);
|
||||
const roomMember = mkRoomMember(room.roomId, MatrixClientPeg.get()!.getSafeUserId(), "leave", true, {
|
||||
membership: "knock",
|
||||
});
|
||||
const roomMember = mkRoomMember(
|
||||
room.roomId,
|
||||
MatrixClientPeg.get()!.getSafeUserId(),
|
||||
KnownMembership.Leave,
|
||||
true,
|
||||
{
|
||||
membership: KnownMembership.Knock,
|
||||
},
|
||||
);
|
||||
jest.spyOn(room, "getMember").mockReturnValue(roomMember);
|
||||
const { container } = renderRoomTile();
|
||||
expect(container.querySelector(".mx_RoomTile_sticky")).toBeInTheDocument();
|
||||
|
|
|
@ -28,6 +28,7 @@ import {
|
|||
MatrixError,
|
||||
Visibility,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { defer, IDeferred } from "matrix-js-sdk/src/utils";
|
||||
|
||||
import {
|
||||
|
@ -177,7 +178,7 @@ describe("<JoinRuleSettings />", () => {
|
|||
const memberBob = new RoomMember(roomId, "@bob:server.org");
|
||||
const memberCharlie = new RoomMember(roomId, "@charlie:server.org");
|
||||
jest.spyOn(room, "getMembersWithMembership").mockImplementation((membership) =>
|
||||
membership === "join" ? [memberAlice, memberBob] : [memberCharlie],
|
||||
membership === KnownMembership.Join ? [memberAlice, memberBob] : [memberCharlie],
|
||||
);
|
||||
const upgradedRoom = new Room(newRoomId, client, userId);
|
||||
setRoomStateEvents(upgradedRoom, preferredRoomVersion);
|
||||
|
|
|
@ -24,6 +24,7 @@ import {
|
|||
RoomMember,
|
||||
RoomStateEvent,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import React from "react";
|
||||
|
||||
import ErrorDialog from "../../../../../../src/components/views/dialogs/ErrorDialog";
|
||||
|
@ -91,7 +92,7 @@ describe("PeopleRoomSettingsTab", () => {
|
|||
content: {
|
||||
avatar_url: "mxc://example.org/albert-einstein.png",
|
||||
displayname: "Albert Einstein",
|
||||
membership: "knock",
|
||||
membership: KnownMembership.Knock,
|
||||
reason,
|
||||
},
|
||||
origin_server_ts: -464140800000,
|
||||
|
@ -110,7 +111,7 @@ describe("PeopleRoomSettingsTab", () => {
|
|||
new MatrixEvent({
|
||||
content: {
|
||||
displayname: "albert.einstein",
|
||||
membership: "knock",
|
||||
membership: KnownMembership.Knock,
|
||||
},
|
||||
type: EventType.RoomMember,
|
||||
}),
|
||||
|
@ -138,7 +139,7 @@ describe("PeopleRoomSettingsTab", () => {
|
|||
new MatrixEvent({
|
||||
content: {
|
||||
displayname: "albert.einstein",
|
||||
membership: "knock",
|
||||
membership: KnownMembership.Knock,
|
||||
reason,
|
||||
},
|
||||
type: EventType.RoomMember,
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
import React from "react";
|
||||
import { fireEvent, getByRole, render, RenderResult, screen, waitFor } from "@testing-library/react";
|
||||
import { MatrixClient, EventType, MatrixEvent, Room, RoomMember, ISendEventResponse } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { mocked } from "jest-mock";
|
||||
import { defer } from "matrix-js-sdk/src/utils";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
@ -198,7 +199,7 @@ describe("RolesRoomSettingsTab", () => {
|
|||
new MatrixEvent({
|
||||
type: EventType.RoomMember,
|
||||
content: {
|
||||
membership: "ban",
|
||||
membership: KnownMembership.Ban,
|
||||
reason: "just testing",
|
||||
},
|
||||
sender: userId,
|
||||
|
@ -219,7 +220,7 @@ describe("RolesRoomSettingsTab", () => {
|
|||
new MatrixEvent({
|
||||
type: EventType.RoomMember,
|
||||
content: {
|
||||
membership: "ban",
|
||||
membership: KnownMembership.Ban,
|
||||
reason: "just testing",
|
||||
},
|
||||
sender: userId,
|
||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
import { waitFor } from "@testing-library/react";
|
||||
import { renderHook, act } from "@testing-library/react-hooks/dom";
|
||||
import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { MatrixClientPeg } from "../../src/MatrixClientPeg";
|
||||
import { stubClient } from "../test-utils";
|
||||
|
@ -49,7 +50,7 @@ describe("useRoomMembers", () => {
|
|||
state_key: "!user:server",
|
||||
room_id: room.roomId,
|
||||
content: {
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
@ -85,7 +86,7 @@ describe("useRoomMemberCount", () => {
|
|||
state_key: "!user:server",
|
||||
room_id: room.roomId,
|
||||
content: {
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
@ -109,14 +110,14 @@ describe("useMyRoomMembership", () => {
|
|||
});
|
||||
|
||||
it("should update on RoomState.Members events", async () => {
|
||||
room.updateMyMembership("join");
|
||||
room.updateMyMembership(KnownMembership.Join);
|
||||
const { result } = render(room);
|
||||
|
||||
expect(result.current).toBe("join");
|
||||
expect(result.current).toBe(KnownMembership.Join);
|
||||
|
||||
act(() => {
|
||||
room.updateMyMembership("leave");
|
||||
room.updateMyMembership(KnownMembership.Leave);
|
||||
});
|
||||
await waitFor(() => expect(result.current).toBe("leave"));
|
||||
await waitFor(() => expect(result.current).toBe(KnownMembership.Leave));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import { renderHook } from "@testing-library/react-hooks";
|
||||
import { EventStatus, NotificationCountType, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { useUnreadNotifications } from "../../src/hooks/useUnreadNotifications";
|
||||
|
@ -66,7 +67,7 @@ describe("useUnreadNotifications", () => {
|
|||
});
|
||||
|
||||
it("indicates the user has been invited to a channel", async () => {
|
||||
room.updateMyMembership("invite");
|
||||
room.updateMyMembership(KnownMembership.Invite);
|
||||
|
||||
const { result } = renderHook(() => useUnreadNotifications(room));
|
||||
const { level, symbol, count } = result.current;
|
||||
|
|
|
@ -26,6 +26,7 @@ import {
|
|||
PendingEventOrdering,
|
||||
IContent,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { Widget } from "matrix-widget-api";
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { MatrixRTCSessionManagerEvents } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSessionManager";
|
||||
|
@ -103,7 +104,7 @@ const setUpClientRoomAndStores = (): {
|
|||
}
|
||||
});
|
||||
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue("join");
|
||||
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
|
||||
|
||||
client.getRoom.mockImplementation((roomId) => (roomId === room.roomId ? room : null));
|
||||
client.getRoom.mockImplementation((roomId) => (roomId === room.roomId ? room : null));
|
||||
|
@ -388,7 +389,7 @@ describe("JitsiCall", () => {
|
|||
it("disconnects when we leave the room", async () => {
|
||||
await call.start();
|
||||
expect(call.connectionState).toBe(ConnectionState.Connected);
|
||||
room.emit(RoomEvent.MyMembership, room, "leave");
|
||||
room.emit(RoomEvent.MyMembership, room, KnownMembership.Leave);
|
||||
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
||||
});
|
||||
|
||||
|
@ -403,7 +404,7 @@ describe("JitsiCall", () => {
|
|||
it("remains connected if we stay in the room", async () => {
|
||||
await call.start();
|
||||
expect(call.connectionState).toBe(ConnectionState.Connected);
|
||||
room.emit(RoomEvent.MyMembership, room, "join");
|
||||
room.emit(RoomEvent.MyMembership, room, KnownMembership.Join);
|
||||
expect(call.connectionState).toBe(ConnectionState.Connected);
|
||||
});
|
||||
|
||||
|
@ -919,14 +920,14 @@ describe("ElementCall", () => {
|
|||
it("disconnects when we leave the room", async () => {
|
||||
await callConnectProcedure(call);
|
||||
expect(call.connectionState).toBe(ConnectionState.Connected);
|
||||
room.emit(RoomEvent.MyMembership, room, "leave");
|
||||
room.emit(RoomEvent.MyMembership, room, KnownMembership.Leave);
|
||||
expect(call.connectionState).toBe(ConnectionState.Disconnected);
|
||||
});
|
||||
|
||||
it("remains connected if we stay in the room", async () => {
|
||||
await callConnectProcedure(call);
|
||||
expect(call.connectionState).toBe(ConnectionState.Connected);
|
||||
room.emit(RoomEvent.MyMembership, room, "join");
|
||||
room.emit(RoomEvent.MyMembership, room, KnownMembership.Join);
|
||||
expect(call.connectionState).toBe(ConnectionState.Connected);
|
||||
});
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import { mocked } from "jest-mock";
|
||||
import { EventType, IContent, MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import SdkConfig from "../../src/SdkConfig";
|
||||
import SettingsStore from "../../src/settings/SettingsStore";
|
||||
|
@ -55,7 +56,7 @@ describe("MemberListStore", () => {
|
|||
type: EventType.RoomMember,
|
||||
state_key: alice,
|
||||
content: {
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
},
|
||||
sender: alice,
|
||||
room_id: roomId,
|
||||
|
@ -77,8 +78,8 @@ describe("MemberListStore", () => {
|
|||
});
|
||||
|
||||
it("loads members in a room", async () => {
|
||||
addMember(room, bob, "invite");
|
||||
addMember(room, charlie, "leave");
|
||||
addMember(room, bob, KnownMembership.Invite);
|
||||
addMember(room, charlie, KnownMembership.Leave);
|
||||
|
||||
const { invited, joined } = await store.loadMemberList(roomId);
|
||||
expect(invited).toEqual([room.getMember(bob)]);
|
||||
|
@ -92,8 +93,8 @@ describe("MemberListStore", () => {
|
|||
});
|
||||
|
||||
it("sorts by power level", async () => {
|
||||
addMember(room, bob, "join");
|
||||
addMember(room, charlie, "join");
|
||||
addMember(room, bob, KnownMembership.Join);
|
||||
addMember(room, charlie, KnownMembership.Join);
|
||||
setPowerLevels(room, {
|
||||
users: {
|
||||
[alice]: 100,
|
||||
|
@ -109,8 +110,8 @@ describe("MemberListStore", () => {
|
|||
|
||||
it("sorts by name if power level is equal", async () => {
|
||||
const doris = "@doris:bar";
|
||||
addMember(room, bob, "join");
|
||||
addMember(room, charlie, "join");
|
||||
addMember(room, bob, KnownMembership.Join);
|
||||
addMember(room, charlie, KnownMembership.Join);
|
||||
setPowerLevels(room, {
|
||||
users_default: 10,
|
||||
});
|
||||
|
@ -120,7 +121,7 @@ describe("MemberListStore", () => {
|
|||
expect(joined).toEqual([room.getMember(alice), room.getMember(bob), room.getMember(charlie)]);
|
||||
|
||||
// Ensure it sorts by display name if they are set
|
||||
addMember(room, doris, "join", "AAAAA");
|
||||
addMember(room, doris, KnownMembership.Join, "AAAAA");
|
||||
({ invited, joined } = await store.loadMemberList(roomId));
|
||||
expect(invited).toEqual([]);
|
||||
expect(joined).toEqual([
|
||||
|
@ -134,15 +135,15 @@ describe("MemberListStore", () => {
|
|||
it("filters based on a search query", async () => {
|
||||
const mice = "@mice:bar";
|
||||
const zorro = "@zorro:bar";
|
||||
addMember(room, bob, "join");
|
||||
addMember(room, mice, "join");
|
||||
addMember(room, bob, KnownMembership.Join);
|
||||
addMember(room, mice, KnownMembership.Join);
|
||||
|
||||
let { invited, joined } = await store.loadMemberList(roomId, "ice");
|
||||
expect(invited).toEqual([]);
|
||||
expect(joined).toEqual([room.getMember(alice), room.getMember(mice)]);
|
||||
|
||||
// Ensure it filters by display name if they are set
|
||||
addMember(room, zorro, "join", "ice ice baby");
|
||||
addMember(room, zorro, KnownMembership.Join, "ice ice baby");
|
||||
({ invited, joined } = await store.loadMemberList(roomId, "ice"));
|
||||
expect(invited).toEqual([]);
|
||||
expect(joined).toEqual([room.getMember(alice), room.getMember(zorro), room.getMember(mice)]);
|
||||
|
@ -180,7 +181,7 @@ describe("MemberListStore", () => {
|
|||
type: EventType.RoomMember,
|
||||
state_key: bob,
|
||||
content: {
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
displayname: "Bob",
|
||||
},
|
||||
sender: bob,
|
||||
|
|
|
@ -25,6 +25,7 @@ import {
|
|||
ContentHelpers,
|
||||
M_BEACON,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { Mocked } from "jest-mock";
|
||||
|
||||
|
@ -556,7 +557,7 @@ describe("OwnBeaconStore", () => {
|
|||
|
||||
it("destroys and removes beacons when current user leaves room", async () => {
|
||||
// alice leaves room1
|
||||
const membershipEvent = makeMembershipEvent(room1Id, aliceId, "leave");
|
||||
const membershipEvent = makeMembershipEvent(room1Id, aliceId, KnownMembership.Leave);
|
||||
const member = new RoomMember(room1Id, aliceId);
|
||||
member.setMembershipEvent(membershipEvent);
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import {
|
|||
Room,
|
||||
RoomEvent,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { defer } from "matrix-js-sdk/src/utils";
|
||||
|
||||
import SpaceStore from "../../src/stores/spaces/SpaceStore";
|
||||
|
@ -57,13 +58,13 @@ const fav2 = "!fav2:server";
|
|||
const fav3 = "!fav3:server";
|
||||
const dm1 = "!dm1:server";
|
||||
const dm1Partner = new RoomMember(dm1, "@dm1Partner:server");
|
||||
dm1Partner.membership = "join";
|
||||
dm1Partner.membership = KnownMembership.Join;
|
||||
const dm2 = "!dm2:server";
|
||||
const dm2Partner = new RoomMember(dm2, "@dm2Partner:server");
|
||||
dm2Partner.membership = "join";
|
||||
dm2Partner.membership = KnownMembership.Join;
|
||||
const dm3 = "!dm3:server";
|
||||
const dm3Partner = new RoomMember(dm3, "@dm3Partner:server");
|
||||
dm3Partner.membership = "join";
|
||||
dm3Partner.membership = KnownMembership.Join;
|
||||
const orphan1 = "!orphan1:server";
|
||||
const orphan2 = "!orphan2:server";
|
||||
const invite1 = "!invite1:server";
|
||||
|
@ -289,7 +290,7 @@ describe("SpaceStore", () => {
|
|||
});
|
||||
|
||||
it("invite to a subspace is only shown at the top level", async () => {
|
||||
mkSpace(invite1).getMyMembership.mockReturnValue("invite");
|
||||
mkSpace(invite1).getMyMembership.mockReturnValue(KnownMembership.Invite);
|
||||
mkSpace(space1, [invite1]);
|
||||
await run();
|
||||
|
||||
|
@ -335,19 +336,19 @@ describe("SpaceStore", () => {
|
|||
});
|
||||
|
||||
[invite1, invite2].forEach((roomId) => {
|
||||
mocked(client.getRoom(roomId)!).getMyMembership.mockReturnValue("invite");
|
||||
mocked(client.getRoom(roomId)!).getMyMembership.mockReturnValue(KnownMembership.Invite);
|
||||
});
|
||||
|
||||
// have dmPartner1 be in space1 with you
|
||||
const mySpace1Member = new RoomMember(space1, testUserId);
|
||||
mySpace1Member.membership = "join";
|
||||
mySpace1Member.membership = KnownMembership.Join;
|
||||
(rooms.find((r) => r.roomId === space1)!.getMembers as jest.Mock).mockReturnValue([
|
||||
mySpace1Member,
|
||||
dm1Partner,
|
||||
]);
|
||||
// have dmPartner2 be in space2 with you
|
||||
const mySpace2Member = new RoomMember(space2, testUserId);
|
||||
mySpace2Member.membership = "join";
|
||||
mySpace2Member.membership = KnownMembership.Join;
|
||||
(rooms.find((r) => r.roomId === space2)!.getMembers as jest.Mock).mockReturnValue([
|
||||
mySpace2Member,
|
||||
dm2Partner,
|
||||
|
@ -683,16 +684,16 @@ describe("SpaceStore", () => {
|
|||
|
||||
it("should add new DM Invites to the People Space Notification State", async () => {
|
||||
mkRoom(dm1);
|
||||
mocked(client.getRoom(dm1)!).getMyMembership.mockReturnValue("join");
|
||||
mocked(client.getRoom(dm1)!).getMyMembership.mockReturnValue(KnownMembership.Join);
|
||||
mocked(client).getRoom.mockImplementation((roomId) => rooms.find((room) => room.roomId === roomId) || null);
|
||||
|
||||
await run();
|
||||
|
||||
mkRoom(dm2);
|
||||
const cliDm2 = client.getRoom(dm2)!;
|
||||
mocked(cliDm2).getMyMembership.mockReturnValue("invite");
|
||||
mocked(cliDm2).getMyMembership.mockReturnValue(KnownMembership.Invite);
|
||||
mocked(client).getRoom.mockImplementation((roomId) => rooms.find((room) => room.roomId === roomId) || null);
|
||||
client.emit(RoomEvent.MyMembership, cliDm2, "invite");
|
||||
client.emit(RoomEvent.MyMembership, cliDm2, KnownMembership.Invite);
|
||||
|
||||
[dm1, dm2].forEach((d) => {
|
||||
expect(
|
||||
|
@ -721,9 +722,9 @@ describe("SpaceStore", () => {
|
|||
await run();
|
||||
|
||||
expect(store.spacePanelSpaces).toStrictEqual([space]);
|
||||
space.getMyMembership.mockReturnValue("leave");
|
||||
space.getMyMembership.mockReturnValue(KnownMembership.Leave);
|
||||
const prom = testUtils.emitPromise(store, UPDATE_TOP_LEVEL_SPACES);
|
||||
client.emit(RoomEvent.MyMembership, space, "leave", "join");
|
||||
client.emit(RoomEvent.MyMembership, space, KnownMembership.Leave, KnownMembership.Join);
|
||||
await prom;
|
||||
expect(store.spacePanelSpaces).toStrictEqual([]);
|
||||
});
|
||||
|
@ -733,7 +734,7 @@ describe("SpaceStore", () => {
|
|||
expect(store.spacePanelSpaces).toStrictEqual([]);
|
||||
expect(store.invitedSpaces).toStrictEqual([]);
|
||||
const space = mkSpace(space1);
|
||||
space.getMyMembership.mockReturnValue("invite");
|
||||
space.getMyMembership.mockReturnValue(KnownMembership.Invite);
|
||||
const prom = testUtils.emitPromise(store, UPDATE_INVITED_SPACES);
|
||||
client.emit(ClientEvent.Room, space);
|
||||
await prom;
|
||||
|
@ -743,14 +744,14 @@ describe("SpaceStore", () => {
|
|||
|
||||
it("updates state when space invite is accepted", async () => {
|
||||
const space = mkSpace(space1);
|
||||
space.getMyMembership.mockReturnValue("invite");
|
||||
space.getMyMembership.mockReturnValue(KnownMembership.Invite);
|
||||
await run();
|
||||
|
||||
expect(store.spacePanelSpaces).toStrictEqual([]);
|
||||
expect(store.invitedSpaces).toStrictEqual([space]);
|
||||
space.getMyMembership.mockReturnValue("join");
|
||||
space.getMyMembership.mockReturnValue(KnownMembership.Join);
|
||||
const prom = testUtils.emitPromise(store, UPDATE_TOP_LEVEL_SPACES);
|
||||
client.emit(RoomEvent.MyMembership, space, "join", "invite");
|
||||
client.emit(RoomEvent.MyMembership, space, KnownMembership.Join, KnownMembership.Invite);
|
||||
await prom;
|
||||
expect(store.spacePanelSpaces).toStrictEqual([space]);
|
||||
expect(store.invitedSpaces).toStrictEqual([]);
|
||||
|
@ -758,14 +759,14 @@ describe("SpaceStore", () => {
|
|||
|
||||
it("updates state when space invite is rejected", async () => {
|
||||
const space = mkSpace(space1);
|
||||
space.getMyMembership.mockReturnValue("invite");
|
||||
space.getMyMembership.mockReturnValue(KnownMembership.Invite);
|
||||
await run();
|
||||
|
||||
expect(store.spacePanelSpaces).toStrictEqual([]);
|
||||
expect(store.invitedSpaces).toStrictEqual([space]);
|
||||
space.getMyMembership.mockReturnValue("leave");
|
||||
space.getMyMembership.mockReturnValue(KnownMembership.Leave);
|
||||
const prom = testUtils.emitPromise(store, UPDATE_INVITED_SPACES);
|
||||
client.emit(RoomEvent.MyMembership, space, "leave", "invite");
|
||||
client.emit(RoomEvent.MyMembership, space, KnownMembership.Leave, KnownMembership.Invite);
|
||||
await prom;
|
||||
expect(store.spacePanelSpaces).toStrictEqual([]);
|
||||
expect(store.invitedSpaces).toStrictEqual([]);
|
||||
|
@ -783,7 +784,7 @@ describe("SpaceStore", () => {
|
|||
expect(store.isRoomInSpace(MetaSpace.Home, invite1)).toBeFalsy();
|
||||
|
||||
const invite = mkRoom(invite1);
|
||||
invite.getMyMembership.mockReturnValue("invite");
|
||||
invite.getMyMembership.mockReturnValue(KnownMembership.Invite);
|
||||
const prom = testUtils.emitPromise(store, space1);
|
||||
client.emit(ClientEvent.Room, space);
|
||||
await prom;
|
||||
|
@ -845,7 +846,7 @@ describe("SpaceStore", () => {
|
|||
room: spaceId,
|
||||
user: client.getUserId()!,
|
||||
skey: user.userId,
|
||||
content: { membership: "join" },
|
||||
content: { membership: KnownMembership.Join },
|
||||
ts: Date.now(),
|
||||
});
|
||||
const spaceRoom = client.getRoom(spaceId)!;
|
||||
|
@ -926,7 +927,7 @@ describe("SpaceStore", () => {
|
|||
beforeEach(async () => {
|
||||
mkRoom(room1); // not a space
|
||||
mkSpace(space1, [mkSpace(space2).roomId]);
|
||||
mkSpace(space3).getMyMembership.mockReturnValue("invite");
|
||||
mkSpace(space3).getMyMembership.mockReturnValue(KnownMembership.Invite);
|
||||
await run();
|
||||
store.setActiveSpace(MetaSpace.Home);
|
||||
expect(store.activeSpace).toBe(MetaSpace.Home);
|
||||
|
@ -986,7 +987,7 @@ describe("SpaceStore", () => {
|
|||
const event = mkEvent({
|
||||
event: true,
|
||||
type: EventType.RoomMember,
|
||||
content: { membership: "join" },
|
||||
content: { membership: KnownMembership.Join },
|
||||
skey: dm1Partner.userId,
|
||||
user: dm1Partner.userId,
|
||||
room: space1,
|
||||
|
@ -994,7 +995,7 @@ describe("SpaceStore", () => {
|
|||
space.getMember.mockImplementation((userId) => {
|
||||
if (userId === dm1Partner.userId) {
|
||||
const member = new RoomMember(space1, dm1Partner.userId);
|
||||
member.membership = "join";
|
||||
member.membership = KnownMembership.Join;
|
||||
return member;
|
||||
}
|
||||
return null;
|
||||
|
@ -1249,15 +1250,15 @@ describe("SpaceStore", () => {
|
|||
|
||||
// receive invite to space
|
||||
const rootSpace = mkSpace(space1, [room1, room2, space2]);
|
||||
rootSpace.getMyMembership.mockReturnValue("invite");
|
||||
rootSpace.getMyMembership.mockReturnValue(KnownMembership.Invite);
|
||||
client.emit(ClientEvent.Room, rootSpace);
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(SpaceStore.instance.invitedSpaces).toStrictEqual([rootSpace]);
|
||||
expect(SpaceStore.instance.spacePanelSpaces).toStrictEqual([]);
|
||||
|
||||
// accept invite to space
|
||||
rootSpace.getMyMembership.mockReturnValue("join");
|
||||
client.emit(RoomEvent.MyMembership, rootSpace, "join", "invite");
|
||||
rootSpace.getMyMembership.mockReturnValue(KnownMembership.Join);
|
||||
client.emit(RoomEvent.MyMembership, rootSpace, KnownMembership.Join, KnownMembership.Invite);
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(SpaceStore.instance.invitedSpaces).toStrictEqual([]);
|
||||
expect(SpaceStore.instance.spacePanelSpaces).toStrictEqual([rootSpace]);
|
||||
|
@ -1265,7 +1266,7 @@ describe("SpaceStore", () => {
|
|||
// join room in space
|
||||
expect(SpaceStore.instance.isRoomInSpace(space1, room1)).toBeFalsy();
|
||||
const rootSpaceRoom1 = mkRoom(room1);
|
||||
rootSpaceRoom1.getMyMembership.mockReturnValue("join");
|
||||
rootSpaceRoom1.getMyMembership.mockReturnValue(KnownMembership.Join);
|
||||
client.emit(ClientEvent.Room, rootSpaceRoom1);
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(SpaceStore.instance.invitedSpaces).toStrictEqual([]);
|
||||
|
@ -1279,7 +1280,7 @@ describe("SpaceStore", () => {
|
|||
// receive room invite
|
||||
expect(SpaceStore.instance.isRoomInSpace(space1, room2)).toBeFalsy();
|
||||
const rootSpaceRoom2 = mkRoom(room2);
|
||||
rootSpaceRoom2.getMyMembership.mockReturnValue("invite");
|
||||
rootSpaceRoom2.getMyMembership.mockReturnValue(KnownMembership.Invite);
|
||||
client.emit(ClientEvent.Room, rootSpaceRoom2);
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(SpaceStore.instance.invitedSpaces).toStrictEqual([]);
|
||||
|
@ -1292,9 +1293,9 @@ describe("SpaceStore", () => {
|
|||
|
||||
// start DM in space
|
||||
const myRootSpaceMember = new RoomMember(space1, testUserId);
|
||||
myRootSpaceMember.membership = "join";
|
||||
myRootSpaceMember.membership = KnownMembership.Join;
|
||||
const rootSpaceFriend = new RoomMember(space1, dm1Partner.userId);
|
||||
rootSpaceFriend.membership = "join";
|
||||
rootSpaceFriend.membership = KnownMembership.Join;
|
||||
rootSpace.getMembers.mockReturnValue([myRootSpaceMember, rootSpaceFriend]);
|
||||
rootSpace.getMember.mockImplementation((userId) => {
|
||||
switch (userId) {
|
||||
|
@ -1310,7 +1311,7 @@ describe("SpaceStore", () => {
|
|||
event: true,
|
||||
type: EventType.RoomMember,
|
||||
content: {
|
||||
membership: "join",
|
||||
membership: KnownMembership.Join,
|
||||
},
|
||||
skey: dm1Partner.userId,
|
||||
user: dm1Partner.userId,
|
||||
|
@ -1320,7 +1321,7 @@ describe("SpaceStore", () => {
|
|||
jest.runOnlyPendingTimers();
|
||||
expect(SpaceStore.instance.getSpaceFilteredUserIds(space1)!.has(dm1Partner.userId)).toBeTruthy();
|
||||
const dm1Room = mkRoom(dm1);
|
||||
dm1Room.getMyMembership.mockReturnValue("join");
|
||||
dm1Room.getMyMembership.mockReturnValue(KnownMembership.Join);
|
||||
client.emit(ClientEvent.Room, dm1Room);
|
||||
jest.runOnlyPendingTimers();
|
||||
expect(SpaceStore.instance.invitedSpaces).toStrictEqual([]);
|
||||
|
@ -1333,7 +1334,7 @@ describe("SpaceStore", () => {
|
|||
|
||||
// join subspace
|
||||
const subspace = mkSpace(space2);
|
||||
subspace.getMyMembership.mockReturnValue("join");
|
||||
subspace.getMyMembership.mockReturnValue(KnownMembership.Join);
|
||||
const prom = testUtils.emitPromise(SpaceStore.instance, space1);
|
||||
client.emit(ClientEvent.Room, subspace);
|
||||
jest.runOnlyPendingTimers();
|
||||
|
|
|
@ -24,6 +24,7 @@ import {
|
|||
MatrixEvent,
|
||||
RoomEvent,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { mkEvent, muteRoom, stubClient } from "../../test-utils";
|
||||
|
@ -150,7 +151,7 @@ describe("RoomNotificationState", () => {
|
|||
|
||||
muteRoom(room);
|
||||
setUnreads(room, 1234, 0);
|
||||
room.updateMyMembership("join"); // emit
|
||||
room.updateMyMembership(KnownMembership.Join); // emit
|
||||
|
||||
expect(roomNotifState.level).toBe(NotificationLevel.None);
|
||||
expect(roomNotifState.symbol).toBe(null);
|
||||
|
@ -160,7 +161,7 @@ describe("RoomNotificationState", () => {
|
|||
it("suggests a red ! if the user has been invited to a room", () => {
|
||||
const roomNotifState = new RoomNotificationState(room, false);
|
||||
|
||||
room.updateMyMembership("invite"); // emit
|
||||
room.updateMyMembership(KnownMembership.Invite); // emit
|
||||
|
||||
expect(roomNotifState.level).toBe(NotificationLevel.Highlight);
|
||||
expect(roomNotifState.symbol).toBe("!");
|
||||
|
@ -171,7 +172,7 @@ describe("RoomNotificationState", () => {
|
|||
const roomNotifState = new RoomNotificationState(room, false);
|
||||
|
||||
setUnreads(room, 4321, 0);
|
||||
room.updateMyMembership("join"); // emit
|
||||
room.updateMyMembership(KnownMembership.Join); // emit
|
||||
|
||||
expect(roomNotifState.level).toBe(NotificationLevel.Notification);
|
||||
expect(roomNotifState.symbol).toBe(null);
|
||||
|
@ -182,7 +183,7 @@ describe("RoomNotificationState", () => {
|
|||
const roomNotifState = new RoomNotificationState(room, false);
|
||||
|
||||
setUnreads(room, 0, 69);
|
||||
room.updateMyMembership("join"); // emit
|
||||
room.updateMyMembership(KnownMembership.Join); // emit
|
||||
|
||||
expect(roomNotifState.level).toBe(NotificationLevel.Highlight);
|
||||
expect(roomNotifState.symbol).toBe(null);
|
||||
|
@ -202,7 +203,7 @@ describe("RoomNotificationState", () => {
|
|||
);
|
||||
|
||||
addThread(room);
|
||||
room.updateMyMembership("join"); // emit
|
||||
room.updateMyMembership(KnownMembership.Join); // emit
|
||||
|
||||
expect(roomNotifState.level).toBe(NotificationLevel.Activity);
|
||||
expect(roomNotifState.symbol).toBe(null);
|
||||
|
|
|
@ -23,6 +23,7 @@ import {
|
|||
PushRuleActionName,
|
||||
Room,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
||||
import defaultDispatcher, { MatrixDispatcher } from "../../../src/dispatcher/dispatcher";
|
||||
import { SettingLevel } from "../../../src/settings/SettingLevel";
|
||||
|
@ -123,8 +124,8 @@ describe("RoomListStore", () => {
|
|||
// When we tell it we joined a new room that has an old room as
|
||||
// predecessor in the create event
|
||||
const payload = {
|
||||
oldMembership: "invite",
|
||||
membership: "join",
|
||||
oldMembership: KnownMembership.Invite,
|
||||
membership: KnownMembership.Join,
|
||||
room: roomWithCreatePredecessor,
|
||||
};
|
||||
store.onDispatchMyMembership(payload);
|
||||
|
@ -142,8 +143,8 @@ describe("RoomListStore", () => {
|
|||
|
||||
// When we tell it we joined a new room with no predecessor
|
||||
const payload = {
|
||||
oldMembership: "invite",
|
||||
membership: "join",
|
||||
oldMembership: KnownMembership.Invite,
|
||||
membership: KnownMembership.Join,
|
||||
room: roomNoPredecessor,
|
||||
};
|
||||
store.onDispatchMyMembership(payload);
|
||||
|
@ -159,9 +160,9 @@ describe("RoomListStore", () => {
|
|||
const room1 = new Room("!r1:e.com", client, userId, { pendingEventOrdering: PendingEventOrdering.Detached });
|
||||
const room2 = new Room("!r2:e.com", client, userId, { pendingEventOrdering: PendingEventOrdering.Detached });
|
||||
const room3 = new Room("!r3:e.com", client, userId, { pendingEventOrdering: PendingEventOrdering.Detached });
|
||||
room1.updateMyMembership("join");
|
||||
room2.updateMyMembership("join");
|
||||
room3.updateMyMembership("join");
|
||||
room1.updateMyMembership(KnownMembership.Join);
|
||||
room2.updateMyMembership(KnownMembership.Join);
|
||||
room3.updateMyMembership(KnownMembership.Join);
|
||||
DMRoomMap.makeShared(client);
|
||||
const { store } = createStore();
|
||||
client.getVisibleRooms = jest.fn().mockReturnValue([room1, room2, room3]);
|
||||
|
@ -259,8 +260,8 @@ describe("RoomListStore", () => {
|
|||
// When we tell it we joined a new room that has an old room as
|
||||
// predecessor in the create event
|
||||
const payload = {
|
||||
oldMembership: "invite",
|
||||
membership: "join",
|
||||
oldMembership: KnownMembership.Invite,
|
||||
membership: KnownMembership.Join,
|
||||
room: roomWithPredecessorEvent,
|
||||
};
|
||||
store.onDispatchMyMembership(payload);
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
import { mocked, MockedObject } from "jest-mock";
|
||||
import { PendingEventOrdering, Room, RoomStateEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
import { Widget } from "matrix-widget-api";
|
||||
|
||||
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
@ -82,7 +83,7 @@ describe("Algorithm", () => {
|
|||
client.reEmitter.reEmit(room, [RoomStateEvent.Events]);
|
||||
client.reEmitter.reEmit(roomWithCall, [RoomStateEvent.Events]);
|
||||
|
||||
for (const room of client.getRooms()) jest.spyOn(room, "getMyMembership").mockReturnValue("join");
|
||||
for (const room of client.getRooms()) jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
|
||||
algorithm.setKnownRooms(client.getRooms());
|
||||
|
||||
setupAsyncStoreWithClient(CallStore.instance, client);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue