parent
f0ef9e3521
commit
b7b28bbc2a
4 changed files with 215 additions and 1 deletions
90
src/components/PurgeRoomDialog.vue
Normal file
90
src/components/PurgeRoomDialog.vue
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<template>
|
||||
<v-dialog v-model="showDialog" v-show="room" class="ma-0 pa-0" width="80%">
|
||||
<div class="dialog-content text-center">
|
||||
<template>
|
||||
<v-icon color="black" size="30">lock</v-icon>
|
||||
<h2 class="dialog-title">Purge room?</h2>
|
||||
<div class="dialog-text">
|
||||
This operation will close the room for all members. It cannot be
|
||||
undone.
|
||||
</div>
|
||||
</template>
|
||||
<v-container fluid>
|
||||
<v-row cols="12">
|
||||
<v-col cols="6">
|
||||
<v-btn
|
||||
depressed
|
||||
text
|
||||
block
|
||||
class="text-button"
|
||||
@click="showDialog = false"
|
||||
>Cancel</v-btn
|
||||
>
|
||||
</v-col>
|
||||
<v-col cols="6" align="center">
|
||||
<v-btn
|
||||
color="red"
|
||||
depressed
|
||||
block
|
||||
class="filled-button"
|
||||
@click.stop="onPurgeRoom()"
|
||||
>Purge room</v-btn
|
||||
>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-container>
|
||||
</div>
|
||||
</v-dialog>
|
||||
</template>
|
||||
<script>
|
||||
import roomInfoMixin from "./roomInfoMixin";
|
||||
|
||||
export default {
|
||||
name: "LeaveRoomDialog",
|
||||
mixins: [roomInfoMixin],
|
||||
props: {
|
||||
show: {
|
||||
type: Boolean,
|
||||
default: function () {
|
||||
return false;
|
||||
},
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
showDialog: false,
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
show: {
|
||||
handler(newVal, ignoredOldVal) {
|
||||
this.showDialog = newVal;
|
||||
},
|
||||
},
|
||||
showDialog() {
|
||||
if (!this.showDialog) {
|
||||
this.$emit("close");
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
onPurgeRoom() {
|
||||
this.$matrix
|
||||
.purgeRoom(this.room.roomId)
|
||||
.then(() => {
|
||||
this.showDialog = false;
|
||||
console.log("Purged room");
|
||||
this.$navigation.push({ name: "Home", params: { roomId: null } }, -1);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error purging", err);
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
@import "@/assets/css/chat.scss";
|
||||
</style>
|
||||
|
|
@ -63,6 +63,15 @@
|
|||
<div v-if="publicRoomLinkCopied" class="link-copied">Link copied!</div>
|
||||
</v-radio-group>
|
||||
|
||||
<v-btn
|
||||
v-if="userCanPurgeRoom"
|
||||
color="red"
|
||||
depressed
|
||||
block
|
||||
class="filled-button"
|
||||
@click.stop="showPurgeConfirmation = true"
|
||||
>Purge room</v-btn
|
||||
>
|
||||
<!-- <div v-if="anyoneCanJoin">
|
||||
<div>Anyone with a link can join.</div>
|
||||
<v-text-field
|
||||
|
|
@ -158,11 +167,19 @@
|
|||
:room="room"
|
||||
@close="showLeaveConfirmation = false"
|
||||
/>
|
||||
|
||||
<PurgeRoomDialog
|
||||
:show="showPurgeConfirmation"
|
||||
:room="room"
|
||||
@close="showPurgeConfirmation = false"
|
||||
/>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import LeaveRoomDialog from "../components/LeaveRoomDialog";
|
||||
import PurgeRoomDialog from "../components/PurgeRoomDialog";
|
||||
import DeviceList from "../components/DeviceList";
|
||||
import QRCode from "qrcode";
|
||||
import roomInfoMixin from "./roomInfoMixin";
|
||||
|
|
@ -172,6 +189,7 @@ export default {
|
|||
mixins: [roomInfoMixin],
|
||||
components: {
|
||||
LeaveRoomDialog,
|
||||
PurgeRoomDialog,
|
||||
DeviceList,
|
||||
},
|
||||
data() {
|
||||
|
|
@ -181,6 +199,7 @@ export default {
|
|||
displayName: "",
|
||||
showAllMembers: false,
|
||||
showLeaveConfirmation: false,
|
||||
showPurgeConfirmation: false,
|
||||
expandedMembers: [],
|
||||
buildVersion: "",
|
||||
updatingJoinRule: false, // Flag if we are processing update curerntly
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ export default {
|
|||
data() {
|
||||
return {
|
||||
roomJoinRule: null,
|
||||
userCanChangeJoinRule: false
|
||||
userCanChangeJoinRule: false,
|
||||
userCanPurgeRoom: false
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
|
@ -81,9 +82,11 @@ export default {
|
|||
this.$matrix.matrixClient
|
||||
);
|
||||
this.userCanChangeJoinRule = canChangeAccess;
|
||||
this.userCanPurgeRoom = canChangeAccess; //TODO - need different permissions here?
|
||||
} else {
|
||||
this.roomJoinRule = null;
|
||||
this.userCanChangeJoinRule = false;
|
||||
this.userCanPurgeRoom = false;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
global.Olm = require("olm");
|
||||
import sdk from "matrix-js-sdk";
|
||||
import { TimelineWindow, EventTimeline } from "matrix-js-sdk";
|
||||
import util from "../plugins/utils";
|
||||
import User from "../models/user";
|
||||
import config from "../assets/config";
|
||||
|
|
@ -434,6 +435,107 @@ export default {
|
|||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Purge the room with the given id! This means:
|
||||
* - Make room invite only
|
||||
* - Disallow guest access
|
||||
* - Set history visibility to 'joined'
|
||||
* - Redact all events
|
||||
* - Kick all members
|
||||
* @param roomId
|
||||
*/
|
||||
purgeRoom(roomId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const room = this.getRoom(roomId);
|
||||
if (!room) {
|
||||
reject("Room not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
const timelineWindow = new TimelineWindow(
|
||||
this.matrixClient,
|
||||
room.getUnfilteredTimelineSet(),
|
||||
{}
|
||||
);
|
||||
const self = this;
|
||||
|
||||
console.log("Purge: set invite only");
|
||||
this.matrixClient.sendStateEvent(
|
||||
roomId,
|
||||
"m.room.join_rules",
|
||||
{ join_rule: "invite" },
|
||||
""
|
||||
)
|
||||
.then(() => {
|
||||
console.log("Purge: forbid guest access");
|
||||
return this.matrixClient.sendStateEvent(
|
||||
roomId,
|
||||
"m.room.guest_access",
|
||||
{ guest_access: "forbidden" },
|
||||
""
|
||||
);
|
||||
})
|
||||
.then(() => {
|
||||
console.log("Purge: set history visibility to 'joined'");
|
||||
return this.matrixClient.sendStateEvent(roomId, "m.room.history_visibility", {
|
||||
history_visibility: "joined",
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
console.log("Purge: create timeline");
|
||||
return timelineWindow.load(null, 100)
|
||||
})
|
||||
.then(() => {
|
||||
const getMoreIfAvailable = function _getMoreIfAvailable() {
|
||||
if (timelineWindow.canPaginate(EventTimeline.BACKWARDS)
|
||||
) {
|
||||
console.log("Purge: page back");
|
||||
return timelineWindow
|
||||
.paginate(EventTimeline.BACKWARDS, 100, true, 5)
|
||||
.then((ignoredsuccess) => {
|
||||
return _getMoreIfAvailable.call(self);
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve("Done");
|
||||
}
|
||||
}.bind(self);
|
||||
return getMoreIfAvailable();
|
||||
})
|
||||
.then(() => {
|
||||
console.log("Purge: redact events");
|
||||
var redactionPromises = [];
|
||||
timelineWindow.getEvents().forEach(event => {
|
||||
if (!event.isRedacted() && !event.isRedaction() && !event.isState()) {
|
||||
// Redact!
|
||||
redactionPromises.push(this.matrixClient.redactEvent(event.getRoomId(), event.getId()));
|
||||
}
|
||||
});
|
||||
return Promise.all(redactionPromises);
|
||||
})
|
||||
.then(() => {
|
||||
console.log("Purge: kick members");
|
||||
var joined = room.getMembersWithMembership("join");
|
||||
var invited = room.getMembersWithMembership("invite");
|
||||
var members = joined.concat(invited);
|
||||
|
||||
var kickPromises = [];
|
||||
members.forEach(member => {
|
||||
if (member.userId != self.currentUserId) {
|
||||
kickPromises.push(this.matrixClient.kick(roomId, member.userId));
|
||||
}
|
||||
});
|
||||
return Promise.all(kickPromises);
|
||||
})
|
||||
.then(() => {
|
||||
resolve(true); // Done!
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error purging room", err);
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
on(event, handler) {
|
||||
if (this.matrixClient) {
|
||||
this.matrixClient.on(event, handler);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue