Use partial entity for message update + Fix backend deps intellisense

This commit is contained in:
ADAMJR 2021-12-23 16:32:04 +00:00
parent 87356994d3
commit 63638b0cea
4 changed files with 15 additions and 10 deletions

View File

@ -1,23 +1,26 @@
import { WS } from '@accord/types';
import { Entity, WS } from '@accord/types';
import { Socket } from 'socket.io';
import { WebSocket } from '../websocket';
import { WSEvent, } from './ws-event';
export default class implements WSEvent<'MESSAGE_UPDATE'> {
on = 'MESSAGE_UPDATE' as const;
public on = 'MESSAGE_UPDATE' as const;
public async invoke(ws: WebSocket, client: Socket, { messageId, content, embed }: WS.Params.MessageUpdate) {
const message = await deps.messages.get(messageId);
deps.wsGuard.validateIsUser(client, message.authorId);
if (content) message.content = content;
message.updatedAt = new Date();
const partial: Partial<Entity.Message> = {};
if (content) partial.content = content;
partial.updatedAt = new Date();
Object.assign(message, partial);
await message.save();
return [{
emit: this.on,
to: [message.channelId],
send: { message },
send: { messageId, partialMessage: partial },
}];
}
}

View File

@ -1,5 +1,5 @@
declare global {
const log: import('winston').Logger;
const deps: import('./deps').Deps;
const deps: import('../src/modules/deps').Deps;
}
export {}

View File

@ -25,8 +25,8 @@ const slice = createSlice({
total[payload.channelId]--;
},
updated: ({ list }, { payload }: Store.Action<WS.Args.MessageUpdate>) => {
const message = list.find(m => m.id === payload.message.id);
Object.assign(message, payload.message);
const message = list.find(m => m.id === payload.messageId);
Object.assign(message, payload.partialMessage);
},
},
});

View File

@ -345,8 +345,10 @@ export declare namespace WS {
messageId: string;
}
export interface MessageUpdate {
/** Full object of the message that was updated. */
message: Entity.Message;
/** ID of the message that was updated. */
messageId: string;
/** Objects with updated properties from the updated message. */
partialMessage: Entity.Message;
}
export interface Ping {
channelId: string;