Add eslint

This commit is contained in:
2026-03-03 22:56:12 +01:00
parent d641229f9d
commit ad0e28bf84
92 changed files with 2656 additions and 1127 deletions

View File

@@ -8,6 +8,7 @@
* The giant `incomingMessages$` switch-case has been replaced by a
* handler registry in `messages-incoming.handlers.ts`.
*/
/* eslint-disable @typescript-eslint/member-ordering */
import { Injectable, inject } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Store } from '@ngrx/store';
@@ -25,7 +26,7 @@ import { Message, Reaction } from '../../core/models';
import { hydrateMessages } from './messages.helpers';
import {
dispatchIncomingMessage,
IncomingMessageContext,
IncomingMessageContext
} from './messages-incoming.handlers';
@Injectable()
@@ -45,14 +46,15 @@ export class MessagesEffects {
from(this.db.getMessages(roomId)).pipe(
mergeMap(async (messages) => {
const hydrated = await hydrateMessages(messages, this.db);
return MessagesActions.loadMessagesSuccess({ messages: hydrated });
}),
catchError((error) =>
of(MessagesActions.loadMessagesFailure({ error: error.message })),
),
),
),
),
of(MessagesActions.loadMessagesFailure({ error: error.message }))
)
)
)
)
);
/** Constructs a new message, persists it locally, and broadcasts to all peers. */
@@ -61,7 +63,7 @@ export class MessagesEffects {
ofType(MessagesActions.sendMessage),
withLatestFrom(
this.store.select(selectCurrentUser),
this.store.select(selectCurrentRoom),
this.store.select(selectCurrentRoom)
),
mergeMap(([{ content, replyToId, channelId }, currentUser, currentRoom]) => {
if (!currentUser || !currentRoom) {
@@ -78,7 +80,7 @@ export class MessagesEffects {
timestamp: this.timeSync.now(),
reactions: [],
isDeleted: false,
replyToId,
replyToId
};
this.db.saveMessage(message);
@@ -87,9 +89,9 @@ export class MessagesEffects {
return of(MessagesActions.sendMessageSuccess({ message }));
}),
catchError((error) =>
of(MessagesActions.sendMessageFailure({ error: error.message })),
),
),
of(MessagesActions.sendMessageFailure({ error: error.message }))
)
)
);
/** Edits an existing message (author-only), updates DB, and broadcasts the change. */
@@ -107,22 +109,24 @@ export class MessagesEffects {
if (!existing) {
return of(MessagesActions.editMessageFailure({ error: 'Message not found' }));
}
if (existing.senderId !== currentUser.id) {
return of(MessagesActions.editMessageFailure({ error: 'Cannot edit others messages' }));
}
const editedAt = this.timeSync.now();
this.db.updateMessage(messageId, { content, editedAt });
this.webrtc.broadcastMessage({ type: 'message-edited', messageId, content, editedAt });
return of(MessagesActions.editMessageSuccess({ messageId, content, editedAt }));
}),
catchError((error) =>
of(MessagesActions.editMessageFailure({ error: error.message })),
),
of(MessagesActions.editMessageFailure({ error: error.message }))
)
);
}),
),
})
)
);
/** Soft-deletes a message (author-only), marks it deleted in DB, and broadcasts. */
@@ -140,6 +144,7 @@ export class MessagesEffects {
if (!existing) {
return of(MessagesActions.deleteMessageFailure({ error: 'Message not found' }));
}
if (existing.senderId !== currentUser.id) {
return of(MessagesActions.deleteMessageFailure({ error: 'Cannot delete others messages' }));
}
@@ -150,11 +155,11 @@ export class MessagesEffects {
return of(MessagesActions.deleteMessageSuccess({ messageId }));
}),
catchError((error) =>
of(MessagesActions.deleteMessageFailure({ error: error.message })),
),
of(MessagesActions.deleteMessageFailure({ error: error.message }))
)
);
}),
),
})
)
);
/** Soft-deletes any message (admin+ only). */
@@ -182,9 +187,9 @@ export class MessagesEffects {
return of(MessagesActions.deleteMessageSuccess({ messageId }));
}),
catchError((error) =>
of(MessagesActions.deleteMessageFailure({ error: error.message })),
),
),
of(MessagesActions.deleteMessageFailure({ error: error.message }))
)
)
);
/** Adds an emoji reaction to a message, persists it, and broadcasts to peers. */
@@ -193,7 +198,8 @@ export class MessagesEffects {
ofType(MessagesActions.addReaction),
withLatestFrom(this.store.select(selectCurrentUser)),
mergeMap(([{ messageId, emoji }, currentUser]) => {
if (!currentUser) return EMPTY;
if (!currentUser)
return EMPTY;
const reaction: Reaction = {
id: uuidv4(),
@@ -201,15 +207,15 @@ export class MessagesEffects {
oderId: currentUser.id,
userId: currentUser.id,
emoji,
timestamp: this.timeSync.now(),
timestamp: this.timeSync.now()
};
this.db.saveReaction(reaction);
this.webrtc.broadcastMessage({ type: 'reaction-added', messageId, reaction });
return of(MessagesActions.addReactionSuccess({ reaction }));
}),
),
})
)
);
/** Removes the current user's reaction from a message, deletes from DB, and broadcasts. */
@@ -218,25 +224,26 @@ export class MessagesEffects {
ofType(MessagesActions.removeReaction),
withLatestFrom(this.store.select(selectCurrentUser)),
mergeMap(([{ messageId, emoji }, currentUser]) => {
if (!currentUser) return EMPTY;
if (!currentUser)
return EMPTY;
this.db.removeReaction(messageId, currentUser.id, emoji);
this.webrtc.broadcastMessage({
type: 'reaction-removed',
messageId,
oderId: currentUser.id,
emoji,
emoji
});
return of(
MessagesActions.removeReactionSuccess({
messageId,
oderId: currentUser.id,
emoji,
}),
emoji
})
);
}),
),
})
)
);
/**
@@ -247,7 +254,7 @@ export class MessagesEffects {
this.webrtc.onMessageReceived.pipe(
withLatestFrom(
this.store.select(selectCurrentUser),
this.store.select(selectCurrentRoom),
this.store.select(selectCurrentRoom)
),
mergeMap(([event, currentUser, currentRoom]: [any, any, any]) => {
const ctx: IncomingMessageContext = {
@@ -255,10 +262,11 @@ export class MessagesEffects {
webrtc: this.webrtc,
attachments: this.attachments,
currentUser,
currentRoom,
currentRoom
};
return dispatchIncomingMessage(event, ctx);
}),
),
})
)
);
}