Add timed message retention feature
This commit is contained in:
parent
f8e67afa31
commit
3313da0cb8
5 changed files with 404 additions and 47 deletions
|
|
@ -14,7 +14,7 @@ export default {
|
|||
editedRoomTopic: "",
|
||||
isRoomTopicEditMode: false,
|
||||
roomTopicErrorMessage: null,
|
||||
}
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.$matrix.on("Room.timeline", this.roomInfoMixinOnEvent);
|
||||
|
|
@ -61,7 +61,10 @@ export default {
|
|||
publicRoomLink() {
|
||||
if (this.room && this.roomJoinRule == "public") {
|
||||
return this.$router.getRoomLink(
|
||||
this.room.getCanonicalAlias(), this.room.roomId, this.room.name, utils.roomDisplayTypeToQueryParam(this.room, this.roomDisplayType)
|
||||
this.room.getCanonicalAlias(),
|
||||
this.room.roomId,
|
||||
this.room.name,
|
||||
utils.roomDisplayTypeToQueryParam(this.room, this.roomDisplayType)
|
||||
);
|
||||
}
|
||||
return null;
|
||||
|
|
@ -69,7 +72,7 @@ export default {
|
|||
|
||||
roomHistory() {
|
||||
if (this.room) {
|
||||
return this.room.shouldEncryptForInvitedMembers()
|
||||
return this.room.shouldEncryptForInvitedMembers();
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
|
@ -92,13 +95,24 @@ export default {
|
|||
*/
|
||||
privateParty() {
|
||||
if (this.isPrivate) {
|
||||
const membersButMe = this.room.getMembers().filter(m => m.userId != this.$matrix.currentUserId);
|
||||
const membersButMe = this.room.getMembers().filter((m) => m.userId != this.$matrix.currentUserId);
|
||||
if (membersButMe.length == 1) {
|
||||
return membersButMe[0];
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
canViewRetentionPolicy() {
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Return true if we can set message retention policy in the room.
|
||||
*/
|
||||
canChangeRetentionPolicy() {
|
||||
return true;
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
room: {
|
||||
|
|
@ -115,14 +129,48 @@ export default {
|
|||
},
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* Get a string describing current room retention setting.
|
||||
* Can be "None", "1 week", "1 hour" etc...
|
||||
*/
|
||||
roomMessageRetentionDisplay(maybeEvent) {
|
||||
const retention = this.roomMessageRetention(maybeEvent);
|
||||
if (retention == 0) {
|
||||
return this.$t("room_info.message_retention_none");
|
||||
} else if (retention == 60 * 60 * 1000) {
|
||||
return this.$t("room_info.message_retention_1_hour");
|
||||
} else if (retention == 24 * 60 * 60 * 1000) {
|
||||
return this.$t("room_info.message_retention_1_day");
|
||||
} else if (retention == 7 * 24 * 60 * 60 * 1000) {
|
||||
return this.$t("room_info.message_retention_1_week");
|
||||
} else if (retention == 30 * 24 * 60 * 60 * 1000) {
|
||||
return this.$t("room_info.message_retention_30_days");
|
||||
} else if (retention == 365 * 24 * 60 * 60 * 1000) {
|
||||
return this.$t("room_info.message_retention_365_days");
|
||||
}
|
||||
return this.$t("room_info.message_retention_other_seconds", { count: retention / 1000 });
|
||||
},
|
||||
|
||||
roomMessageRetention(maybeEvent) {
|
||||
const retentionEvent = maybeEvent || (this.room && this.room.currentState.getStateEvents("m.room.retention", ""));
|
||||
if (retentionEvent) {
|
||||
console.log("Retention event found", JSON.stringify(retentionEvent));
|
||||
const maxLifetime = parseInt(retentionEvent.getContent().max_lifetime);
|
||||
if (maxLifetime) {
|
||||
return maxLifetime;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
|
||||
onRoomNameClicked() {
|
||||
if(this.userCanPurgeRoom) {
|
||||
if (this.userCanPurgeRoom) {
|
||||
this.isRoomNameEditMode = !this.isRoomNameEditMode;
|
||||
this.editedRoomName = this.roomName;
|
||||
}
|
||||
},
|
||||
updateRoomName() {
|
||||
if(this.editedRoomName) {
|
||||
if (this.editedRoomName) {
|
||||
this.$matrix.matrixClient.setRoomName(this.room.roomId, this.editedRoomName);
|
||||
this.isRoomNameEditMode = !this.isRoomNameEditMode;
|
||||
} else {
|
||||
|
|
@ -130,13 +178,13 @@ export default {
|
|||
}
|
||||
},
|
||||
onRoomTopicClicked() {
|
||||
if(this.userCanPurgeRoom) {
|
||||
if (this.userCanPurgeRoom) {
|
||||
this.isRoomTopicEditMode = !this.isRoomTopicEditMode;
|
||||
this.editedRoomTopic = this.roomTopic;
|
||||
}
|
||||
},
|
||||
updateRoomTopic() {
|
||||
if(this.editedRoomTopic) {
|
||||
if (this.editedRoomTopic) {
|
||||
this.$matrix.matrixClient.setRoomTopic(this.room.roomId, this.editedRoomTopic);
|
||||
this.isRoomTopicEditMode = !this.isRoomTopicEditMode;
|
||||
} else {
|
||||
|
|
@ -154,14 +202,8 @@ export default {
|
|||
if (this.room) {
|
||||
this.roomJoinRule = this.getRoomJoinRule();
|
||||
const canChangeAccess =
|
||||
this.room.currentState.mayClientSendStateEvent(
|
||||
"m.room.join_rules",
|
||||
this.$matrix.matrixClient
|
||||
) &&
|
||||
this.room.currentState.mayClientSendStateEvent(
|
||||
"m.room.guest_access",
|
||||
this.$matrix.matrixClient
|
||||
);
|
||||
this.room.currentState.mayClientSendStateEvent("m.room.join_rules", this.$matrix.matrixClient) &&
|
||||
this.room.currentState.mayClientSendStateEvent("m.room.guest_access", this.$matrix.matrixClient);
|
||||
this.userCanChangeJoinRule = canChangeAccess;
|
||||
this.userCanPurgeRoom = canChangeAccess; //TODO - need different permissions here?
|
||||
} else {
|
||||
|
|
@ -175,10 +217,7 @@ export default {
|
|||
if (event.getRoomId() !== this.roomId) {
|
||||
return; // Not for this room
|
||||
}
|
||||
if (
|
||||
event.getType() == "m.room.join_rules" ||
|
||||
event.getType() == "m.room.guest_access"
|
||||
) {
|
||||
if (event.getType() == "m.room.join_rules" || event.getType() == "m.room.guest_access") {
|
||||
this.updatePermissions();
|
||||
}
|
||||
},
|
||||
|
|
@ -186,15 +225,9 @@ export default {
|
|||
privatePartyAvatar(size) {
|
||||
const other = this.privateParty;
|
||||
if (other) {
|
||||
return other.getAvatarUrl(
|
||||
this.$matrix.matrixClient.getHomeserverUrl(),
|
||||
size,
|
||||
size,
|
||||
"scale",
|
||||
true
|
||||
);
|
||||
return other.getAvatarUrl(this.$matrix.matrixClient.getHomeserverUrl(), size, size, "scale", true);
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue