Use vite as bundler

This commit is contained in:
N-Pex 2025-03-31 16:33:54 +02:00
parent 16dc5df9e5
commit b6f7f75fdd
44 changed files with 4308 additions and 15961 deletions

View file

@ -4,9 +4,9 @@ import * as sdk from "matrix-js-sdk";
import { TimelineWindow, EventTimeline, EventStatus } from "matrix-js-sdk";
import util, { STATE_EVENT_ROOM_DELETED, STATE_EVENT_ROOM_TYPE, ROOM_TYPE_CHANNEL, ROOM_TYPE_FILE_MODE, ROOM_TYPE_VOICE_MODE, ROOM_TYPE_DEFAULT } from "../plugins/utils";
import User from "../models/user";
import * as LocalStorageCryptoStoreClass from "matrix-js-sdk/lib/crypto/store/localStorage-crypto-store";
const LocalStorageCryptoStore =
require("matrix-js-sdk/lib/crypto/store/localStorage-crypto-store").LocalStorageCryptoStore;
const LocalStorageCryptoStore = LocalStorageCryptoStoreClass.LocalStorageCryptoStore;
export const CHANNEL_POWER_LEVELS = {
"m.room.encrypted": 0, // NOTE! Since practically all events in encrypted rooms get sent as "m.room.encrypted" we need to set
@ -50,6 +50,7 @@ export default {
userCanSendReactionAndAnswerPollInCurrentRoom: true,
currentRoomBeingPurged: false,
notificationCount: 0,
useAuthedMedia: false,
};
},
mounted() {
@ -297,14 +298,16 @@ export default {
accessToken: user.access_token,
timelineSupport: true,
unstableClientRelationAggregation: true,
cryptoStore: this.createCryptoStore()
//useAuthorizationHeader: true
};
this.matrixClient = sdk.createClient(opts);
// if (user.is_guest) {
// this.matrixClient.setGuest(true);
// }
console.error("Created client", this.matrixClient);
return this.matrixClient
.initCrypto()
.initRustCrypto()
.then(() => {
console.log("Crypto initialized");
@ -331,6 +334,11 @@ export default {
}
})
.then(() => {
return this.matrixClient.isVersionSupported("v1.11");
})
.then((authedMediaSupported) => {
this.useAuthedMedia = authedMediaSupported;
// Ready to use! Start by loading rooms.
this.initClient();
return user;
@ -391,7 +399,7 @@ export default {
Vue.set(
room,
"avatar",
room.getAvatarUrl(this.matrixClient.getHomeserverUrl(), 80, 80, "scale", true)
room.getAvatarUrl(this.matrixClient.getHomeserverUrl(), 80, 80, "scale", true, this.useAuthedMedia)
);
}
}
@ -517,7 +525,7 @@ export default {
});
updatedRooms.forEach((room) => {
if (!room.avatar) {
Vue.set(room, "avatar", room.getAvatarUrl(this.matrixClient.getHomeserverUrl(), 80, 80, "scale", true));
Vue.set(room, "avatar", room.getAvatarUrl(this.matrixClient.getHomeserverUrl(), 80, 80, "scale", true, this.useAuthedMedia));
}
});
Vue.set(this, "rooms", updatedRooms);
@ -1208,34 +1216,6 @@ export default {
}
},
getPublicUserInfo(userId) {
if (!userId) {
return Promise.reject("Invalid parameters");
}
const parts = userId.split(":");
if (parts.length != 2) {
return Promise.reject("Unknown home server");
}
const clientPromise = this.getPublicQueryMatrixClient();
let matrixClient;
return clientPromise
.then((client) => {
matrixClient = client;
return client.getProfileInfo(userId);
})
.then((response) => {
if (response.avatar_url) {
response.avatar = matrixClient.mxcUrlToHttp(response.avatar_url, 80, 80, "scale", true);
}
return Promise.resolve(response);
})
.catch((err) => {
return Promise.reject("Failed to find user info: " + err);
});
},
getPublicRoomInfo(roomId) {
if (!roomId) {
return Promise.reject("Invalid parameters");
@ -1249,14 +1229,14 @@ export default {
const clientPromise = this.getPublicQueryMatrixClient();
const findOrGetMore = function _findOrGetMore(client, response) {
const findOrGetMore = function _findOrGetMore(client, useAuthedMedia, response) {
for (var room of response.chunk) {
if (
(roomId.startsWith("#") && room.canonical_alias == roomId) ||
(roomId.startsWith("!") && room.room_id == roomId)
) {
if (room.avatar_url) {
room.avatar = client.mxcUrlToHttp(room.avatar_url, 80, 80, "scale", true);
room.avatar = client.mxcUrlToHttp(room.avatar_url, 80, 80, "scale", true, undefined, useAuthedMedia);
}
return Promise.resolve(room);
}
@ -1280,13 +1260,18 @@ export default {
};
var matrixClient;
let useAuthedMedia = false;
return clientPromise
.then((client) => {
matrixClient = client;
return client.isVersionSupported("v1.11");
})
.then((version1_11) => {
useAuthedMedia = version1_11;
return matrixClient.publicRooms({ server: server, limit: 1000 });
})
.then((response) => {
return findOrGetMore(matrixClient, response);
return findOrGetMore(matrixClient, useAuthedMedia, response);
})
.catch((err) => {
return Promise.reject("Failed to find room: " + err);