Fix the mechanical style rules. [skip build]

This commit is contained in:
2026-11-01 09:01:32 +11:00
parent 831ce01150
commit 9591d8d01b
42 changed files with 762 additions and 756 deletions
+110 -113
View File
@@ -174,6 +174,51 @@ export function initPaarrotAPI(matrixClient: MatrixClient) {
console.log('Paarrot API: Handler initialized');
}
/**
* Get the currently active room ID
* Extracts room ID from the current URL pathname
*/
function getCurrentRoomId(): string | null {
try {
// Get the pathname from URL
// Support both normal routing and hash routing
let { pathname } = window.location;
// If using hash router, parse from hash
if (window.location.hash) {
const hashMatch = window.location.hash.match(/#(.+)/);
if (hashMatch) {
pathname = hashMatch[1];
}
}
// URL patterns:
// /home/:roomIdOrAlias/:eventId?/
// /direct/:roomIdOrAlias/:eventId?/
// /:spaceIdOrAlias/:roomIdOrAlias/:eventId?/
// Try to match room patterns
const patterns = [
/^\/home\/([^/]+)/, // /home/:roomIdOrAlias
/^\/direct\/([^/]+)/, // /direct/:roomIdOrAlias
/^\/[^/]+\/([^/]+)/, // /:spaceIdOrAlias/:roomIdOrAlias (space rooms)
];
for (const pattern of patterns) {
const match = pathname.match(pattern);
if (match && match[1]) {
// Decode URI component in case the room ID was encoded
return decodeURIComponent(match[1]);
}
}
return null;
} catch (error) {
console.error('Paarrot API: Error getting current room ID:', error);
return null;
}
}
/**
* Get current app status
*/
@@ -483,49 +528,48 @@ function collectRecentMessages(room: any, limit: number): ApiMessage[] {
for (let i = liveEvents.length - 1; i >= 0 && messages.length < limit; i -= 1) {
const evt = liveEvents[i];
if (!evt) continue;
if (typeof evt.isRedacted === 'function' && evt.isRedacted()) continue;
if (reactionOrEditEvent(evt)) continue;
const type = evt.getType?.();
if (
type !== MessageEvent.RoomMessage &&
type !== MessageEvent.RoomMessageEncrypted &&
type !== MessageEvent.Sticker
evt &&
!(typeof evt.isRedacted === 'function' && evt.isRedacted()) &&
!reactionOrEditEvent(evt)
) {
continue;
const type = evt.getType?.();
if (
type === MessageEvent.RoomMessage ||
type === MessageEvent.RoomMessageEncrypted ||
type === MessageEvent.Sticker
) {
const content = evt.getContent?.() ?? {};
const sender = evt.getSender?.() ?? '';
const member = sender ? room.getMember?.(sender) : null;
if (type === MessageEvent.RoomMessageEncrypted && !content.msgtype) {
messages.push({
eventId: evt.getId?.() ?? '',
roomId,
roomName,
isDirect,
sender,
senderName: member?.name ?? sender,
timestamp: evt.getTs?.() ?? 0,
msgtype: 'm.encrypted',
body: '[encrypted]',
});
} else {
messages.push({
eventId: evt.getId?.() ?? '',
roomId,
roomName,
isDirect,
sender,
senderName: member?.name ?? sender,
timestamp: evt.getTs?.() ?? 0,
msgtype: content.msgtype || (type === MessageEvent.Sticker ? 'm.sticker' : 'm.text'),
body: content.body || '',
});
}
}
}
const content = evt.getContent?.() ?? {};
const sender = evt.getSender?.() ?? '';
const member = sender ? room.getMember?.(sender) : null;
if (type === MessageEvent.RoomMessageEncrypted && !content.msgtype) {
messages.push({
eventId: evt.getId?.() ?? '',
roomId,
roomName,
isDirect,
sender,
senderName: member?.name ?? sender,
timestamp: evt.getTs?.() ?? 0,
msgtype: 'm.encrypted',
body: '[encrypted]',
});
continue;
}
messages.push({
eventId: evt.getId?.() ?? '',
roomId,
roomName,
isDirect,
sender,
senderName: member?.name ?? sender,
timestamp: evt.getTs?.() ?? 0,
msgtype: content.msgtype || (type === MessageEvent.Sticker ? 'm.sticker' : 'm.text'),
body: content.body || '',
});
}
return messages.reverse();
@@ -592,35 +636,33 @@ async function getUnreadsByScope(matrixClient: any, scope: MessageScope) {
}> = [];
for (const room of rooms) {
if (getNotificationType(matrixClient, room.roomId) === NotificationType.Mute) {
continue;
}
if (!roomHaveNotification(room) && !roomHaveUnread(matrixClient, room)) {
continue;
}
if (
getNotificationType(matrixClient, room.roomId) !== NotificationType.Mute &&
(roomHaveNotification(room) || roomHaveUnread(matrixClient, room))
) {
const unreadInfo = getUnreadInfo(room);
const latestMessages = collectRecentMessages(room, 1);
const latest = latestMessages[0];
const unreadInfo = getUnreadInfo(room);
const latestMessages = collectRecentMessages(room, 1);
const latest = latestMessages[0];
unreads.push({
roomId: room.roomId,
name: room.name || 'Unnamed Room',
isDirect: isDirectRoom(room),
avatar: room.getMxcAvatarUrl?.() || null,
total: unreadInfo.total,
highlight: unreadInfo.highlight,
latest: latest
? {
eventId: latest.eventId,
sender: latest.sender,
senderName: latest.senderName,
timestamp: latest.timestamp,
msgtype: latest.msgtype,
body: latest.body,
}
: undefined,
});
unreads.push({
roomId: room.roomId,
name: room.name || 'Unnamed Room',
isDirect: isDirectRoom(room),
avatar: room.getMxcAvatarUrl?.() || null,
total: unreadInfo.total,
highlight: unreadInfo.highlight,
latest: latest
? {
eventId: latest.eventId,
sender: latest.sender,
senderName: latest.senderName,
timestamp: latest.timestamp,
msgtype: latest.msgtype,
body: latest.body,
}
: undefined,
});
}
}
unreads.sort((a, b) => {
@@ -638,49 +680,4 @@ async function getUnreadsByScope(matrixClient: any, scope: MessageScope) {
};
}
/**
* Get the currently active room ID
* Extracts room ID from the current URL pathname
*/
function getCurrentRoomId(): string | null {
try {
// Get the pathname from URL
// Support both normal routing and hash routing
let { pathname } = window.location;
// If using hash router, parse from hash
if (window.location.hash) {
const hashMatch = window.location.hash.match(/#(.+)/);
if (hashMatch) {
pathname = hashMatch[1];
}
}
// URL patterns:
// /home/:roomIdOrAlias/:eventId?/
// /direct/:roomIdOrAlias/:eventId?/
// /:spaceIdOrAlias/:roomIdOrAlias/:eventId?/
// Try to match room patterns
const patterns = [
/^\/home\/([^/]+)/, // /home/:roomIdOrAlias
/^\/direct\/([^/]+)/, // /direct/:roomIdOrAlias
/^\/[^/]+\/([^/]+)/, // /:spaceIdOrAlias/:roomIdOrAlias (space rooms)
];
for (const pattern of patterns) {
const match = pathname.match(pattern);
if (match && match[1]) {
// Decode URI component in case the room ID was encoded
return decodeURIComponent(match[1]);
}
}
return null;
} catch (error) {
console.error('Paarrot API: Error getting current room ID:', error);
return null;
}
}
export default { initPaarrotAPI };