Timeout on room deletion

And custom deletion notice state event.

Issue #118.
This commit is contained in:
N-Pex 2021-07-06 09:33:19 +02:00
parent d39357401b
commit abd3892349
7 changed files with 164 additions and 17 deletions

View file

@ -1,6 +1,6 @@
<template>
<v-dialog v-model="showDialog" v-show="room" class="ma-0 pa-0" width="80%">
<div class="dialog-content text-center">
<div v-if="timeout == -1" class="dialog-content text-center">
<template>
<v-img contain height="28" src="@/assets/icons/trash_black.svg" />
<h2 class="dialog-title">{{ $t("purge_room.title") }}</h2>
@ -38,6 +38,48 @@
</v-row>
</v-container>
</div>
<!-- Timer -->
<div v-if="timeout >= 0 && !isPurging" class="dialog-content text-center">
<template>
<v-img
contain
width="20"
class="d-inline-block me-2"
src="@/assets/icons/timer.svg"
/>{{ $t("purge_room.n_seconds", { seconds: timeout }) }}
<h2 class="dialog-title">{{ $t("purge_room.self_destruct") }}</h2>
<div class="dialog-text">
{{ $t("purge_room.notified") }}
</div>
<div class="dialog-text">
{{ status }}
</div>
</template>
<v-container fluid>
<v-row cols="12">
<v-col cols="12">
<v-btn
depressed
text
block
class="text-button"
:disabled="isPurging"
@click="undo"
>{{ $t("menu.undo") }}</v-btn
>
</v-col>
</v-row>
</v-container>
</div>
<!-- Purging -->
<div v-if="isPurging" class="dialog-content text-center">
<h2 class="dialog-title">{{ $t("purge_room.deleting") }}</h2>
<div class="dialog-text">
{{ status }}
</div>
</div>
</v-dialog>
</template>
<script>
@ -56,6 +98,8 @@ export default {
},
data() {
return {
timeout: -1,
timeoutTimer: null,
showDialog: false,
isPurging: false,
status: null,
@ -75,7 +119,41 @@ export default {
},
methods: {
undo() {
if (this.timeoutTimer) {
clearInterval(this.timeoutTimer);
this.timeoutTimer = null;
}
this.timeout = -1;
// Cancel the state event for deletion
this.$matrix.matrixClient.sendStateEvent(
this.room.roomId,
"im.keanu.room_deletion_notice",
{ status: "cancel" }
);
this.showDialog = false;
},
onPurgeRoom() {
// Send custom state event!
this.$matrix.matrixClient.sendStateEvent(
this.room.roomId,
"im.keanu.room_deletion_notice",
{ status: "delete" }
);
this.timeout = 30;
this.timeoutTimer = setInterval(() => {
this.timeout = this.timeout - 1;
if (this.timeout == 0) {
clearInterval(this.timeoutTimer);
this.timeoutTimer = null;
this.onDoPurgeRoom();
}
}, 1000);
},
onDoPurgeRoom() {
this.isPurging = true;
this.$matrix
.purgeRoom(this.room.roomId, this.onPurgeStatus)