Support upgraded rooms (via links to successor/predecessor)

This commit is contained in:
N-Pex 2025-08-04 09:44:06 +02:00
parent 970f82ba29
commit 615aa2b781
11 changed files with 181 additions and 48 deletions

View file

@ -61,7 +61,7 @@
</v-list-item>
<v-list-item v-for="room in joinedRooms" :key="room.roomId" :value="room.roomId"
@click="currentRoomId = room.roomId" class="room-list-room">
v-on:click="() => goToRoom(room)" class="room-list-room">
<template v-slot:prepend>
<v-avatar size="42" color="#d9d9d9" :class="[{ 'rounded-circle': isDirect(room) }]">
<AuthedImage v-if="roomAvatar(room)" :src="roomAvatar(room)" />
@ -87,7 +87,7 @@
</template>
<script>
import util from "../plugins/utils";
import utils from "../plugins/utils";
import AuthedImage from "./AuthedImage.vue";
export default {
@ -124,7 +124,19 @@ export default {
},
joinedRooms() {
// show room with notification on top, followed by room decending order by active Timestamp
return [...this.$matrix.joinedRooms].sort((a, b) => {
let rooms = this.$matrix.joinedRooms;
let upgradedRooms = rooms.filter((r) => r.currentState.getStateEvents("m.room.tombstone").length > 0);
let normalRooms = rooms.filter((r) => r.currentState.getStateEvents("m.room.tombstone").length == 0);
let normalRoomsId = normalRooms.map((r) => r.roomId);
upgradedRooms.forEach(r => {
const history = this.$matrix.matrixClient.getRoomUpgradeHistory(r.roomId, true, true);
const successor = history[history.length - 1];
if (!normalRoomsId.includes(successor.roomId)) {
normalRoomsId.push(successor.roomId);
normalRooms.push(successor);
}
});
return [...normalRooms].sort((a, b) => {
if (this.notificationCount(a)) return -1;
if (this.notificationCount(b)) return 1;
return b.getLastActiveTimestamp() - a.getLastActiveTimestamp()
@ -132,6 +144,25 @@ export default {
},
},
methods: {
goToRoom(room) {
const events = room.currentState.getStateEvents("m.room.tombstone");
if (events && events.length > 0) {
const replacement_room = events[events.length - 1].getContent().replacement_room;
this.$navigation.push(
{
name: "Join",
params: {
roomId: utils.sanitizeRoomId(replacement_room),
join: true
},
query: this.$route.query
},
0
);
} else {
this.currentRoomId = utils.sanitizeRoomId(room.roomId);
}
},
roomAvatar(room) {
if (this.isDirect(room)) {
if (room.avatar) {
@ -184,7 +215,7 @@ export default {
{
name: "Chat",
params: {
roomId: util.sanitizeRoomId(
roomId: utils.sanitizeRoomId(
room.getCanonicalAlias() || room.roomId
),
},
@ -232,7 +263,7 @@ export default {
this.$navigation.push(
{
name: "Chat",
params: { roomId: util.sanitizeRoomId(this.currentRoomId) },
params: { roomId: utils.sanitizeRoomId(this.currentRoomId) },
},
-1
);