Apply the auto-fixable lint rules and the formatter, and drop the Vite build artifacts.
This commit is contained in:
@@ -46,7 +46,7 @@ function isForumRootContent(content: Record<string, unknown>): boolean {
|
||||
|
||||
function syncForumRootContentAfterEdit(
|
||||
merged: Record<string, unknown>,
|
||||
baseContent: Record<string, unknown>
|
||||
baseContent: Record<string, unknown>,
|
||||
): Record<string, unknown> {
|
||||
if (!isForumRootContent(baseContent)) return merged;
|
||||
|
||||
@@ -77,7 +77,7 @@ function syncForumRootContentAfterEdit(
|
||||
|
||||
function getLatestEditContent(
|
||||
event: IRoomEvent,
|
||||
timelineEvents: IRoomEvent[]
|
||||
timelineEvents: IRoomEvent[],
|
||||
): Record<string, unknown> {
|
||||
const baseContent = event.content as Record<string, unknown>;
|
||||
const targetId = event.event_id;
|
||||
@@ -151,7 +151,7 @@ function sortRepliesRecursively(posts: ForumPost[]) {
|
||||
|
||||
function buildPosts(mx: MatrixClient, roomId: string, timelineEvents: IRoomEvent[]): ForumPost[] {
|
||||
const redactedIds = new Set(
|
||||
timelineEvents.filter((e) => e.unsigned?.redacted_because).map((e) => e.event_id)
|
||||
timelineEvents.filter((e) => e.unsigned?.redacted_because).map((e) => e.event_id),
|
||||
);
|
||||
|
||||
const normalized = timelineEvents
|
||||
@@ -160,7 +160,7 @@ function buildPosts(mx: MatrixClient, roomId: string, timelineEvents: IRoomEvent
|
||||
event.type === EventType.RoomMessage &&
|
||||
event.event_id &&
|
||||
event.content &&
|
||||
!redactedIds.has(event.event_id)
|
||||
!redactedIds.has(event.event_id),
|
||||
)
|
||||
.map((event) => {
|
||||
const rawContent = event.content as Record<string, unknown>;
|
||||
@@ -183,7 +183,7 @@ function buildPosts(mx: MatrixClient, roomId: string, timelineEvents: IRoomEvent
|
||||
});
|
||||
const room = mx.getRoom(roomId);
|
||||
const displayName = room
|
||||
? getMemberDisplayName(room, event.sender || '') ?? event.sender
|
||||
? (getMemberDisplayName(room, event.sender || '') ?? event.sender)
|
||||
: event.sender;
|
||||
|
||||
return {
|
||||
@@ -223,7 +223,7 @@ function buildPosts(mx: MatrixClient, roomId: string, timelineEvents: IRoomEvent
|
||||
const current = postsById.get(event.eventId);
|
||||
if (!current) continue;
|
||||
|
||||
const relation = event.relation;
|
||||
const { relation } = event;
|
||||
let threadRootId: string | null = null;
|
||||
let parentEventId: string | null = null;
|
||||
|
||||
@@ -271,7 +271,10 @@ function buildPosts(mx: MatrixClient, roomId: string, timelineEvents: IRoomEvent
|
||||
return roots.sort((a, b) => b.timestamp - a.timestamp);
|
||||
}
|
||||
|
||||
export async function listForumTopics(mx: MatrixClient, spaceRoomId: string): Promise<ForumTopic[]> {
|
||||
export async function listForumTopics(
|
||||
mx: MatrixClient,
|
||||
spaceRoomId: string,
|
||||
): Promise<ForumTopic[]> {
|
||||
const rooms: IHierarchyRoom[] = [];
|
||||
let nextBatch: string | undefined;
|
||||
for (let page = 0; page < 5; page += 1) {
|
||||
@@ -285,7 +288,8 @@ export async function listForumTopics(mx: MatrixClient, spaceRoomId: string): Pr
|
||||
for (const room of rooms) {
|
||||
if (!room?.room_id || !Array.isArray(room.children_state)) continue;
|
||||
for (const childState of room.children_state) {
|
||||
if (childState?.type !== 'm.space.child' || typeof childState.state_key !== 'string') continue;
|
||||
if (childState?.type !== 'm.space.child' || typeof childState.state_key !== 'string')
|
||||
continue;
|
||||
parentByRoomId.set(childState.state_key, room.room_id);
|
||||
}
|
||||
}
|
||||
@@ -339,7 +343,7 @@ export async function listForumTopics(mx: MatrixClient, spaceRoomId: string): Pr
|
||||
export async function listTopicFeedPosts(
|
||||
mx: MatrixClient,
|
||||
roomId: string,
|
||||
options: { from?: string; minRoots?: number } = {}
|
||||
options: { from?: string; minRoots?: number } = {},
|
||||
): Promise<{ posts: ForumPost[]; nextBatch: string | null }> {
|
||||
const pageSize = 40;
|
||||
const minRoots = options.minRoots ?? 8;
|
||||
@@ -352,7 +356,7 @@ export async function listTopicFeedPosts(
|
||||
roomId,
|
||||
nextBatch ?? null,
|
||||
pageSize,
|
||||
Direction.Backward
|
||||
Direction.Backward,
|
||||
);
|
||||
const chunk = [...(response.chunk || [])].reverse();
|
||||
const pagePosts = buildPosts(mx, roomId, chunk);
|
||||
@@ -437,7 +441,7 @@ function matrixEventToRoomEvent(mEvent: MatrixEvent): IRoomEvent {
|
||||
export function collectLocalThreadEvents(
|
||||
mx: MatrixClient,
|
||||
roomId: string,
|
||||
rootEventId: string
|
||||
rootEventId: string,
|
||||
): IRoomEvent[] {
|
||||
const rootId = rootEventId.trim();
|
||||
const room = mx.getRoom(roomId);
|
||||
@@ -524,7 +528,7 @@ function collectLocalRootPosts(mx: MatrixClient, roomId: string): IRoomEvent[] {
|
||||
export function loadPostThreadLocal(
|
||||
mx: MatrixClient,
|
||||
roomId: string,
|
||||
rootEventId: string
|
||||
rootEventId: string,
|
||||
): ForumPost | null {
|
||||
const rootId = rootEventId.trim();
|
||||
const events = collectLocalThreadEvents(mx, roomId, rootId);
|
||||
@@ -536,7 +540,7 @@ export function loadPostThreadLocal(
|
||||
async function fetchRootEvent(
|
||||
mx: MatrixClient,
|
||||
roomId: string,
|
||||
rootEventId: string
|
||||
rootEventId: string,
|
||||
): Promise<IRoomEvent | null> {
|
||||
const rootId = rootEventId.trim();
|
||||
if (!rootId) return null;
|
||||
@@ -556,7 +560,7 @@ async function fetchRootEvent(
|
||||
export async function loadPostThread(
|
||||
mx: MatrixClient,
|
||||
roomId: string,
|
||||
rootEventId: string
|
||||
rootEventId: string,
|
||||
): Promise<ForumPost | null> {
|
||||
const rootId = rootEventId.trim();
|
||||
const localEvents = collectLocalThreadEvents(mx, roomId, rootId);
|
||||
@@ -566,7 +570,7 @@ export async function loadPostThread(
|
||||
|
||||
const collectRelations = async (
|
||||
relationType: RelationType | null,
|
||||
eventType: EventType | null
|
||||
eventType: EventType | null,
|
||||
) => {
|
||||
let from: string | undefined;
|
||||
for (let page = 0; page < 20; page += 1) {
|
||||
@@ -610,7 +614,7 @@ export async function loadPostThread(
|
||||
|
||||
export async function loadAggregatedTopicFeed(
|
||||
mx: MatrixClient,
|
||||
scopes: Array<{ roomId: string; sectionTitle?: string; topicName?: string }>
|
||||
scopes: Array<{ roomId: string; sectionTitle?: string; topicName?: string }>,
|
||||
): Promise<ForumPost[]> {
|
||||
const allPosts: ForumPost[] = [];
|
||||
for (const scope of scopes) {
|
||||
@@ -639,7 +643,7 @@ export type ForumNewPostPayload = {
|
||||
export async function sendForumPost(
|
||||
mx: MatrixClient,
|
||||
roomId: string,
|
||||
post: ForumNewPostPayload
|
||||
post: ForumNewPostPayload,
|
||||
): Promise<string> {
|
||||
const title = post.title.trim();
|
||||
const plainText = post.plainText.trim();
|
||||
@@ -674,7 +678,7 @@ export async function sendForumMediaRoot(
|
||||
mx: MatrixClient,
|
||||
roomId: string,
|
||||
title: string,
|
||||
content: IContent
|
||||
content: IContent,
|
||||
): Promise<string> {
|
||||
const trimmedTitle = title.trim();
|
||||
if (!trimmedTitle) {
|
||||
@@ -697,7 +701,7 @@ export async function sendForumThreadAttachment(
|
||||
roomId: string,
|
||||
threadRootId: string,
|
||||
content: IContent,
|
||||
replyToEventId?: string
|
||||
replyToEventId?: string,
|
||||
): Promise<string> {
|
||||
const rootId = threadRootId.trim();
|
||||
const parentId = replyToEventId?.trim() || rootId;
|
||||
@@ -728,7 +732,7 @@ export function sendForumReply(
|
||||
roomId: string,
|
||||
threadRootId: string,
|
||||
replyToEventId: string,
|
||||
message: string | ForumReplyPayload
|
||||
message: string | ForumReplyPayload,
|
||||
): Promise<string> {
|
||||
const rootId = threadRootId.trim();
|
||||
const parentId = replyToEventId.trim() || rootId;
|
||||
@@ -741,8 +745,7 @@ export function sendForumReply(
|
||||
throw new Error('Reply message is required.');
|
||||
}
|
||||
|
||||
let formattedHtml =
|
||||
typeof message === 'string' ? '' : String(message.formattedHtml || '').trim();
|
||||
let formattedHtml = typeof message === 'string' ? '' : String(message.formattedHtml || '').trim();
|
||||
formattedHtml = formattedHtml.replace(/(<br\s*\/?>\s*)+$/gi, '');
|
||||
|
||||
const content: Record<string, unknown> = {
|
||||
@@ -769,13 +772,11 @@ export function createForumPostFromPayload(
|
||||
roomId: string,
|
||||
eventId: string,
|
||||
payload: ForumNewPostPayload,
|
||||
meta: { topicRoomId?: string; sectionTitle?: string; topicName?: string } = {}
|
||||
meta: { topicRoomId?: string; sectionTitle?: string; topicName?: string } = {},
|
||||
): ForumPost {
|
||||
const userId = mx.getUserId() || 'unknown';
|
||||
const room = mx.getRoom(roomId);
|
||||
const displayName = room
|
||||
? getMemberDisplayName(room, userId) ?? userId
|
||||
: userId;
|
||||
const displayName = room ? (getMemberDisplayName(room, userId) ?? userId) : userId;
|
||||
const title = payload.title.trim();
|
||||
const plainText = payload.plainText.trim();
|
||||
let formattedHtml = payload.formattedHtml.trim().replace(/(<br\s*\/?>\s*)+$/gi, '');
|
||||
@@ -792,7 +793,7 @@ export function createForumPostFromPayload(
|
||||
format: 'org.matrix.custom.html',
|
||||
formatted_body: `<h1>${escapeHtml(title)}</h1>${formattedHtml}`,
|
||||
},
|
||||
{ stripTitleHeading: true }
|
||||
{ stripTitleHeading: true },
|
||||
),
|
||||
sender: userId,
|
||||
senderDisplayName: displayName,
|
||||
@@ -810,15 +811,15 @@ export function createForumReplyFromPayload(
|
||||
roomId: string,
|
||||
eventId: string,
|
||||
replyToEventId: string,
|
||||
payload: ForumReplyPayload
|
||||
payload: ForumReplyPayload,
|
||||
): ForumPost {
|
||||
const userId = mx.getUserId() || 'unknown';
|
||||
const room = mx.getRoom(roomId);
|
||||
const displayName = room
|
||||
? getMemberDisplayName(room, userId) ?? userId
|
||||
: userId;
|
||||
const displayName = room ? (getMemberDisplayName(room, userId) ?? userId) : userId;
|
||||
const plainText = payload.plainText.trim();
|
||||
let formattedHtml = String(payload.formattedHtml || '').trim().replace(/(<br\s*\/?>\s*)+$/gi, '');
|
||||
const formattedHtml = String(payload.formattedHtml || '')
|
||||
.trim()
|
||||
.replace(/(<br\s*\/?>\s*)+$/gi, '');
|
||||
|
||||
const content: Record<string, unknown> = { body: plainText };
|
||||
if (formattedHtml) {
|
||||
|
||||
Reference in New Issue
Block a user