support matrix.to links (#1849)

* support room via server params and eventId

* change copy link to matrix.to links

* display matrix.to links in messages as pill and stop generating url previews for them

* improve editor mention to include viaServers and eventId

* fix mention custom attributes

* always try to open room in current space

* jump to latest remove target eventId from url

* add create direct search options to open/create dm with url
This commit is contained in:
Ajay Bura 2024-07-30 17:48:59 +05:30 committed by GitHub
parent 74dc76e22e
commit 5058136737
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 781 additions and 476 deletions

View file

@ -95,67 +95,11 @@ export function joinRuleToIconSrc(joinRule, isSpace) {
}[joinRule]?.() || null);
}
// NOTE: it gives userId with minimum power level 50;
function getHighestPowerUserId(room) {
const userIdToPower = room.currentState.getStateEvents('m.room.power_levels', '')?.getContent().users;
let powerUserId = null;
if (!userIdToPower) return powerUserId;
Object.keys(userIdToPower).forEach((userId) => {
if (userIdToPower[userId] < 50) return;
if (powerUserId === null) {
powerUserId = userId;
return;
}
if (userIdToPower[userId] > userIdToPower[powerUserId]) {
powerUserId = userId;
}
});
return powerUserId;
}
export function getIdServer(userId) {
const idParts = userId.split(':');
return idParts[1];
}
export function getServerToPopulation(room) {
const members = room.getMembers();
const serverToPop = {};
members?.forEach((member) => {
const { userId } = member;
const server = getIdServer(userId);
const serverPop = serverToPop[server];
if (serverPop === undefined) {
serverToPop[server] = 1;
return;
}
serverToPop[server] = serverPop + 1;
});
return serverToPop;
}
export function genRoomVia(room) {
const via = [];
const userId = getHighestPowerUserId(room);
if (userId) {
const server = getIdServer(userId);
if (server) via.push(server);
}
const serverToPop = getServerToPopulation(room);
const sortedServers = Object.keys(serverToPop).sort(
(svrA, svrB) => serverToPop[svrB] - serverToPop[svrA],
);
const mostPop3 = sortedServers.slice(0, 3);
if (via.length === 0) return mostPop3;
if (mostPop3.includes(via[0])) {
mostPop3.splice(mostPop3.indexOf(via[0]), 1);
}
return via.concat(mostPop3.slice(0, 2));
}
export function isCrossVerified(mx, deviceId) {
try {
const crossSignInfo = mx.getStoredCrossSigningForUser(mx.getUserId());