Skip to content

Commit

Permalink
NapCat 分组信息支持
Browse files Browse the repository at this point in the history
💚 [build-electron]
  • Loading branch information
Stapxs committed May 11, 2024
1 parent b1c880b commit 6a897a8
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div id="base-app">
<div class="layui-tab layui-tab-brief main-body">
<ul class="layui-tab-title" :style="get('fs_adaptation') > 0 ? `padding-bottom: ${get('fs_adaptation')}px;` : ''">
<li @click="changeTab('主页', 'Home', true)" :class="loginInfo.status ? 'hiden-home' : 'layui-this'">
<li id="bar-home" @click="changeTab('主页', 'Home', true)" :class="loginInfo.status ? 'hiden-home' : 'layui-this'">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512">>
<path
d="M575.8 255.5c0 18-15 32.1-32 32.1h-32l.7 160.2c0 2.7-.2 5.4-.5 8.1V472c0 22.1-17.9 40-40 40H456c-1.1 0-2.2 0-3.3-.1c-1.4 .1-2.8 .1-4.2 .1H416 392c-22.1 0-40-17.9-40-40V448 384c0-17.7-14.3-32-32-32H256c-17.7 0-32 14.3-32 32v64 24c0 22.1-17.9 40-40 40H160 128.1c-1.5 0-3-.1-4.5-.2c-1.2 .1-2.4 .2-3.6 .2H104c-22.1 0-40-17.9-40-40V360c0-.9 0-1.9 .1-2.8V287.6H32c-18 0-32-14-32-32.1c0-9 3-17 10-24L266.4 8c7-7 15-8 22-8s15 2 21 7L564.8 231.5c8 7 12 15 11 24z" />
Expand Down
1 change: 1 addition & 0 deletions src/assets/l10n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@
"menu_unhide": "全部显示",
"menu_quit": "退出",
"menu_account": "账户",
"menu_login": "连接",
"menu_user_list": "用户列表({count})",
"menu_flush_user": "刷新列表…",
"menu_logout": "登出",
Expand Down
10 changes: 9 additions & 1 deletion src/assets/pathMap/NapCat.Onebot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,12 @@ set_message_read:
name: mark_group_msg_as_read
private_name: mark_private_msg_as_read
send_respond:
name: set_msg_emoji_like
name: set_msg_emoji_like
class_list:
name: get_friend_category
source: $.data[*]
list:
class_id: /categoryId
class_name: /categroyName
user_count: /categroyMbCount
list: /buddyList
13 changes: 12 additions & 1 deletion src/function/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ export class Connector {
// 加载初始化数据
// PS:标记登陆成功在获取用户信息的回调位置,防止无法获取到内容
Connector.send('get_version_info', {}, 'getVersionInfo')
// 更新菜单
updateMenu({
id: 'logout',
action: 'visible',
value: true
})
}
websocket.onmessage = (e) => {
// 心跳包输出到日志里太烦人了
Expand All @@ -86,10 +92,15 @@ export class Connector {
websocket.onclose = (e) => {
websocket = undefined
updateMenu({
id: 'account',
id: 'logout',
action: 'visible',
value: false
})
updateMenu({
id: 'userName',
action: 'label',
value: $t('menu_login')
})

switch(e.code) {
case 1000: break; // 正常关闭
Expand Down
19 changes: 6 additions & 13 deletions src/function/electron/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,13 @@ export function regIpcListener() {
{ label: args.selectAll, role: 'selectall' }
],
}, {
id: 'account',
label: args.account,
submenu: [
{ id: 'userName', label: '' },
{ id: 'userName', label: args.login },
{ id: 'logout', label: args.logout, visible: false, click: () => { sendMenuClick('bot:logout') } },
{ type: 'separator' },
{ id: 'userList', label: args.userList, click: () => { sendMenuClick('app:changeTab', 'Friends') } },
{ label: args.flushUser, click: () => { sendMenuClick('bot:flushUser') } },
{ type: 'separator' },
{ label: args.logout, click: () => { sendMenuClick('bot:logout') } }
{ label: args.flushUser, click: () => { sendMenuClick('bot:flushUser') } }
],
}, {
label: args.help,
Expand Down Expand Up @@ -306,15 +304,10 @@ export function regIpcListener() {
}
}
if (menuIndex > -1) {
const item = itemIndex > -1 ? template[menuIndex].submenu[itemIndex] : template[menuIndex]
switch (action) {
case 'label': itemIndex > -1 ?
template[menuIndex].submenu[itemIndex].label = value :
template[menuIndex].label = value
break
case 'visible': itemIndex > -1 ?
template[menuIndex].submenu[itemIndex].visible = value :
template[menuIndex].visible = value
break
case 'label': item.label = value; break
case 'visible': item.visible = value; break
}
}
Menu.setApplicationMenu(Menu.buildFromTemplate(template))
Expand Down
44 changes: 31 additions & 13 deletions src/function/msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,19 @@ function saveClassInfo(data: any) {
const names = [] as string[]
list.forEach((item: any) => {
names.push(Object.values(item)[0] as string)
// 如果分组 ID 没有返回在用户列表中而是在这儿……
if (item.list != undefined) {
item.list.forEach((user: any) => {
const user_id = Number(user.uin)
runtimeData.userList.forEach((get) => {
if (get.user_id == user_id) {
// 保存分组信息,特别关心(9999)优先覆盖
if(get.class_id == undefined || item.class_id == 9999)
get.class_id = item.class_id
}
})
})
}
})
const sortedData = names.sort(pinyin.compare)

Expand Down Expand Up @@ -722,6 +735,11 @@ function newMsg(data: any) {
const loginId = runtimeData.loginInfo.uin
const showId = runtimeData.chatInfo.show.id
const sender = info.sender
// 在好友列表里找一下他
const user = runtimeData.userList.find((item) => {
return item.user_id == id || item.group_id == id
})
const isImportant = user?.class_id == 9999

// 消息回调检查
// PS:如果在新消息中获取到了自己的消息,则自动打开“停止消息回调”设置防止发送的消息重复
Expand Down Expand Up @@ -813,8 +831,8 @@ function newMsg(data: any) {
if (data.sub_type === 'group') {
data.sender.nickname = data.sender.user_id
}
// (发送者不是自己 && (发送者不是群组 || 群组 AT || 群组 AT 全体 || 打开了通知全部消息)) 这些情况需要进行新消息处理
if (sender != loginId && (data.message_type !== 'group' || data.atme || data.atall || Option.get('notice_all') === true)) {
// (发送者不是自己 && (在特别关心列表里 || 发送者不是群组 || 群组 AT || 群组 AT 全体 || 打开了通知全部消息)) 这些情况需要进行新消息处理
if (sender != loginId && (isImportant || data.message_type !== 'group' || data.atme || data.atall || Option.get('notice_all') === true)) {
// (发送者没有被打开 || 窗口被最小化) 这些情况需要进行消息通知
if (id !== showId || document.hidden) {
// 准备消息内容
Expand Down Expand Up @@ -844,17 +862,17 @@ function newMsg(data: any) {
msgInfo.image = item.url
}
})
// // 检查这个用户是否有通知,有的话删除旧的
// // PS:这个处理逻辑主要用于防止大量消息刷大量的通知
// const index = notificationList.findIndex((item) => {
// const tag = item.tag
// const userId = Number(tag.split('/')[0])
// return userId === msg.user_id || userId === msg.group_id
// })
// if (index !== -1) {
// notificationList.splice(index, 1)
// notificationList[index].close()
// }
// 检查这个用户是否有通知,有的话删除旧的
// PS:这儿的是 web 通知,electron 通知在 electron 里处理
const index = notificationList.findIndex((item) => {
const tag = item.tag
const userId = Number(tag.split('/')[0])
return userId === id
})
if (index !== -1) {
notificationList.splice(index, 1)
notificationList[index].close()
}
// 发送消息
if (Option.get('close_notice') !== true) {
if (runtimeData.tags.isElectron) {
Expand Down
3 changes: 2 additions & 1 deletion src/function/utils/appUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,10 @@ export function createMenu() {
menuTitles.selectAll = $t('menu_select_all')

menuTitles.account = $t('menu_account')
menuTitles.login = $t('menu_login')
menuTitles.logout = $t('menu_logout')
menuTitles.userList = $t('menu_user_list', { count: runtimeData.userList.length })
menuTitles.flushUser = $t('menu_flush_user')
menuTitles.logout = $t('menu_logout')

menuTitles.help = $t('menu_help')
menuTitles.doc = $t('menu_doc')
Expand Down
16 changes: 8 additions & 8 deletions src/pages/Friends.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@
</div>
<div :class="(runtimeData.tags.openSideBar ? 'open' : '')">
<template v-if="runtimeData.showList.length <= 0">
<template v-for="name in runtimeData.tags.classes"
:key="'class-' + Object.keys(name)[0]">
<div :class="'list exp-body' + (classStatus[Object.keys(name)[0]] == true ? ' open' : '')">
<header :title="(Object.values(name)[0] as string)" :class="'exp-header' + (runtimeData.tags.openSideBar ? ' open' : '')" @click="classClick(Object.keys(name)[0])">
<template v-for="info in runtimeData.tags.classes"
:key="'class-' + info.class_id">
<div :class="'list exp-body' + (classStatus[info.class_id] == true ? ' open' : '')">
<header :title="info.class_name" :class="'exp-header' + (runtimeData.tags.openSideBar ? ' open' : '')" @click="classClick(info.class_id)">
<div></div>
<span>{{ Object.values(name)[0] }}</span>
<a>{{ runtimeData.userList.filter((get) => { return get.class_id == Number(Object.keys(name)[0]) }).length }}</a>
<span>{{ info.class_name }}</span>
<a>{{ info.user_count ?? runtimeData.userList.filter((get) => { return get.class_id == info.class_id }).length }}</a>
</header>
<div :id="'class-' + Object.keys(name)[0]">
<div :id="'class-' + info.class_id">
<FriendBody
v-for="item in runtimeData.userList.filter((get) => { return get.class_id == Number(Object.keys(name)[0]) })"
v-for="item in runtimeData.userList.filter((get) => { return get.class_id == info.class_id })"
:key="'fb-' + (item.user_id ? item.user_id : item.group_id)" :data="item"
@click="userClick(item, $event)">
</FriendBody>
Expand Down

0 comments on commit 6a897a8

Please sign in to comment.