keanu-weblite/src/components/PurgeRoomDialog.vue

178 lines
4.6 KiB
Vue
Raw Normal View History

2021-05-06 13:23:17 +02:00
<template>
2022-01-27 11:59:25 +00:00
<v-dialog
2023-10-10 10:46:17 +02:00
persistent
2022-01-27 11:59:25 +00:00
v-model="showDialog"
2025-05-08 11:52:39 +02:00
class="ma-0 pa-0"
2025-05-06 10:53:34 +02:00
:width="$vuetify.display.smAndUp ? '688px' : '95%'"
2022-01-27 11:59:25 +00:00
>
<div v-if="timeout == -1" class="dialog-content text-center">
2021-05-06 13:23:17 +02:00
<template>
2025-05-08 13:10:06 +02:00
<v-icon size="28">$vuetify.icons.trash_black</v-icon>
<h2 class="dialog-title">{{ $t("purge_room.title") }}</h2>
2022-03-14 15:02:06 +00:00
<div class="dialog-text">
{{ $t("purge_room.info") }}
</div>
<div class="dialog-text">
{{ status }}
2021-05-06 13:23:17 +02:00
</div>
</template>
<v-container fluid>
<v-row cols="12">
<v-col cols="6">
<v-btn
id="btn-purge-room-cancel"
2021-05-06 13:23:17 +02:00
depressed
text
block
class="text-button"
:disabled="isPurging"
2021-05-06 13:23:17 +02:00
@click="showDialog = false"
>{{ $t("menu.cancel") }}</v-btn
2021-05-06 13:23:17 +02:00
>
</v-col>
<v-col cols="6" align="center">
<v-btn
id="btn-purge-room"
2021-05-06 13:23:17 +02:00
color="red"
depressed
block
class="filled-button"
:disabled="isPurging"
2021-05-06 13:23:17 +02:00
@click.stop="onPurgeRoom()"
>{{ $t("purge_room.button") }}</v-btn
2021-05-06 13:23:17 +02:00
>
</v-col>
</v-row>
</v-container>
</div>
<!-- Timer -->
<div v-if="timeout >= 0 && !isPurging" class="dialog-content text-center">
<template>
2025-05-08 13:10:06 +02:00
<v-icon size="20"
class="d-inline-block me-2">$vuetify.icons.timer</v-icon>
{{ $t("purge_room.n_seconds", { seconds: timeout }) }}
<h2 class="dialog-title mb-0">{{ $t("purge_room.self_destruct") }}</h2>
<div class="dialog-text text-center mb-5">
{{ $t("purge_room.notified") }}
</div>
<div class="dialog-text">
{{ status }}
</div>
</template>
<v-container fluid>
<v-row cols="12">
<v-col cols="6">
<v-btn
id="btn-purge-room-undo"
depressed
text
block
class="text-button"
:disabled="isPurging"
@click="undo"
>{{ $t("menu.undo") }}</v-btn
>
</v-col>
<v-col cols="6">
<v-btn depressed block class="outlined-button" @click="onDoPurgeRoom">
{{ $t("menu.delete_now") }}
</v-btn>
</v-col>
</v-row>
</v-container>
</div>
<!-- Purging -->
2022-03-14 15:02:06 +00:00
<div v-if="isPurging" class="dialog-content">
<h2 class="dialog-title">{{ $t("purge_room.deleting") }}</h2>
<div class="dialog-text">
{{ status }}
</div>
</div>
2021-05-06 13:23:17 +02:00
</v-dialog>
</template>
<script>
import { STATE_EVENT_ROOM_DELETION_NOTICE } from "../plugins/utils";
2025-05-08 11:52:39 +02:00
import RoomDialogBase from "./RoomDialogBase.vue";
2021-05-06 13:23:17 +02:00
export default {
2025-05-08 11:52:39 +02:00
name: "PurgeRoomDialog",
extends: RoomDialogBase,
2021-05-06 13:23:17 +02:00
data() {
return {
timeout: -1,
timeoutTimer: null,
isPurging: false,
status: null,
2021-05-06 13:23:17 +02:00
};
},
methods: {
2025-05-08 11:52:39 +02:00
onOpenDialog() {
// Showing, reset
this.status = null;
},
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,
STATE_EVENT_ROOM_DELETION_NOTICE,
{ status: "cancel" }
);
this.showDialog = false;
},
2021-05-06 13:23:17 +02:00
onPurgeRoom() {
// Send custom state event!
this.$matrix.matrixClient.sendStateEvent(
this.room.roomId,
STATE_EVENT_ROOM_DELETION_NOTICE,
{ status: "delete" }
);
this.timeout = 7;
this.timeoutTimer = setInterval(() => {
this.timeout = this.timeout - 1;
if (this.timeout == 0) {
this.onDoPurgeRoom();
}
}, 1000);
},
onDoPurgeRoom() {
this.timeout = 0
clearInterval(this.timeoutTimer);
this.timeoutTimer = null;
this.isPurging = true;
2021-05-06 13:23:17 +02:00
this.$matrix
.purgeRoom(this.room.roomId, this.onPurgeStatus)
2021-05-06 13:23:17 +02:00
.then(() => {
this.showDialog = false;
console.log("Purged room");
this.$navigation.push({ name: "Home", params: { roomId: null } }, -1);
})
.catch((err) => {
console.error("Error purging", err);
this.status = this.$t("room.purge_failed");
})
.finally(() => {
this.isPurging = false;
2021-05-06 13:23:17 +02:00
});
},
onPurgeStatus(message) {
this.status = message;
},
2021-05-06 13:23:17 +02:00
},
};
</script>
<style lang="scss">
@import "@/assets/css/chat.scss";
</style>