Knock support

Also, fix token refresh functionality
This commit is contained in:
N-Pex 2025-05-28 12:29:04 +02:00
parent cfabd8be08
commit e8f04d79c9
11 changed files with 310 additions and 75 deletions

View file

@ -90,13 +90,22 @@
<interactive-auth ref="interactiveAuth" />
<v-text-field
v-if="roomNeedsKnock"
variant="solo"
density="compact"
:label="$t('join.knock_reason')"
counter="100"
maxlength="100"
v-model="knockReason" />
<v-btn id="btn-join" class="btn-dark" :disabled="!acceptUA || (room && room.getMyMembership() == 'ban')" size="large"
@click.stop="handleJoin" :loading="loading" v-if="!currentUser">{{
roomId && roomId.startsWith("@") ? $t("join.enter_room_user") : $t("join.enter_room")
roomId && roomId.startsWith("@") ? $t("join.enter_room_user") : this.roomNeedsKnock ? $t("join.enter_knock") : $t("join.enter_room")
}}</v-btn>
<v-btn id="btn-join" class="btn-dark" :disabled="!acceptUA || (room && room.getMyMembership() == 'ban')" size="large"
block @click.stop="handleJoin" :loading="loading" v-else>{{
roomId && roomId.startsWith("@") ? $t("join.join_user") : $t("join.join")
roomId && roomId.startsWith("@") ? $t("join.join_user") : this.roomNeedsKnock ? $t("join.knock") : $t("join.join")
}}</v-btn>
<div v-if="loadingMessage" class="text-center">{{ loadingMessage }}</div>
@ -164,6 +173,20 @@ export default {
InteractiveAuth,
AuthedImage
},
props: {
roomDisplayName: {
type: String,
default: function () {
return null;
}
},
roomNeedsKnock: {
type: Boolean,
default: function () {
return false;
}
}
},
data() {
return {
roomName: null,
@ -178,6 +201,7 @@ export default {
showEditDisplaynameDialog: false,
showSelectLanguageDialog: false,
acceptUA: false,
knockReason: "",
};
},
computed: {
@ -233,14 +257,6 @@ export default {
let activeLanguages = [...this.getLanguages()];
return activeLanguages.filter((lang) => lang.value === this.$i18n.locale);
},
roomDisplayName() {
// If there is a display name in to invite link, use that!
try {
return new URL(location.href).searchParams.get('roomName');
} catch(ignoredError) {
return undefined;
}
}
},
watch: {
roomId: {
@ -312,8 +328,13 @@ export default {
this.$nextTick(() => {
this.handleJoin();
});
}
else if (this.roomId.startsWith("#")) {
} else if (this.roomId.startsWith("@")) {
// Direct chat with user
this.waitingForRoomCreation = true;
this.$nextTick(() => {
this.handleJoin();
});
} else {
this.$matrix
.getPublicRoomInfo(this.roomId)
.then((room) => {
@ -323,25 +344,18 @@ export default {
})
.catch((err) => {
console.log("Could not find room info", err);
// Private room, try to get name
const room = this.$matrix.getRoom(this.roomId);
if (room) {
this.roomName = this.removeHomeServer(room.name || this.roomName);
} else {
this.roomName = this.removeHomeServer(this.roomAliasOrId);
}
})
.finally(() => {
this.waitingForInfo = false;
});
} else if (this.roomId.startsWith("@")) {
// Direct chat with user
this.waitingForRoomCreation = true;
this.$nextTick(() => {
this.handleJoin();
});
} else {
// Private room, try to get name
const room = this.$matrix.getRoom(this.roomId);
if (room) {
this.roomName = this.removeHomeServer(room.name || this.roomName);
} else {
this.roomName = this.removeHomeServer(this.roomAliasOrId);
}
this.waitingForInfo = false;
}
},
@ -359,10 +373,6 @@ export default {
}
},
handleOpenApp() {
console.log("Open app..."); //TODO
},
handleJoin() {
this.loading = true;
this.loadingMessage = this.$t("join.status_logging_in");
@ -412,6 +422,11 @@ export default {
this.$matrix.setCurrentRoomId(room.roomId);
return room;
});
} else if (this.roomNeedsKnock) {
console.log("Join: knocking room");
this.$analytics.event("Invitations", "Room Knocked");
this.loadingMessage = this.$t("join.status_knocking");
return this.$matrix.matrixClient.knockRoom(this.roomId, this.knockReason.length > 0 ? { reason: this.knockReason} : undefined);
} else {
console.log("Join: joining room");
this.$analytics.event("Invitations", "Room Joined");
@ -423,13 +438,23 @@ export default {
this.loading = false;
this.loadingMessage = null;
this.$nextTick(() => {
this.$navigation.push(
{
name: "Chat",
params: { roomId: util.sanitizeRoomId(room.roomId) },
},
-1
);
if (this.roomNeedsKnock) {
// For knocks, send to room list
this.$navigation.push(
{
name: "Home",
},
-1
);
} else {
this.$navigation.push(
{
name: "Chat",
params: { roomId: util.sanitizeRoomId(room.roomId) },
},
-1
);
}
});
})
.catch((err) => {