Adapt Membership usage for the change to an enum KnownMembership

This commit is contained in:
Andy Balaam 2024-03-12 14:52:54 +00:00
parent da99bad7b9
commit 34559d2a89
115 changed files with 764 additions and 593 deletions

View file

@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { KnownMembership } from "matrix-js-sdk/src/matrix";
import type { Page } from "@playwright/test"; import type { Page } from "@playwright/test";
import { test, expect } from "../../element-web-test"; import { test, expect } from "../../element-web-test";
import { import {
@ -87,7 +89,7 @@ const bobJoin = async (page: Page, bob: Bot) => {
async function autoJoin(client: Client) { async function autoJoin(client: Client) {
await client.evaluate((cli) => { await client.evaluate((cli) => {
cli.on(window.matrixcs.RoomMemberEvent.Membership, (event, member) => { cli.on(window.matrixcs.RoomMemberEvent.Membership, (event, member) => {
if (member.membership === Membership.Invite && member.userId === cli.getUserId()) { if (member.membership === KnownMembership.Invite && member.userId === cli.getUserId()) {
cli.joinRoom(member.roomId); cli.joinRoom(member.roomId);
} }
}); });

View file

@ -15,9 +15,9 @@ limitations under the License.
*/ */
import jsQR from "jsqr"; import jsQR from "jsqr";
import { KnownMembership, type Preset, type Visibility } from "matrix-js-sdk/src/matrix";
import type { JSHandle, Locator, Page } from "@playwright/test"; 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 type { VerificationRequest, Verifier } from "matrix-js-sdk/src/crypto-api";
import { test, expect } from "../../element-web-test"; import { test, expect } from "../../element-web-test";
import { import {
@ -262,7 +262,7 @@ test.describe("User verification", () => {
const bobVerificationRequest = await bob.evaluateHandle( const bobVerificationRequest = await bob.evaluateHandle(
async (client, { dmRoomId, aliceCredentials }) => { async (client, { dmRoomId, aliceCredentials }) => {
const room = client.getRoom(dmRoomId); const room = client.getRoom(dmRoomId);
while (room.getMember(aliceCredentials.userId)?.membership !== Membership.Join) { while (room.getMember(aliceCredentials.userId)?.membership !== KnownMembership.Join) {
await new Promise((resolve) => { await new Promise((resolve) => {
room.once(window.matrixcs.RoomStateEvent.Members, resolve); room.once(window.matrixcs.RoomStateEvent.Members, resolve);
}); });

View file

@ -16,7 +16,8 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import type { Visibility } from "matrix-js-sdk/src/matrix"; import { KnownMembership, type Visibility } from "matrix-js-sdk/src/matrix";
import { test, expect } from "../../element-web-test"; import { test, expect } from "../../element-web-test";
import { waitForRoom } from "../utils"; import { waitForRoom } from "../utils";
import { Filter } from "../../pages/Spotlight"; import { Filter } from "../../pages/Spotlight";
@ -73,7 +74,7 @@ test.describe("Knock Into Room", () => {
return events.some( return events.some(
(e) => (e) =>
e.getType() === "m.room.member" && e.getType() === "m.room.member" &&
e.getContent()?.membership === Membership.Knock && e.getContent()?.membership === KnownMembership.Knock &&
e.getContent()?.displayname === "Alice", e.getContent()?.displayname === "Alice",
); );
}); });
@ -108,7 +109,7 @@ test.describe("Knock Into Room", () => {
return events.some( return events.some(
(e) => (e) =>
e.getType() === "m.room.member" && e.getType() === "m.room.member" &&
e.getContent()?.membership === Membership.Knock && e.getContent()?.membership === KnownMembership.Knock &&
e.getContent()?.displayname === "Alice", e.getContent()?.displayname === "Alice",
); );
}); });
@ -150,7 +151,7 @@ test.describe("Knock Into Room", () => {
return events.some( return events.some(
(e) => (e) =>
e.getType() === "m.room.member" && e.getType() === "m.room.member" &&
e.getContent()?.membership === Membership.Knock && e.getContent()?.membership === KnownMembership.Knock &&
e.getContent()?.displayname === "Alice", e.getContent()?.displayname === "Alice",
); );
}); });
@ -192,7 +193,7 @@ test.describe("Knock Into Room", () => {
return events.some( return events.some(
(e) => (e) =>
e.getType() === "m.room.member" && e.getType() === "m.room.member" &&
e.getContent()?.membership === Membership.Knock && e.getContent()?.membership === KnownMembership.Knock &&
e.getContent()?.displayname === "Alice", e.getContent()?.displayname === "Alice",
); );
}); });
@ -258,7 +259,7 @@ test.describe("Knock Into Room", () => {
return events.some( return events.some(
(e) => (e) =>
e.getType() === "m.room.member" && e.getType() === "m.room.member" &&
e.getContent()?.membership === Membership.Knock && e.getContent()?.membership === KnownMembership.Knock &&
e.getContent()?.displayname === "Alice", e.getContent()?.displayname === "Alice",
); );
}); });

View file

@ -16,6 +16,8 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { KnownMembership } from "matrix-js-sdk/src/matrix";
import { test, expect } from "../../element-web-test"; import { test, expect } from "../../element-web-test";
import { waitForRoom } from "../utils"; import { waitForRoom } from "../utils";
@ -73,7 +75,7 @@ test.describe("Manage Knocks", () => {
return events.some( return events.some(
(e) => (e) =>
e.getType() === "m.room.member" && e.getType() === "m.room.member" &&
e.getContent()?.membership === Membership.Leave && e.getContent()?.membership === KnownMembership.Leave &&
e.getContent()?.displayname === "Bob", e.getContent()?.displayname === "Bob",
); );
}); });
@ -110,7 +112,7 @@ test.describe("Manage Knocks", () => {
return events.some( return events.some(
(e) => (e) =>
e.getType() === "m.room.member" && e.getType() === "m.room.member" &&
e.getContent()?.membership === Membership.Leave && e.getContent()?.membership === KnownMembership.Leave &&
e.getContent()?.displayname === "Bob", e.getContent()?.displayname === "Bob",
); );
}); });

View file

@ -16,8 +16,8 @@ limitations under the License.
import { JSHandle, Page } from "@playwright/test"; import { JSHandle, Page } from "@playwright/test";
import { uniqueId } from "lodash"; import { uniqueId } from "lodash";
import { KnownMembership, 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 { Logger } from "matrix-js-sdk/src/logger";
import type { SecretStorageKeyDescription } from "matrix-js-sdk/src/secret-storage"; import type { SecretStorageKeyDescription } from "matrix-js-sdk/src/secret-storage";
import type { Credentials, HomeserverInstance } from "../plugins/homeserver"; import type { Credentials, HomeserverInstance } from "../plugins/homeserver";
@ -178,7 +178,7 @@ export class Bot extends Client {
if (opts.autoAcceptInvites) { if (opts.autoAcceptInvites) {
cli.on(window.matrixcs.RoomMemberEvent.Membership, (event, member) => { cli.on(window.matrixcs.RoomMemberEvent.Membership, (event, member) => {
if (member.membership === Membership.Invite && member.userId === cli.getUserId()) { if (member.membership === KnownMembership.Invite && member.userId === cli.getUserId()) {
cli.joinRoom(member.roomId); cli.joinRoom(member.roomId);
} }
}); });

View file

@ -291,7 +291,7 @@ Response:
*/ */
import { IContent, MatrixEvent, IEvent } from "matrix-js-sdk/src/matrix"; import { IContent, MatrixEvent, IEvent, KnownMembership } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { MatrixClientPeg } from "./MatrixClientPeg"; import { MatrixClientPeg } from "./MatrixClientPeg";
@ -357,7 +357,10 @@ function inviteUser(event: MessageEvent<any>, roomId: string, userId: string): v
if (room) { if (room) {
// if they are already invited or joined we can resolve immediately. // if they are already invited or joined we can resolve immediately.
const member = room.getMember(userId); const member = room.getMember(userId);
if (member && [Membership.Join, Membership.Invite].includes(member.membership)) { if (
member &&
([KnownMembership.Join, KnownMembership.Invite] as Array<string | undefined>).includes(member.membership)
) {
sendResponse(event, { sendResponse(event, {
success: true, success: true,
}); });
@ -669,7 +672,7 @@ function canSendEvent(event: MessageEvent<any>, roomId: string): void {
sendError(event, _t("scalar|error_room_unknown")); sendError(event, _t("scalar|error_room_unknown"));
return; return;
} }
if (room.getMyMembership() !== Membership.Join) { if (room.getMyMembership() !== KnownMembership.Join) {
sendError(event, _t("scalar|error_membership")); sendError(event, _t("scalar|error_membership"));
return; return;
} }

View file

@ -18,7 +18,14 @@ limitations under the License.
*/ */
import * as React from "react"; import * as React from "react";
import { User, IContent, Direction, ContentHelpers, MRoomTopicEventContent } from "matrix-js-sdk/src/matrix"; import {
User,
IContent,
Direction,
ContentHelpers,
MRoomTopicEventContent,
KnownMembership,
} from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import dis from "./dispatcher/dispatcher"; import dis from "./dispatcher/dispatcher";
@ -241,7 +248,7 @@ export const Commands = [
if (args) { if (args) {
const ev = cli.getRoom(roomId)?.currentState.getStateEvents("m.room.member", cli.getSafeUserId()); const ev = cli.getRoom(roomId)?.currentState.getStateEvents("m.room.member", cli.getSafeUserId());
const content = { const content = {
...(ev ? ev.getContent() : { membership: Membership.Join }), ...(ev ? ev.getContent() : { membership: KnownMembership.Join }),
displayname: args, displayname: args,
}; };
return success(cli.sendStateEvent(roomId, "m.room.member", content, cli.getSafeUserId())); return success(cli.sendStateEvent(roomId, "m.room.member", content, cli.getSafeUserId()));
@ -291,7 +298,7 @@ export const Commands = [
if (!url) return; if (!url) return;
const ev = room?.currentState.getStateEvents("m.room.member", userId); const ev = room?.currentState.getStateEvents("m.room.member", userId);
const content = { const content = {
...(ev ? ev.getContent() : { membership: Membership.Join }), ...(ev ? ev.getContent() : { membership: KnownMembership.Join }),
avatar_url: url, avatar_url: url,
}; };
return cli.sendStateEvent(roomId, "m.room.member", content, userId); return cli.sendStateEvent(roomId, "m.room.member", content, userId);

View file

@ -25,6 +25,7 @@ import {
MsgType, MsgType,
M_POLL_START, M_POLL_START,
M_POLL_END, M_POLL_END,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { removeDirectionOverrideChars } from "matrix-js-sdk/src/utils"; import { removeDirectionOverrideChars } from "matrix-js-sdk/src/utils";
@ -122,7 +123,7 @@ function textForMemberEvent(
const reason = content.reason; const reason = content.reason;
switch (content.membership) { switch (content.membership) {
case Membership.Invite: { case KnownMembership.Invite: {
const threePidContent = content.third_party_invite; const threePidContent = content.third_party_invite;
if (threePidContent) { if (threePidContent) {
if (threePidContent.display_name) { if (threePidContent.display_name) {
@ -138,13 +139,13 @@ function textForMemberEvent(
return () => _t("timeline|m.room.member|invite", { senderName, targetName }); return () => _t("timeline|m.room.member|invite", { senderName, targetName });
} }
} }
case Membership.Ban: case KnownMembership.Ban:
return () => return () =>
reason reason
? _t("timeline|m.room.member|ban_reason", { senderName, targetName, reason }) ? _t("timeline|m.room.member|ban_reason", { senderName, targetName, reason })
: _t("timeline|m.room.member|ban", { senderName, targetName }); : _t("timeline|m.room.member|ban", { senderName, targetName });
case Membership.Join: case KnownMembership.Join:
if (prevContent && prevContent.membership === Membership.Join) { if (prevContent && prevContent.membership === KnownMembership.Join) {
const modDisplayname = getModification(prevContent.displayname, content.displayname); const modDisplayname = getModification(prevContent.displayname, content.displayname);
const modAvatarUrl = getModification(prevContent.avatar_url, content.avatar_url); 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); if (!ev.target) logger.warn("Join message has no target! -- " + ev.getContent().state_key);
return () => _t("timeline|m.room.member|join", { targetName }); return () => _t("timeline|m.room.member|join", { targetName });
} }
case Membership.Leave: case KnownMembership.Leave:
if (ev.getSender() === ev.getStateKey()) { if (ev.getSender() === ev.getStateKey()) {
if (prevContent.membership === Membership.Invite) { if (prevContent.membership === KnownMembership.Invite) {
return () => _t("timeline|m.room.member|reject_invite", { targetName }); return () => _t("timeline|m.room.member|reject_invite", { targetName });
} else { } else {
return () => return () =>
@ -204,9 +205,9 @@ function textForMemberEvent(
? _t("timeline|m.room.member|left_reason", { targetName, reason }) ? _t("timeline|m.room.member|left_reason", { targetName, reason })
: _t("timeline|m.room.member|left", { targetName }); : _t("timeline|m.room.member|left", { targetName });
} }
} else if (prevContent.membership === Membership.Ban) { } else if (prevContent.membership === KnownMembership.Ban) {
return () => _t("timeline|m.room.member|unban", { senderName, targetName }); return () => _t("timeline|m.room.member|unban", { senderName, targetName });
} else if (prevContent.membership === Membership.Invite) { } else if (prevContent.membership === KnownMembership.Invite) {
return () => return () =>
reason reason
? _t("timeline|m.room.member|withdrew_invite_reason", { ? _t("timeline|m.room.member|withdrew_invite_reason", {
@ -215,7 +216,7 @@ function textForMemberEvent(
reason, reason,
}) })
: _t("timeline|m.room.member|withdrew_invite", { senderName, targetName }); : _t("timeline|m.room.member|withdrew_invite", { senderName, targetName });
} else if (prevContent.membership === Membership.Join) { } else if (prevContent.membership === KnownMembership.Join) {
return () => return () =>
reason reason
? _t("timeline|m.room.member|kick_reason", { ? _t("timeline|m.room.member|kick_reason", {

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { Room, EventType } from "matrix-js-sdk/src/matrix"; import { Room, EventType, KnownMembership } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { ensureVirtualRoomExists } from "./createRoom"; import { ensureVirtualRoomExists } from "./createRoom";
@ -95,7 +95,7 @@ export default class VoipUserMapper {
if (!virtualRoomEvent || !virtualRoomEvent.getContent()) return null; if (!virtualRoomEvent || !virtualRoomEvent.getContent()) return null;
const nativeRoomID = virtualRoomEvent.getContent()["native_room"]; const nativeRoomID = virtualRoomEvent.getContent()["native_room"];
const nativeRoom = cli.getRoom(nativeRoomID); const nativeRoom = cli.getRoom(nativeRoomID);
if (!nativeRoom || nativeRoom.getMyMembership() !== Membership.Join) return null; if (!nativeRoom || nativeRoom.getMyMembership() !== KnownMembership.Join) return null;
return nativeRoomID; return nativeRoomID;
} }

View file

@ -27,6 +27,7 @@ import {
RoomState, RoomState,
RoomStateEvent, RoomStateEvent,
IRoomTimelineData, IRoomTimelineData,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { MatrixClientPeg } from "../MatrixClientPeg"; import { MatrixClientPeg } from "../MatrixClientPeg";
@ -159,7 +160,7 @@ export default class UserProvider extends AutocompleteProvider {
const currentUserId = MatrixClientPeg.safeGet().credentials.userId; const currentUserId = MatrixClientPeg.safeGet().credentials.userId;
this.users = this.room.getJoinedMembers().filter(({ userId }) => userId !== currentUserId); this.users = this.room.getJoinedMembers().filter(({ userId }) => userId !== currentUserId);
this.users = this.users.concat(this.room.getMembersWithMembership(Membership.Invite)); this.users = this.users.concat(this.room.getMembersWithMembership(KnownMembership.Invite));
this.users = sortBy(this.users, (member) => 1e20 - lastSpoken[member.userId] || 1e20); this.users = sortBy(this.users, (member) => 1e20 - lastSpoken[member.userId] || 1e20);

View file

@ -37,6 +37,7 @@ import {
MatrixError, MatrixError,
ISearchResults, ISearchResults,
THREAD_RELATION_TYPE, THREAD_RELATION_TYPE,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { CallState, MatrixCall } from "matrix-js-sdk/src/webrtc/call"; import { CallState, MatrixCall } from "matrix-js-sdk/src/webrtc/call";
@ -1454,7 +1455,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
private async loadMembersIfJoined(room: Room): Promise<void> { private async loadMembersIfJoined(room: Room): Promise<void> {
// lazy load members if enabled // lazy load members if enabled
if (this.context.client?.hasLazyLoadMembersEnabled()) { if (this.context.client?.hasLazyLoadMembersEnabled()) {
if (room && room.getMyMembership() === Membership.Join) { if (room && room.getMyMembership() === KnownMembership.Join) {
try { try {
await room.loadMembersIfNeeded(); await room.loadMembersIfNeeded();
if (!this.unmounted) { if (!this.unmounted) {
@ -1588,7 +1589,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
if (room && this.context.client) { if (room && this.context.client) {
const me = this.context.client.getSafeUserId(); const me = this.context.client.getSafeUserId();
const canReact = const canReact =
room.getMyMembership() === Membership.Join && room.currentState.maySendEvent(EventType.Reaction, me); room.getMyMembership() === KnownMembership.Join &&
room.currentState.maySendEvent(EventType.Reaction, me);
const canSendMessages = room.maySendMessage(); const canSendMessages = room.maySendMessage();
const canSelfRedact = room.currentState.maySendEvent(EventType.RoomRedaction, me); const canSelfRedact = room.currentState.maySendEvent(EventType.RoomRedaction, me);
@ -1622,10 +1624,10 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
private updateDMState(): void { private updateDMState(): void {
const room = this.state.room; const room = this.state.room;
if (room.getMyMembership() != Membership.Join) { if (room?.getMyMembership() != KnownMembership.Join) {
return; return;
} }
const dmInviter = room.getDMInviter(); const dmInviter = room?.getDMInviter();
if (dmInviter) { if (dmInviter) {
Rooms.setDMRoom(room.client, room.roomId, dmInviter); Rooms.setDMRoom(room.client, room.roomId, dmInviter);
} }
@ -1663,7 +1665,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
roomId, roomId,
opts: { inviteSignUrl: signUrl }, opts: { inviteSignUrl: signUrl },
metricsTrigger: metricsTrigger:
this.state.room?.getMyMembership() === Membership.Invite ? "Invite" : "RoomPreview", this.state.room?.getMyMembership() === KnownMembership.Invite ? "Invite" : "RoomPreview",
canAskToJoin: this.state.canAskToJoin, canAskToJoin: this.state.canAskToJoin,
}); });
} }
@ -2184,7 +2186,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
const myMembership = this.state.room.getMyMembership(); const myMembership = this.state.room.getMyMembership();
if ( if (
isVideoRoom(this.state.room) && isVideoRoom(this.state.room) &&
!(SettingsStore.getValue("feature_video_rooms") && myMembership === Membership.Join) !(SettingsStore.getValue("feature_video_rooms") && myMembership === KnownMembership.Join)
) { ) {
return ( return (
<ErrorBoundary> <ErrorBoundary>
@ -2201,7 +2203,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
} }
// SpaceRoomView handles invites itself // SpaceRoomView handles invites itself
if (myMembership === Membership.Invite && !this.state.room.isSpaceRoom()) { if (myMembership === KnownMembership.Invite && !this.state.room.isSpaceRoom()) {
if (this.state.joining || this.state.rejecting) { if (this.state.joining || this.state.rejecting) {
return ( return (
<ErrorBoundary> <ErrorBoundary>
@ -2248,16 +2250,19 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
} }
} }
if (this.state.canAskToJoin && [Membership.Knock, Membership.Leave].includes(myMembership)) { if (
this.state.canAskToJoin &&
([KnownMembership.Knock, KnownMembership.Leave] as Array<string>).includes(myMembership)
) {
return ( return (
<div className="mx_RoomView" data-room-header={roomHeaderType}> <div className="mx_RoomView" data-room-header={roomHeaderType}>
<ErrorBoundary> <ErrorBoundary>
<RoomPreviewBar <RoomPreviewBar
onJoinClick={this.onJoinButtonClicked} onJoinClick={this.onJoinButtonClicked}
room={this.state.room} room={this.state.room}
canAskToJoinAndMembershipIsLeave={myMembership === Membership.Leave} canAskToJoinAndMembershipIsLeave={myMembership === KnownMembership.Leave}
promptAskToJoin={this.state.promptAskToJoin} promptAskToJoin={this.state.promptAskToJoin}
knocked={myMembership === Membership.Knock} knocked={myMembership === KnownMembership.Knock}
onSubmitAskToJoin={this.onSubmitAskToJoin} onSubmitAskToJoin={this.onSubmitAskToJoin}
onCancelAskToJoin={this.onCancelAskToJoin} onCancelAskToJoin={this.onCancelAskToJoin}
onForgetClick={this.onForgetClick} onForgetClick={this.onForgetClick}
@ -2289,7 +2294,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
statusBar = ( statusBar = (
<RoomStatusBar <RoomStatusBar
room={this.state.room} room={this.state.room}
isPeeking={myMembership !== Membership.Join} isPeeking={myMembership !== KnownMembership.Join}
onInviteClick={this.onInviteClick} onInviteClick={this.onInviteClick}
onVisible={this.onStatusBarVisible} onVisible={this.onStatusBarVisible}
onHidden={this.onStatusBarHidden} onHidden={this.onStatusBarHidden}
@ -2333,7 +2338,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
); );
} else if (showRoomUpgradeBar) { } else if (showRoomUpgradeBar) {
aux = <RoomUpgradeWarningBar room={this.state.room} />; aux = <RoomUpgradeWarningBar room={this.state.room} />;
} else if (myMembership !== Membership.Join) { } else if (myMembership !== KnownMembership.Join) {
// We do have a room object for this room, but we're not currently in it. // 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. // We may have a 3rd party invite to it.
let inviterName: string | undefined; let inviterName: string | undefined;
@ -2407,7 +2412,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
let messageComposer; let messageComposer;
const showComposer = const showComposer =
// joined and not showing search results // joined and not showing search results
myMembership === Membership.Join && !this.state.search; myMembership === KnownMembership.Join && !this.state.search;
if (showComposer) { if (showComposer) {
messageComposer = ( messageComposer = (
<MessageComposer <MessageComposer
@ -2605,7 +2610,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
const myMember = this.state.room!.getMember(this.context.client!.getSafeUserId()); const myMember = this.state.room!.getMember(this.context.client!.getSafeUserId());
const showForgetButton = const showForgetButton =
!this.context.client.isGuest() && !this.context.client.isGuest() &&
([Membership.Leave, Membership.Ban].includes(myMembership) || myMember?.isKicked()); (([KnownMembership.Leave, KnownMembership.Ban] as Array<string>).includes(myMembership) ||
myMember?.isKicked());
return ( return (
<RoomContext.Provider value={this.state}> <RoomContext.Provider value={this.state}>
@ -2642,7 +2648,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
room={this.state.room} room={this.state.room}
searchInfo={this.state.search} searchInfo={this.state.search}
oobData={this.props.oobData} oobData={this.props.oobData}
inRoom={myMembership === Membership.Join} inRoom={myMembership === KnownMembership.Join}
onSearchClick={onSearchClick} onSearchClick={onSearchClick}
onInviteClick={onInviteClick} onInviteClick={onInviteClick}
onForgetClick={showForgetButton ? onForgetClick : null} onForgetClick={showForgetButton ? onForgetClick : null}

View file

@ -41,6 +41,7 @@ import {
HistoryVisibility, HistoryVisibility,
HierarchyRelation, HierarchyRelation,
HierarchyRoom, HierarchyRoom,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy"; import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy";
import classNames from "classnames"; import classNames from "classnames";
@ -112,7 +113,7 @@ const Tile: React.FC<ITileProps> = ({
const cli = useContext(MatrixClientContext); const cli = useContext(MatrixClientContext);
const joinedRoom = useTypedEventEmitterState(cli, ClientEvent.Room, () => { const joinedRoom = useTypedEventEmitterState(cli, ClientEvent.Room, () => {
const cliRoom = cli?.getRoom(room.room_id); const cliRoom = cli?.getRoom(room.room_id);
return cliRoom?.getMyMembership() === Membership.Join ? cliRoom : undefined; return cliRoom?.getMyMembership() === KnownMembership.Join ? cliRoom : undefined;
}); });
const joinedRoomName = useTypedEventEmitterState(joinedRoom, RoomEvent.Name, (room) => room?.name); const joinedRoomName = useTypedEventEmitterState(joinedRoom, RoomEvent.Name, (room) => room?.name);
const name = const name =
@ -828,7 +829,7 @@ const SpaceHierarchy: React.FC<IProps> = ({ space, initialText = "", showRoom, a
content = <Spinner />; content = <Spinner />;
} else { } else {
const hasPermissions = const hasPermissions =
space?.getMyMembership() === Membership.Join && space?.getMyMembership() === KnownMembership.Join &&
space.currentState.maySendStateEvent(EventType.SpaceChild, cli.getSafeUserId()); space.currentState.maySendStateEvent(EventType.SpaceChild, cli.getSafeUserId());
const root = hierarchy.roomMap.get(space.roomId); const root = hierarchy.roomMap.get(space.roomId);
@ -846,7 +847,7 @@ const SpaceHierarchy: React.FC<IProps> = ({ space, initialText = "", showRoom, a
onViewRoomClick={(roomId, roomType) => showRoom(cli, hierarchy, roomId, roomType)} onViewRoomClick={(roomId, roomType) => showRoom(cli, hierarchy, roomId, roomType)}
onJoinRoomClick={async (roomId, parents) => { onJoinRoomClick={async (roomId, parents) => {
for (const parent of parents) { for (const parent of parents) {
if (cli.getRoom(parent)?.getMyMembership() !== Membership.Join) { if (cli.getRoom(parent)?.getMyMembership() !== KnownMembership.Join) {
await joinRoom(cli, hierarchy, parent); await joinRoom(cli, hierarchy, parent);
} }
} }

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { EventType, RoomType, JoinRule, Preset, Room, RoomEvent } from "matrix-js-sdk/src/matrix"; import { EventType, RoomType, JoinRule, Preset, Room, RoomEvent, KnownMembership } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import React, { useCallback, useContext, useRef, useState } from "react"; import React, { useCallback, useContext, useRef, useState } from "react";
@ -237,7 +237,7 @@ const SpaceLanding: React.FC<{ space: Room }> = ({ space }) => {
} }
const hasAddRoomPermissions = const hasAddRoomPermissions =
myMembership === Membership.Join && space.currentState.maySendStateEvent(EventType.SpaceChild, userId); myMembership === KnownMembership.Join && space.currentState.maySendStateEvent(EventType.SpaceChild, userId);
let addRoomButton; let addRoomButton;
if (hasAddRoomPermissions) { if (hasAddRoomPermissions) {
@ -678,7 +678,7 @@ export default class SpaceRoomView extends React.PureComponent<IProps, IState> {
private renderBody(): JSX.Element { private renderBody(): JSX.Element {
switch (this.state.phase) { switch (this.state.phase) {
case Phase.Landing: case Phase.Landing:
if (this.state.myMembership === Membership.Join) { if (this.state.myMembership === KnownMembership.Join) {
return <SpaceLanding space={this.props.space} />; return <SpaceLanding space={this.props.space} />;
} else { } else {
return ( return (

View file

@ -38,6 +38,8 @@ import {
Thread, Thread,
ThreadEvent, ThreadEvent,
ReceiptType, ReceiptType,
KnownMembership,
Membership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { debounce, findLastIndex, throttle } from "lodash"; import { debounce, findLastIndex, throttle } from "lodash";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
@ -1824,7 +1826,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
// that the event belongs to, and traversing the timeline looking for // that the event belongs to, and traversing the timeline looking for
// that event, while keeping track of the user's membership // that event, while keeping track of the user's membership
let i = events.length - 1; let i = events.length - 1;
let userMembership = Membership.Leave; let userMembership: Membership = KnownMembership.Leave;
for (; i >= 0; i--) { for (; i >= 0; i--) {
const timeline = this.props.timelineSet.getTimelineForEvent(events[i].getId()!); const timeline = this.props.timelineSet.getTimelineForEvent(events[i].getId()!);
if (!timeline) { if (!timeline) {
@ -1838,14 +1840,14 @@ class TimelinePanel extends React.Component<IProps, IState> {
} }
userMembership = userMembership =
timeline.getState(EventTimeline.FORWARDS)?.getMember(userId)?.membership ?? Membership.Leave; timeline.getState(EventTimeline.FORWARDS)?.getMember(userId)?.membership ?? KnownMembership.Leave;
const timelineEvents = timeline.getEvents(); const timelineEvents = timeline.getEvents();
for (let j = timelineEvents.length - 1; j >= 0; j--) { for (let j = timelineEvents.length - 1; j >= 0; j--) {
const event = timelineEvents[j]; const event = timelineEvents[j];
if (event.getId() === events[i].getId()) { if (event.getId() === events[i].getId()) {
break; break;
} else if (event.getStateKey() === userId && event.getType() === EventType.RoomMember) { } else if (event.getStateKey() === userId && event.getType() === EventType.RoomMember) {
userMembership = event.getPrevContent().membership || Membership.Leave; userMembership = event.getPrevContent().membership || KnownMembership.Leave;
} }
} }
break; break;
@ -1856,9 +1858,9 @@ class TimelinePanel extends React.Component<IProps, IState> {
for (; i >= 0; i--) { for (; i >= 0; i--) {
const event = events[i]; const event = events[i];
if (event.getStateKey() === userId && event.getType() === EventType.RoomMember) { if (event.getStateKey() === userId && event.getType() === EventType.RoomMember) {
userMembership = event.getPrevContent().membership || Membership.Leave; userMembership = event.getPrevContent().membership || KnownMembership.Leave;
} else if ( } else if (
userMembership === Membership.Leave && userMembership === KnownMembership.Leave &&
(event.isDecryptionFailure() || event.isBeingDecrypted()) (event.isDecryptionFailure() || event.isBeingDecrypted())
) { ) {
// reached an undecryptable message when the user wasn't in the room -- don't try to load any more // reached an undecryptable message when the user wasn't in the room -- don't try to load any more

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import React, { ReactNode } from "react"; import React, { ReactNode } from "react";
import { EventType, M_BEACON_INFO, MatrixEvent } from "matrix-js-sdk/src/matrix"; import { EventType, KnownMembership, M_BEACON_INFO, MatrixEvent } from "matrix-js-sdk/src/matrix";
import { BaseGrouper } from "./BaseGrouper"; import { BaseGrouper } from "./BaseGrouper";
import MessagePanel, { WrappedEvent } from "../MessagePanel"; import MessagePanel, { WrappedEvent } from "../MessagePanel";
@ -48,7 +48,8 @@ export class CreationGrouper extends BaseGrouper {
const eventType = event.getType(); const eventType = event.getType();
if ( if (
eventType === EventType.RoomMember && eventType === EventType.RoomMember &&
(event.getStateKey() !== createEvent.getSender() || event.getContent()["membership"] !== Membership.Join) (event.getStateKey() !== createEvent.getSender() ||
event.getContent()["membership"] !== KnownMembership.Join)
) { ) {
return false; return false;
} }

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import React, { useContext } from "react"; import React, { useContext } from "react";
import { Room } from "matrix-js-sdk/src/matrix"; import { KnownMembership, Room } from "matrix-js-sdk/src/matrix";
import { IProps as IContextMenuProps } from "../../structures/ContextMenu"; import { IProps as IContextMenuProps } from "../../structures/ContextMenu";
import IconizedContextMenu, { import IconizedContextMenu, {
@ -144,7 +144,7 @@ const RoomContextMenu: React.FC<IProps> = ({ room, onFinished, ...props }) => {
let favouriteOption: JSX.Element | undefined; let favouriteOption: JSX.Element | undefined;
let lowPriorityOption: JSX.Element | undefined; let lowPriorityOption: JSX.Element | undefined;
let notificationOption: JSX.Element | undefined; let notificationOption: JSX.Element | undefined;
if (room.getMyMembership() === Membership.Join) { if (room.getMyMembership() === KnownMembership.Join) {
const isFavorite = roomTags.includes(DefaultTagID.Favourite); const isFavorite = roomTags.includes(DefaultTagID.Favourite);
favouriteOption = ( favouriteOption = (
<IconizedContextMenuCheckbox <IconizedContextMenuCheckbox

View file

@ -16,7 +16,7 @@ limitations under the License.
import React, { ReactElement, ReactNode, useContext, useMemo, useRef, useState } from "react"; import React, { ReactElement, ReactNode, useContext, useMemo, useRef, useState } from "react";
import classNames from "classnames"; import classNames from "classnames";
import { Room, EventType } from "matrix-js-sdk/src/matrix"; import { Room, EventType, KnownMembership } from "matrix-js-sdk/src/matrix";
import { sleep } from "matrix-js-sdk/src/utils"; import { sleep } from "matrix-js-sdk/src/utils";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
@ -140,7 +140,9 @@ export const AddExistingToSpace: React.FC<IAddExistingToSpaceProps> = ({
const msc3946ProcessDynamicPredecessor = useSettingValue<boolean>("feature_dynamic_room_predecessors"); const msc3946ProcessDynamicPredecessor = useSettingValue<boolean>("feature_dynamic_room_predecessors");
const visibleRooms = useMemo( const visibleRooms = useMemo(
() => () =>
cli?.getVisibleRooms(msc3946ProcessDynamicPredecessor).filter((r) => r.getMyMembership() === Membership.Join) ?? [], cli
?.getVisibleRooms(msc3946ProcessDynamicPredecessor)
.filter((r) => r.getMyMembership() === KnownMembership.Join) ?? [],
[cli, msc3946ProcessDynamicPredecessor], [cli, msc3946ProcessDynamicPredecessor],
); );

View file

@ -28,6 +28,7 @@ import {
LocationAssetType, LocationAssetType,
M_TIMESTAMP, M_TIMESTAMP,
M_BEACON, M_BEACON,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { _t } from "../../../languageHandler"; import { _t } from "../../../languageHandler";
@ -267,7 +268,7 @@ const ForwardDialog: React.FC<IProps> = ({ matrixClient: cli, event, permalinkCr
sortRooms( sortRooms(
cli cli
.getVisibleRooms(msc3946DynamicRoomPredecessors) .getVisibleRooms(msc3946DynamicRoomPredecessors)
.filter((room) => room.getMyMembership() === Membership.Join && !room.isSpaceRoom()), .filter((room) => room.getMyMembership() === KnownMembership.Join && !room.isSpaceRoom()),
), ),
[cli, msc3946DynamicRoomPredecessors], [cli, msc3946DynamicRoomPredecessors],
); );

View file

@ -16,7 +16,7 @@ limitations under the License.
import React, { createRef, ReactNode, SyntheticEvent } from "react"; import React, { createRef, ReactNode, SyntheticEvent } from "react";
import classNames from "classnames"; import classNames from "classnames";
import { RoomMember, Room, MatrixError, EventType } from "matrix-js-sdk/src/matrix"; import { RoomMember, Room, MatrixError, EventType, KnownMembership } from "matrix-js-sdk/src/matrix";
import { MatrixCall } from "matrix-js-sdk/src/webrtc/call"; import { MatrixCall } from "matrix-js-sdk/src/webrtc/call";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { uniqBy } from "lodash"; import { uniqBy } from "lodash";
@ -372,10 +372,10 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
const room = MatrixClientPeg.safeGet().getRoom(props.roomId); const room = MatrixClientPeg.safeGet().getRoom(props.roomId);
const isFederated = room?.currentState.getStateEvents(EventType.RoomCreate, "")?.getContent()["m.federate"]; 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"); if (!room) throw new Error("Room ID given to InviteDialog does not look like a room");
room.getMembersWithMembership(Membership.Invite).forEach((m) => excludedIds.add(m.userId)); room.getMembersWithMembership(KnownMembership.Invite).forEach((m) => excludedIds.add(m.userId));
room.getMembersWithMembership(Membership.Join).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 // add banned users, so we don't try to invite them
room.getMembersWithMembership(Membership.Ban).forEach((m) => excludedIds.add(m.userId)); room.getMembersWithMembership(KnownMembership.Ban).forEach((m) => excludedIds.add(m.userId));
if (isFederated === false) { if (isFederated === false) {
// exclude users from external servers // exclude users from external servers
const homeserver = props.roomId.split(":")[1]; const homeserver = props.roomId.split(":")[1];

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import React, { useMemo, useState } from "react"; import React, { useMemo, useState } from "react";
import { Room } from "matrix-js-sdk/src/matrix"; import { KnownMembership, Room } from "matrix-js-sdk/src/matrix";
import { _t } from "../../../languageHandler"; import { _t } from "../../../languageHandler";
import BaseDialog from "./BaseDialog"; import BaseDialog from "./BaseDialog";
@ -102,7 +102,7 @@ const ManageRestrictedJoinRuleDialog: React.FC<IProps> = ({ room, selected = [],
if (!room) { if (!room) {
return { roomId, name: roomId } as Room; return { roomId, name: roomId } as Room;
} }
if (room.getMyMembership() !== Membership.Join || !room.isSpaceRoom()) { if (room.getMyMembership() !== KnownMembership.Join || !room.isSpaceRoom()) {
return room; return room;
} }
}), }),

View file

@ -16,7 +16,7 @@ limitations under the License.
*/ */
import React, { useContext, useMemo } from "react"; import React, { useContext, useMemo } from "react";
import { EventType } from "matrix-js-sdk/src/matrix"; import { EventType, KnownMembership } from "matrix-js-sdk/src/matrix";
import BaseTool, { DevtoolsContext, IDevtoolsProps } from "./BaseTool"; import BaseTool, { DevtoolsContext, IDevtoolsProps } from "./BaseTool";
import { _t } from "../../../../languageHandler"; import { _t } from "../../../../languageHandler";
@ -27,7 +27,7 @@ const ServersInRoom: React.FC<IDevtoolsProps> = ({ onBack }) => {
const servers = useMemo<Record<string, number>>(() => { const servers = useMemo<Record<string, number>>(() => {
const servers: Record<string, number> = {}; const servers: Record<string, number> = {};
context.room.currentState.getStateEvents(EventType.RoomMember).forEach((ev) => { context.room.currentState.getStateEvents(EventType.RoomMember).forEach((ev) => {
if (ev.getContent().membership !== Membership.Join) return; // only count joined users if (ev.getContent().membership !== KnownMembership.Join) return; // only count joined users
const server = ev.getSender()!.split(":")[1]; const server = ev.getSender()!.split(":")[1];
servers[server] = (servers[server] ?? 0) + 1; servers[server] = (servers[server] ?? 0) + 1;
}); });

View file

@ -25,6 +25,7 @@ import {
Room, Room,
HierarchyRoom, HierarchyRoom,
JoinRule, JoinRule,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { normalize } from "matrix-js-sdk/src/utils"; import { normalize } from "matrix-js-sdk/src/utils";
import React, { ChangeEvent, RefObject, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react"; import React, { ChangeEvent, RefObject, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
@ -244,7 +245,7 @@ const findVisibleRooms = (cli: MatrixClient, msc3946ProcessDynamicPredecessor: b
if (isLocalRoom(room)) return false; if (isLocalRoom(room)) return false;
// TODO we may want to put invites in their own list // TODO we may want to put invites in their own list
return room.getMyMembership() === Membership.Join || room.getMyMembership() == Membership.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 // world readable, a modal will appear asking you to register first. If
// it is readable, the preview appears as normal. // it is readable, the preview appears as normal.
const showViewButton = const showViewButton =
clientRoom?.getMyMembership() === Membership.Join || clientRoom?.getMyMembership() === KnownMembership.Join ||
(result.publicRoom.world_readable && !canAskToJoin(joinRule)) || (result.publicRoom.world_readable && !canAskToJoin(joinRule)) ||
cli.isGuest(); cli.isGuest();

View file

@ -20,7 +20,7 @@ limitations under the License.
import React, { ContextType, createRef, CSSProperties, MutableRefObject, ReactNode } from "react"; import React, { ContextType, createRef, CSSProperties, MutableRefObject, ReactNode } from "react";
import classNames from "classnames"; import classNames from "classnames";
import { IWidget, MatrixCapabilities } from "matrix-widget-api"; import { IWidget, MatrixCapabilities } from "matrix-widget-api";
import { Room, RoomEvent } from "matrix-js-sdk/src/matrix"; import { KnownMembership, Room, RoomEvent } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { ApprovalOpts, WidgetLifecycle } from "@matrix-org/react-sdk-module-api/lib/lifecycles/WidgetLifecycle"; import { ApprovalOpts, WidgetLifecycle } from "@matrix-org/react-sdk-module-api/lib/lifecycles/WidgetLifecycle";
@ -220,7 +220,7 @@ export default class AppTile extends React.Component<IProps, IState> {
private onMyMembership = (room: Room, membership: string): void => { private onMyMembership = (room: Room, membership: string): void => {
if ( if (
(membership === Membership.Leave || membership === Membership.Ban) && (membership === KnownMembership.Leave || membership === KnownMembership.Ban) &&
room.roomId === this.props.room?.roomId room.roomId === this.props.room?.roomId
) { ) {
this.onUserLeftRoom(); this.onUserLeftRoom();

View file

@ -17,7 +17,7 @@ limitations under the License.
*/ */
import React, { ComponentProps, ReactNode } from "react"; import React, { ComponentProps, ReactNode } from "react";
import { MatrixEvent, RoomMember, EventType } from "matrix-js-sdk/src/matrix"; import { MatrixEvent, RoomMember, EventType, KnownMembership } from "matrix-js-sdk/src/matrix";
import { _t } from "../../../languageHandler"; import { _t } from "../../../languageHandler";
import { formatList } from "../../../utils/FormattingUtils"; import { formatList } from "../../../utils/FormattingUtils";
@ -416,12 +416,12 @@ export default class EventListSummary extends React.Component<
case EventType.RoomMember: case EventType.RoomMember:
switch (e.mxEvent.getContent().membership) { switch (e.mxEvent.getContent().membership) {
case Membership.Invite: case KnownMembership.Invite:
return TransitionType.Invited; return TransitionType.Invited;
case Membership.Ban: case KnownMembership.Ban:
return TransitionType.Banned; return TransitionType.Banned;
case Membership.Join: case KnownMembership.Join:
if (e.mxEvent.getPrevContent().membership === Membership.Join) { if (e.mxEvent.getPrevContent().membership === KnownMembership.Join) {
if (e.mxEvent.getContent().displayname !== e.mxEvent.getPrevContent().displayname) { if (e.mxEvent.getContent().displayname !== e.mxEvent.getPrevContent().displayname) {
return TransitionType.ChangedName; return TransitionType.ChangedName;
} else if (e.mxEvent.getContent().avatar_url !== e.mxEvent.getPrevContent().avatar_url) { } else if (e.mxEvent.getContent().avatar_url !== e.mxEvent.getPrevContent().avatar_url) {
@ -431,17 +431,17 @@ export default class EventListSummary extends React.Component<
} else { } else {
return TransitionType.Joined; return TransitionType.Joined;
} }
case Membership.Leave: case KnownMembership.Leave:
if (e.mxEvent.getSender() === e.mxEvent.getStateKey()) { if (e.mxEvent.getSender() === e.mxEvent.getStateKey()) {
if (e.mxEvent.getPrevContent().membership === Membership.Invite) { if (e.mxEvent.getPrevContent().membership === KnownMembership.Invite) {
return TransitionType.InviteReject; return TransitionType.InviteReject;
} }
return TransitionType.Left; return TransitionType.Left;
} }
switch (e.mxEvent.getPrevContent().membership) { switch (e.mxEvent.getPrevContent().membership) {
case Membership.Invite: case KnownMembership.Invite:
return TransitionType.InviteWithdrawal; return TransitionType.InviteWithdrawal;
case Membership.Ban: case KnownMembership.Ban:
return TransitionType.Unbanned; return TransitionType.Unbanned;
// sender is not target and made the target leave, if not from invite/ban then this is a kick // sender is not target and made the target leave, if not from invite/ban then this is a kick
default: default:

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import React, { FC, HTMLAttributes, useContext } from "react"; import React, { FC, HTMLAttributes, useContext } from "react";
import { Room, RoomMember } from "matrix-js-sdk/src/matrix"; import { KnownMembership, Room, RoomMember } from "matrix-js-sdk/src/matrix";
import { sortBy } from "lodash"; import { sortBy } from "lodash";
import { _t } from "../../../languageHandler"; import { _t } from "../../../languageHandler";
@ -38,7 +38,7 @@ interface IProps extends HTMLAttributes<HTMLSpanElement> {
const RoomFacePile: FC<IProps> = ({ room, onlyKnownUsers = true, numShown = DEFAULT_NUM_FACES, ...props }) => { const RoomFacePile: FC<IProps> = ({ room, onlyKnownUsers = true, numShown = DEFAULT_NUM_FACES, ...props }) => {
const cli = useContext(MatrixClientContext); const cli = useContext(MatrixClientContext);
const isJoined = room.getMyMembership() === Membership.Join; const isJoined = room.getMyMembership() === KnownMembership.Join;
let members = useRoomMembers(room); let members = useRoomMembers(room);
const count = members.length; const count = members.length;

View file

@ -22,6 +22,7 @@ import {
Room, Room,
EventTimelineSet, EventTimelineSet,
Thread, Thread,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import BaseCard from "./BaseCard"; import BaseCard from "./BaseCard";
@ -217,7 +218,7 @@ export default class TimelineCard extends React.Component<IProps, IState> {
const isUploading = ContentMessages.sharedInstance().getCurrentUploads(this.props.composerRelation).length > 0; const isUploading = ContentMessages.sharedInstance().getCurrentUploads(this.props.composerRelation).length > 0;
const myMembership = this.props.room.getMyMembership(); const myMembership = this.props.room.getMyMembership();
const showComposer = myMembership === Membership.Join; const showComposer = myMembership === KnownMembership.Join;
return ( return (
<RoomContext.Provider <RoomContext.Provider

View file

@ -29,6 +29,7 @@ import {
User, User,
Device, Device,
EventType, EventType,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { UserVerificationStatus, VerificationRequest } from "matrix-js-sdk/src/crypto-api"; import { UserVerificationStatus, VerificationRequest } from "matrix-js-sdk/src/crypto-api";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
@ -473,7 +474,7 @@ export const UserOptionsSection: React.FC<{
if ( if (
member instanceof RoomMember && member instanceof RoomMember &&
canInvite && canInvite &&
(member?.membership ?? Membership.Leave) === Membership.Leave && (member?.membership ?? KnownMembership.Leave) === KnownMembership.Leave &&
shouldShowComponent(UIComponent.InviteUsers) shouldShowComponent(UIComponent.InviteUsers)
) { ) {
const roomId = member && member.roomId ? member.roomId : SdkContextClass.instance.roomViewStore.getRoomId(); const roomId = member && member.roomId ? member.roomId : SdkContextClass.instance.roomViewStore.getRoomId();
@ -638,7 +639,7 @@ export const RoomKickButton = ({
const cli = useContext(MatrixClientContext); const cli = useContext(MatrixClientContext);
// check if user can be kicked/disinvited // check if user can be kicked/disinvited
if (member.membership !== Membership.Invite && member.membership !== Membership.Join) return <></>; if (member.membership !== KnownMembership.Invite && member.membership !== KnownMembership.Join) return <></>;
const onKick = async (): Promise<void> => { const onKick = async (): Promise<void> => {
if (isUpdating) return; // only allow one operation at a time if (isUpdating) return; // only allow one operation at a time
@ -647,17 +648,17 @@ export const RoomKickButton = ({
const commonProps = { const commonProps = {
member, member,
action: room.isSpaceRoom() action: room.isSpaceRoom()
? member.membership === Membership.Invite ? member.membership === KnownMembership.Invite
? _t("user_info|disinvite_button_space") ? _t("user_info|disinvite_button_space")
: _t("user_info|kick_button_space") : _t("user_info|kick_button_space")
: member.membership === Membership.Invite : member.membership === KnownMembership.Invite
? _t("user_info|disinvite_button_room") ? _t("user_info|disinvite_button_room")
: _t("user_info|kick_button_room"), : _t("user_info|kick_button_room"),
title: title:
member.membership === Membership.Invite member.membership === KnownMembership.Invite
? _t("user_info|disinvite_button_room_name", { roomName: room.name }) ? _t("user_info|disinvite_button_room_name", { roomName: room.name })
: _t("user_info|kick_button_room_name", { roomName: room.name }), : _t("user_info|kick_button_room_name", { roomName: room.name }),
askReason: member.membership === Membership.Join, askReason: member.membership === KnownMembership.Join,
danger: true, danger: true,
}; };
@ -718,10 +719,10 @@ export const RoomKickButton = ({
}; };
const kickLabel = room.isSpaceRoom() const kickLabel = room.isSpaceRoom()
? member.membership === Membership.Invite ? member.membership === KnownMembership.Invite
? _t("user_info|disinvite_button_space") ? _t("user_info|disinvite_button_space")
: _t("user_info|kick_button_space") : _t("user_info|kick_button_space")
: member.membership === Membership.Invite : member.membership === KnownMembership.Invite
? _t("user_info|disinvite_button_room") ? _t("user_info|disinvite_button_room")
: _t("user_info|kick_button_room"); : _t("user_info|kick_button_room");
@ -771,7 +772,7 @@ export const BanToggleButton = ({
}: Omit<IBaseRoomProps, "powerLevels">): JSX.Element => { }: Omit<IBaseRoomProps, "powerLevels">): JSX.Element => {
const cli = useContext(MatrixClientContext); const cli = useContext(MatrixClientContext);
const isBanned = member.membership === Membership.Ban; const isBanned = member.membership === KnownMembership.Ban;
const onBanOrUnban = async (): Promise<void> => { const onBanOrUnban = async (): Promise<void> => {
if (isUpdating) return; // only allow one operation at a time if (isUpdating) return; // only allow one operation at a time
startUpdating(); startUpdating();
@ -808,9 +809,9 @@ export const BanToggleButton = ({
return ( return (
!!myMember && !!myMember &&
!!theirMember && !!theirMember &&
theirMember.membership === Membership.Ban && theirMember.membership === KnownMembership.Ban &&
myMember.powerLevel > theirMember.powerLevel && myMember.powerLevel > theirMember.powerLevel &&
child.currentState.hasSufficientPowerLevelFor(Membership.Ban, myMember.powerLevel) child.currentState.hasSufficientPowerLevelFor("ban", myMember.powerLevel)
); );
} }
: (child: Room) => { : (child: Room) => {
@ -820,9 +821,9 @@ export const BanToggleButton = ({
return ( return (
!!myMember && !!myMember &&
!!theirMember && !!theirMember &&
theirMember.membership !== Membership.Ban && theirMember.membership !== KnownMembership.Ban &&
myMember.powerLevel > theirMember.powerLevel && myMember.powerLevel > theirMember.powerLevel &&
child.currentState.hasSufficientPowerLevelFor(Membership.Ban, myMember.powerLevel) child.currentState.hasSufficientPowerLevelFor("ban", myMember.powerLevel)
); );
}, },
allLabel: isBanned ? _t("user_info|unban_space_everything") : _t("user_info|ban_space_everything"), allLabel: isBanned ? _t("user_info|unban_space_everything") : _t("user_info|ban_space_everything"),
@ -903,7 +904,7 @@ const MuteToggleButton: React.FC<IBaseRoomProps> = ({
const cli = useContext(MatrixClientContext); const cli = useContext(MatrixClientContext);
// Don't show the mute/unmute option if the user is not in the room // Don't show the mute/unmute option if the user is not in the room
if (member.membership !== Membership.Join) return null; if (member.membership !== KnownMembership.Join) return null;
const muted = isMuted(member, powerLevels); const muted = isMuted(member, powerLevels);
const onMuteToggle = async (): Promise<void> => { const onMuteToggle = async (): Promise<void> => {

View file

@ -30,6 +30,7 @@ import {
UserEvent, UserEvent,
EventType, EventType,
ClientEvent, ClientEvent,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { throttle } from "lodash"; import { throttle } from "lodash";
import { Button, Tooltip } from "@vector-im/compound-web"; import { Button, Tooltip } from "@vector-im/compound-web";
@ -171,7 +172,11 @@ export default class MemberList extends React.Component<IProps, IState> {
}; };
private onMyMembership = (room: Room, membership: string, oldMembership?: string): void => { private onMyMembership = (room: Room, membership: string, oldMembership?: string): void => {
if (room.roomId === this.props.roomId && membership === Membership.Join && oldMembership !== Membership.Join) { if (
room.roomId === this.props.roomId &&
membership === KnownMembership.Join &&
oldMembership !== KnownMembership.Join
) {
// we just joined the room, load the member list // we just joined the room, load the member list
this.updateListNow(true); this.updateListNow(true);
} }
@ -363,7 +368,7 @@ export default class MemberList extends React.Component<IProps, IState> {
const room = cli.getRoom(this.props.roomId); const room = cli.getRoom(this.props.roomId);
let inviteButton: JSX.Element | undefined; let inviteButton: JSX.Element | undefined;
if (room?.getMyMembership() === Membership.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 inviteButtonText = room.isSpaceRoom() ? _t("space|invite_this_space") : _t("room|invite_this_room");
const button = ( const button = (

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import React, { useContext } from "react"; import React, { useContext } from "react";
import { EventType, Room, User, MatrixClient } from "matrix-js-sdk/src/matrix"; import { EventType, Room, User, MatrixClient, KnownMembership } from "matrix-js-sdk/src/matrix";
import MatrixClientContext from "../../../contexts/MatrixClientContext"; import MatrixClientContext from "../../../contexts/MatrixClientContext";
import RoomContext from "../../../contexts/RoomContext"; import RoomContext from "../../../contexts/RoomContext";
@ -112,7 +112,7 @@ const NewRoomIntro: React.FC = () => {
</React.Fragment> </React.Fragment>
); );
} else { } else {
const inRoom = room && room.getMyMembership() === Membership.Join; const inRoom = room && room.getMyMembership() === KnownMembership.Join;
const topic = room.currentState.getStateEvents(EventType.RoomTopic, "")?.getContent()?.topic; const topic = room.currentState.getStateEvents(EventType.RoomTopic, "")?.getContent()?.topic;
const canAddTopic = inRoom && room.currentState.maySendStateEvent(EventType.RoomTopic, cli.getSafeUserId()); const canAddTopic = inRoom && room.currentState.maySendStateEvent(EventType.RoomTopic, cli.getSafeUserId());

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import React, { FC } from "react"; import React, { FC } from "react";
import { Room, JoinRule, MatrixClient } from "matrix-js-sdk/src/matrix"; import { Room, JoinRule, MatrixClient, KnownMembership } from "matrix-js-sdk/src/matrix";
import { _t } from "../../../languageHandler"; import { _t } from "../../../languageHandler";
import RightPanelStore from "../../../stores/right-panel/RightPanelStore"; import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
@ -33,7 +33,7 @@ interface IProps {
const RoomInfoLine: FC<IProps> = ({ room }) => { 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. // 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> => { const summary = useAsyncMemo(async (): Promise<Awaited<ReturnType<MatrixClient["getRoomSummary"]>> | null> => {
if (room.getMyMembership() !== Membership.Invite) return null; if (room.getMyMembership() !== KnownMembership.Invite) return null;
try { try {
return await room.client.getRoomSummary(room.roomId); return await room.client.getRoomSummary(room.roomId);
} catch (e) { } catch (e) {
@ -61,7 +61,7 @@ const RoomInfoLine: FC<IProps> = ({ room }) => {
} }
let members: JSX.Element | undefined; let members: JSX.Element | undefined;
if (membership === Membership.Invite && summary) { if (membership === KnownMembership.Invite && summary) {
// Don't trust local state and instead use the summary API // Don't trust local state and instead use the summary API
members = ( members = (
<span className="mx_RoomInfoLine_members"> <span className="mx_RoomInfoLine_members">

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { EventTimeline, JoinRule, MatrixError, Room, RoomStateEvent } from "matrix-js-sdk/src/matrix"; import { EventTimeline, JoinRule, KnownMembership, MatrixError, Room, RoomStateEvent } from "matrix-js-sdk/src/matrix";
import React, { ReactElement, ReactNode, useCallback, useState, VFC } from "react"; import React, { ReactElement, ReactNode, useCallback, useState, VFC } from "react";
import { Icon as CheckIcon } from "../../../../res/img/feather-customised/check.svg"; import { Icon as CheckIcon } from "../../../../res/img/feather-customised/check.svg";
@ -35,7 +35,7 @@ export const RoomKnocksBar: VFC<{ room: Room }> = ({ room }) => {
const knockMembers = useTypedEventEmitterState( const knockMembers = useTypedEventEmitterState(
room, room,
RoomStateEvent.Update, RoomStateEvent.Update,
useCallback(() => room.getMembersWithMembership(Membership.Knock), [room]), useCallback(() => room.getMembersWithMembership(KnownMembership.Knock), [room]),
); );
const knockMembersCount = knockMembers.length; const knockMembersCount = knockMembers.length;

View file

@ -23,6 +23,7 @@ import {
IJoinRuleEventContent, IJoinRuleEventContent,
JoinRule, JoinRule,
MatrixError, MatrixError,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import classNames from "classnames"; import classNames from "classnames";
import { RoomPreviewOpts, RoomViewLifecycle } from "@matrix-org/react-sdk-module-api/lib/lifecycles/RoomViewLifecycle"; 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) { if (myMember) {
const previousMembership = myMember.events.member?.getPrevContent().membership; const previousMembership = myMember.events.member?.getPrevContent().membership;
if (myMember.isKicked()) { if (myMember.isKicked()) {
if (previousMembership === Membership.Knock) { if (previousMembership === KnownMembership.Knock) {
return MessageCase.RequestDenied; return MessageCase.RequestDenied;
} else if (this.props.promptAskToJoin) { } else if (this.props.promptAskToJoin) {
return MessageCase.PromptAskToJoin; return MessageCase.PromptAskToJoin;
} }
return MessageCase.Kicked; return MessageCase.Kicked;
} else if (myMember.membership === Membership.Ban) { } else if (myMember.membership === KnownMembership.Ban) {
return MessageCase.Banned; return MessageCase.Banned;
} }
} }
@ -284,7 +285,7 @@ export default class RoomPreviewBar extends React.Component<IProps, IState> {
return false; return false;
} }
const memberContent = myMember.events.member?.getContent(); const memberContent = myMember.events.member?.getContent();
return memberContent?.membership === Membership.Invite && memberContent.is_direct; return memberContent?.membership === KnownMembership.Invite && memberContent.is_direct;
} }
private makeScreenAfterLogin(): { screen: string; params: Record<string, any> } { private makeScreenAfterLogin(): { screen: string; params: Record<string, any> } {

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import React, { FC, useContext, useState } from "react"; import React, { FC, useContext, useState } from "react";
import { Room, JoinRule } from "matrix-js-sdk/src/matrix"; import { Room, JoinRule, KnownMembership } from "matrix-js-sdk/src/matrix";
import { _t } from "../../../languageHandler"; import { _t } from "../../../languageHandler";
import defaultDispatcher from "../../../dispatcher/dispatcher"; import defaultDispatcher from "../../../dispatcher/dispatcher";
@ -73,7 +73,7 @@ const RoomPreviewCard: FC<IProps> = ({ room, onJoinButtonClicked, onRejectButton
let inviterSection: JSX.Element | null = null; let inviterSection: JSX.Element | null = null;
let joinButtons: JSX.Element; let joinButtons: JSX.Element;
if (myMembership === Membership.Join) { if (myMembership === KnownMembership.Join) {
joinButtons = ( joinButtons = (
<AccessibleButton <AccessibleButton
kind="danger_outline" kind="danger_outline"
@ -87,7 +87,7 @@ const RoomPreviewCard: FC<IProps> = ({ room, onJoinButtonClicked, onRejectButton
{_t("action|leave")} {_t("action|leave")}
</AccessibleButton> </AccessibleButton>
); );
} else if (myMembership === Membership.Invite) { } else if (myMembership === KnownMembership.Invite) {
const inviteSender = room.getMember(cli.getUserId()!)?.events.member?.getSender(); const inviteSender = room.getMember(cli.getUserId()!)?.events.member?.getSender();
if (inviteSender) { if (inviteSender) {
@ -178,7 +178,7 @@ const RoomPreviewCard: FC<IProps> = ({ room, onJoinButtonClicked, onRejectButton
}); });
} else if (isVideoRoom && !videoRoomsEnabled) { } else if (isVideoRoom && !videoRoomsEnabled) {
notice = notice =
myMembership === Membership.Join myMembership === KnownMembership.Join
? _t("room|view_failed_enable_video_rooms") ? _t("room|view_failed_enable_video_rooms")
: _t("room|join_failed_enable_video_rooms"); : _t("room|join_failed_enable_video_rooms");

View file

@ -16,7 +16,7 @@ limitations under the License.
*/ */
import React, { createRef } from "react"; import React, { createRef } from "react";
import { Room, RoomEvent } from "matrix-js-sdk/src/matrix"; import { KnownMembership, Room, RoomEvent } from "matrix-js-sdk/src/matrix";
import classNames from "classnames"; import classNames from "classnames";
import type { Call } from "../../../models/Call"; import type { Call } from "../../../models/Call";
@ -124,7 +124,7 @@ export class RoomTile extends React.PureComponent<ClassProps, State> {
private get showContextMenu(): boolean { private get showContextMenu(): boolean {
return ( return (
this.props.tag !== DefaultTagID.Invite && this.props.tag !== DefaultTagID.Invite &&
this.props.room.getMyMembership() !== Membership.Knock && this.props.room.getMyMembership() !== KnownMembership.Knock &&
!isKnockDenied(this.props.room) && !isKnockDenied(this.props.room) &&
shouldShowComponent(UIComponent.RoomOptionsMenu) shouldShowComponent(UIComponent.RoomOptionsMenu)
); );
@ -387,7 +387,7 @@ export class RoomTile extends React.PureComponent<ClassProps, State> {
mx_RoomTile: true, mx_RoomTile: true,
mx_RoomTile_sticky: mx_RoomTile_sticky:
SettingsStore.getValue("feature_ask_to_join") && SettingsStore.getValue("feature_ask_to_join") &&
(this.props.room.getMyMembership() === Membership.Knock || isKnockDenied(this.props.room)), (this.props.room.getMyMembership() === KnownMembership.Knock || isKnockDenied(this.props.room)),
mx_RoomTile_selected: this.state.selected, mx_RoomTile_selected: this.state.selected,
mx_RoomTile_hasMenuOpen: !!(this.state.generalMenuPosition || this.state.notificationsMenuPosition), mx_RoomTile_hasMenuOpen: !!(this.state.generalMenuPosition || this.state.notificationsMenuPosition),
mx_RoomTile_minimized: this.props.isMinimized, mx_RoomTile_minimized: this.props.isMinimized,

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import React, { ContextType } from "react"; import React, { ContextType } from "react";
import { Room } from "matrix-js-sdk/src/matrix"; import { KnownMembership, Room } from "matrix-js-sdk/src/matrix";
import { _t } from "../../../../../languageHandler"; import { _t } from "../../../../../languageHandler";
import RoomProfileSettings from "../../../room_settings/RoomProfileSettings"; import RoomProfileSettings from "../../../room_settings/RoomProfileSettings";
@ -73,7 +73,7 @@ export default class GeneralRoomSettingsTab extends React.Component<IProps, ISta
) : null; ) : null;
let leaveSection; let leaveSection;
if (room.getMyMembership() === Membership.Join) { if (room.getMyMembership() === KnownMembership.Join) {
leaveSection = ( leaveSection = (
<SettingsSubsection heading={_t("action|leave_room")}> <SettingsSubsection heading={_t("action|leave_room")}>
<AccessibleButton kind="danger" onClick={this.onLeaveClick}> <AccessibleButton kind="danger" onClick={this.onLeaveClick}>

View file

@ -14,7 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { EventTimeline, MatrixError, Room, RoomMember, RoomStateEvent } from "matrix-js-sdk/src/matrix"; import {
EventTimeline,
KnownMembership,
MatrixError,
Room,
RoomMember,
RoomStateEvent,
} from "matrix-js-sdk/src/matrix";
import React, { useCallback, useState, VFC } from "react"; import React, { useCallback, useState, VFC } from "react";
import { Icon as CheckIcon } from "../../../../../../res/img/feather-customised/check.svg"; import { Icon as CheckIcon } from "../../../../../../res/img/feather-customised/check.svg";
@ -145,7 +152,7 @@ export const PeopleRoomSettingsTab: VFC<{ room: Room }> = ({ room }) => {
const knockMembers = useTypedEventEmitterState( const knockMembers = useTypedEventEmitterState(
room, room,
RoomStateEvent.Update, RoomStateEvent.Update,
useCallback(() => room.getMembersWithMembership(Membership.Knock), [room]), useCallback(() => room.getMembersWithMembership(KnownMembership.Knock), [room]),
); );
return ( return (

View file

@ -15,7 +15,15 @@ limitations under the License.
*/ */
import React from "react"; import React from "react";
import { EventType, RoomMember, RoomState, RoomStateEvent, Room, IContent } from "matrix-js-sdk/src/matrix"; import {
EventType,
RoomMember,
RoomState,
RoomStateEvent,
Room,
IContent,
KnownMembership,
} from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { throttle, get } from "lodash"; import { throttle, get } from "lodash";
import { compare } from "matrix-js-sdk/src/utils"; import { compare } from "matrix-js-sdk/src/utils";
@ -413,7 +421,7 @@ export default class RolesRoomSettingsTab extends React.Component<IProps> {
} }
} }
const banned = room.getMembersWithMembership(Membership.Ban); const banned = room.getMembersWithMembership(KnownMembership.Ban);
let bannedUsersSection: JSX.Element | undefined; let bannedUsersSection: JSX.Element | undefined;
if (banned?.length) { if (banned?.length) {
const canBanUsers = currentUserLevel >= banLevel; const canBanUsers = currentUserLevel >= banLevel;

View file

@ -16,7 +16,7 @@ limitations under the License.
import React, { ReactNode } from "react"; import React, { ReactNode } from "react";
import { sleep } from "matrix-js-sdk/src/utils"; import { sleep } from "matrix-js-sdk/src/utils";
import { Room, RoomEvent } from "matrix-js-sdk/src/matrix"; import { KnownMembership, Room, RoomEvent } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { _t } from "../../../../../languageHandler"; import { _t } from "../../../../../languageHandler";
@ -37,7 +37,7 @@ import InlineSpinner from "../../../elements/InlineSpinner";
import { PosthogAnalytics } from "../../../../../PosthogAnalytics"; import { PosthogAnalytics } from "../../../../../PosthogAnalytics";
import { showDialog as showAnalyticsLearnMoreDialog } from "../../../dialogs/AnalyticsLearnMoreDialog"; import { showDialog as showAnalyticsLearnMoreDialog } from "../../../dialogs/AnalyticsLearnMoreDialog";
import { privateShouldBeEncrypted } from "../../../../../utils/rooms"; import { privateShouldBeEncrypted } from "../../../../../utils/rooms";
import type { IServerVersions } from "matrix-js-sdk/src/matrix"; import type { IServerVersions, Membership } from "matrix-js-sdk/src/matrix";
import SettingsTab from "../SettingsTab"; import SettingsTab from "../SettingsTab";
import { SettingsSection } from "../../shared/SettingsSection"; import { SettingsSection } from "../../shared/SettingsSection";
import SettingsSubsection, { SettingsSubsectionText } from "../../shared/SettingsSubsection"; import SettingsSubsection, { SettingsSubsectionText } from "../../shared/SettingsSubsection";
@ -126,7 +126,7 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt
return; return;
} }
if (membership === Membership.Invite) { if (membership === KnownMembership.Invite) {
this.addInvitedRoom(room); this.addInvitedRoom(room);
} else if (this.state.invitedRoomIds.has(room.roomId)) { } else if (this.state.invitedRoomIds.has(room.roomId)) {
// The user isn't invited anymore // The user isn't invited anymore
@ -167,7 +167,7 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt
return MatrixClientPeg.safeGet() return MatrixClientPeg.safeGet()
.getRooms() .getRooms()
.filter((r) => { .filter((r) => {
return r.hasMembershipState(MatrixClientPeg.safeGet().getUserId()!, Membership.Invite); return r.hasMembershipState(MatrixClientPeg.safeGet().getUserId()!, KnownMembership.Invite);
}); });
}; };

View file

@ -24,7 +24,7 @@ import React, {
RefObject, RefObject,
} from "react"; } from "react";
import classNames from "classnames"; import classNames from "classnames";
import { Room, RoomEvent } from "matrix-js-sdk/src/matrix"; import { KnownMembership, Room, RoomEvent } from "matrix-js-sdk/src/matrix";
import { DraggableProvidedDragHandleProps } from "react-beautiful-dnd"; import { DraggableProvidedDragHandleProps } from "react-beautiful-dnd";
import RoomAvatar from "../avatars/RoomAvatar"; import RoomAvatar from "../avatars/RoomAvatar";
@ -99,7 +99,7 @@ export const SpaceButton = <T extends keyof JSX.IntrinsicElements>({
let notifBadge; let notifBadge;
if (spaceKey && notificationState) { if (spaceKey && notificationState) {
let ariaLabel = _t("a11y_jump_first_unread_room"); let ariaLabel = _t("a11y_jump_first_unread_room");
if (space?.getMyMembership() === Membership.Invite) { if (space?.getMyMembership() === KnownMembership.Invite) {
ariaLabel = _t("a11y|jump_first_invite"); ariaLabel = _t("a11y|jump_first_invite");
} }
@ -325,7 +325,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
hasSubSpaces: this.state.childSpaces?.length, hasSubSpaces: this.state.childSpaces?.length,
}); });
const isInvite = space.getMyMembership() === Membership.Invite; const isInvite = space.getMyMembership() === KnownMembership.Invite;
const notificationState = isInvite const notificationState = isInvite
? StaticNotificationState.forSymbol("!", NotificationLevel.Highlight) ? StaticNotificationState.forSymbol("!", NotificationLevel.Highlight)
@ -379,7 +379,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
size={isNested ? "24px" : "32px"} size={isNested ? "24px" : "32px"}
onKeyDown={this.onKeyDown} onKeyDown={this.onKeyDown}
ContextMenuComponent={ ContextMenuComponent={
this.props.space.getMyMembership() === Membership.Join ? SpaceContextMenu : undefined this.props.space.getMyMembership() === KnownMembership.Join ? SpaceContextMenu : undefined
} }
> >
{toggleCollapseButton} {toggleCollapseButton}

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import { useMemo, useState } from "react"; import { useMemo, useState } from "react";
import { Room, RoomEvent, RoomMember, RoomStateEvent } from "matrix-js-sdk/src/matrix"; import { Membership, Room, RoomEvent, RoomMember, RoomStateEvent } from "matrix-js-sdk/src/matrix";
import { throttle } from "lodash"; import { throttle } from "lodash";
import { useTypedEventEmitter } from "./useEventEmitter"; import { useTypedEventEmitter } from "./useEventEmitter";

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import { useCallback, useEffect, useMemo, useState } from "react"; import { useCallback, useEffect, useMemo, useState } from "react";
import { Room, RoomType, HierarchyRoom } from "matrix-js-sdk/src/matrix"; import { Room, RoomType, HierarchyRoom, KnownMembership } from "matrix-js-sdk/src/matrix";
import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy"; import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy";
import { normalize } from "matrix-js-sdk/src/utils"; import { normalize } from "matrix-js-sdk/src/utils";
@ -57,7 +57,7 @@ export const useSpaceResults = (space: Room | undefined, query: string): [Hierar
return rooms?.filter((r) => { return rooms?.filter((r) => {
return ( return (
r.room_type !== RoomType.Space && r.room_type !== RoomType.Space &&
cli.getRoom(r.room_id)?.getMyMembership() !== Membership.Join && cli.getRoom(r.room_id)?.getMyMembership() !== KnownMembership.Join &&
(normalize(r.name || "").includes(normalizedQuery) || (r.canonical_alias || "").includes(lcQuery)) (normalize(r.name || "").includes(normalizedQuery) || (r.canonical_alias || "").includes(lcQuery))
); );
}); });

View file

@ -37,6 +37,7 @@ import {
SyncState, SyncState,
TimelineIndex, TimelineIndex,
TimelineWindow, TimelineWindow,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { sleep } from "matrix-js-sdk/src/utils"; import { sleep } from "matrix-js-sdk/src/utils";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
@ -533,7 +534,7 @@ export default class EventIndex extends EventEmitter {
const profiles: Record<string, IMatrixProfile> = {}; const profiles: Record<string, IMatrixProfile> = {};
stateEvents.forEach((ev) => { stateEvents.forEach((ev) => {
if (ev.getContent().membership === Membership.Join) { if (ev.getContent().membership === KnownMembership.Join) {
profiles[ev.getSender()!] = { profiles[ev.getSender()!] = {
displayname: ev.getContent().displayname, displayname: ev.getContent().displayname,
avatar_url: ev.getContent().avatar_url, avatar_url: ev.getContent().avatar_url,
@ -754,7 +755,7 @@ export default class EventIndex extends EventEmitter {
// This is sets the avatar URL. // This is sets the avatar URL.
const memberEvent = eventMapper({ const memberEvent = eventMapper({
content: { content: {
membership: Membership.Join, membership: KnownMembership.Join,
avatar_url: e.profile.avatar_url, avatar_url: e.profile.avatar_url,
displayname: e.profile.displayname, displayname: e.profile.displayname,
}, },

View file

@ -23,6 +23,8 @@ import {
IMyDevice, IMyDevice,
Room, Room,
RoomMember, RoomMember,
Membership,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { randomString } from "matrix-js-sdk/src/randomstring"; import { randomString } from "matrix-js-sdk/src/randomstring";
@ -308,7 +310,7 @@ export abstract class Call extends TypedEventEmitter<CallEvent, CallEventHandler
} }
private onMyMembership = async (_room: Room, membership: Membership): Promise<void> => { private onMyMembership = async (_room: Room, membership: Membership): Promise<void> => {
if (membership !== Membership.Join) this.setDisconnected(); if (membership !== KnownMembership.Join) this.setDisconnected();
}; };
private onStopMessaging = (uid: string): void => { private onStopMessaging = (uid: string): void => {
@ -386,7 +388,7 @@ export class JitsiCall extends Call {
devices = devices.filter((d) => d !== this.client.getDeviceId()); devices = devices.filter((d) => d !== this.client.getDeviceId());
} }
// Must have a connected device and still be joined to the room // Must have a connected device and still be joined to the room
if (devices.length > 0 && member?.membership === Membership.Join) { if (devices.length > 0 && member?.membership === KnownMembership.Join) {
participants.set(member, new Set(devices)); participants.set(member, new Set(devices));
if (expiresAt < allExpireAt) allExpireAt = expiresAt; if (expiresAt < allExpireAt) allExpireAt = expiresAt;
} }
@ -416,7 +418,7 @@ export class JitsiCall extends Call {
* returns null, the update is skipped. * returns null, the update is skipped.
*/ */
private async updateDevices(fn: (devices: string[]) => string[] | null): Promise<void> { private async updateDevices(fn: (devices: string[]) => string[] | null): Promise<void> {
if (this.room.getMyMembership() !== Membership.Join) return; if (this.room.getMyMembership() !== KnownMembership.Join) return;
const event = this.room.currentState.getStateEvents(JitsiCall.MEMBER_EVENT_TYPE, this.client.getUserId()!); const event = this.room.currentState.getStateEvents(JitsiCall.MEMBER_EVENT_TYPE, this.client.getUserId()!);
const content = event?.getContent<JitsiCallMemberContent>(); const content = event?.getContent<JitsiCallMemberContent>();

View file

@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
*/ */
import { MatrixEvent, EventType, RelationType } from "matrix-js-sdk/src/matrix"; import { MatrixEvent, EventType, RelationType, KnownMembership } from "matrix-js-sdk/src/matrix";
import SettingsStore from "./settings/SettingsStore"; import SettingsStore from "./settings/SettingsStore";
import { IRoomState } from "./components/structures/RoomView"; import { IRoomState } from "./components/structures/RoomView";
@ -39,10 +39,11 @@ function memberEventDiff(ev: MatrixEvent): IDiff {
const prevContent = ev.getPrevContent(); const prevContent = ev.getPrevContent();
const isMembershipChanged = content.membership !== prevContent.membership; const isMembershipChanged = content.membership !== prevContent.membership;
diff.isJoin = isMembershipChanged && content.membership === Membership.Join; diff.isJoin = isMembershipChanged && content.membership === KnownMembership.Join;
diff.isPart = isMembershipChanged && content.membership === Membership.Leave && ev.getStateKey() === ev.getSender(); diff.isPart =
isMembershipChanged && content.membership === KnownMembership.Leave && ev.getStateKey() === ev.getSender();
const isJoinToJoin = !isMembershipChanged && content.membership === Membership.Join; const isJoinToJoin = !isMembershipChanged && content.membership === KnownMembership.Join;
diff.isDisplaynameChange = isJoinToJoin && content.displayname !== prevContent.displayname; diff.isDisplaynameChange = isJoinToJoin && content.displayname !== prevContent.displayname;
diff.isAvatarChange = isJoinToJoin && content.avatar_url !== prevContent.avatar_url; diff.isAvatarChange = isJoinToJoin && content.avatar_url !== prevContent.avatar_url;
return diff; return diff;

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { Room, RoomEvent, ClientEvent } from "matrix-js-sdk/src/matrix"; import { Room, RoomEvent, ClientEvent, KnownMembership } from "matrix-js-sdk/src/matrix";
import { isNullOrUndefined } from "matrix-js-sdk/src/utils"; import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
import SettingsStore from "../settings/SettingsStore"; import SettingsStore from "../settings/SettingsStore";
@ -91,7 +91,7 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
// The tests might not result in a valid room object. // The tests might not result in a valid room object.
const room = this.matrixClient.getRoom(payload.room_id); const room = this.matrixClient.getRoom(payload.room_id);
const membership = room?.getMyMembership(); const membership = room?.getMyMembership();
if (room && membership === Membership.Join) await this.appendRoom(room); if (room && membership === KnownMembership.Join) await this.appendRoom(room);
} }
} else if (payload.action === Action.JoinRoom) { } else if (payload.action === Action.JoinRoom) {
const room = this.matrixClient.getRoom(payload.roomId); const room = this.matrixClient.getRoom(payload.roomId);

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { Room, RoomMember } from "matrix-js-sdk/src/matrix"; import { KnownMembership, Room, RoomMember } from "matrix-js-sdk/src/matrix";
import SettingsStore from "../settings/SettingsStore"; import SettingsStore from "../settings/SettingsStore";
import { SdkContextClass } from "../contexts/SDKContext"; import { SdkContextClass } from "../contexts/SDKContext";
@ -90,7 +90,7 @@ export class MemberListStore {
// pull straight from the server. Don't use a since token as we don't have earlier deltas // pull straight from the server. Don't use a since token as we don't have earlier deltas
// accumulated. // accumulated.
room.currentState.markOutOfBandMembersStarted(); room.currentState.markOutOfBandMembersStarted();
const response = await this.stores.client!.members(roomId, undefined, Membership.Leave); const response = await this.stores.client!.members(roomId, undefined, KnownMembership.Leave);
const memberEvents = response.chunk.map(this.stores.client!.getEventMapper()); const memberEvents = response.chunk.map(this.stores.client!.getEventMapper());
room.currentState.setOutOfBandMembers(memberEvents); room.currentState.setOutOfBandMembers(memberEvents);
} else { } else {
@ -167,7 +167,7 @@ export class MemberListStore {
invited: [], invited: [],
}; };
members.forEach((m) => { members.forEach((m) => {
if (m.membership !== Membership.Join && m.membership !== Membership.Invite) { if (m.membership !== KnownMembership.Join && m.membership !== KnownMembership.Invite) {
return; // bail early for left/banned users return; // bail early for left/banned users
} }
if (query) { if (query) {
@ -179,10 +179,10 @@ export class MemberListStore {
} }
} }
switch (m.membership) { switch (m.membership) {
case Membership.Join: case KnownMembership.Join:
result.joined.push(m); result.joined.push(m);
break; break;
case Membership.Invite: case KnownMembership.Invite:
result.invited.push(m); result.invited.push(m);
break; break;
} }

View file

@ -27,6 +27,7 @@ import {
ContentHelpers, ContentHelpers,
MBeaconInfoEventContent, MBeaconInfoEventContent,
M_BEACON, M_BEACON,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
@ -313,7 +314,7 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
// in PSF-797 // in PSF-797
// stop watching beacons in rooms where user is no longer a member // stop watching beacons in rooms where user is no longer a member
if (member.membership === Membership.Leave || member.membership === Membership.Ban) { if (member.membership === KnownMembership.Leave || member.membership === KnownMembership.Ban) {
this.beaconsByRoomId.get(roomState.roomId)?.forEach(this.removeBeacon); this.beaconsByRoomId.get(roomState.roomId)?.forEach(this.removeBeacon);
this.beaconsByRoomId.delete(roomState.roomId); this.beaconsByRoomId.delete(roomState.roomId);
} }

View file

@ -18,7 +18,7 @@ limitations under the License.
import React, { ReactNode } from "react"; import React, { ReactNode } from "react";
import * as utils from "matrix-js-sdk/src/utils"; import * as utils from "matrix-js-sdk/src/utils";
import { MatrixError, JoinRule, Room, MatrixEvent } from "matrix-js-sdk/src/matrix"; import { MatrixError, JoinRule, Room, MatrixEvent, KnownMembership } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { ViewRoom as ViewRoomEvent } from "@matrix-org/analytics-events/types/typescript/ViewRoom"; import { ViewRoom as ViewRoomEvent } from "@matrix-org/analytics-events/types/typescript/ViewRoom";
import { JoinedRoom as JoinedRoomEvent } from "@matrix-org/analytics-events/types/typescript/JoinedRoom"; import { JoinedRoom as JoinedRoomEvent } from "@matrix-org/analytics-events/types/typescript/JoinedRoom";
@ -607,7 +607,7 @@ export class RoomViewStore extends EventEmitter {
private getInvitingUserId(roomId: string): string | undefined { private getInvitingUserId(roomId: string): string | undefined {
const cli = MatrixClientPeg.safeGet(); const cli = MatrixClientPeg.safeGet();
const room = cli.getRoom(roomId); const room = cli.getRoom(roomId);
if (room?.getMyMembership() === Membership.Invite) { if (room?.getMyMembership() === KnownMembership.Invite) {
const myMember = room.getMember(cli.getSafeUserId()); const myMember = room.getMember(cli.getSafeUserId());
const inviteEvent = myMember ? myMember.events.member : null; const inviteEvent = myMember ? myMember.events.member : null;
return inviteEvent?.getSender(); return inviteEvent?.getSender();

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { MatrixEventEvent, RoomEvent, ClientEvent } from "matrix-js-sdk/src/matrix"; import { MatrixEventEvent, RoomEvent, ClientEvent, KnownMembership } from "matrix-js-sdk/src/matrix";
import type { Room, MatrixEvent } from "matrix-js-sdk/src/matrix"; import type { Room, MatrixEvent } from "matrix-js-sdk/src/matrix";
import type { IDestroyable } from "../../utils/IDestroyable"; import type { IDestroyable } from "../../utils/IDestroyable";
@ -97,7 +97,7 @@ export class RoomNotificationState extends NotificationState implements IDestroy
const muted = const muted =
RoomNotifs.getRoomNotifsState(this.room.client, this.room.roomId) === RoomNotifs.RoomNotifState.Mute; RoomNotifs.getRoomNotifsState(this.room.client, this.room.roomId) === RoomNotifs.RoomNotifState.Mute;
const knocked = const knocked =
SettingsStore.getValue("feature_ask_to_join") && this.room.getMyMembership() === Membership.Knock; SettingsStore.getValue("feature_ask_to_join") && this.room.getMyMembership() === KnownMembership.Knock;
this._level = level; this._level = level;
this._symbol = symbol; this._symbol = symbol;
this._count = count; this._count = count;

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { MatrixClient, Room, RoomState, EventType } from "matrix-js-sdk/src/matrix"; import { MatrixClient, Room, RoomState, EventType, KnownMembership } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import SettingsStore from "../../settings/SettingsStore"; import SettingsStore from "../../settings/SettingsStore";
@ -350,7 +350,7 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> implements
} }
private async handleRoomUpdate(room: Room, cause: RoomUpdateCause): Promise<any> { private async handleRoomUpdate(room: Room, cause: RoomUpdateCause): Promise<any> {
if (cause === RoomUpdateCause.NewRoom && room.getMyMembership() === Membership.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 // 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 // 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 // we delay doing anything about this room until the VoipUserMapper had had a chance

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { Room } from "matrix-js-sdk/src/matrix"; import { KnownMembership, Room } from "matrix-js-sdk/src/matrix";
import { isNullOrUndefined } from "matrix-js-sdk/src/utils"; import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
@ -172,7 +172,7 @@ export class Algorithm extends EventEmitter {
} }
private doUpdateStickyRoom(val: Room | null): void { private doUpdateStickyRoom(val: Room | null): void {
if (val?.isSpaceRoom() && val.getMyMembership() !== Membership.Invite) { if (val?.isSpaceRoom() && val.getMyMembership() !== KnownMembership.Invite) {
// no-op sticky rooms for spaces - they're effectively virtual rooms // no-op sticky rooms for spaces - they're effectively virtual rooms
val = null; val = null;
} }

View file

@ -25,6 +25,7 @@ import {
MatrixEvent, MatrixEvent,
ClientEvent, ClientEvent,
ISendEventResponse, ISendEventResponse,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
@ -255,8 +256,8 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
// else view space home or home depending on what is being clicked on // else view space home or home depending on what is being clicked on
if ( if (
roomId && roomId &&
cliSpace?.getMyMembership() !== Membership.Invite && cliSpace?.getMyMembership() !== KnownMembership.Invite &&
this.matrixClient.getRoom(roomId)?.getMyMembership() === Membership.Join && this.matrixClient.getRoom(roomId)?.getMyMembership() === KnownMembership.Join &&
this.isRoomInSpace(space, roomId) this.isRoomInSpace(space, roomId)
) { ) {
defaultDispatcher.dispatch<ViewRoomPayload>({ defaultDispatcher.dispatch<ViewRoomPayload>({
@ -325,7 +326,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
.filter((roomInfo) => { .filter((roomInfo) => {
return ( return (
roomInfo.room_type !== RoomType.Space && roomInfo.room_type !== RoomType.Space &&
this.matrixClient.getRoom(roomInfo.room_id)?.getMyMembership() !== Membership.Join this.matrixClient?.getRoom(roomInfo.room_id)?.getMyMembership() !== KnownMembership.Join
); );
}) })
.map((roomInfo) => ({ .map((roomInfo) => ({
@ -368,7 +369,10 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
return history[history.length - 1]; return history[history.length - 1];
}) })
.filter((room) => { .filter((room) => {
return room?.getMyMembership() === Membership.Join || room?.getMyMembership() === Membership.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[] { public getChildSpaces(spaceId: string): Room[] {
// don't show invited subspaces as they surface at the top level for better visibility // 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() === Membership.Join); return this.getChildren(spaceId).filter((r) => r.isSpaceRoom() && r.getMyMembership() === KnownMembership.Join);
} }
public getParents(roomId: string, canonicalOnly = false): Room[] { public getParents(roomId: string, canonicalOnly = false): Room[] {
@ -593,7 +597,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
private rebuildParentMap = (): void => { private rebuildParentMap = (): void => {
if (!this.matrixClient) return; if (!this.matrixClient) return;
const joinedSpaces = this.matrixClient.getVisibleRooms(this._msc3946ProcessDynamicPredecessor).filter((r) => { const joinedSpaces = this.matrixClient.getVisibleRooms(this._msc3946ProcessDynamicPredecessor).filter((r) => {
return r.isSpaceRoom() && r.getMyMembership() === Membership.Join; return r.isSpaceRoom() && r.getMyMembership() === KnownMembership.Join;
}); });
this.parentMap = new EnhancedMap<string, Set<string>>(); this.parentMap = new EnhancedMap<string, Set<string>>();
@ -717,12 +721,12 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
return ( return (
!this.parentMap.get(room.roomId)?.size || // put all orphaned rooms in the Home Space !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 !!DMRoomMap.shared().getUserIdForRoomId(room.roomId) || // put all DMs in the Home Space
room.getMyMembership() === Membership.Invite room.getMyMembership() === KnownMembership.Invite
); // put all invites in the Home Space ); // put all invites in the Home Space
}; };
private static isInSpace(member: RoomMember): boolean { private static isInSpace(member?: RoomMember | null): boolean {
return member.membership === Membership.Join || member.membership === 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 // 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>>(); const hiddenChildren = new EnhancedMap<string, Set<string>>();
visibleRooms.forEach((room) => { visibleRooms.forEach((room) => {
if (![Membership.Join, Membership.Invite].includes(room.getMyMembership())) return; if (!([KnownMembership.Join, KnownMembership.Invite] as Array<string>).includes(room.getMyMembership()))
return;
this.getParents(room.roomId).forEach((parent) => { this.getParents(room.roomId).forEach((parent) => {
hiddenChildren.getOrCreate(parent.roomId, new Set()).add(room.roomId); hiddenChildren.getOrCreate(parent.roomId, new Set()).add(room.roomId);
}); });
@ -796,7 +801,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
space space
?.getMembers() ?.getMembers()
.filter((m) => { .filter((m) => {
return m.membership === Membership.Join || m.membership === Membership.Invite; return m.membership === KnownMembership.Join || m.membership === KnownMembership.Invite;
}) })
.map((m) => m.userId), .map((m) => m.userId),
); );
@ -924,7 +929,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
if (!room.isSpaceRoom()) { if (!room.isSpaceRoom()) {
this.onRoomsUpdate(); this.onRoomsUpdate();
if (membership === Membership.Join) { if (membership === KnownMembership.Join) {
// the user just joined a room, remove it from the suggested list if it was there // the user just joined a room, remove it from the suggested list if it was there
const numSuggestedRooms = this._suggestedRooms.length; const numSuggestedRooms = this._suggestedRooms.length;
this._suggestedRooms = this._suggestedRooms.filter((r) => r.room_id !== room.roomId); this._suggestedRooms = this._suggestedRooms.filter((r) => r.room_id !== room.roomId);
@ -936,7 +941,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
// if the room currently being viewed was just joined then switch to its related space // if the room currently being viewed was just joined then switch to its related space
if ( if (
newMembership === Membership.Join && newMembership === KnownMembership.Join &&
room.roomId === SdkContextClass.instance.roomViewStore.getRoomId() room.roomId === SdkContextClass.instance.roomViewStore.getRoomId()
) { ) {
this.switchSpaceIfNeeded(room.roomId); this.switchSpaceIfNeeded(room.roomId);
@ -946,13 +951,13 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
} }
// Space // Space
if (membership === Membership.Invite) { if (membership === KnownMembership.Invite) {
const len = this._invitedSpaces.size; const len = this._invitedSpaces.size;
this._invitedSpaces.add(room); this._invitedSpaces.add(room);
if (len !== this._invitedSpaces.size) { if (len !== this._invitedSpaces.size) {
this.emit(UPDATE_INVITED_SPACES, this.invitedSpaces); this.emit(UPDATE_INVITED_SPACES, this.invitedSpaces);
} }
} else if (oldMembership === Membership.Invite && membership !== Membership.Join) { } else if (oldMembership === KnownMembership.Invite && membership !== KnownMembership.Join) {
if (this._invitedSpaces.delete(room)) { if (this._invitedSpaces.delete(room)) {
this.emit(UPDATE_INVITED_SPACES, this.invitedSpaces); this.emit(UPDATE_INVITED_SPACES, this.invitedSpaces);
} }
@ -965,10 +970,10 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
this.emit(room.roomId); this.emit(room.roomId);
} }
if (membership === 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 // if the user was looking at the space and then joined: select that space
this.setActiveSpace(room.roomId, false); this.setActiveSpace(room.roomId, false);
} else if (membership === 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 // user's active space has gone away, go back to home
this.goToFirstSpace(true); this.goToFirstSpace(true);
} }
@ -1003,7 +1008,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
if ( if (
room.roomId === this.activeSpace && // current space room.roomId === this.activeSpace && // current space
target?.getMyMembership() !== Membership.Join && // target not joined target?.getMyMembership() !== KnownMembership.Join && // target not joined
ev.getPrevContent().suggested !== ev.getContent().suggested // suggested flag changed ev.getPrevContent().suggested !== ev.getContent().suggested // suggested flag changed
) { ) {
this.loadSuggestedRooms(room); this.loadSuggestedRooms(room);

View file

@ -14,7 +14,14 @@
* limitations under the License. * limitations under the License.
*/ */
import { Room, MatrixEvent, MatrixEventEvent, MatrixClient, ClientEvent } from "matrix-js-sdk/src/matrix"; import {
Room,
MatrixEvent,
MatrixEventEvent,
MatrixClient,
ClientEvent,
KnownMembership,
} from "matrix-js-sdk/src/matrix";
import { import {
ClientWidgetApi, ClientWidgetApi,
IModalWidgetOpenRequest, IModalWidgetOpenRequest,
@ -550,7 +557,7 @@ export class StopGapWidget extends EventEmitter {
const evId = ev.getId(); const evId = ev.getId();
if (evRoomId && evId) { if (evRoomId && evId) {
const room = this.client.getRoom(evRoomId); const room = this.client.getRoom(evRoomId);
if (room && room.getMyMembership() === Membership.Join && !isRelationToUnknown) { if (room && room.getMyMembership() === KnownMembership.Join && !isRelationToUnknown) {
this.readUpToMap[evRoomId] = evId; this.readUpToMap[evRoomId] = evId;
} }
} }

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import { uniq } from "lodash"; import { uniq } from "lodash";
import { Room, MatrixEvent, EventType, ClientEvent, MatrixClient } from "matrix-js-sdk/src/matrix"; import { Room, MatrixEvent, EventType, ClientEvent, MatrixClient, KnownMembership } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { Optional } from "matrix-events-sdk"; import { Optional } from "matrix-events-sdk";
@ -172,7 +172,7 @@ export default class DMRoomMap {
const joinedRooms = commonRooms const joinedRooms = commonRooms
.map((r) => this.matrixClient.getRoom(r)) .map((r) => this.matrixClient.getRoom(r))
.filter((r) => r && r.getMyMembership() === Membership.Join); .filter((r) => r && r.getMyMembership() === KnownMembership.Join);
return joinedRooms[0]; return joinedRooms[0];
} }

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { MatrixError, MatrixClient, EventType, HistoryVisibility } from "matrix-js-sdk/src/matrix"; import { MatrixError, MatrixClient, EventType, HistoryVisibility, KnownMembership } from "matrix-js-sdk/src/matrix";
import { defer, IDeferred } from "matrix-js-sdk/src/utils"; import { defer, IDeferred } from "matrix-js-sdk/src/utils";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
@ -159,17 +159,17 @@ export default class MultiInviter {
if (!room) throw new Error("Room not found"); if (!room) throw new Error("Room not found");
const member = room.getMember(addr); const member = room.getMember(addr);
if (member?.membership === Membership.Join) { if (member?.membership === KnownMembership.Join) {
throw new MatrixError({ throw new MatrixError({
errcode: USER_ALREADY_JOINED, errcode: USER_ALREADY_JOINED,
error: "Member already joined", error: "Member already joined",
}); });
} else if (member?.membership === Membership.Invite) { } else if (member?.membership === KnownMembership.Invite) {
throw new MatrixError({ throw new MatrixError({
errcode: USER_ALREADY_INVITED, errcode: USER_ALREADY_INVITED,
error: "Member already invited", error: "Member already invited",
}); });
} else if (member?.membership === Membership.Ban) { } else if (member?.membership === KnownMembership.Ban) {
let proceed = false; let proceed = false;
// Check if we can unban the invitee. // 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. // See https://spec.matrix.org/v1.7/rooms/v10/#authorization-rules, particularly 4.5.3 and 4.5.4.
@ -177,8 +177,8 @@ export default class MultiInviter {
if ( if (
!!ourMember && !!ourMember &&
member.powerLevel < ourMember.powerLevel && member.powerLevel < ourMember.powerLevel &&
room.currentState.hasSufficientPowerLevelFor(Membership.Ban, ourMember.powerLevel) && room.currentState.hasSufficientPowerLevelFor("ban", ourMember.powerLevel) &&
room.currentState.hasSufficientPowerLevelFor(Membership.Kick, ourMember.powerLevel) room.currentState.hasSufficientPowerLevelFor("kick", ourMember.powerLevel)
) { ) {
const { finished } = Modal.createDialog(ConfirmUserActionDialog, { const { finished } = Modal.createDialog(ConfirmUserActionDialog, {
member, member,

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { Room, EventType, ClientEvent, MatrixClient } from "matrix-js-sdk/src/matrix"; import { Room, EventType, ClientEvent, MatrixClient, KnownMembership } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { inviteUsersToRoom } from "../RoomInvite"; import { inviteUsersToRoom } from "../RoomInvite";
@ -68,8 +68,8 @@ export async function upgradeRoom(
let toInvite: string[] = []; let toInvite: string[] = [];
if (inviteUsers) { if (inviteUsers) {
toInvite = [ toInvite = [
...room.getMembersWithMembership(Membership.Join), ...room.getMembersWithMembership(KnownMembership.Join),
...room.getMembersWithMembership(Membership.Invite), ...room.getMembersWithMembership(KnownMembership.Invite),
] ]
.map((m) => m.userId) .map((m) => m.userId)
.filter((m) => m !== cli.getUserId()); .filter((m) => m !== cli.getUserId());

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import { groupBy, mapValues, maxBy, minBy, sumBy, takeRight } from "lodash"; import { groupBy, mapValues, maxBy, minBy, sumBy, takeRight } from "lodash";
import { MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix"; import { KnownMembership, MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix";
import { Member } from "./direct-messages"; import { Member } from "./direct-messages";
import DMRoomMap from "./DMRoomMap"; import DMRoomMap from "./DMRoomMap";
@ -52,7 +52,7 @@ function joinedRooms(cli: MatrixClient): Room[] {
return ( return (
cli cli
.getRooms() .getRooms()
.filter((r) => r.getMyMembership() === Membership.Join) .filter((r) => r.getMyMembership() === KnownMembership.Join)
// Skip low priority rooms and DMs // Skip low priority rooms and DMs
.filter((r) => !DMRoomMap.shared().getUserIdForRoomId(r.roomId)) .filter((r) => !DMRoomMap.shared().getUserIdForRoomId(r.roomId))
.filter((r) => !Object.keys(r.tags).includes("m.lowpriority")) .filter((r) => !Object.keys(r.tags).includes("m.lowpriority"))

View file

@ -17,7 +17,14 @@ limitations under the License.
import { base32 } from "rfc4648"; import { base32 } from "rfc4648";
import { IWidget, IWidgetData } from "matrix-widget-api"; import { IWidget, IWidgetData } from "matrix-widget-api";
import { Room, ClientEvent, MatrixClient, RoomStateEvent, MatrixEvent } from "matrix-js-sdk/src/matrix"; import {
Room,
ClientEvent,
MatrixClient,
RoomStateEvent,
MatrixEvent,
KnownMembership,
} from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { CallType } from "matrix-js-sdk/src/webrtc/call"; import { CallType } from "matrix-js-sdk/src/webrtc/call";
import { randomString, randomLowercaseString, randomUppercaseString } from "matrix-js-sdk/src/randomstring"; import { randomString, randomLowercaseString, randomUppercaseString } from "matrix-js-sdk/src/randomstring";
@ -83,7 +90,7 @@ export default class WidgetUtils {
return false; return false;
} }
if (room.getMyMembership() !== Membership.Join) { if (room.getMyMembership() !== KnownMembership.Join) {
logger.warn(`User ${me} is not in room ${roomId}`); logger.warn(`User ${me} is not in room ${roomId}`);
return false; return false;
} }

View file

@ -15,7 +15,13 @@ limitations under the License.
*/ */
import { MEGOLM_ALGORITHM } from "matrix-js-sdk/src/crypto/olmlib"; 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 {
EventType,
KNOWN_SAFE_ROOM_VERSION,
KnownMembership,
MatrixClient,
MatrixEvent,
} from "matrix-js-sdk/src/matrix";
import { LocalRoom, LOCAL_ROOM_ID_PREFIX } from "../../../src/models/LocalRoom"; import { LocalRoom, LOCAL_ROOM_ID_PREFIX } from "../../../src/models/LocalRoom";
import { determineCreateRoomEncryptionOption, Member } from "../../../src/utils/direct-messages"; import { determineCreateRoomEncryptionOption, Member } from "../../../src/utils/direct-messages";
@ -76,7 +82,7 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
type: EventType.RoomMember, type: EventType.RoomMember,
content: { content: {
displayname: userId, displayname: userId,
membership: MembershipJoin, membership: KnownMembership.Join,
}, },
state_key: userId, state_key: userId,
user_id: userId, user_id: userId,
@ -93,7 +99,7 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
content: { content: {
displayname: target.name, displayname: target.name,
avatar_url: target.getMxcAvatarUrl() ?? undefined, avatar_url: target.getMxcAvatarUrl() ?? undefined,
membership: Membership.Invite, membership: KnownMembership.Invite,
isDirect: true, isDirect: true,
}, },
state_key: target.userId, state_key: target.userId,
@ -108,7 +114,7 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
content: { content: {
displayname: target.name, displayname: target.name,
avatar_url: target.getMxcAvatarUrl() ?? undefined, avatar_url: target.getMxcAvatarUrl() ?? undefined,
membership: Membership.Join, membership: KnownMembership.Join,
}, },
state_key: target.userId, state_key: target.userId,
sender: target.userId, sender: target.userId,
@ -118,7 +124,7 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
}); });
localRoom.targets = targets; localRoom.targets = targets;
localRoom.updateMyMembership(Membership.Join); localRoom.updateMyMembership(KnownMembership.Join);
localRoom.addLiveEvents(events); localRoom.addLiveEvents(events);
localRoom.currentState.setStateEvents(events); localRoom.currentState.setStateEvents(events);
localRoom.name = localRoom.getDefaultRoomName(client.getUserId()!); localRoom.name = localRoom.getDefaultRoomName(client.getUserId()!);

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { MatrixClient, Room } from "matrix-js-sdk/src/matrix"; import { KnownMembership, MatrixClient, Room } from "matrix-js-sdk/src/matrix";
import DMRoomMap from "../DMRoomMap"; import DMRoomMap from "../DMRoomMap";
import { isLocalRoom } from "../localRoom/isLocalRoom"; import { isLocalRoom } from "../localRoom/isLocalRoom";
@ -42,7 +42,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 // 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 // that bots, assistants, etc will ruin a room's DM-ness, though this is a problem for
// canonical DMs to solve. // canonical DMs to solve.
if (r && r.getMyMembership() === Membership.Join) { if (r && r.getMyMembership() === KnownMembership.Join) {
if (isLocalRoom(r)) return false; if (isLocalRoom(r)) return false;
const functionalUsers = getFunctionalMembers(r); const functionalUsers = getFunctionalMembers(r);

View file

@ -14,7 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { Room, RoomMember, RoomState, RoomStateEvent, MatrixEvent, MatrixClient } from "matrix-js-sdk/src/matrix"; import {
Room,
RoomMember,
RoomState,
RoomStateEvent,
MatrixEvent,
MatrixClient,
Membership,
KnownMembership,
} from "matrix-js-sdk/src/matrix";
import { MatrixClientPeg } from "../MatrixClientPeg"; import { MatrixClientPeg } from "../MatrixClientPeg";
import SettingsStore from "../settings/SettingsStore"; import SettingsStore from "../settings/SettingsStore";
@ -66,11 +75,11 @@ export function splitRoomsByMembership(rooms: Room[]): MembershipSplit {
} }
export function getEffectiveMembership(membership: Membership): EffectiveMembership { export function getEffectiveMembership(membership: Membership): EffectiveMembership {
if (membership === Membership.Invite) { if (membership === KnownMembership.Invite) {
return EffectiveMembership.Invite; return EffectiveMembership.Invite;
} else if ( } else if (
membership === Membership.Join || membership === KnownMembership.Join ||
(SettingsStore.getValue("feature_ask_to_join") && membership === Membership.Knock) (SettingsStore.getValue("feature_ask_to_join") && membership === KnownMembership.Knock)
) { ) {
return EffectiveMembership.Join; return EffectiveMembership.Join;
} else { } else {
@ -84,7 +93,7 @@ export function isKnockDenied(room: Room): boolean | undefined {
const member = memberId ? room.getMember(memberId) : null; const member = memberId ? room.getMember(memberId) : null;
const previousMembership = member?.events.member?.getPrevContent().membership; const previousMembership = member?.events.member?.getPrevContent().membership;
return member?.isKicked() && previousMembership === Membership.Knock; return member?.isKicked() && previousMembership === KnownMembership.Knock;
} }
export function getEffectiveMembershipTag(room: Room, membership?: string): EffectiveMembership { export function getEffectiveMembershipTag(room: Room, membership?: string): EffectiveMembership {

View file

@ -16,7 +16,7 @@ limitations under the License.
import isIp from "is-ip"; import isIp from "is-ip";
import * as utils from "matrix-js-sdk/src/utils"; import * as utils from "matrix-js-sdk/src/utils";
import { Room, MatrixClient, RoomStateEvent, EventType } from "matrix-js-sdk/src/matrix"; import { Room, MatrixClient, RoomStateEvent, EventType, KnownMembership } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import MatrixToPermalinkConstructor, { import MatrixToPermalinkConstructor, {
@ -178,7 +178,7 @@ export class RoomPermalinkCreator {
const entries = Object.entries(users); const entries = Object.entries(users);
const allowedEntries = entries.filter(([userId]) => { const allowedEntries = entries.filter(([userId]) => {
const member = this.room?.getMember(userId); const member = this.room?.getMember(userId);
if (!member || member.membership !== Membership.Join) { if (!member || member.membership !== KnownMembership.Join) {
return false; return false;
} }
const serverName = getServerName(userId); const serverName = getServerName(userId);

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { JoinRule, Room } from "matrix-js-sdk/src/matrix"; import { JoinRule, KnownMembership, Room } from "matrix-js-sdk/src/matrix";
import { shouldShowComponent } from "../../customisations/helpers/UIComponents"; import { shouldShowComponent } from "../../customisations/helpers/UIComponents";
import { UIComponent } from "../../settings/UIFeature"; import { UIComponent } from "../../settings/UIFeature";
@ -29,5 +29,5 @@ export function canInviteTo(room: Room): boolean {
const canInvite = const canInvite =
!!room.canInvite(client.getSafeUserId()) || !!(room.isSpaceRoom() && room.getJoinRule() === JoinRule.Public); !!room.canInvite(client.getSafeUserId()) || !!(room.isSpaceRoom() && room.getJoinRule() === JoinRule.Public);
return canInvite && room.getMyMembership() === Membership.Join && shouldShowComponent(UIComponent.InviteUsers); return canInvite && room.getMyMembership() === KnownMembership.Join && shouldShowComponent(UIComponent.InviteUsers);
} }

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import React from "react"; import React from "react";
import { Room, ICreateRoomStateEvent, RoomType, EventType, JoinRule } from "matrix-js-sdk/src/matrix"; import { Room, ICreateRoomStateEvent, RoomType, EventType, JoinRule, KnownMembership } from "matrix-js-sdk/src/matrix";
import { calculateRoomVia } from "./permalinks/Permalinks"; import { calculateRoomVia } from "./permalinks/Permalinks";
import Modal from "../Modal"; import Modal from "../Modal";
@ -40,7 +40,7 @@ import { SdkContextClass } from "../contexts/SDKContext";
export const shouldShowSpaceSettings = (space: Room): boolean => { export const shouldShowSpaceSettings = (space: Room): boolean => {
const userId = space.client.getUserId()!; const userId = space.client.getUserId()!;
return ( return (
space.getMyMembership() === Membership.Join && space.getMyMembership() === KnownMembership.Join &&
(space.currentState.maySendStateEvent(EventType.RoomAvatar, userId) || (space.currentState.maySendStateEvent(EventType.RoomAvatar, userId) ||
space.currentState.maySendStateEvent(EventType.RoomName, userId) || space.currentState.maySendStateEvent(EventType.RoomName, userId) ||
space.currentState.maySendStateEvent(EventType.RoomTopic, userId) || space.currentState.maySendStateEvent(EventType.RoomTopic, userId) ||
@ -85,7 +85,7 @@ export const showCreateNewRoom = async (space: Room, type?: RoomType): Promise<b
}; };
export const shouldShowSpaceInvite = (space: Room): boolean => export const shouldShowSpaceInvite = (space: Room): boolean =>
((space?.getMyMembership() === Membership.Join && space.canInvite(space.client.getUserId()!)) || ((space?.getMyMembership() === KnownMembership.Join && space.canInvite(space.client.getUserId()!)) ||
space.getJoinRule() === JoinRule.Public) && space.getJoinRule() === JoinRule.Public) &&
shouldShowComponent(UIComponent.InviteUsers); shouldShowComponent(UIComponent.InviteUsers);

View file

@ -16,6 +16,7 @@ limitations under the License.
import { import {
IProtocol, IProtocol,
KnownMembership,
LOCAL_NOTIFICATION_SETTINGS_PREFIX, LOCAL_NOTIFICATION_SETTINGS_PREFIX,
MatrixEvent, MatrixEvent,
PushRuleKind, PushRuleKind,
@ -102,7 +103,7 @@ function mkStubDM(roomId: string, userId: string) {
name: "Member", name: "Member",
rawDisplayName: "Member", rawDisplayName: "Member",
roomId: roomId, roomId: roomId,
membership: Membership.Join, membership: KnownMembership.Join,
getAvatarUrl: () => "mxc://avatar.url/image.png", getAvatarUrl: () => "mxc://avatar.url/image.png",
getMxcAvatarUrl: () => "mxc://avatar.url/image.png", getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
}, },
@ -111,7 +112,7 @@ function mkStubDM(roomId: string, userId: string) {
name: "Member", name: "Member",
rawDisplayName: "Member", rawDisplayName: "Member",
roomId: roomId, roomId: roomId,
membership: Membership.Join, membership: KnownMembership.Join,
getAvatarUrl: () => "mxc://avatar.url/image.png", getAvatarUrl: () => "mxc://avatar.url/image.png",
getMxcAvatarUrl: () => "mxc://avatar.url/image.png", getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
}, },
@ -120,7 +121,7 @@ function mkStubDM(roomId: string, userId: string) {
name: "Bot user", name: "Bot user",
rawDisplayName: "Bot user", rawDisplayName: "Bot user",
roomId: roomId, roomId: roomId,
membership: Membership.Join, membership: KnownMembership.Join,
getAvatarUrl: () => "mxc://avatar.url/image.png", getAvatarUrl: () => "mxc://avatar.url/image.png",
getMxcAvatarUrl: () => "mxc://avatar.url/image.png", getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
}, },

View file

@ -24,6 +24,7 @@ import {
EventType, EventType,
MatrixEvent, MatrixEvent,
PendingEventOrdering, PendingEventOrdering,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import type { MatrixClient } from "matrix-js-sdk/src/matrix"; import type { MatrixClient } from "matrix-js-sdk/src/matrix";
@ -277,7 +278,7 @@ describe("RoomNotifs test", () => {
}); });
it("indicates the user has been invited to a channel", async () => { it("indicates the user has been invited to a channel", async () => {
room.updateMyMembership(Membership.Invite); room.updateMyMembership(KnownMembership.Invite);
const { level, symbol, count } = determineUnreadState(room); const { level, symbol, count } = determineUnreadState(room);
@ -293,10 +294,10 @@ describe("RoomNotifs test", () => {
const roomMember = mkRoomMember( const roomMember = mkRoomMember(
room.roomId, room.roomId,
MatrixClientPeg.get()!.getSafeUserId(), MatrixClientPeg.get()!.getSafeUserId(),
Membership.Leave, KnownMembership.Leave,
true, true,
{ {
membership: Membership.Knock, membership: KnownMembership.Knock,
}, },
); );
jest.spyOn(room, "getMember").mockReturnValue(roomMember); jest.spyOn(room, "getMember").mockReturnValue(roomMember);

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix"; import { KnownMembership, MatrixClient, Room, RoomMember } from "matrix-js-sdk/src/matrix";
import { mocked } from "jest-mock"; import { mocked } from "jest-mock";
import { Command, Commands, getCommand } from "../src/SlashCommands"; import { Command, Commands, getCommand } from "../src/SlashCommands";
@ -162,7 +162,7 @@ describe("SlashCommands", () => {
it("should warn about self demotion", async () => { it("should warn about self demotion", async () => {
setCurrentRoom(); setCurrentRoom();
const member = new RoomMember(roomId, client.getSafeUserId()); const member = new RoomMember(roomId, client.getSafeUserId());
member.membership = Membership.Join; member.membership = KnownMembership.Join;
member.powerLevel = 100; member.powerLevel = 100;
room.getMember = () => member; room.getMember = () => member;
command.run(client, roomId, null, `${client.getUserId()} 0`); command.run(client, roomId, null, `${client.getUserId()} 0`);
@ -172,7 +172,7 @@ describe("SlashCommands", () => {
it("should default to 50 if no powerlevel specified", async () => { it("should default to 50 if no powerlevel specified", async () => {
setCurrentRoom(); setCurrentRoom();
const member = new RoomMember(roomId, "@user:server"); const member = new RoomMember(roomId, "@user:server");
member.membership = Membership.Join; member.membership = KnownMembership.Join;
room.getMember = () => member; room.getMember = () => member;
command.run(client, roomId, null, member.userId); command.run(client, roomId, null, member.userId);
expect(client.setPowerLevel).toHaveBeenCalledWith(roomId, member.userId, 50); expect(client.setPowerLevel).toHaveBeenCalledWith(roomId, member.userId, 50);
@ -191,7 +191,7 @@ describe("SlashCommands", () => {
it("should warn about self demotion", async () => { it("should warn about self demotion", async () => {
setCurrentRoom(); setCurrentRoom();
const member = new RoomMember(roomId, client.getSafeUserId()); const member = new RoomMember(roomId, client.getSafeUserId());
member.membership = Membership.Join; member.membership = KnownMembership.Join;
member.powerLevel = 100; member.powerLevel = 100;
room.getMember = () => member; room.getMember = () => member;
command.run(client, roomId, null, client.getSafeUserId()); command.run(client, roomId, null, client.getSafeUserId());
@ -366,7 +366,7 @@ describe("SlashCommands", () => {
describe("/join", () => { describe("/join", () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(dispatcher, "dispatch"); jest.spyOn(dispatcher, "dispatch");
command = findCommand(Membership.Join)!; command = findCommand(KnownMembership.Join)!;
}); });
it("should return usage if no args", () => { it("should return usage if no args", () => {

View file

@ -18,6 +18,7 @@ import {
EventType, EventType,
HistoryVisibility, HistoryVisibility,
JoinRule, JoinRule,
KnownMembership,
MatrixClient, MatrixClient,
MatrixEvent, MatrixEvent,
Room, Room,
@ -504,12 +505,12 @@ describe("TextForEvent", () => {
type: "m.room.member", type: "m.room.member",
sender: "@a:foo", sender: "@a:foo",
content: { content: {
membership: Membership.Join, membership: KnownMembership.Join,
avatar_url: "b", avatar_url: "b",
displayname: "Bob", displayname: "Bob",
}, },
prev_content: { prev_content: {
membership: Membership.Join, membership: KnownMembership.Join,
avatar_url: "a", avatar_url: "a",
displayname: "Andy", displayname: "Andy",
}, },

View file

@ -17,7 +17,7 @@ limitations under the License.
import React from "react"; import React from "react";
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import { MatrixEvent, Room, RoomMember, Thread, ReceiptType } from "matrix-js-sdk/src/matrix"; import { MatrixEvent, Room, RoomMember, Thread, ReceiptType, KnownMembership } from "matrix-js-sdk/src/matrix";
import { render } from "@testing-library/react"; import { render } from "@testing-library/react";
import { TooltipProvider } from "@vector-im/compound-web"; import { TooltipProvider } from "@vector-im/compound-web";
@ -171,8 +171,8 @@ describe("MessagePanel", function () {
user: "@user:id", user: "@user:id",
target: bobMember, target: bobMember,
ts: ts0 + i * 1000, ts: ts0 + i * 1000,
mship: Membership.Join, mship: KnownMembership.Join,
prevMship: Membership.Join, prevMship: KnownMembership.Join,
name: "A user", name: "A user",
}), }),
); );
@ -205,8 +205,8 @@ describe("MessagePanel", function () {
user: "@user:id", user: "@user:id",
target: bobMember, target: bobMember,
ts: ts0 + i * 1000, ts: ts0 + i * 1000,
mship: Membership.Join, mship: KnownMembership.Join,
prevMship: Membership.Join, prevMship: KnownMembership.Join,
name: "A user", name: "A user",
}), }),
); );
@ -245,7 +245,7 @@ describe("MessagePanel", function () {
user: alice, user: alice,
target: aliceMember, target: aliceMember,
ts: ts0 + 1, ts: ts0 + 1,
mship: Membership.Join, mship: KnownMembership.Join,
name: "Alice", name: "Alice",
}), }),
mkEvent({ mkEvent({
@ -285,7 +285,7 @@ describe("MessagePanel", function () {
skey: "@bob:example.org", skey: "@bob:example.org",
target: bobMember, target: bobMember,
ts: ts0 + 5, ts: ts0 + 5,
mship: Membership.Invite, mship: KnownMembership.Invite,
name: "Bob", name: "Bob",
}), }),
]; ];
@ -542,8 +542,8 @@ describe("MessagePanel", function () {
user: "@user:id", user: "@user:id",
target: bobMember, target: bobMember,
ts: Date.now(), ts: Date.now(),
mship: Membership.Join, mship: KnownMembership.Join,
prevMship: Membership.Join, prevMship: KnownMembership.Join,
name: "A user", name: "A user",
}), }),
]; ];
@ -571,8 +571,8 @@ describe("MessagePanel", function () {
user: "@user:id", user: "@user:id",
target: bobMember, target: bobMember,
ts: Date.now(), ts: Date.now(),
mship: Membership.Join, mship: KnownMembership.Join,
prevMship: Membership.Join, prevMship: KnownMembership.Join,
name: "A user", name: "A user",
}), }),
...events, ...events,
@ -695,8 +695,8 @@ describe("MessagePanel", function () {
for (let i = 0; i < 100; i++) { for (let i = 0; i < 100; i++) {
events.push( events.push(
TestUtilsMatrix.mkMembership({ TestUtilsMatrix.mkMembership({
mship: Membership.Join, mship: KnownMembership.Join,
prevMship: Membership.Join, prevMship: KnownMembership.Join,
room: "!room:id", room: "!room:id",
user: "@user:id", user: "@user:id",
event: true, event: true,
@ -716,8 +716,8 @@ describe("MessagePanel", function () {
for (let i = 0; i < 100; i++) { for (let i = 0; i < 100; i++) {
events.push( events.push(
TestUtilsMatrix.mkMembership({ TestUtilsMatrix.mkMembership({
mship: Membership.Join, mship: KnownMembership.Join,
prevMship: Membership.Join, prevMship: KnownMembership.Join,
room: "!room:id", room: "!room:id",
user: "@user:id", user: "@user:id",
event: true, event: true,

View file

@ -28,6 +28,7 @@ import {
MatrixEvent, MatrixEvent,
SearchResult, SearchResult,
IEvent, IEvent,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { MEGOLM_ALGORITHM } from "matrix-js-sdk/src/crypto/olmlib"; import { MEGOLM_ALGORITHM } from "matrix-js-sdk/src/crypto/olmlib";
import { fireEvent, render, screen, RenderResult, waitForElementToBeRemoved, waitFor } from "@testing-library/react"; import { fireEvent, render, screen, RenderResult, waitForElementToBeRemoved, waitFor } from "@testing-library/react";
@ -238,7 +239,7 @@ describe("RoomView", () => {
}); });
it("updates url preview visibility on encryption state change", async () => { it("updates url preview visibility on encryption state change", async () => {
room.getMyMembership = jest.fn().mockReturnValue(Membership.Join); room.getMyMembership = jest.fn().mockReturnValue(KnownMembership.Join);
// we should be starting unencrypted // we should be starting unencrypted
expect(cli.isCryptoEnabled()).toEqual(false); expect(cli.isCryptoEnabled()).toEqual(false);
expect(cli.isRoomEncrypted(room.roomId)).toEqual(false); expect(cli.isRoomEncrypted(room.roomId)).toEqual(false);
@ -583,7 +584,7 @@ describe("RoomView", () => {
it("allows to cancel a join request", async () => { it("allows to cancel a join request", async () => {
jest.spyOn(MatrixClientPeg, "safeGet").mockReturnValue(client); jest.spyOn(MatrixClientPeg, "safeGet").mockReturnValue(client);
jest.spyOn(client, "leave").mockResolvedValue({}); jest.spyOn(client, "leave").mockResolvedValue({});
jest.spyOn(room, "getMyMembership").mockReturnValue(Membership.Knock); jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Knock);
await mountRoomView(); await mountRoomView();
fireEvent.click(screen.getByRole("button", { name: "Cancel request" })); fireEvent.click(screen.getByRole("button", { name: "Cancel request" }));
@ -594,7 +595,7 @@ describe("RoomView", () => {
}); });
it("should close search results when edit is clicked", async () => { it("should close search results when edit is clicked", async () => {
room.getMyMembership = jest.fn().mockReturnValue(Membership.Join); room.getMyMembership = jest.fn().mockReturnValue(KnownMembership.Join);
const eventMapper = (obj: Partial<IEvent>) => new MatrixEvent(obj); 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"); const room2 = new Room(`!${roomCount++}:example.org`, cli, "@alice:example.org");
rooms.set(room2.roomId, room2); rooms.set(room2.roomId, room2);
room.getMyMembership = jest.fn().mockReturnValue(Membership.Join); room.getMyMembership = jest.fn().mockReturnValue(KnownMembership.Join);
const eventMapper = (obj: Partial<IEvent>) => new MatrixEvent(obj); const eventMapper = (obj: Partial<IEvent>) => new MatrixEvent(obj);

View file

@ -17,7 +17,7 @@ limitations under the License.
import React from "react"; import React from "react";
import { mocked } from "jest-mock"; import { mocked } from "jest-mock";
import { fireEvent, render, screen, waitFor, waitForElementToBeRemoved } from "@testing-library/react"; import { fireEvent, render, screen, waitFor, waitForElementToBeRemoved } from "@testing-library/react";
import { MatrixClient, Room, HierarchyRoom } from "matrix-js-sdk/src/matrix"; import { MatrixClient, Room, HierarchyRoom, KnownMembership } from "matrix-js-sdk/src/matrix";
import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy"; import { RoomHierarchy } from "matrix-js-sdk/src/room-hierarchy";
import { TooltipProvider } from "@vector-im/compound-web"; import { TooltipProvider } from "@vector-im/compound-web";
@ -181,7 +181,7 @@ describe("SpaceHierarchy", () => {
mocked(client.getRoom).mockImplementation( mocked(client.getRoom).mockImplementation(
(roomId) => client.getRooms().find((room) => room.roomId === roomId) ?? null, (roomId) => client.getRooms().find((room) => room.roomId === roomId) ?? null,
); );
[room1, room2, space1, room3].forEach((r) => mocked(r.getMyMembership).mockReturnValue(Membership.Leave)); [room1, room2, space1, room3].forEach((r) => mocked(r.getMyMembership).mockReturnValue(KnownMembership.Leave));
const hierarchyRoot: HierarchyRoom = { const hierarchyRoot: HierarchyRoom = {
room_id: root.roomId, room_id: root.roomId,

View file

@ -34,6 +34,7 @@ import {
THREAD_RELATION_TYPE, THREAD_RELATION_TYPE,
ThreadEvent, ThreadEvent,
ThreadFilterType, ThreadFilterType,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import React, { createRef } from "react"; import React, { createRef } from "react";
import { Mocked, mocked } from "jest-mock"; import { Mocked, mocked } from "jest-mock";
@ -988,8 +989,8 @@ describe("TimelinePanel", () => {
events.forEach((event) => timelineSet.getLiveTimeline().addEvent(event, { toStartOfTimeline: true })); events.forEach((event) => timelineSet.getLiveTimeline().addEvent(event, { toStartOfTimeline: true }));
const roomMembership = mkMembership({ const roomMembership = mkMembership({
mship: Membership.Join, mship: KnownMembership.Join,
prevMship: Membership.Join, prevMship: KnownMembership.Join,
user: authorId, user: authorId,
room: room.roomId, room: room.roomId,
event: true, event: true,
@ -999,7 +1000,7 @@ describe("TimelinePanel", () => {
events.push(roomMembership); events.push(roomMembership);
const member = new RoomMember(room.roomId, authorId); const member = new RoomMember(room.roomId, authorId);
member.membership = Membership.Join; member.membership = KnownMembership.Join;
const roomState = new RoomState(room.roomId); const roomState = new RoomState(room.roomId);
jest.spyOn(roomState, "getMember").mockReturnValue(member); jest.spyOn(roomState, "getMember").mockReturnValue(member);

View file

@ -19,7 +19,7 @@ limitations under the License.
import { render, screen } from "@testing-library/react"; import { render, screen } from "@testing-library/react";
import React, { ComponentProps } from "react"; import React, { ComponentProps } from "react";
import { mocked } from "jest-mock"; import { mocked } from "jest-mock";
import { MatrixClient, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix"; import { KnownMembership, MatrixClient, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix";
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext"; import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
import RoomContextMenu from "../../../../src/components/views/context_menus/RoomContextMenu"; import RoomContextMenu from "../../../../src/components/views/context_menus/RoomContextMenu";
@ -106,7 +106,7 @@ describe("RoomContextMenu", () => {
it("should render notification option for joined rooms", () => { it("should render notification option for joined rooms", () => {
const chamber = EchoChamber.forRoom(room); const chamber = EchoChamber.forRoom(room);
chamber.notificationVolume = RoomNotifState.Mute; chamber.notificationVolume = RoomNotifState.Mute;
jest.spyOn(room, "getMyMembership").mockReturnValue(Membership.Join); jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
renderComponent(); renderComponent();
expect( expect(

View file

@ -16,7 +16,7 @@ limitations under the License.
import { fireEvent, getByLabelText, render, screen } from "@testing-library/react"; import { fireEvent, getByLabelText, render, screen } from "@testing-library/react";
import { mocked } from "jest-mock"; import { mocked } from "jest-mock";
import { ReceiptType, MatrixClient, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix"; import { ReceiptType, MatrixClient, PendingEventOrdering, Room, KnownMembership } from "matrix-js-sdk/src/matrix";
import React from "react"; import React from "react";
import userEvent from "@testing-library/user-event"; import userEvent from "@testing-library/user-event";
@ -105,7 +105,7 @@ describe("RoomGeneralContextMenu", () => {
}); });
it("does not render invite menu item when UIComponent customisations disable room invite", () => { it("does not render invite menu item when UIComponent customisations disable room invite", () => {
room.updateMyMembership(Membership.Join); room.updateMyMembership(KnownMembership.Join);
jest.spyOn(room, "canInvite").mockReturnValue(true); jest.spyOn(room, "canInvite").mockReturnValue(true);
mocked(shouldShowComponent).mockReturnValue(false); mocked(shouldShowComponent).mockReturnValue(false);
@ -116,7 +116,7 @@ describe("RoomGeneralContextMenu", () => {
}); });
it("renders invite menu item when UIComponent customisations enables room invite", () => { it("renders invite menu item when UIComponent customisations enables room invite", () => {
room.updateMyMembership(Membership.Join); room.updateMyMembership(KnownMembership.Join);
jest.spyOn(room, "canInvite").mockReturnValue(true); jest.spyOn(room, "canInvite").mockReturnValue(true);
mocked(shouldShowComponent).mockReturnValue(true); mocked(shouldShowComponent).mockReturnValue(true);

View file

@ -16,6 +16,7 @@ limitations under the License.
import React from "react"; import React from "react";
import { render } from "@testing-library/react"; import { render } from "@testing-library/react";
import { KnownMembership } from "matrix-js-sdk/src/matrix";
import ConfirmUserActionDialog from "../../../../src/components/views/dialogs/ConfirmUserActionDialog"; import ConfirmUserActionDialog from "../../../../src/components/views/dialogs/ConfirmUserActionDialog";
import { mkRoomMember } from "../../../test-utils"; import { mkRoomMember } from "../../../test-utils";
@ -25,7 +26,7 @@ describe("ConfirmUserActionDialog", () => {
const { asFragment } = render( const { asFragment } = render(
<ConfirmUserActionDialog <ConfirmUserActionDialog
onFinished={jest.fn()} onFinished={jest.fn()}
member={mkRoomMember("123", "@user:test.com", Membership.Join)} member={mkRoomMember("123", "@user:test.com", KnownMembership.Join)}
action="Ban" action="Ban"
title="Ban this " // eg. 'Ban this user?' title="Ban this " // eg. 'Ban this user?'
/>, />,

View file

@ -17,7 +17,7 @@ limitations under the License.
import React from "react"; import React from "react";
import { fireEvent, render, screen } from "@testing-library/react"; import { fireEvent, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event"; import userEvent from "@testing-library/user-event";
import { RoomType, MatrixClient, MatrixError, Room } from "matrix-js-sdk/src/matrix"; import { RoomType, MatrixClient, MatrixError, Room, KnownMembership } from "matrix-js-sdk/src/matrix";
import { sleep } from "matrix-js-sdk/src/utils"; import { sleep } from "matrix-js-sdk/src/utils";
import { mocked, Mocked } from "jest-mock"; import { mocked, Mocked } from "jest-mock";
@ -163,7 +163,7 @@ describe("InviteDialog", () => {
mkMembership({ mkMembership({
event: true, event: true,
room: roomId, room: roomId,
mship: Membership.Join, mship: KnownMembership.Join,
user: aliceId, user: aliceId,
skey: aliceId, skey: aliceId,
}), }),

View file

@ -21,6 +21,7 @@ import {
IProtocol, IProtocol,
IPublicRoomsChunkRoom, IPublicRoomsChunkRoom,
JoinRule, JoinRule,
KnownMembership,
MatrixClient, MatrixClient,
Room, Room,
RoomMember, RoomMember,
@ -158,9 +159,9 @@ describe("Spotlight Dialog", () => {
beforeEach(() => { beforeEach(() => {
mockedClient = mockClient({ rooms: [testPublicRoom], users: [testPerson] }); mockedClient = mockClient({ rooms: [testPublicRoom], users: [testPerson] });
testRoom = mkRoom(mockedClient, "!test23:example.com"); testRoom = mkRoom(mockedClient, "!test23:example.com");
mocked(testRoom.getMyMembership).mockReturnValue(Membership.Join); mocked(testRoom.getMyMembership).mockReturnValue(KnownMembership.Join);
testLocalRoom = new LocalRoom(LOCAL_ROOM_ID_PREFIX + "test23", mockedClient, mockedClient.getUserId()!); testLocalRoom = new LocalRoom(LOCAL_ROOM_ID_PREFIX + "test23", mockedClient, mockedClient.getUserId()!);
testLocalRoom.updateMyMembership(Membership.Join); testLocalRoom.updateMyMembership(KnownMembership.Join);
mocked(mockedClient.getVisibleRooms).mockReturnValue([testRoom, testLocalRoom]); mocked(mockedClient.getVisibleRooms).mockReturnValue([testRoom, testLocalRoom]);
jest.spyOn(DMRoomMap, "shared").mockReturnValue({ jest.spyOn(DMRoomMap, "shared").mockReturnValue({
@ -169,7 +170,7 @@ describe("Spotlight Dialog", () => {
testDM = mkRoom(mockedClient, testDMRoomId); testDM = mkRoom(mockedClient, testDMRoomId);
testDM.name = "Chat with Alice"; testDM.name = "Chat with Alice";
mocked(testDM.getMyMembership).mockReturnValue(Membership.Join); mocked(testDM.getMyMembership).mockReturnValue(KnownMembership.Join);
mocked(DMRoomMap.shared().getUserIdForRoomId).mockImplementation((roomId: string) => { mocked(DMRoomMap.shared().getUserIdForRoomId).mockImplementation((roomId: string) => {
if (roomId === testDMRoomId) { if (roomId === testDMRoomId) {

View file

@ -16,7 +16,7 @@ limitations under the License.
import React, { ComponentProps } from "react"; import React, { ComponentProps } from "react";
import { render, RenderResult } from "@testing-library/react"; import { render, RenderResult } from "@testing-library/react";
import { MatrixEvent, RoomMember } from "matrix-js-sdk/src/matrix"; import { KnownMembership, MatrixEvent, Membership, RoomMember } from "matrix-js-sdk/src/matrix";
import { import {
getMockClientWithEventEmitter, getMockClientWithEventEmitter,
@ -146,7 +146,7 @@ describe("EventListSummary", function () {
it("renders expanded events if there are less than props.threshold", function () { it("renders expanded events if there are less than props.threshold", function () {
const events = generateEvents([ const events = generateEvents([
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
]); ]);
const props = { const props = {
events: events, events: events,
@ -165,8 +165,8 @@ describe("EventListSummary", function () {
it("renders expanded events if there are less than props.threshold for join and leave", function () { it("renders expanded events if there are less than props.threshold for join and leave", function () {
const events = generateEvents([ const events = generateEvents([
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
]); ]);
const props = { const props = {
events: events, events: events,
@ -186,9 +186,9 @@ describe("EventListSummary", function () {
it("renders collapsed events if events.length = props.threshold", function () { it("renders collapsed events if events.length = props.threshold", function () {
const events = generateEvents([ const events = generateEvents([
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
]); ]);
const props = { const props = {
events: events, events: events,
@ -205,20 +205,20 @@ describe("EventListSummary", function () {
it("truncates long join,leave repetitions", function () { it("truncates long join,leave repetitions", function () {
const events = generateEvents([ const events = generateEvents([
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
]); ]);
const props = { const props = {
events: events, events: events,
@ -237,28 +237,28 @@ describe("EventListSummary", function () {
const events = generateEvents([ const events = generateEvents([
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Ban, prevMembership: KnownMembership.Ban,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Leave, prevMembership: KnownMembership.Leave,
membership: Membership.Invite, membership: KnownMembership.Invite,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
]); ]);
@ -279,30 +279,30 @@ describe("EventListSummary", function () {
const events = generateEvents([ const events = generateEvents([
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Ban, prevMembership: KnownMembership.Ban,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Leave, prevMembership: KnownMembership.Leave,
membership: Membership.Ban, membership: KnownMembership.Ban,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
{ userId: "@user_1:some.domain", prevMembership: Membership.Ban, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Ban, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Leave, prevMembership: KnownMembership.Leave,
membership: Membership.Invite, membership: KnownMembership.Invite,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
]); ]);
@ -326,35 +326,35 @@ describe("EventListSummary", function () {
// user_1 // user_1
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Ban, prevMembership: KnownMembership.Ban,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Leave, prevMembership: KnownMembership.Leave,
membership: Membership.Ban, membership: KnownMembership.Ban,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
// user_2 // user_2
{ {
userId: "@user_2:some.domain", userId: "@user_2:some.domain",
prevMembership: Membership.Ban, prevMembership: KnownMembership.Ban,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
{ userId: "@user_2:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_2:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_2:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_2:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_2:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_2:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_2:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_2:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ {
userId: "@user_2:some.domain", userId: "@user_2:some.domain",
prevMembership: Membership.Leave, prevMembership: KnownMembership.Leave,
membership: Membership.Ban, membership: KnownMembership.Ban,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
]); ]);
@ -376,17 +376,17 @@ describe("EventListSummary", function () {
it("handles many users following the same sequence of memberships", function () { it("handles many users following the same sequence of memberships", function () {
const events = generateEventsForUsers("@user_$:some.domain", 20, [ const events = generateEventsForUsers("@user_$:some.domain", 20, [
{ {
prevMembership: Membership.Ban, prevMembership: KnownMembership.Ban,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
{ prevMembership: Membership.Leave, membership: Membership.Join }, { prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ prevMembership: Membership.Join, membership: Membership.Leave }, { prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ prevMembership: Membership.Leave, membership: Membership.Join }, { prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ prevMembership: Membership.Join, membership: Membership.Leave }, { prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ {
prevMembership: Membership.Leave, prevMembership: KnownMembership.Leave,
membership: Membership.Ban, membership: KnownMembership.Ban,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
]); ]);
@ -409,30 +409,30 @@ describe("EventListSummary", function () {
const events = generateEvents([ const events = generateEvents([
{ {
userId: "@user_2:some.domain", userId: "@user_2:some.domain",
prevMembership: Membership.Ban, prevMembership: KnownMembership.Ban,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Ban, prevMembership: KnownMembership.Ban,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_1:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Leave, prevMembership: KnownMembership.Leave,
membership: Membership.Ban, membership: KnownMembership.Ban,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
{ userId: "@user_2:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_2:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_2:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_2:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
{ userId: "@user_2:some.domain", prevMembership: Membership.Leave, membership: Membership.Join }, { userId: "@user_2:some.domain", prevMembership: KnownMembership.Leave, membership: KnownMembership.Join },
{ userId: "@user_2:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_2:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
]); ]);
const props = { const props = {
events: events, events: events,
@ -453,52 +453,52 @@ describe("EventListSummary", function () {
it("correctly identifies transitions", function () { it("correctly identifies transitions", function () {
const events = generateEvents([ const events = generateEvents([
// invited // invited
{ userId: "@user_1:some.domain", membership: Membership.Invite }, { userId: "@user_1:some.domain", membership: KnownMembership.Invite },
// banned // banned
{ userId: "@user_1:some.domain", membership: Membership.Ban }, { userId: "@user_1:some.domain", membership: KnownMembership.Ban },
// joined // joined
{ userId: "@user_1:some.domain", membership: Membership.Join }, { userId: "@user_1:some.domain", membership: KnownMembership.Join },
// invite_reject // invite_reject
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Invite, prevMembership: KnownMembership.Invite,
membership: Membership.Leave, membership: KnownMembership.Leave,
}, },
// left // left
{ userId: "@user_1:some.domain", prevMembership: Membership.Join, membership: Membership.Leave }, { userId: "@user_1:some.domain", prevMembership: KnownMembership.Join, membership: KnownMembership.Leave },
// invite_withdrawal // invite_withdrawal
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Invite, prevMembership: KnownMembership.Invite,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
// unbanned // unbanned
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Ban, prevMembership: KnownMembership.Ban,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
// kicked // kicked
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Join, prevMembership: KnownMembership.Join,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
// default for sender=target (leave) // default for sender=target (leave)
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: "????" as Membership, prevMembership: "????" as Membership,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@user_1:some.domain", senderId: "@user_1:some.domain",
}, },
// default for sender<>target (kicked) // default for sender<>target (kicked)
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: "????" as Membership, prevMembership: "????" as Membership,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
]); ]);
@ -522,24 +522,24 @@ describe("EventListSummary", function () {
const events = generateEvents([ const events = generateEvents([
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Invite, prevMembership: KnownMembership.Invite,
membership: Membership.Leave, membership: KnownMembership.Leave,
}, },
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Invite, prevMembership: KnownMembership.Invite,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
{ {
userId: "@user_2:some.domain", userId: "@user_2:some.domain",
prevMembership: Membership.Invite, prevMembership: KnownMembership.Invite,
membership: Membership.Leave, membership: KnownMembership.Leave,
}, },
{ {
userId: "@user_2:some.domain", userId: "@user_2:some.domain",
prevMembership: Membership.Invite, prevMembership: KnownMembership.Invite,
membership: Membership.Leave, membership: KnownMembership.Leave,
senderId: "@some_other_user:some.domain", senderId: "@some_other_user:some.domain",
}, },
]); ]);
@ -562,13 +562,13 @@ describe("EventListSummary", function () {
const events = generateEvents([ const events = generateEvents([
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Invite, prevMembership: KnownMembership.Invite,
membership: Membership.Leave, membership: KnownMembership.Leave,
}, },
{ {
userId: "@user_1:some.domain", userId: "@user_1:some.domain",
prevMembership: Membership.Invite, prevMembership: KnownMembership.Invite,
membership: Membership.Leave, membership: KnownMembership.Leave,
}, },
]); ]);
const props = { const props = {
@ -586,10 +586,10 @@ describe("EventListSummary", function () {
it('handles a summary length = 2, with no "others"', function () { it('handles a summary length = 2, with no "others"', function () {
const events = generateEvents([ const events = generateEvents([
{ userId: "@user_1:some.domain", membership: Membership.Join }, { userId: "@user_1:some.domain", membership: KnownMembership.Join },
{ userId: "@user_1:some.domain", membership: Membership.Join }, { userId: "@user_1:some.domain", membership: KnownMembership.Join },
{ userId: "@user_2:some.domain", membership: Membership.Join }, { userId: "@user_2:some.domain", membership: KnownMembership.Join },
{ userId: "@user_2:some.domain", membership: Membership.Join }, { userId: "@user_2:some.domain", membership: KnownMembership.Join },
]); ]);
const props = { const props = {
events: events, events: events,
@ -606,9 +606,9 @@ describe("EventListSummary", function () {
it('handles a summary length = 2, with 1 "other"', function () { it('handles a summary length = 2, with 1 "other"', function () {
const events = generateEvents([ const events = generateEvents([
{ userId: "@user_1:some.domain", membership: Membership.Join }, { userId: "@user_1:some.domain", membership: KnownMembership.Join },
{ userId: "@user_2:some.domain", membership: Membership.Join }, { userId: "@user_2:some.domain", membership: KnownMembership.Join },
{ userId: "@user_3:some.domain", membership: Membership.Join }, { userId: "@user_3:some.domain", membership: KnownMembership.Join },
]); ]);
const props = { const props = {
events: events, events: events,
@ -624,7 +624,7 @@ describe("EventListSummary", function () {
}); });
it('handles a summary length = 2, with many "others"', function () { it('handles a summary length = 2, with many "others"', function () {
const events = generateEventsForUsers("@user_$:some.domain", 20, [{ membership: Membership.Join }]); const events = generateEventsForUsers("@user_$:some.domain", 20, [{ membership: KnownMembership.Join }]);
const props = { const props = {
events: events, events: events,
children: generateTiles(events), children: generateTiles(events),

View file

@ -15,13 +15,14 @@ limitations under the License.
import { render } from "@testing-library/react"; import { render } from "@testing-library/react";
import React from "react"; import React from "react";
import { TooltipProvider } from "@vector-im/compound-web"; import { TooltipProvider } from "@vector-im/compound-web";
import { KnownMembership } from "matrix-js-sdk/src/matrix";
import FacePile from "../../../../src/components/views/elements/FacePile"; import FacePile from "../../../../src/components/views/elements/FacePile";
import { mkRoomMember } from "../../../test-utils"; import { mkRoomMember } from "../../../test-utils";
describe("<FacePile />", () => { describe("<FacePile />", () => {
it("renders with a tooltip", () => { it("renders with a tooltip", () => {
const member = mkRoomMember("123", "456", Membership.Join); const member = mkRoomMember("123", "456", KnownMembership.Join);
const { asFragment } = render( const { asFragment } = render(
<FacePile members={[member]} size="36px" overflow={false} tooltipLabel="tooltip" />, <FacePile members={[member]} size="36px" overflow={false} tooltipLabel="tooltip" />,

View file

@ -15,6 +15,7 @@ limitations under the License.
import { render } from "@testing-library/react"; import { render } from "@testing-library/react";
import React from "react"; import React from "react";
import { TooltipProvider } from "@vector-im/compound-web"; import { TooltipProvider } from "@vector-im/compound-web";
import { KnownMembership } from "matrix-js-sdk/src/matrix";
import { mkRoom, mkRoomMember, stubClient, withClientContextRenderOptions } from "../../../test-utils"; import { mkRoom, mkRoomMember, stubClient, withClientContextRenderOptions } from "../../../test-utils";
import RoomFacePile from "../../../../src/components/views/elements/RoomFacePile"; import RoomFacePile from "../../../../src/components/views/elements/RoomFacePile";
@ -28,7 +29,7 @@ describe("<RoomFacePile />", () => {
const room = mkRoom(cli, "!123"); const room = mkRoom(cli, "!123");
jest.spyOn(room, "getJoinedMembers").mockReturnValue([ jest.spyOn(room, "getJoinedMembers").mockReturnValue([
mkRoomMember(room.roomId, "@bob:example.org", Membership.Join), mkRoomMember(room.roomId, "@bob:example.org", KnownMembership.Join),
]); ]);
const { asFragment } = render( const { asFragment } = render(

View file

@ -16,7 +16,7 @@ limitations under the License.
import React from "react"; import React from "react";
import { render, fireEvent, screen } from "@testing-library/react"; import { render, fireEvent, screen } from "@testing-library/react";
import { EventType, MatrixEvent, Room, MatrixClient, JoinRule } from "matrix-js-sdk/src/matrix"; import { EventType, MatrixEvent, Room, MatrixClient, JoinRule, KnownMembership } from "matrix-js-sdk/src/matrix";
import { mocked, MockedObject } from "jest-mock"; import { mocked, MockedObject } from "jest-mock";
import { TooltipProvider } from "@vector-im/compound-web"; import { TooltipProvider } from "@vector-im/compound-web";
@ -86,7 +86,7 @@ describe("<RoomSummaryCard />", () => {
state_key: "", state_key: "",
}); });
room.currentState.setStateEvents([roomCreateEvent]); room.currentState.setStateEvents([roomCreateEvent]);
room.updateMyMembership(Membership.Join); room.updateMyMembership(KnownMembership.Join);
jest.spyOn(Modal, "createDialog"); jest.spyOn(Modal, "createDialog");
jest.spyOn(RightPanelStore.instance, "pushCard"); jest.spyOn(RightPanelStore.instance, "pushCard");

View file

@ -28,6 +28,7 @@ import {
CryptoApi, CryptoApi,
DeviceVerificationStatus, DeviceVerificationStatus,
Device, Device,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { import {
Phase, Phase,
@ -943,8 +944,8 @@ describe("<PowerLevelEditor />", () => {
describe("<RoomKickButton />", () => { describe("<RoomKickButton />", () => {
const defaultMember = new RoomMember(defaultRoomId, defaultUserId); const defaultMember = new RoomMember(defaultRoomId, defaultUserId);
const memberWithInviteMembership = { ...defaultMember, membership: Membership.Invite }; const memberWithInviteMembership = { ...defaultMember, membership: KnownMembership.Invite };
const memberWithJoinMembership = { ...defaultMember, membership: Membership.Join }; const memberWithJoinMembership = { ...defaultMember, membership: KnownMembership.Join };
let defaultProps: Parameters<typeof RoomKickButton>[0]; let defaultProps: Parameters<typeof RoomKickButton>[0];
beforeEach(() => { beforeEach(() => {
@ -1031,7 +1032,7 @@ describe("<RoomKickButton />", () => {
// null vs their member followed by // null vs their member followed by
// my member vs their member // my member vs their member
const mockMyMember = { powerLevel: 1 }; const mockMyMember = { powerLevel: 1 };
const mockTheirMember = { membership: Membership.Invite, powerLevel: 0 }; const mockTheirMember = { membership: KnownMembership.Invite, powerLevel: 0 };
const mockRoom = { const mockRoom = {
getMember: jest getMember: jest
@ -1052,7 +1053,7 @@ describe("<RoomKickButton />", () => {
describe("<BanToggleButton />", () => { describe("<BanToggleButton />", () => {
const defaultMember = new RoomMember(defaultRoomId, defaultUserId); const defaultMember = new RoomMember(defaultRoomId, defaultUserId);
const memberWithBanMembership = { ...defaultMember, membership: Membership.Ban }; const memberWithBanMembership = { ...defaultMember, membership: KnownMembership.Ban };
let defaultProps: Parameters<typeof BanToggleButton>[0]; let defaultProps: Parameters<typeof BanToggleButton>[0];
beforeEach(() => { beforeEach(() => {
defaultProps = { defaultProps = {
@ -1161,7 +1162,7 @@ describe("<BanToggleButton />", () => {
// null vs their member followed by // null vs their member followed by
// my member vs their member // my member vs their member
const mockMyMember = { powerLevel: 1 }; const mockMyMember = { powerLevel: 1 };
const mockTheirMember = { membership: Membership.Ban, powerLevel: 0 }; const mockTheirMember = { membership: KnownMembership.Ban, powerLevel: 0 };
const mockRoom = { const mockRoom = {
getMember: jest getMember: jest
@ -1182,7 +1183,7 @@ describe("<BanToggleButton />", () => {
describe("<RoomAdminToolsContainer />", () => { describe("<RoomAdminToolsContainer />", () => {
const defaultMember = new RoomMember(defaultRoomId, defaultUserId); const defaultMember = new RoomMember(defaultRoomId, defaultUserId);
defaultMember.membership = Membership.Invite; defaultMember.membership = KnownMembership.Invite;
let defaultProps: Parameters<typeof RoomAdminToolsContainer>[0]; let defaultProps: Parameters<typeof RoomAdminToolsContainer>[0];
beforeEach(() => { beforeEach(() => {
@ -1248,7 +1249,7 @@ describe("<RoomAdminToolsContainer />", () => {
const defaultMemberWithPowerLevelAndJoinMembership = { const defaultMemberWithPowerLevelAndJoinMembership = {
...defaultMember, ...defaultMember,
powerLevel: 0, powerLevel: 0,
membership: Membership.Join, membership: KnownMembership.Join,
}; };
renderComponent({ renderComponent({
@ -1270,7 +1271,7 @@ describe("<RoomAdminToolsContainer />", () => {
const defaultMemberWithPowerLevelAndJoinMembership = { const defaultMemberWithPowerLevelAndJoinMembership = {
...defaultMember, ...defaultMember,
powerLevel: 0, powerLevel: 0,
membership: Membership.Join, membership: KnownMembership.Join,
}; };
renderComponent({ renderComponent({

View file

@ -24,6 +24,7 @@ import {
RoomStateEvent, RoomStateEvent,
PendingEventOrdering, PendingEventOrdering,
ISearchResults, ISearchResults,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { CallType } from "matrix-js-sdk/src/webrtc/call"; import { CallType } from "matrix-js-sdk/src/webrtc/call";
import { ClientWidgetApi, Widget } from "matrix-widget-api"; import { ClientWidgetApi, Widget } from "matrix-widget-api";
@ -906,7 +907,7 @@ function mkJoinEvent(roomId: string, userId: string) {
room: roomId, room: roomId,
user: userId, user: userId,
content: { content: {
membership: Membership.Join, membership: KnownMembership.Join,
avatar_url: "mxc://example.org/" + userId, avatar_url: "mxc://example.org/" + userId,
}, },
}); });

View file

@ -17,7 +17,15 @@ limitations under the License.
import React from "react"; import React from "react";
import { act, fireEvent, render, RenderResult, screen } from "@testing-library/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 {
Room,
MatrixClient,
RoomState,
RoomMember,
User,
MatrixEvent,
KnownMembership,
} from "matrix-js-sdk/src/matrix";
import { compare } from "matrix-js-sdk/src/utils"; import { compare } from "matrix-js-sdk/src/utils";
import { mocked, MockedObject } from "jest-mock"; import { mocked, MockedObject } from "jest-mock";
import { TooltipProvider } from "@vector-im/compound-web"; import { TooltipProvider } from "@vector-im/compound-web";
@ -170,7 +178,7 @@ describe("MemberList", () => {
const usersPerLevel = 2; const usersPerLevel = 2;
for (let i = 0; i < usersPerLevel; i++) { for (let i = 0; i < usersPerLevel; i++) {
const adminUser = new RoomMember(memberListRoom.roomId, `@admin${i}:localhost`); const adminUser = new RoomMember(memberListRoom.roomId, `@admin${i}:localhost`);
adminUser.membership = Membership.Join; adminUser.membership = KnownMembership.Join;
adminUser.powerLevel = 100; adminUser.powerLevel = 100;
adminUser.user = User.createUser(adminUser.userId, client); adminUser.user = User.createUser(adminUser.userId, client);
adminUser.user.currentlyActive = true; adminUser.user.currentlyActive = true;
@ -180,7 +188,7 @@ describe("MemberList", () => {
adminUsers.push(adminUser); adminUsers.push(adminUser);
const moderatorUser = new RoomMember(memberListRoom.roomId, `@moderator${i}:localhost`); const moderatorUser = new RoomMember(memberListRoom.roomId, `@moderator${i}:localhost`);
moderatorUser.membership = Membership.Join; moderatorUser.membership = KnownMembership.Join;
moderatorUser.powerLevel = 50; moderatorUser.powerLevel = 50;
moderatorUser.user = User.createUser(moderatorUser.userId, client); moderatorUser.user = User.createUser(moderatorUser.userId, client);
moderatorUser.user.currentlyActive = true; moderatorUser.user.currentlyActive = true;
@ -190,7 +198,7 @@ describe("MemberList", () => {
moderatorUsers.push(moderatorUser); moderatorUsers.push(moderatorUser);
const defaultUser = new RoomMember(memberListRoom.roomId, `@default${i}:localhost`); const defaultUser = new RoomMember(memberListRoom.roomId, `@default${i}:localhost`);
defaultUser.membership = Membership.Join; defaultUser.membership = KnownMembership.Join;
defaultUser.powerLevel = 0; defaultUser.powerLevel = 0;
defaultUser.user = User.createUser(defaultUser.userId, client); defaultUser.user = User.createUser(defaultUser.userId, client);
defaultUser.user.currentlyActive = true; defaultUser.user.currentlyActive = true;
@ -402,7 +410,7 @@ describe("MemberList", () => {
}); });
it("renders disabled invite button when current user is a member but does not have rights to invite", async () => { it("renders disabled invite button when current user is a member but does not have rights to invite", async () => {
jest.spyOn(room, "getMyMembership").mockReturnValue(Membership.Join); jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
jest.spyOn(room, "canInvite").mockReturnValue(false); jest.spyOn(room, "canInvite").mockReturnValue(false);
renderComponent(); renderComponent();
@ -413,7 +421,7 @@ describe("MemberList", () => {
}); });
it("renders enabled invite button when current user is a member and has rights to invite", async () => { it("renders enabled invite button when current user is a member and has rights to invite", async () => {
jest.spyOn(room, "getMyMembership").mockReturnValue(Membership.Join); jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
jest.spyOn(room, "canInvite").mockReturnValue(true); jest.spyOn(room, "canInvite").mockReturnValue(true);
renderComponent(); renderComponent();
@ -424,7 +432,7 @@ describe("MemberList", () => {
it("opens room inviter on button click", async () => { it("opens room inviter on button click", async () => {
jest.spyOn(defaultDispatcher, "dispatch"); jest.spyOn(defaultDispatcher, "dispatch");
jest.spyOn(room, "getMyMembership").mockReturnValue(Membership.Join); jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
jest.spyOn(room, "canInvite").mockReturnValue(true); jest.spyOn(room, "canInvite").mockReturnValue(true);
renderComponent(); renderComponent();

View file

@ -26,6 +26,7 @@ import {
EventStatus, EventStatus,
PendingEventOrdering, PendingEventOrdering,
ReceiptType, ReceiptType,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import type { MatrixClient } from "matrix-js-sdk/src/matrix"; import type { MatrixClient } from "matrix-js-sdk/src/matrix";
@ -140,7 +141,7 @@ describe("UnreadNotificationBadge", () => {
}); });
it("adds a warning for invites", () => { it("adds a warning for invites", () => {
room.updateMyMembership(Membership.Invite); room.updateMyMembership(KnownMembership.Invite);
render(getComponent()); render(getComponent());
expect(screen.queryByText("!")).not.toBeNull(); expect(screen.queryByText("!")).not.toBeNull();
}); });

View file

@ -19,6 +19,7 @@ import { CallType, MatrixCall } from "matrix-js-sdk/src/webrtc/call";
import { import {
EventType, EventType,
JoinRule, JoinRule,
KnownMembership,
MatrixClient, MatrixClient,
MatrixEvent, MatrixEvent,
PendingEventOrdering, PendingEventOrdering,
@ -154,7 +155,7 @@ describe("RoomHeader", () => {
name: "Member", name: "Member",
rawDisplayName: "Member", rawDisplayName: "Member",
roomId: room.roomId, roomId: room.roomId,
membership: Membership.Join, membership: KnownMembership.Join,
getAvatarUrl: () => "mxc://avatar.url/image.png", getAvatarUrl: () => "mxc://avatar.url/image.png",
getMxcAvatarUrl: () => "mxc://avatar.url/image.png", getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
}, },
@ -172,7 +173,7 @@ describe("RoomHeader", () => {
name: "Member", name: "Member",
rawDisplayName: "Member", rawDisplayName: "Member",
roomId: room.roomId, roomId: room.roomId,
membership: Membership.Join, membership: KnownMembership.Join,
getAvatarUrl: () => "mxc://avatar.url/image.png", getAvatarUrl: () => "mxc://avatar.url/image.png",
getMxcAvatarUrl: () => "mxc://avatar.url/image.png", getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
}, },
@ -181,7 +182,7 @@ describe("RoomHeader", () => {
name: "Member", name: "Member",
rawDisplayName: "Member", rawDisplayName: "Member",
roomId: room.roomId, roomId: room.roomId,
membership: Membership.Join, membership: KnownMembership.Join,
getAvatarUrl: () => "mxc://avatar.url/image.png", getAvatarUrl: () => "mxc://avatar.url/image.png",
getMxcAvatarUrl: () => "mxc://avatar.url/image.png", getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
}, },
@ -190,7 +191,7 @@ describe("RoomHeader", () => {
name: "Member", name: "Member",
rawDisplayName: "Member", rawDisplayName: "Member",
roomId: room.roomId, roomId: room.roomId,
membership: Membership.Join, membership: KnownMembership.Join,
getAvatarUrl: () => "mxc://avatar.url/image.png", getAvatarUrl: () => "mxc://avatar.url/image.png",
getMxcAvatarUrl: () => "mxc://avatar.url/image.png", getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
}, },
@ -199,7 +200,7 @@ describe("RoomHeader", () => {
name: "Bot user", name: "Bot user",
rawDisplayName: "Bot user", rawDisplayName: "Bot user",
roomId: room.roomId, roomId: room.roomId,
membership: Membership.Join, membership: KnownMembership.Join,
getAvatarUrl: () => "mxc://avatar.url/image.png", getAvatarUrl: () => "mxc://avatar.url/image.png",
getMxcAvatarUrl: () => "mxc://avatar.url/image.png", getMxcAvatarUrl: () => "mxc://avatar.url/image.png",
}, },
@ -703,7 +704,7 @@ function mockRoomMembers(room: Room, count: number) {
name: `Member ${index}`, name: `Member ${index}`,
rawDisplayName: `Member ${index}`, rawDisplayName: `Member ${index}`,
roomId: room.roomId, roomId: room.roomId,
membership: Membership.Join, membership: KnownMembership.Join,
getAvatarUrl: () => `mxc://avatar.url/user-${index}.png`, getAvatarUrl: () => `mxc://avatar.url/user-${index}.png`,
getMxcAvatarUrl: () => `mxc://avatar.url/user-${index}.png`, getMxcAvatarUrl: () => `mxc://avatar.url/user-${index}.png`,
})); }));

View file

@ -19,6 +19,7 @@ import {
EventTimeline, EventTimeline,
EventType, EventType,
JoinRule, JoinRule,
KnownMembership,
MatrixError, MatrixError,
MatrixEvent, MatrixEvent,
Room, Room,
@ -112,24 +113,24 @@ describe("RoomKnocksBar", () => {
bob.setMembershipEvent( bob.setMembershipEvent(
new MatrixEvent({ new MatrixEvent({
content: { displayname: "Bob", membership: Membership.Knock }, content: { displayname: "Bob", membership: KnownMembership.Knock },
type: EventType.RoomMember, type: EventType.RoomMember,
}), }),
); );
jane.setMembershipEvent( jane.setMembershipEvent(
new MatrixEvent({ new MatrixEvent({
content: { displayname: "Jane", membership: Membership.Knock }, content: { displayname: "Jane", membership: KnownMembership.Knock },
type: EventType.RoomMember, type: EventType.RoomMember,
}), }),
); );
john.setMembershipEvent( john.setMembershipEvent(
new MatrixEvent({ new MatrixEvent({
content: { displayname: "John", membership: Membership.Knock }, content: { displayname: "John", membership: KnownMembership.Knock },
type: EventType.RoomMember, type: EventType.RoomMember,
}), }),
); );
other.setMembershipEvent( other.setMembershipEvent(
new MatrixEvent({ content: { membership: Membership.Knock }, type: EventType.RoomMember }), new MatrixEvent({ content: { membership: KnownMembership.Knock }, type: EventType.RoomMember }),
); );
beforeEach(async () => { beforeEach(async () => {
@ -189,7 +190,7 @@ describe("RoomKnocksBar", () => {
it("renders a link to open the room settings people tab", () => { it("renders a link to open the room settings people tab", () => {
bob.setMembershipEvent( bob.setMembershipEvent(
new MatrixEvent({ new MatrixEvent({
content: { displayname: "Bob", membership: Membership.Knock, reason: "some reason" }, content: { displayname: "Bob", membership: KnownMembership.Knock, reason: "some reason" },
type: EventType.RoomMember, type: EventType.RoomMember,
}), }),
); );

View file

@ -16,7 +16,7 @@ limitations under the License.
import React, { ComponentProps } from "react"; import React, { ComponentProps } from "react";
import { render, fireEvent, RenderResult, waitFor } from "@testing-library/react"; import { render, fireEvent, RenderResult, waitFor } from "@testing-library/react";
import { Room, RoomMember, MatrixError, IContent } from "matrix-js-sdk/src/matrix"; import { Room, RoomMember, MatrixError, IContent, KnownMembership } from "matrix-js-sdk/src/matrix";
import { withClientContextRenderOptions, stubClient } from "../../../test-utils"; import { withClientContextRenderOptions, stubClient } from "../../../test-utils";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
@ -49,10 +49,10 @@ const makeMockRoomMember = ({
}: { }: {
userId?: string; userId?: string;
isKicked?: boolean; isKicked?: boolean;
membership?: Membership.Invite | Membership.Ban | Membership.Leave; membership?: KnownMembership.Invite | KnownMembership.Ban | KnownMembership.Leave;
content?: Partial<IContent>; content?: Partial<IContent>;
memberContent?: Partial<IContent>; memberContent?: Partial<IContent>;
oldMembership?: Membership.Join | Membership.Knock; oldMembership?: KnownMembership.Join | KnownMembership.Knock;
}) => }) =>
({ ({
userId, userId,
@ -180,7 +180,11 @@ describe("<RoomPreviewBar />", () => {
it("renders denied request message", () => { it("renders denied request message", () => {
const room = createRoom(roomId, otherUserId); const room = createRoom(roomId, otherUserId);
jest.spyOn(room, "getMember").mockReturnValue( jest.spyOn(room, "getMember").mockReturnValue(
makeMockRoomMember({ isKicked: true, membership: Membership.Leave, oldMembership: Membership.Knock }), makeMockRoomMember({
isKicked: true,
membership: KnownMembership.Leave,
oldMembership: KnownMembership.Knock,
}),
); );
const component = getComponent({ room, promptAskToJoin: true }); const component = getComponent({ room, promptAskToJoin: true });
@ -191,7 +195,11 @@ describe("<RoomPreviewBar />", () => {
const onForgetClick = jest.fn(); const onForgetClick = jest.fn();
const room = createRoom(roomId, otherUserId); const room = createRoom(roomId, otherUserId);
jest.spyOn(room, "getMember").mockReturnValue( jest.spyOn(room, "getMember").mockReturnValue(
makeMockRoomMember({ isKicked: true, membership: Membership.Leave, oldMembership: Membership.Knock }), makeMockRoomMember({
isKicked: true,
membership: KnownMembership.Leave,
oldMembership: KnownMembership.Knock,
}),
); );
const component = getComponent({ room, promptAskToJoin: true, onForgetClick }); const component = getComponent({ room, promptAskToJoin: true, onForgetClick });
@ -201,7 +209,7 @@ describe("<RoomPreviewBar />", () => {
it("renders banned message", () => { it("renders banned message", () => {
const room = createRoom(roomId, otherUserId); const room = createRoom(roomId, otherUserId);
jest.spyOn(room, "getMember").mockReturnValue(makeMockRoomMember({ membership: Membership.Ban })); jest.spyOn(room, "getMember").mockReturnValue(makeMockRoomMember({ membership: KnownMembership.Ban }));
const component = getComponent({ loading: true, room }); const component = getComponent({ loading: true, room });
expect(getMessage(component)).toMatchSnapshot(); expect(getMessage(component)).toMatchSnapshot();
@ -244,8 +252,8 @@ describe("<RoomPreviewBar />", () => {
const userMember = makeMockRoomMember({ userId }); const userMember = makeMockRoomMember({ userId });
const userMemberWithDmInvite = makeMockRoomMember({ const userMemberWithDmInvite = makeMockRoomMember({
userId, userId,
membership: Membership.Invite, membership: KnownMembership.Invite,
memberContent: { is_direct: true, membership: Membership.Invite }, memberContent: { is_direct: true, membership: KnownMembership.Invite },
}); });
const inviterMember = makeMockRoomMember({ const inviterMember = makeMockRoomMember({
userId: inviterUserId, userId: inviterUserId,

View file

@ -17,7 +17,7 @@ limitations under the License.
import React from "react"; import React from "react";
import { mocked, Mocked } from "jest-mock"; import { mocked, Mocked } from "jest-mock";
import { render, screen, act } from "@testing-library/react"; import { render, screen, act } from "@testing-library/react";
import { PendingEventOrdering, Room, RoomStateEvent, RoomType } from "matrix-js-sdk/src/matrix"; import { KnownMembership, PendingEventOrdering, Room, RoomStateEvent, RoomType } from "matrix-js-sdk/src/matrix";
import type { MatrixClient, RoomMember } from "matrix-js-sdk/src/matrix"; import type { MatrixClient, RoomMember } from "matrix-js-sdk/src/matrix";
import { stubClient, wrapInMatrixClientContext, mkRoomMember } from "../../../test-utils"; import { stubClient, wrapInMatrixClientContext, mkRoomMember } from "../../../test-utils";
@ -68,7 +68,7 @@ describe("RoomPreviewCard", () => {
it("shows a beta pill on Jitsi video room invites", async () => { it("shows a beta pill on Jitsi video room invites", async () => {
jest.spyOn(room, "getType").mockReturnValue(RoomType.ElementVideo); jest.spyOn(room, "getType").mockReturnValue(RoomType.ElementVideo);
jest.spyOn(room, "getMyMembership").mockReturnValue(Membership.Invite); jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Invite);
enabledFeatures = ["feature_video_rooms"]; enabledFeatures = ["feature_video_rooms"];
await renderPreview(); await renderPreview();
@ -77,7 +77,7 @@ describe("RoomPreviewCard", () => {
it("shows a beta pill on Element video room invites", async () => { it("shows a beta pill on Element video room invites", async () => {
jest.spyOn(room, "getType").mockReturnValue(RoomType.UnstableCall); jest.spyOn(room, "getType").mockReturnValue(RoomType.UnstableCall);
jest.spyOn(room, "getMyMembership").mockReturnValue(Membership.Invite); jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Invite);
enabledFeatures = ["feature_video_rooms", "feature_element_call_video_rooms"]; enabledFeatures = ["feature_video_rooms", "feature_element_call_video_rooms"];
await renderPreview(); await renderPreview();
@ -85,7 +85,7 @@ describe("RoomPreviewCard", () => {
}); });
it("doesn't show a beta pill on normal invites", async () => { it("doesn't show a beta pill on normal invites", async () => {
jest.spyOn(room, "getMyMembership").mockReturnValue(Membership.Invite); jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Invite);
await renderPreview(); await renderPreview();
expect(screen.queryByRole("button", { name: /beta/i })).toBeNull(); expect(screen.queryByRole("button", { name: /beta/i })).toBeNull();
@ -93,7 +93,7 @@ describe("RoomPreviewCard", () => {
it("shows instructions on Jitsi video rooms invites if video rooms are disabled", async () => { it("shows instructions on Jitsi video rooms invites if video rooms are disabled", async () => {
jest.spyOn(room, "getType").mockReturnValue(RoomType.ElementVideo); jest.spyOn(room, "getType").mockReturnValue(RoomType.ElementVideo);
jest.spyOn(room, "getMyMembership").mockReturnValue(Membership.Invite); jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Invite);
await renderPreview(); await renderPreview();
screen.getByText(/enable video rooms in labs/i); screen.getByText(/enable video rooms in labs/i);
@ -101,7 +101,7 @@ describe("RoomPreviewCard", () => {
it("shows instructions on Element video rooms invites if video rooms are disabled", async () => { it("shows instructions on Element video rooms invites if video rooms are disabled", async () => {
jest.spyOn(room, "getType").mockReturnValue(RoomType.UnstableCall); jest.spyOn(room, "getType").mockReturnValue(RoomType.UnstableCall);
jest.spyOn(room, "getMyMembership").mockReturnValue(Membership.Invite); jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Invite);
enabledFeatures = ["feature_element_call_video_rooms"]; enabledFeatures = ["feature_element_call_video_rooms"];
await renderPreview(); await renderPreview();

View file

@ -24,6 +24,7 @@ import {
MatrixEvent, MatrixEvent,
RoomStateEvent, RoomStateEvent,
Thread, Thread,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { Widget } from "matrix-widget-api"; import { Widget } from "matrix-widget-api";
@ -187,7 +188,7 @@ describe("RoomTile", () => {
return name === "feature_ask_to_join"; return name === "feature_ask_to_join";
}); });
mocked(shouldShowComponent).mockReturnValue(true); mocked(shouldShowComponent).mockReturnValue(true);
jest.spyOn(room, "getMyMembership").mockReturnValue(Membership.Knock); jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Knock);
const { container } = renderRoomTile(); const { container } = renderRoomTile();
expect(container.querySelector(".mx_RoomTile_sticky")).toBeInTheDocument(); expect(container.querySelector(".mx_RoomTile_sticky")).toBeInTheDocument();
expect(screen.queryByRole("button", { name: "Room options" })).not.toBeInTheDocument(); expect(screen.queryByRole("button", { name: "Room options" })).not.toBeInTheDocument();
@ -201,10 +202,10 @@ describe("RoomTile", () => {
const roomMember = mkRoomMember( const roomMember = mkRoomMember(
room.roomId, room.roomId,
MatrixClientPeg.get()!.getSafeUserId(), MatrixClientPeg.get()!.getSafeUserId(),
Membership.Leave, KnownMembership.Leave,
true, true,
{ {
membership: Membership.Knock, membership: KnownMembership.Knock,
}, },
); );
jest.spyOn(room, "getMember").mockReturnValue(roomMember); jest.spyOn(room, "getMember").mockReturnValue(roomMember);

View file

@ -27,6 +27,7 @@ import {
RoomMember, RoomMember,
MatrixError, MatrixError,
Visibility, Visibility,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { defer, IDeferred } from "matrix-js-sdk/src/utils"; import { defer, IDeferred } from "matrix-js-sdk/src/utils";
@ -177,7 +178,7 @@ describe("<JoinRuleSettings />", () => {
const memberBob = new RoomMember(roomId, "@bob:server.org"); const memberBob = new RoomMember(roomId, "@bob:server.org");
const memberCharlie = new RoomMember(roomId, "@charlie:server.org"); const memberCharlie = new RoomMember(roomId, "@charlie:server.org");
jest.spyOn(room, "getMembersWithMembership").mockImplementation((membership) => jest.spyOn(room, "getMembersWithMembership").mockImplementation((membership) =>
membership === Membership.Join ? [memberAlice, memberBob] : [memberCharlie], membership === KnownMembership.Join ? [memberAlice, memberBob] : [memberCharlie],
); );
const upgradedRoom = new Room(newRoomId, client, userId); const upgradedRoom = new Room(newRoomId, client, userId);
setRoomStateEvents(upgradedRoom, preferredRoomVersion); setRoomStateEvents(upgradedRoom, preferredRoomVersion);

View file

@ -18,6 +18,7 @@ import { act, fireEvent, render, screen, within } from "@testing-library/react";
import { import {
EventTimeline, EventTimeline,
EventType, EventType,
KnownMembership,
MatrixError, MatrixError,
MatrixEvent, MatrixEvent,
Room, Room,
@ -91,7 +92,7 @@ describe("PeopleRoomSettingsTab", () => {
content: { content: {
avatar_url: "mxc://example.org/albert-einstein.png", avatar_url: "mxc://example.org/albert-einstein.png",
displayname: "Albert Einstein", displayname: "Albert Einstein",
membership: Membership.Knock, membership: KnownMembership.Knock,
reason, reason,
}, },
origin_server_ts: -464140800000, origin_server_ts: -464140800000,
@ -110,7 +111,7 @@ describe("PeopleRoomSettingsTab", () => {
new MatrixEvent({ new MatrixEvent({
content: { content: {
displayname: "albert.einstein", displayname: "albert.einstein",
membership: Membership.Knock, membership: KnownMembership.Knock,
}, },
type: EventType.RoomMember, type: EventType.RoomMember,
}), }),
@ -138,7 +139,7 @@ describe("PeopleRoomSettingsTab", () => {
new MatrixEvent({ new MatrixEvent({
content: { content: {
displayname: "albert.einstein", displayname: "albert.einstein",
membership: Membership.Knock, membership: KnownMembership.Knock,
reason, reason,
}, },
type: EventType.RoomMember, type: EventType.RoomMember,

View file

@ -16,7 +16,15 @@ limitations under the License.
import React from "react"; import React from "react";
import { fireEvent, render, RenderResult, screen, waitFor } from "@testing-library/react"; import { fireEvent, render, RenderResult, screen, waitFor } from "@testing-library/react";
import { MatrixClient, EventType, MatrixEvent, Room, RoomMember, ISendEventResponse } from "matrix-js-sdk/src/matrix"; import {
MatrixClient,
EventType,
MatrixEvent,
Room,
RoomMember,
ISendEventResponse,
KnownMembership,
} from "matrix-js-sdk/src/matrix";
import { mocked } from "jest-mock"; import { mocked } from "jest-mock";
import { defer } from "matrix-js-sdk/src/utils"; import { defer } from "matrix-js-sdk/src/utils";
@ -197,7 +205,7 @@ describe("RolesRoomSettingsTab", () => {
new MatrixEvent({ new MatrixEvent({
type: EventType.RoomMember, type: EventType.RoomMember,
content: { content: {
membership: Membership.Ban, membership: KnownMembership.Ban,
reason: "just testing", reason: "just testing",
}, },
sender: userId, sender: userId,
@ -218,7 +226,7 @@ describe("RolesRoomSettingsTab", () => {
new MatrixEvent({ new MatrixEvent({
type: EventType.RoomMember, type: EventType.RoomMember,
content: { content: {
membership: Membership.Ban, membership: KnownMembership.Ban,
reason: "just testing", reason: "just testing",
}, },
sender: userId, sender: userId,

View file

@ -16,7 +16,7 @@ limitations under the License.
import { waitFor } from "@testing-library/react"; import { waitFor } from "@testing-library/react";
import { renderHook, act } from "@testing-library/react-hooks/dom"; import { renderHook, act } from "@testing-library/react-hooks/dom";
import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix"; import { KnownMembership, MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
import { MatrixClientPeg } from "../../src/MatrixClientPeg"; import { MatrixClientPeg } from "../../src/MatrixClientPeg";
import { stubClient } from "../test-utils"; import { stubClient } from "../test-utils";
@ -49,7 +49,7 @@ describe("useRoomMembers", () => {
state_key: "!user:server", state_key: "!user:server",
room_id: room.roomId, room_id: room.roomId,
content: { content: {
membership: Membership.Join, membership: KnownMembership.Join,
}, },
}), }),
]); ]);
@ -85,7 +85,7 @@ describe("useRoomMemberCount", () => {
state_key: "!user:server", state_key: "!user:server",
room_id: room.roomId, room_id: room.roomId,
content: { content: {
membership: Membership.Join, membership: KnownMembership.Join,
}, },
}), }),
]); ]);
@ -109,14 +109,14 @@ describe("useMyRoomMembership", () => {
}); });
it("should update on RoomState.Members events", async () => { it("should update on RoomState.Members events", async () => {
room.updateMyMembership(Membership.Join); room.updateMyMembership(KnownMembership.Join);
const { result } = render(room); const { result } = render(room);
expect(result.current).toBe(Membership.Join); expect(result.current).toBe(KnownMembership.Join);
act(() => { act(() => {
room.updateMyMembership(Membership.Leave); room.updateMyMembership(KnownMembership.Leave);
}); });
await waitFor(() => expect(result.current).toBe(Membership.Leave)); await waitFor(() => expect(result.current).toBe(KnownMembership.Leave));
}); });
}); });

View file

@ -15,7 +15,13 @@ limitations under the License.
*/ */
import { renderHook } from "@testing-library/react-hooks"; import { renderHook } from "@testing-library/react-hooks";
import { EventStatus, NotificationCountType, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix"; import {
EventStatus,
KnownMembership,
NotificationCountType,
PendingEventOrdering,
Room,
} from "matrix-js-sdk/src/matrix";
import type { MatrixClient } from "matrix-js-sdk/src/matrix"; import type { MatrixClient } from "matrix-js-sdk/src/matrix";
import { useUnreadNotifications } from "../../src/hooks/useUnreadNotifications"; import { useUnreadNotifications } from "../../src/hooks/useUnreadNotifications";
@ -66,7 +72,7 @@ describe("useUnreadNotifications", () => {
}); });
it("indicates the user has been invited to a channel", async () => { it("indicates the user has been invited to a channel", async () => {
room.updateMyMembership(Membership.Invite); room.updateMyMembership(KnownMembership.Invite);
const { result } = renderHook(() => useUnreadNotifications(room)); const { result } = renderHook(() => useUnreadNotifications(room));
const { level, symbol, count } = result.current; const { level, symbol, count } = result.current;

View file

@ -17,7 +17,15 @@ limitations under the License.
import EventEmitter from "events"; import EventEmitter from "events";
import { mocked } from "jest-mock"; import { mocked } from "jest-mock";
import { waitFor } from "@testing-library/react"; import { waitFor } from "@testing-library/react";
import { RoomType, Room, RoomEvent, MatrixEvent, RoomStateEvent, PendingEventOrdering } from "matrix-js-sdk/src/matrix"; import {
RoomType,
Room,
RoomEvent,
MatrixEvent,
RoomStateEvent,
PendingEventOrdering,
KnownMembership,
} from "matrix-js-sdk/src/matrix";
import { Widget } from "matrix-widget-api"; import { Widget } from "matrix-widget-api";
// eslint-disable-next-line no-restricted-imports // eslint-disable-next-line no-restricted-imports
import { MatrixRTCSessionManagerEvents } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSessionManager"; import { MatrixRTCSessionManagerEvents } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSessionManager";
@ -95,7 +103,7 @@ const setUpClientRoomAndStores = (): {
} }
}); });
jest.spyOn(room, "getMyMembership").mockReturnValue(Membership.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));
client.getRoom.mockImplementation((roomId) => (roomId === room.roomId ? room : null)); client.getRoom.mockImplementation((roomId) => (roomId === room.roomId ? room : null));
@ -380,7 +388,7 @@ describe("JitsiCall", () => {
it("disconnects when we leave the room", async () => { it("disconnects when we leave the room", async () => {
await call.start(); await call.start();
expect(call.connectionState).toBe(ConnectionState.Connected); expect(call.connectionState).toBe(ConnectionState.Connected);
room.emit(RoomEvent.MyMembership, room, Membership.Leave); room.emit(RoomEvent.MyMembership, room, KnownMembership.Leave);
expect(call.connectionState).toBe(ConnectionState.Disconnected); expect(call.connectionState).toBe(ConnectionState.Disconnected);
}); });
@ -395,7 +403,7 @@ describe("JitsiCall", () => {
it("remains connected if we stay in the room", async () => { it("remains connected if we stay in the room", async () => {
await call.start(); await call.start();
expect(call.connectionState).toBe(ConnectionState.Connected); expect(call.connectionState).toBe(ConnectionState.Connected);
room.emit(RoomEvent.MyMembership, room, Membership.Join); room.emit(RoomEvent.MyMembership, room, KnownMembership.Join);
expect(call.connectionState).toBe(ConnectionState.Connected); expect(call.connectionState).toBe(ConnectionState.Connected);
}); });
@ -911,14 +919,14 @@ describe("ElementCall", () => {
it("disconnects when we leave the room", async () => { it("disconnects when we leave the room", async () => {
await callConnectProcedure(call); await callConnectProcedure(call);
expect(call.connectionState).toBe(ConnectionState.Connected); expect(call.connectionState).toBe(ConnectionState.Connected);
room.emit(RoomEvent.MyMembership, room, Membership.Leave); room.emit(RoomEvent.MyMembership, room, KnownMembership.Leave);
expect(call.connectionState).toBe(ConnectionState.Disconnected); expect(call.connectionState).toBe(ConnectionState.Disconnected);
}); });
it("remains connected if we stay in the room", async () => { it("remains connected if we stay in the room", async () => {
await callConnectProcedure(call); await callConnectProcedure(call);
expect(call.connectionState).toBe(ConnectionState.Connected); expect(call.connectionState).toBe(ConnectionState.Connected);
room.emit(RoomEvent.MyMembership, room, Membership.Join); room.emit(RoomEvent.MyMembership, room, KnownMembership.Join);
expect(call.connectionState).toBe(ConnectionState.Connected); expect(call.connectionState).toBe(ConnectionState.Connected);
}); });

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import { mocked } from "jest-mock"; import { mocked } from "jest-mock";
import { EventType, IContent, MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix"; import { EventType, IContent, KnownMembership, MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
import SdkConfig from "../../src/SdkConfig"; import SdkConfig from "../../src/SdkConfig";
import SettingsStore from "../../src/settings/SettingsStore"; import SettingsStore from "../../src/settings/SettingsStore";
@ -55,7 +55,7 @@ describe("MemberListStore", () => {
type: EventType.RoomMember, type: EventType.RoomMember,
state_key: alice, state_key: alice,
content: { content: {
membership: Membership.Join, membership: KnownMembership.Join,
}, },
sender: alice, sender: alice,
room_id: roomId, room_id: roomId,
@ -77,8 +77,8 @@ describe("MemberListStore", () => {
}); });
it("loads members in a room", async () => { it("loads members in a room", async () => {
addMember(room, bob, Membership.Invite); addMember(room, bob, KnownMembership.Invite);
addMember(room, charlie, Membership.Leave); addMember(room, charlie, KnownMembership.Leave);
const { invited, joined } = await store.loadMemberList(roomId); const { invited, joined } = await store.loadMemberList(roomId);
expect(invited).toEqual([room.getMember(bob)]); expect(invited).toEqual([room.getMember(bob)]);
@ -92,8 +92,8 @@ describe("MemberListStore", () => {
}); });
it("sorts by power level", async () => { it("sorts by power level", async () => {
addMember(room, bob, Membership.Join); addMember(room, bob, KnownMembership.Join);
addMember(room, charlie, Membership.Join); addMember(room, charlie, KnownMembership.Join);
setPowerLevels(room, { setPowerLevels(room, {
users: { users: {
[alice]: 100, [alice]: 100,
@ -109,8 +109,8 @@ describe("MemberListStore", () => {
it("sorts by name if power level is equal", async () => { it("sorts by name if power level is equal", async () => {
const doris = "@doris:bar"; const doris = "@doris:bar";
addMember(room, bob, Membership.Join); addMember(room, bob, KnownMembership.Join);
addMember(room, charlie, Membership.Join); addMember(room, charlie, KnownMembership.Join);
setPowerLevels(room, { setPowerLevels(room, {
users_default: 10, users_default: 10,
}); });
@ -120,7 +120,7 @@ describe("MemberListStore", () => {
expect(joined).toEqual([room.getMember(alice), room.getMember(bob), room.getMember(charlie)]); expect(joined).toEqual([room.getMember(alice), room.getMember(bob), room.getMember(charlie)]);
// Ensure it sorts by display name if they are set // Ensure it sorts by display name if they are set
addMember(room, doris, Membership.Join, "AAAAA"); addMember(room, doris, KnownMembership.Join, "AAAAA");
({ invited, joined } = await store.loadMemberList(roomId)); ({ invited, joined } = await store.loadMemberList(roomId));
expect(invited).toEqual([]); expect(invited).toEqual([]);
expect(joined).toEqual([ expect(joined).toEqual([
@ -134,15 +134,15 @@ describe("MemberListStore", () => {
it("filters based on a search query", async () => { it("filters based on a search query", async () => {
const mice = "@mice:bar"; const mice = "@mice:bar";
const zorro = "@zorro:bar"; const zorro = "@zorro:bar";
addMember(room, bob, Membership.Join); addMember(room, bob, KnownMembership.Join);
addMember(room, mice, Membership.Join); addMember(room, mice, KnownMembership.Join);
let { invited, joined } = await store.loadMemberList(roomId, "ice"); let { invited, joined } = await store.loadMemberList(roomId, "ice");
expect(invited).toEqual([]); expect(invited).toEqual([]);
expect(joined).toEqual([room.getMember(alice), room.getMember(mice)]); expect(joined).toEqual([room.getMember(alice), room.getMember(mice)]);
// Ensure it filters by display name if they are set // Ensure it filters by display name if they are set
addMember(room, zorro, Membership.Join, "ice ice baby"); addMember(room, zorro, KnownMembership.Join, "ice ice baby");
({ invited, joined } = await store.loadMemberList(roomId, "ice")); ({ invited, joined } = await store.loadMemberList(roomId, "ice"));
expect(invited).toEqual([]); expect(invited).toEqual([]);
expect(joined).toEqual([room.getMember(alice), room.getMember(zorro), room.getMember(mice)]); expect(joined).toEqual([room.getMember(alice), room.getMember(zorro), room.getMember(mice)]);
@ -180,7 +180,7 @@ describe("MemberListStore", () => {
type: EventType.RoomMember, type: EventType.RoomMember,
state_key: bob, state_key: bob,
content: { content: {
membership: Membership.Join, membership: KnownMembership.Join,
displayname: "Bob", displayname: "Bob",
}, },
sender: bob, sender: bob,

View file

@ -24,6 +24,7 @@ import {
RoomMember, RoomMember,
ContentHelpers, ContentHelpers,
M_BEACON, M_BEACON,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { Mocked } from "jest-mock"; import { Mocked } from "jest-mock";
@ -556,7 +557,7 @@ describe("OwnBeaconStore", () => {
it("destroys and removes beacons when current user leaves room", async () => { it("destroys and removes beacons when current user leaves room", async () => {
// alice leaves room1 // alice leaves room1
const membershipEvent = makeMembershipEvent(room1Id, aliceId, Membership.Leave); const membershipEvent = makeMembershipEvent(room1Id, aliceId, KnownMembership.Leave);
const member = new RoomMember(room1Id, aliceId); const member = new RoomMember(room1Id, aliceId);
member.setMembershipEvent(membershipEvent); member.setMembershipEvent(membershipEvent);

View file

@ -24,6 +24,7 @@ import {
MatrixEvent, MatrixEvent,
Room, Room,
RoomEvent, RoomEvent,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import { defer } from "matrix-js-sdk/src/utils"; import { defer } from "matrix-js-sdk/src/utils";
@ -57,13 +58,13 @@ const fav2 = "!fav2:server";
const fav3 = "!fav3:server"; const fav3 = "!fav3:server";
const dm1 = "!dm1:server"; const dm1 = "!dm1:server";
const dm1Partner = new RoomMember(dm1, "@dm1Partner:server"); const dm1Partner = new RoomMember(dm1, "@dm1Partner:server");
dm1Partner.membership = Membership.Join; dm1Partner.membership = KnownMembership.Join;
const dm2 = "!dm2:server"; const dm2 = "!dm2:server";
const dm2Partner = new RoomMember(dm2, "@dm2Partner:server"); const dm2Partner = new RoomMember(dm2, "@dm2Partner:server");
dm2Partner.membership = Membership.Join; dm2Partner.membership = KnownMembership.Join;
const dm3 = "!dm3:server"; const dm3 = "!dm3:server";
const dm3Partner = new RoomMember(dm3, "@dm3Partner:server"); const dm3Partner = new RoomMember(dm3, "@dm3Partner:server");
dm3Partner.membership = Membership.Join; dm3Partner.membership = KnownMembership.Join;
const orphan1 = "!orphan1:server"; const orphan1 = "!orphan1:server";
const orphan2 = "!orphan2:server"; const orphan2 = "!orphan2:server";
const invite1 = "!invite1:server"; const invite1 = "!invite1:server";
@ -289,7 +290,7 @@ describe("SpaceStore", () => {
}); });
it("invite to a subspace is only shown at the top level", async () => { it("invite to a subspace is only shown at the top level", async () => {
mkSpace(invite1).getMyMembership.mockReturnValue(Membership.Invite); mkSpace(invite1).getMyMembership.mockReturnValue(KnownMembership.Invite);
mkSpace(space1, [invite1]); mkSpace(space1, [invite1]);
await run(); await run();
@ -335,20 +336,20 @@ describe("SpaceStore", () => {
}); });
[invite1, invite2].forEach((roomId) => { [invite1, invite2].forEach((roomId) => {
mocked(client.getRoom(roomId)).getMyMembership.mockReturnValue(Membership.Invite); mocked(client.getRoom(roomId)!).getMyMembership.mockReturnValue(KnownMembership.Invite);
}); });
// have dmPartner1 be in space1 with you // have dmPartner1 be in space1 with you
const mySpace1Member = new RoomMember(space1, testUserId); const mySpace1Member = new RoomMember(space1, testUserId);
mySpace1Member.membership = Membership.Join; mySpace1Member.membership = KnownMembership.Join;
(rooms.find((r) => r.roomId === space1).getMembers as jest.Mock).mockReturnValue([ (rooms.find((r) => r.roomId === space1)!.getMembers as jest.Mock).mockReturnValue([
mySpace1Member, mySpace1Member,
dm1Partner, dm1Partner,
]); ]);
// have dmPartner2 be in space2 with you // have dmPartner2 be in space2 with you
const mySpace2Member = new RoomMember(space2, testUserId); const mySpace2Member = new RoomMember(space2, testUserId);
mySpace2Member.membership = Membership.Join; mySpace2Member.membership = KnownMembership.Join;
(rooms.find((r) => r.roomId === space2).getMembers as jest.Mock).mockReturnValue([ (rooms.find((r) => r.roomId === space2)!.getMembers as jest.Mock).mockReturnValue([
mySpace2Member, mySpace2Member,
dm2Partner, dm2Partner,
]); ]);
@ -683,16 +684,16 @@ describe("SpaceStore", () => {
it("should add new DM Invites to the People Space Notification State", async () => { it("should add new DM Invites to the People Space Notification State", async () => {
mkRoom(dm1); mkRoom(dm1);
mocked(client.getRoom(dm1)!).getMyMembership.mockReturnValue(Membership.Join); mocked(client.getRoom(dm1)!).getMyMembership.mockReturnValue(KnownMembership.Join);
mocked(client).getRoom.mockImplementation((roomId) => rooms.find((room) => room.roomId === roomId) || null); mocked(client).getRoom.mockImplementation((roomId) => rooms.find((room) => room.roomId === roomId) || null);
await run(); await run();
mkRoom(dm2); mkRoom(dm2);
const cliDm2 = client.getRoom(dm2)!; const cliDm2 = client.getRoom(dm2)!;
mocked(cliDm2).getMyMembership.mockReturnValue(Membership.Invite); mocked(cliDm2).getMyMembership.mockReturnValue(KnownMembership.Invite);
mocked(client).getRoom.mockImplementation((roomId) => rooms.find((room) => room.roomId === roomId) || null); mocked(client).getRoom.mockImplementation((roomId) => rooms.find((room) => room.roomId === roomId) || null);
client.emit(RoomEvent.MyMembership, cliDm2, Membership.Invite); client.emit(RoomEvent.MyMembership, cliDm2, KnownMembership.Invite);
[dm1, dm2].forEach((d) => { [dm1, dm2].forEach((d) => {
expect( expect(
@ -721,9 +722,9 @@ describe("SpaceStore", () => {
await run(); await run();
expect(store.spacePanelSpaces).toStrictEqual([space]); expect(store.spacePanelSpaces).toStrictEqual([space]);
space.getMyMembership.mockReturnValue(Membership.Leave); space.getMyMembership.mockReturnValue(KnownMembership.Leave);
const prom = testUtils.emitPromise(store, UPDATE_TOP_LEVEL_SPACES); const prom = testUtils.emitPromise(store, UPDATE_TOP_LEVEL_SPACES);
client.emit(RoomEvent.MyMembership, space, Membership.Leave, Membership.Join); client.emit(RoomEvent.MyMembership, space, KnownMembership.Leave, KnownMembership.Join);
await prom; await prom;
expect(store.spacePanelSpaces).toStrictEqual([]); expect(store.spacePanelSpaces).toStrictEqual([]);
}); });
@ -733,7 +734,7 @@ describe("SpaceStore", () => {
expect(store.spacePanelSpaces).toStrictEqual([]); expect(store.spacePanelSpaces).toStrictEqual([]);
expect(store.invitedSpaces).toStrictEqual([]); expect(store.invitedSpaces).toStrictEqual([]);
const space = mkSpace(space1); const space = mkSpace(space1);
space.getMyMembership.mockReturnValue(Membership.Invite); space.getMyMembership.mockReturnValue(KnownMembership.Invite);
const prom = testUtils.emitPromise(store, UPDATE_INVITED_SPACES); const prom = testUtils.emitPromise(store, UPDATE_INVITED_SPACES);
client.emit(ClientEvent.Room, space); client.emit(ClientEvent.Room, space);
await prom; await prom;
@ -743,14 +744,14 @@ describe("SpaceStore", () => {
it("updates state when space invite is accepted", async () => { it("updates state when space invite is accepted", async () => {
const space = mkSpace(space1); const space = mkSpace(space1);
space.getMyMembership.mockReturnValue(Membership.Invite); space.getMyMembership.mockReturnValue(KnownMembership.Invite);
await run(); await run();
expect(store.spacePanelSpaces).toStrictEqual([]); expect(store.spacePanelSpaces).toStrictEqual([]);
expect(store.invitedSpaces).toStrictEqual([space]); expect(store.invitedSpaces).toStrictEqual([space]);
space.getMyMembership.mockReturnValue(Membership.Join); space.getMyMembership.mockReturnValue(KnownMembership.Join);
const prom = testUtils.emitPromise(store, UPDATE_TOP_LEVEL_SPACES); const prom = testUtils.emitPromise(store, UPDATE_TOP_LEVEL_SPACES);
client.emit(RoomEvent.MyMembership, space, Membership.Join, Membership.Invite); client.emit(RoomEvent.MyMembership, space, KnownMembership.Join, KnownMembership.Invite);
await prom; await prom;
expect(store.spacePanelSpaces).toStrictEqual([space]); expect(store.spacePanelSpaces).toStrictEqual([space]);
expect(store.invitedSpaces).toStrictEqual([]); expect(store.invitedSpaces).toStrictEqual([]);
@ -758,14 +759,14 @@ describe("SpaceStore", () => {
it("updates state when space invite is rejected", async () => { it("updates state when space invite is rejected", async () => {
const space = mkSpace(space1); const space = mkSpace(space1);
space.getMyMembership.mockReturnValue(Membership.Invite); space.getMyMembership.mockReturnValue(KnownMembership.Invite);
await run(); await run();
expect(store.spacePanelSpaces).toStrictEqual([]); expect(store.spacePanelSpaces).toStrictEqual([]);
expect(store.invitedSpaces).toStrictEqual([space]); expect(store.invitedSpaces).toStrictEqual([space]);
space.getMyMembership.mockReturnValue(Membership.Leave); space.getMyMembership.mockReturnValue(KnownMembership.Leave);
const prom = testUtils.emitPromise(store, UPDATE_INVITED_SPACES); const prom = testUtils.emitPromise(store, UPDATE_INVITED_SPACES);
client.emit(RoomEvent.MyMembership, space, Membership.Leave, Membership.Invite); client.emit(RoomEvent.MyMembership, space, KnownMembership.Leave, KnownMembership.Invite);
await prom; await prom;
expect(store.spacePanelSpaces).toStrictEqual([]); expect(store.spacePanelSpaces).toStrictEqual([]);
expect(store.invitedSpaces).toStrictEqual([]); expect(store.invitedSpaces).toStrictEqual([]);
@ -783,7 +784,7 @@ describe("SpaceStore", () => {
expect(store.isRoomInSpace(MetaSpace.Home, invite1)).toBeFalsy(); expect(store.isRoomInSpace(MetaSpace.Home, invite1)).toBeFalsy();
const invite = mkRoom(invite1); const invite = mkRoom(invite1);
invite.getMyMembership.mockReturnValue(Membership.Invite); invite.getMyMembership.mockReturnValue(KnownMembership.Invite);
const prom = testUtils.emitPromise(store, space1); const prom = testUtils.emitPromise(store, space1);
client.emit(ClientEvent.Room, space); client.emit(ClientEvent.Room, space);
await prom; await prom;
@ -845,7 +846,7 @@ describe("SpaceStore", () => {
room: spaceId, room: spaceId,
user: client.getUserId()!, user: client.getUserId()!,
skey: user.userId, skey: user.userId,
content: { membership: Membership.Join }, content: { membership: KnownMembership.Join },
ts: Date.now(), ts: Date.now(),
}); });
const spaceRoom = client.getRoom(spaceId)!; const spaceRoom = client.getRoom(spaceId)!;
@ -926,7 +927,7 @@ describe("SpaceStore", () => {
beforeEach(async () => { beforeEach(async () => {
mkRoom(room1); // not a space mkRoom(room1); // not a space
mkSpace(space1, [mkSpace(space2).roomId]); mkSpace(space1, [mkSpace(space2).roomId]);
mkSpace(space3).getMyMembership.mockReturnValue(Membership.Invite); mkSpace(space3).getMyMembership.mockReturnValue(KnownMembership.Invite);
await run(); await run();
store.setActiveSpace(MetaSpace.Home); store.setActiveSpace(MetaSpace.Home);
expect(store.activeSpace).toBe(MetaSpace.Home); expect(store.activeSpace).toBe(MetaSpace.Home);
@ -986,7 +987,7 @@ describe("SpaceStore", () => {
const event = mkEvent({ const event = mkEvent({
event: true, event: true,
type: EventType.RoomMember, type: EventType.RoomMember,
content: { membership: Membership.Join }, content: { membership: KnownMembership.Join },
skey: dm1Partner.userId, skey: dm1Partner.userId,
user: dm1Partner.userId, user: dm1Partner.userId,
room: space1, room: space1,
@ -994,7 +995,7 @@ describe("SpaceStore", () => {
space.getMember.mockImplementation((userId) => { space.getMember.mockImplementation((userId) => {
if (userId === dm1Partner.userId) { if (userId === dm1Partner.userId) {
const member = new RoomMember(space1, dm1Partner.userId); const member = new RoomMember(space1, dm1Partner.userId);
member.membership = Membership.Join; member.membership = KnownMembership.Join;
return member; return member;
} }
return null; return null;
@ -1249,15 +1250,15 @@ describe("SpaceStore", () => {
// receive invite to space // receive invite to space
const rootSpace = mkSpace(space1, [room1, room2, space2]); const rootSpace = mkSpace(space1, [room1, room2, space2]);
rootSpace.getMyMembership.mockReturnValue(Membership.Invite); rootSpace.getMyMembership.mockReturnValue(KnownMembership.Invite);
client.emit(ClientEvent.Room, rootSpace); client.emit(ClientEvent.Room, rootSpace);
jest.runOnlyPendingTimers(); jest.runOnlyPendingTimers();
expect(SpaceStore.instance.invitedSpaces).toStrictEqual([rootSpace]); expect(SpaceStore.instance.invitedSpaces).toStrictEqual([rootSpace]);
expect(SpaceStore.instance.spacePanelSpaces).toStrictEqual([]); expect(SpaceStore.instance.spacePanelSpaces).toStrictEqual([]);
// accept invite to space // accept invite to space
rootSpace.getMyMembership.mockReturnValue(Membership.Join); rootSpace.getMyMembership.mockReturnValue(KnownMembership.Join);
client.emit(RoomEvent.MyMembership, rootSpace, Membership.Join, Membership.Invite); client.emit(RoomEvent.MyMembership, rootSpace, KnownMembership.Join, KnownMembership.Invite);
jest.runOnlyPendingTimers(); jest.runOnlyPendingTimers();
expect(SpaceStore.instance.invitedSpaces).toStrictEqual([]); expect(SpaceStore.instance.invitedSpaces).toStrictEqual([]);
expect(SpaceStore.instance.spacePanelSpaces).toStrictEqual([rootSpace]); expect(SpaceStore.instance.spacePanelSpaces).toStrictEqual([rootSpace]);
@ -1265,7 +1266,7 @@ describe("SpaceStore", () => {
// join room in space // join room in space
expect(SpaceStore.instance.isRoomInSpace(space1, room1)).toBeFalsy(); expect(SpaceStore.instance.isRoomInSpace(space1, room1)).toBeFalsy();
const rootSpaceRoom1 = mkRoom(room1); const rootSpaceRoom1 = mkRoom(room1);
rootSpaceRoom1.getMyMembership.mockReturnValue(Membership.Join); rootSpaceRoom1.getMyMembership.mockReturnValue(KnownMembership.Join);
client.emit(ClientEvent.Room, rootSpaceRoom1); client.emit(ClientEvent.Room, rootSpaceRoom1);
jest.runOnlyPendingTimers(); jest.runOnlyPendingTimers();
expect(SpaceStore.instance.invitedSpaces).toStrictEqual([]); expect(SpaceStore.instance.invitedSpaces).toStrictEqual([]);
@ -1279,7 +1280,7 @@ describe("SpaceStore", () => {
// receive room invite // receive room invite
expect(SpaceStore.instance.isRoomInSpace(space1, room2)).toBeFalsy(); expect(SpaceStore.instance.isRoomInSpace(space1, room2)).toBeFalsy();
const rootSpaceRoom2 = mkRoom(room2); const rootSpaceRoom2 = mkRoom(room2);
rootSpaceRoom2.getMyMembership.mockReturnValue(Membership.Invite); rootSpaceRoom2.getMyMembership.mockReturnValue(KnownMembership.Invite);
client.emit(ClientEvent.Room, rootSpaceRoom2); client.emit(ClientEvent.Room, rootSpaceRoom2);
jest.runOnlyPendingTimers(); jest.runOnlyPendingTimers();
expect(SpaceStore.instance.invitedSpaces).toStrictEqual([]); expect(SpaceStore.instance.invitedSpaces).toStrictEqual([]);
@ -1292,9 +1293,9 @@ describe("SpaceStore", () => {
// start DM in space // start DM in space
const myRootSpaceMember = new RoomMember(space1, testUserId); const myRootSpaceMember = new RoomMember(space1, testUserId);
myRootSpaceMember.membership = Membership.Join; myRootSpaceMember.membership = KnownMembership.Join;
const rootSpaceFriend = new RoomMember(space1, dm1Partner.userId); const rootSpaceFriend = new RoomMember(space1, dm1Partner.userId);
rootSpaceFriend.membership = Membership.Join; rootSpaceFriend.membership = KnownMembership.Join;
rootSpace.getMembers.mockReturnValue([myRootSpaceMember, rootSpaceFriend]); rootSpace.getMembers.mockReturnValue([myRootSpaceMember, rootSpaceFriend]);
rootSpace.getMember.mockImplementation((userId) => { rootSpace.getMember.mockImplementation((userId) => {
switch (userId) { switch (userId) {
@ -1310,7 +1311,7 @@ describe("SpaceStore", () => {
event: true, event: true,
type: EventType.RoomMember, type: EventType.RoomMember,
content: { content: {
membership: Membership.Join, membership: KnownMembership.Join,
}, },
skey: dm1Partner.userId, skey: dm1Partner.userId,
user: dm1Partner.userId, user: dm1Partner.userId,
@ -1320,7 +1321,7 @@ describe("SpaceStore", () => {
jest.runOnlyPendingTimers(); jest.runOnlyPendingTimers();
expect(SpaceStore.instance.getSpaceFilteredUserIds(space1)!.has(dm1Partner.userId)).toBeTruthy(); expect(SpaceStore.instance.getSpaceFilteredUserIds(space1)!.has(dm1Partner.userId)).toBeTruthy();
const dm1Room = mkRoom(dm1); const dm1Room = mkRoom(dm1);
dm1Room.getMyMembership.mockReturnValue(Membership.Join); dm1Room.getMyMembership.mockReturnValue(KnownMembership.Join);
client.emit(ClientEvent.Room, dm1Room); client.emit(ClientEvent.Room, dm1Room);
jest.runOnlyPendingTimers(); jest.runOnlyPendingTimers();
expect(SpaceStore.instance.invitedSpaces).toStrictEqual([]); expect(SpaceStore.instance.invitedSpaces).toStrictEqual([]);
@ -1333,7 +1334,7 @@ describe("SpaceStore", () => {
// join subspace // join subspace
const subspace = mkSpace(space2); const subspace = mkSpace(space2);
subspace.getMyMembership.mockReturnValue(Membership.Join); subspace.getMyMembership.mockReturnValue(KnownMembership.Join);
const prom = testUtils.emitPromise(SpaceStore.instance, space1); const prom = testUtils.emitPromise(SpaceStore.instance, space1);
client.emit(ClientEvent.Room, subspace); client.emit(ClientEvent.Room, subspace);
jest.runOnlyPendingTimers(); jest.runOnlyPendingTimers();

View file

@ -22,6 +22,7 @@ import {
NotificationCountType, NotificationCountType,
EventType, EventType,
MatrixEvent, MatrixEvent,
KnownMembership,
} from "matrix-js-sdk/src/matrix"; } from "matrix-js-sdk/src/matrix";
import type { MatrixClient } from "matrix-js-sdk/src/matrix"; import type { MatrixClient } from "matrix-js-sdk/src/matrix";
@ -119,7 +120,7 @@ describe("RoomNotificationState", () => {
muteRoom(room); muteRoom(room);
setUnreads(room, 1234, 0); setUnreads(room, 1234, 0);
room.updateMyMembership(Membership.Join); // emit room.updateMyMembership(KnownMembership.Join); // emit
expect(roomNotifState.level).toBe(NotificationLevel.None); expect(roomNotifState.level).toBe(NotificationLevel.None);
expect(roomNotifState.symbol).toBe(null); expect(roomNotifState.symbol).toBe(null);
@ -129,7 +130,7 @@ describe("RoomNotificationState", () => {
it("suggests a red ! if the user has been invited to a room", () => { it("suggests a red ! if the user has been invited to a room", () => {
const roomNotifState = new RoomNotificationState(room, false); const roomNotifState = new RoomNotificationState(room, false);
room.updateMyMembership(Membership.Invite); // emit room.updateMyMembership(KnownMembership.Invite); // emit
expect(roomNotifState.level).toBe(NotificationLevel.Highlight); expect(roomNotifState.level).toBe(NotificationLevel.Highlight);
expect(roomNotifState.symbol).toBe("!"); expect(roomNotifState.symbol).toBe("!");
@ -140,7 +141,7 @@ describe("RoomNotificationState", () => {
const roomNotifState = new RoomNotificationState(room, false); const roomNotifState = new RoomNotificationState(room, false);
setUnreads(room, 4321, 0); setUnreads(room, 4321, 0);
room.updateMyMembership(Membership.Join); // emit room.updateMyMembership(KnownMembership.Join); // emit
expect(roomNotifState.level).toBe(NotificationLevel.Notification); expect(roomNotifState.level).toBe(NotificationLevel.Notification);
expect(roomNotifState.symbol).toBe(null); expect(roomNotifState.symbol).toBe(null);
@ -151,7 +152,7 @@ describe("RoomNotificationState", () => {
const roomNotifState = new RoomNotificationState(room, false); const roomNotifState = new RoomNotificationState(room, false);
setUnreads(room, 0, 69); setUnreads(room, 0, 69);
room.updateMyMembership(Membership.Join); // emit room.updateMyMembership(KnownMembership.Join); // emit
expect(roomNotifState.level).toBe(NotificationLevel.Highlight); expect(roomNotifState.level).toBe(NotificationLevel.Highlight);
expect(roomNotifState.symbol).toBe(null); expect(roomNotifState.symbol).toBe(null);
@ -171,7 +172,7 @@ describe("RoomNotificationState", () => {
); );
addThread(room); addThread(room);
room.updateMyMembership(Membership.Join); // emit room.updateMyMembership(KnownMembership.Join); // emit
expect(roomNotifState.level).toBe(NotificationLevel.Activity); expect(roomNotifState.level).toBe(NotificationLevel.Activity);
expect(roomNotifState.symbol).toBe(null); expect(roomNotifState.symbol).toBe(null);

Some files were not shown because too many files have changed in this diff Show more