Add custom state event for "room deleted"

This commit is contained in:
N-Pex 2023-09-29 10:28:33 +02:00
parent 9e8ac6ad67
commit 876b79bee6
4 changed files with 44 additions and 8 deletions

View file

@ -2,7 +2,7 @@ import olm from "@matrix-org/olm/olm";
global.Olm = olm;
import * as sdk from "matrix-js-sdk";
import { TimelineWindow, EventTimeline } from "matrix-js-sdk";
import util from "../plugins/utils";
import util, { STATE_EVENT_ROOM_DELETED } from "../plugins/utils";
import User from "../models/user";
const LocalStorageCryptoStore =
@ -376,6 +376,24 @@ export default {
}
}
break;
case STATE_EVENT_ROOM_DELETED:
{
const room = this.matrixClient.getRoom(event.getRoomId());
if (room && room.currentState) {
// Before we do anything, make sure the sender is an admin!
// Also, do not react if WE are the sender, since we are probably
// busy doing the rest of the purging process...
if (room.currentState.maySendStateEvent("m.room.power_levels", event.getSender())) {
if (event.getSender() !== this.currentUserId) {
this.leaveRoomAndNavigate(room.roomId).then(() => {
this.matrixClient.store.removeRoom(room.roomId);
})
}
}
}
}
break;
}
this.updateNotificationCount();
},
@ -725,6 +743,13 @@ export default {
history_visibility: "joined",
});
})
.then(() => {
return this.matrixClient.sendStateEvent(
roomId,
STATE_EVENT_ROOM_DELETED,
{ status: "deleted" }
);
})
.then(() => {
//console.log("Purge: create timeline");
return timelineWindow.load(null, 100);
@ -808,6 +833,13 @@ export default {
return kickFirstMember(allMembers);
})
.then(() => {
return this.matrixClient.sendStateEvent(
roomId,
STATE_EVENT_ROOM_DELETED,
{ status: "deleted" }
);
})
.then(() => {
statusCallback(null);
this.matrixClient.setGlobalErrorOnUnknownDevices(oldGlobalErrorSetting);
@ -908,7 +940,7 @@ export default {
* @param {*} userId
*/
isDirectRoomWith(room, userId) {
if (room.getJoinRule() == "invite" && room.getMembers().length == 2) {
if (room && room.getJoinRule() == "invite" && room.getMembers().length == 2) {
let other = room.getMember(userId);
if (other) {
if (room.getMyMembership() == "invite" && other.membership == "join") {
@ -931,7 +963,7 @@ export default {
isDirectRoom(room) {
// TODO - Use the is_direct accountData flag (m.direct). WE (as the client)
// apprently need to set this...
if (room.getJoinRule() == "invite" && room.getMembers().length == 2) {
if (room && room.getJoinRule() == "invite" && room.getMembers().length == 2) {
return true;
}
return false;