Skip to content

Commit

Permalink
feat(chat): initialize message service
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 15, 2022
1 parent 775989c commit 189f5a5
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 52 deletions.
14 changes: 4 additions & 10 deletions plugins/frontend/chat/client/chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<virtual-list :data="filtered" pinned v-model:active-key="index" key-name="messageId">
<template #header><div class="header-padding"></div></template>
<template #="data">
<chat-message @click="handleClick(data)" :successive="isSuccessive(data, data.index)" :data="data"></chat-message>
<chat-message :successive="isSuccessive(data, data.index)" :data="data"></chat-message>
</template>
<template #footer><div class="footer-padding"></div></template>
</virtual-list>
Expand Down Expand Up @@ -46,7 +46,6 @@ import ChatMessage from './message.vue'
const pinned = ref(true)
const index = ref<string>()
const activeMessage = ref<Message>()
const messages = storage.create<Message[]>('chat', [])
const current = ref<string>('')
Expand Down Expand Up @@ -93,15 +92,10 @@ function isSuccessive({ quote, userId, channelId }: Message, index: number) {
return !quote && !!prev && prev.userId === userId && prev.channelId === channelId
}
function handleClick(message: Message) {
activeMessage.value = message
}
function handleSend(content: string) {
if (!activeMessage.value) return
pinned.value = false
const { platform, selfId, channelId, guildId } = activeMessage.value
send('chat', { content, platform, selfId, channelId, guildId })
if (!current.value) return
const [platform, guildId, channelId] = current.value.split(':')
send('chat', { content, platform, channelId, guildId })
}
</script>
Expand Down
9 changes: 6 additions & 3 deletions plugins/frontend/chat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ declare module 'koishi' {
interface ChatPayload {
content: string
platform: string
selfId: string
channelId: string
guildId: string
}
Expand Down Expand Up @@ -44,6 +43,8 @@ const defaultOptions: Config = {

export const name = 'chat'

export const using = ['database'] as const

export interface Config extends ClientExtension {
refresh?: RefreshConfig
logLevel?: number
Expand Down Expand Up @@ -90,9 +91,11 @@ export function apply(ctx: Context, options: Config = {}) {
prod: resolve(__dirname, '../dist'),
})

ctx.console.addListener('chat', async ({ content, platform, selfId, channelId, guildId }) => {
ctx.console.addListener('chat', async ({ content, platform, channelId, guildId }) => {
if (ctx.assets) content = await ctx.assets.transform(content)
ctx.bots.get(`${platform}:${selfId}`)?.sendMessage(channelId, content, guildId)
const channel = await ctx.database.getChannel(platform, channelId, ['assignee'])
if (!channel || !channel.assignee) return
ctx.bots.get(`${platform}:${channel.assignee}`)?.sendMessage(channelId, content, guildId)
}, { authority: 3 })

ctx.on('chat/receive', async (message) => {
Expand Down
3 changes: 1 addition & 2 deletions plugins/frontend/client/client/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ export * from './form'
export * from './layout'
export * from './notice'

export * from '@satorijs/ui-chat'
export * from '@satorijs/ui-virtual'
export * from '@satorijs/components'

export { icons, ChatImage }

Expand Down
3 changes: 1 addition & 2 deletions plugins/frontend/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
],
"dependencies": {
"@koishijs/segment": "^1.1.1",
"@satorijs/ui-chat": "^0.3.0",
"@satorijs/ui-virtual": "^0.3.0",
"@satorijs/components": "^0.3.0",
"@types/marked": "^4.0.3",
"@vitejs/plugin-vue": "^2.3.1",
"@vueuse/core": "^7.7.1",
Expand Down
9 changes: 0 additions & 9 deletions plugins/messages/package.json

This file was deleted.

16 changes: 0 additions & 16 deletions plugins/messages/src/types.ts

This file was deleted.

10 changes: 0 additions & 10 deletions plugins/messages/tsconfig.json

This file was deleted.

0 comments on commit 189f5a5

Please sign in to comment.