Add custom state event for "room deleted"
This commit is contained in:
parent
9e8ac6ad67
commit
876b79bee6
4 changed files with 44 additions and 8 deletions
|
|
@ -91,6 +91,7 @@
|
|||
</template>
|
||||
<script>
|
||||
import roomInfoMixin from "./roomInfoMixin";
|
||||
import { STATE_EVENT_ROOM_DELETION_NOTICE } from "../plugins/utils";
|
||||
|
||||
export default {
|
||||
name: "LeaveRoomDialog",
|
||||
|
|
@ -136,7 +137,7 @@ export default {
|
|||
// Cancel the state event for deletion
|
||||
this.$matrix.matrixClient.sendStateEvent(
|
||||
this.room.roomId,
|
||||
"im.keanu.room_deletion_notice",
|
||||
STATE_EVENT_ROOM_DELETION_NOTICE,
|
||||
{ status: "cancel" }
|
||||
);
|
||||
|
||||
|
|
@ -146,7 +147,7 @@ export default {
|
|||
// Send custom state event!
|
||||
this.$matrix.matrixClient.sendStateEvent(
|
||||
this.room.roomId,
|
||||
"im.keanu.room_deletion_notice",
|
||||
STATE_EVENT_ROOM_DELETION_NOTICE,
|
||||
{ status: "delete" }
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import util from "../plugins/utils";
|
||||
import util, { STATE_EVENT_ROOM_DELETION_NOTICE } from "../plugins/utils";
|
||||
import MessageIncomingText from "./messages/MessageIncomingText";
|
||||
import MessageIncomingFile from "./messages/MessageIncomingFile";
|
||||
import MessageIncomingImage from "./messages/MessageIncomingImage.vue";
|
||||
|
|
@ -296,9 +296,9 @@ export default {
|
|||
return MessageOutgoingPoll;
|
||||
}
|
||||
|
||||
case "im.keanu.room_deletion_notice": {
|
||||
case STATE_EVENT_ROOM_DELETION_NOTICE: {
|
||||
// Custom event for notice 30 seconds before a room is deleted/purged.
|
||||
const deletionNotices = this.room.currentState.getStateEvents("im.keanu.room_deletion_notice");
|
||||
const deletionNotices = this.room.currentState.getStateEvents(STATE_EVENT_ROOM_DELETION_NOTICE);
|
||||
if (deletionNotices && deletionNotices.length > 0 && deletionNotices[deletionNotices.length - 1] == event) {
|
||||
// This is the latest/last one. Look at the status flag. Show nothing if it is "cancel".
|
||||
if (event.getContent().status != "cancel") {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ import * as ContentHelpers from "matrix-js-sdk/lib/content-helpers";
|
|||
import dataUriToBuffer from "data-uri-to-buffer";
|
||||
import ImageResize from "image-resize";
|
||||
|
||||
export const STATE_EVENT_ROOM_DELETION_NOTICE = "im.keanu.room_deletion_notice";
|
||||
export const STATE_EVENT_ROOM_DELETED = "im.keanu.room_deleted";
|
||||
|
||||
export const ROOM_TYPE_DEFAULT = "im.keanu.room_type_default";
|
||||
export const ROOM_TYPE_VOICE_MODE = "im.keanu.room_type_voice";
|
||||
export const ROOM_TYPE_FILE_MODE = "im.keanu.room_type_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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue