feat(api): implement message.list

This commit is contained in:
Il Harper 2024-03-08 17:01:07 +08:00
parent bf14ad477f
commit df371ce674
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
7 changed files with 60 additions and 3 deletions

View File

@ -0,0 +1,13 @@
import type {
ChronocatContext,
MessageListPayload,
MessageListResponse,
} from '@chronocat/shell'
export const buildMessageList =
(_ctx: ChronocatContext) =>
async (_: MessageListPayload): Promise<MessageListResponse> => {
return {
data: [],
}
}

View File

@ -18,6 +18,7 @@ import { buildLoginGet } from './api/login/get'
import { buildMessageCreate } from './api/message/create'
import { buildMessageDelete } from './api/message/delete'
import { buildMessageGet } from './api/message/get'
import { buildMessageList } from './api/message/list'
import { buildUserChannelCreate } from './api/user/channel/create'
import { buildHandler } from './handler'
@ -49,6 +50,7 @@ export const apply = async (ctx: ChronocatContext) => {
register('message.create', buildMessageCreate(ctx))
register('message.get', buildMessageGet(ctx))
register('message.delete', buildMessageDelete(ctx))
register('message.list', buildMessageList(ctx))
register('login.get', buildLoginGet(ctx))
register('chronocat.internal.message.create.forward', buildMessageCreate(ctx))

View File

@ -16,7 +16,7 @@ import { guildRemove } from './guild/remove'
import { messageCreate } from './message/create'
import { messageDelete } from './message/delete'
import { messageGet } from './message/get'
// import { messageList } from './message/list'
import { messageList } from './message/list'
import { notImplemented } from './notimpl'
import type { Route } from './types'
import { userChannelCreate } from './user/channel/create'
@ -50,7 +50,7 @@ const routesIntl = {
'message.get': messageGet,
'message.delete': messageDelete,
'message.update': notImplemented,
// 'message.list': messageList,
'message.list': messageList,
'reaction.create': notImplemented,
'reaction.delete': notImplemented,
'reaction.clear': notImplemented,

View File

@ -0,0 +1,29 @@
import type { MessageListPayload } from '../../types'
import type { RouteContext } from '../types'
export const messageList = async ({
cctx,
path,
req,
res,
json,
}: RouteContext) => {
const payload = (await json()) as MessageListPayload
const validateResult =
await cctx.chronocat.validate('MessageListPayload')(payload)
if (validateResult) {
const err = `解析 ${path} 请求时出现问题,来自 ${req.socket.remoteAddress}${validateResult}`
cctx.chronocat.l.error(err, {
code: 400,
})
res.writeHead(400)
res.end(`400 bad request\n${err}`)
return
}
return await cctx.chronocat.api['message.list'](payload)
}

View File

@ -1,4 +1,4 @@
import type { Channel, Guild, GuildMember, User } from './satoriEntity'
import type { Channel, Guild, GuildMember, Message, User } from './satoriEntity'
export interface Next {
/**
@ -83,6 +83,14 @@ export interface MessageGetPayload {
message_id: string
}
export interface MessageListPayload extends Next {
channel_id: string
}
export interface MessageListResponse extends Next {
data: Message[]
}
export interface ChannelMutePayload {
channel_id: string
enable: boolean

View File

@ -18,6 +18,8 @@ export type {
GuildRemovePayload,
MessageDeletePayload,
MessageGetPayload,
MessageListPayload,
MessageListResponse,
Next,
UserGetPayload,
UserPayload,

View File

@ -27,6 +27,8 @@ import type {
MessageCreatePayload,
MessageDeletePayload,
MessageGetPayload,
MessageListPayload,
MessageListResponse,
UserPayload,
} from './satori/types'
import type { api } from './services/api'
@ -118,6 +120,7 @@ export interface Methods {
]
'message.get': [[MessageGetPayload], Message]
'message.delete': [[MessageDeletePayload], Record<string, never>]
'message.list': [[MessageListPayload], MessageListResponse]
'login.get': [[], Login]