refactor: write method signature

This commit is contained in:
Wesley F. Young 2024-10-13 17:18:05 +08:00
parent d320550080
commit 7f764625fe

View File

@ -11,52 +11,52 @@ export class LaanaMessageActionImpl {
) {} ) {}
handler: LaanaActionHandler = { handler: LaanaActionHandler = {
sendMessage: async (params) => { sendMessage: async ({ message, targetPeer }) => {
return { msgId: await this.sendMessage(params.message!, params.targetPeer!) }; return { msgId: await this.sendMessage(message!, targetPeer!) };
}, },
getMessage: async (params) => { getMessage: async ({ msgId }) => {
return { message: await this.getMessage(params.msgId) }; return { message: await this.getMessage(msgId) };
}, },
getMessages: async (params) => { getMessages: async ({ msgIds }) => {
if (params.msgIds.length === 0) { if (msgIds.length === 0) {
throw new Error('消息 ID 列表不能为空'); throw new Error('消息 ID 列表不能为空');
} }
return { messages: await this.getMessages(params.msgIds) }; return { messages: await this.getMessages(msgIds) };
}, },
getForwardedMessages: async (params) => { getForwardedMessages: async ({ refId }) => {
return { return {
forwardMessage: { forwardMessage: {
refId: params.refId, refId,
messages: await this.getForwardedMessages(params.refId) messages: await this.getForwardedMessages(refId)
} }
}; };
}, },
getHistoryMessages: async (params) => { getHistoryMessages: async ({ targetPeer, lastMsgId, count }) => {
return { messages: await this.getHistoryMessages(params.targetPeer!, params.lastMsgId, params.count) }; return { messages: await this.getHistoryMessages(targetPeer!, lastMsgId!, count) };
}, },
withdrawMessage: async (params) => { withdrawMessage: async ({ msgId }) => {
await this.withdrawMessage(params.msgId); await this.withdrawMessage(msgId);
return { success: true }; return { success: true };
}, },
markPeerMessageAsRead: async (params) => { markPeerMessageAsRead: async ({ peer }) => {
await this.markPeerMessageAsRead(params.peer!); await this.markPeerMessageAsRead(peer!);
return { success: true }; return { success: true };
}, },
forwardMessage: async (params) => { forwardMessage: async ({ msgIds, targetPeer, operation }) => {
if (params.msgIds.length === 0) { if (msgIds.length === 0) {
throw new Error('消息 ID 列表不能为空'); throw new Error('消息 ID 列表不能为空');
} }
if (params.operation === ForwardMessagePing_Operation.AS_SINGLETONS) { if (operation === ForwardMessagePing_Operation.AS_SINGLETONS) {
await this.forwardMessageAsSingletons(params.msgIds, params.targetPeer!); await this.forwardMessageAsSingletons(msgIds, targetPeer!);
} else { } else {
await this.forwardMessageAsPacked(params.msgIds, params.targetPeer!); await this.forwardMessageAsPacked(msgIds, targetPeer!);
} }
return { success: true }; return { success: true };
}, },