Skip to content

Commit 0da570e

Browse files
committed
feat(chat): inspect guild, channel and message
1 parent be0a514 commit 0da570e

File tree

3 files changed

+89
-10
lines changed

3 files changed

+89
-10
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"shx": "^0.3.4",
3030
"typescript": "^5.4.3",
3131
"yakumo": "^1.0.0-beta.15",
32-
"yakumo-esbuild": "^1.0.0-beta.5",
32+
"yakumo-esbuild": "^1.0.0-beta.6",
3333
"yakumo-mocha": "^1.0.0-beta.2",
3434
"yakumo-tsc": "^1.0.0-beta.3",
3535
"yml-register": "^1.2.5"

packages/chat/client/index.ts

+21
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ declare module '@cordisjs/client' {
1111
interface Context {
1212
chat: ChatService
1313
}
14+
15+
interface ActionContext {
16+
'chat.guild': Universal.Guild
17+
'chat.channel': Universal.Channel
18+
'chat.message': Universal.Message
19+
}
1420
}
1521

1622
interface CachedLogin {
@@ -77,12 +83,27 @@ export default class ChatService extends Service {
7783
component: Chat,
7884
})
7985

86+
ctx.menu('chat.guild', [{
87+
id: '.inspect',
88+
label: '查看群组信息',
89+
}])
90+
91+
ctx.menu('chat.channel', [{
92+
id: '.inspect',
93+
label: '查看频道信息',
94+
}])
95+
8096
ctx.menu('chat.message', [{
8197
id: '.delete',
8298
label: '删除消息',
8399
}, {
84100
id: '.quote',
85101
label: '引用回复',
102+
}, {
103+
id: '@separator',
104+
}, {
105+
id: '.inspect',
106+
label: '查看频道信息',
86107
}])
87108
})
88109
}

packages/chat/client/index.vue

+67-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<k-layout>
2+
<k-layout :title="channelName || '聊天'">
33
<template #left>
44
<div class="header flex grow-0 shrink-0 box-border">
55
<template v-if="guildKey">
@@ -20,6 +20,7 @@
2020
class="flex px-4 py-1 items-center
2121
bg-gray-700 bg-op-0 hover:bg-op-100 transition cursor-pointer"
2222
@click="setChannel(channel)"
23+
@contextmenu.stop="triggerChannel($event, channel)"
2324
>
2425
{{ channel.name }}
2526
</div>
@@ -29,6 +30,7 @@
2930
class="flex px-4 py-3 gap-x-4 justify-between
3031
bg-gray-700 bg-op-0 hover:bg-op-100 transition cursor-pointer"
3132
@click="setGuild(guild)"
33+
@contextmenu.stop="triggerGuild($event, guild)"
3234
>
3335
<img v-if="guild.avatar" :src="withProxy(guild.avatar)" width="48" height="48" class="b-rd-full"/>
3436
<div v-else
@@ -47,9 +49,13 @@
4749

4850
<template v-if="channelId">
4951
<el-scrollbar>
50-
<div v-for="message in messages" :key="message.id" class="message">
52+
<div v-if="messages?.prev">正在加载更多消息……</div>
53+
<div v-for="message in messages?.data" :key="message.id" class="message"
54+
@contextmenu.stop="triggerMessage($event, message)">
55+
{{ message.id }}
5156
<message-content :content="message.content!"></message-content>
5257
</div>
58+
<div v-if="messages?.next">正在加载更多消息……</div>
5359
</el-scrollbar>
5460
<div class="footer shrink-0">
5561
<chat-input class="h-6 px-4 py-2" v-model="input" @send="handleSend" placeholder="发送消息"></chat-input>
@@ -59,12 +65,44 @@
5965
<k-empty>选择一个频道开始聊天</k-empty>
6066
</template>
6167
</k-layout>
68+
69+
<el-dialog
70+
title="群组信息"
71+
:model-value="!!showGuild"
72+
@update:model-value="showGuild = undefined"
73+
destroy-on-close>
74+
<ul v-if="showGuild">
75+
<li>群组 ID: {{ showGuild.id }}</li>
76+
<li>群组名称: {{ showGuild.name }}</li>
77+
</ul>
78+
</el-dialog>
79+
80+
<el-dialog
81+
title="频道信息"
82+
:model-value="!!showChannel"
83+
@update:model-value="showChannel = undefined"
84+
destroy-on-close>
85+
<ul v-if="showChannel">
86+
<li>频道 ID: {{ showChannel.id }}</li>
87+
<li>频道名称: {{ showChannel.name }}</li>
88+
</ul>
89+
</el-dialog>
90+
91+
<el-dialog
92+
title="消息信息"
93+
:model-value="!!showMessage"
94+
@update:model-value="showMessage = undefined"
95+
destroy-on-close>
96+
<ul v-if="showMessage">
97+
<li>消息 ID: {{ showMessage.id }}</li>
98+
</ul>
99+
</el-dialog>
62100
</template>
63101

64102
<script lang="ts" setup>
65103
66104
import { ref } from 'vue'
67-
import { useContext, useRpc } from '@cordisjs/client'
105+
import { useContext, useRpc, useMenu } from '@cordisjs/client'
68106
import type { Data } from '../src'
69107
import { Universal } from '@satorijs/core'
70108
import { ChatInput, MessageContent } from '@satorijs/components-vue'
@@ -75,11 +113,32 @@ const ctx = useContext()
75113
const platform = ref<string>()
76114
const guildKey = ref<string>()
77115
const channelId = ref<string>()
116+
const channelName = ref<string>()
78117
const channels = ref<Universal.Channel[]>([])
79-
const messages = ref<Universal.Message[]>([])
118+
const messages = ref<Universal.TwoWayList<Universal.Message>>()
80119
81120
const input = ref('')
82121
122+
const showGuild = ref<Universal.Guild>()
123+
const showChannel = ref<Universal.Channel>()
124+
const showMessage = ref<Universal.Message>()
125+
126+
const triggerGuild = useMenu('chat.guild')
127+
const triggerChannel = useMenu('chat.channel')
128+
const triggerMessage = useMenu('chat.message')
129+
130+
ctx.action('chat.guild.inspect', async ({ chat }) => {
131+
showGuild.value = chat.guild
132+
})
133+
134+
ctx.action('chat.channel.inspect', async ({ chat }) => {
135+
showChannel.value = chat.channel
136+
})
137+
138+
ctx.action('chat.message.inspect', async ({ chat }) => {
139+
showMessage.value = chat.message
140+
})
141+
83142
function short(name: string) {
84143
return name.slice(0, 2)
85144
}
@@ -101,11 +160,10 @@ async function setGuild(guild?: Universal.Guild & { platform: string; assignees:
101160
102161
async function setChannel(channel: Universal.Channel) {
103162
channelId.value = channel.id
104-
messages.value = []
105-
for await (const message of ctx.bots[ctx.chat.guilds.value[guildKey.value!].assignees[0]].getMessageIter(channel.id)) {
106-
if (channelId.value !== channel.id || messages.value.length >= 100) return
107-
messages.value.unshift(message)
108-
}
163+
messages.value = undefined
164+
const result = await ctx.bots[ctx.chat.guilds.value[guildKey.value!].assignees[0]].getMessageList(channel.id)
165+
result.next = undefined
166+
if (channelId.value === channel.id) messages.value = result
109167
}
110168
111169
function handleSend(content: string) {

0 commit comments

Comments
 (0)