Skip to content

Commit

Permalink
打工人的痛
Browse files Browse the repository at this point in the history
♿ 支持分离式和非分离式的好友群列表
✨ 支持 napcat 1.8.0 获取历史会话列表
✨ 支持 napcat 1.8.0 显示好友签名,优化好友列表显示
💩 去除分离式分组信息支持
  • Loading branch information
Stapxs committed Aug 6, 2024
1 parent b3750fc commit a9e850a
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 91 deletions.
2 changes: 2 additions & 0 deletions src/assets/css/view.css
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ textarea:focus {
font-size: 0.9rem;
flex: 1;
}
/* .friend-body > div > div a.nick {
} */
.friend-body.active > div > div a {
color: var(--color-font-1-r);
}
Expand Down
1 change: 1 addition & 0 deletions src/assets/pathMap/Lagrange.OneBot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ login_info:
nickname: $.data.nickname
# 群、好友列表
user_list:
name: get_friend_list|get_group_list
source: $.data[*]
list:
group_id: /group_id
Expand Down
38 changes: 22 additions & 16 deletions src/assets/pathMap/NapCat.Onebot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ login_info:
bkn: ""
nickname: $.data.nickname
# 群、好友列表
user_list:
friend_list:
name: get_friends_with_category
source: $.data[*]
list:
class_id: /categoryId
class_name: /categroyName
user_id: /user_id
nickname: /nickname
remark: /remark
longNick: /longNick
group_list:
name: get_group_list
source: $.data[*]
list:
group_id: /group_id
group_name: /group_name
member_count: /member_count
admin_flag: $.admins[?(@ == '<uin>')]

class_id: null
user_id: /user_id
nickname: /nickname
remark: /remark
# 消息列表
message_list:
name: get_group_msg_history
Expand Down Expand Up @@ -77,15 +83,6 @@ set_message_read:
# 设置消息回应
send_respond:
name: set_msg_emoji_like
# 获取分组信息
class_list:
name: get_friends_with_category
source: $.data[*]
list:
class_id: /categoryId
class_name: /categroyName
user_count: /categroyMbCount
list: /buddyList
# 获取群公告
group_notices:
name: _get_group_notice
Expand All @@ -112,4 +109,13 @@ group_essence:
# 获取收藏表情
roaming_stamp:
name: fetch_custom_face
pageed: true
pageed: true
# 获取历史会话
recent_contact:
name: get_recent_contact
source: $.data[*]
list:
user_id: /peerUin
time: /msgTime
chat_type: /chatType
name: /peerName
10 changes: 5 additions & 5 deletions src/components/FriendBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
'https://p.qlogo.cn/gh/' + data.group_id + '/' + data.group_id + '/0'">
<div>
<div>
<p>{{getShowName()}}</p>
<p>{{ getShowName() }}</p>
<div style="flex:1"></div>
<a class="time">{{ data.time !== undefined ? Intl.DateTimeFormat(trueLang,
<a class="time" v-if="from == 'message'">{{ data.time !== undefined ? Intl.DateTimeFormat(trueLang,
{ hour: "numeric", minute: "numeric" }).format(new Date(data.time)) : ''
}}</a>
</div>
<div>
<a>{{ data.raw_msg }}</a>
<div style="margin-left:10px;display:flex;">
<a :class="from == 'friend' ? 'nick' : ''">{{ from == 'friend' ? data.longNick ?? '' : data.raw_msg }}</a>
<div style="margin-left:10px;display:flex;" v-if="from == 'message'">
<font-awesome-icon v-if="data.always_top === true" :icon="['fas', 'thumbtack']" />
</div>
</div>
Expand All @@ -40,7 +40,7 @@ import { getMsgRawTxt } from '@/function/utils/msgUtil'

export default defineComponent({
name: 'FriendBody',
props: ['data', 'select', 'menu'],
props: ['data', 'select', 'menu', 'from'],
data () {
return {
trueLang: getTrueLang(),
Expand Down
152 changes: 90 additions & 62 deletions src/function/msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import pinyin from 'pinyin'

import Umami from '@stapxs/umami-logger-typescript'

import { buildMsgList, getMsgData, parseMsgList, getMsgRawTxt } from '@/function/utils/msgUtil'
import { buildMsgList, getMsgData, parseMsgList, getMsgRawTxt, updateLastestHistory } from '@/function/utils/msgUtil'
import { getViewTime, escape2Html, randomNum } from '@/function/utils/systemUtil'
import { reloadUsers, reloadCookies, downloadFile, updateMenu, jumpToChat } from '@/function/utils/appUtil'
import { reactive, markRaw, defineAsyncComponent } from 'vue'
Expand Down Expand Up @@ -52,7 +52,7 @@ export function parse(str: string) {
case 'getUserInfoInGroup' : runtimeData.chatInfo.info.me_info = msg; break
case 'getGroupMemberList' : saveGroupMember(msg.data); break
case 'getChatHistoryFist' : saveMsg(msg, 'top'); break
case 'getChatHistoryTop' : updateTopMsg(msg, echoList); break
case 'getChatHistoryOnMsg' : updateTopMsg(msg, echoList); break
case 'getChatHistory' : saveMsg(msg, 'top'); break
case 'getForwardMsg' : saveForwardMsg(msg); break
case 'sendMsgBack' : showSendedMsg(msg, echoList); break
Expand All @@ -74,7 +74,7 @@ export function parse(str: string) {
case 'setFriendAdd':
case 'setGroupAdd' : updateSysInfo(head); break
case 'loadFileBase' : loadFileBase(echoList, msg); break
case 'getClassInfo' : saveClassInfo(msg); break
case 'GetRecentContact' : createRecentContact(msg); break

case 'getCookies' : saveCookie(msg, echoList); break
}
Expand Down Expand Up @@ -201,11 +201,65 @@ function saveGroupNotices(msg: any) {
}
}

function createRecentContact(data: any) {
const list = getMsgData('recent_contact', data, msgPath.recent_contact)
if (list != undefined) {
// user_id: /peerUin
// time: /msgTime
// chat_type: /chatType
// 过滤掉 chatType 不是 1 和 2 的
let back = list.filter((item) => {
return item.chat_type == 1 || item.chat_type == 2
})
// 排除掉在置顶列表里的
const topList = runtimeData.sysConfig.top_info as { [key: string]: number[] } | null
if(topList != null) {
const top = topList[runtimeData.loginInfo.uin]
if(top != undefined) {
back = back.filter((item) => {
return top.indexOf(Number(item.user_id)) == -1
})
}
}
// 去重
back = back.filter((item, index, arr) => {
return arr.findIndex((item2) => {
return item2.user_id == item.user_id
}) == index
})
back.forEach((item) => {
// 去消息列表里找一下它
const user = runtimeData.userList.find((user) => {
return user.user_id == item.user_id
})
const inMsgList = runtimeData.onMsgList.find((msg) => {
return msg.user_id == item.user_id
}) != undefined
if(user && !inMsgList) {
runtimeData.onMsgList.push(user)
updateLastestHistory(user)
}
})
}
}

function saveUser(msg: { [key: string]: any }, type: string) {
const list = getMsgData('user_list', msg, msgPath.user_list)
let list: any[] | undefined
if(msgPath.user_list)
list = getMsgData('user_list', msg, msgPath.user_list)
else {
switch(type) {
case 'friend':
list = getMsgData('friend_list', msg, msgPath.friend_list)
break
case 'group':
list = getMsgData('group_list', msg, msgPath.group_list)
break
}
}
if (list != undefined) {
const pyConfig = { style: 0 } as IPinyinOptions
const groupNames = {} as { [key: number]: string }
const groupNames = {} as {[key: number]: string}
list.forEach((item, index) => {
// 为所有项目追加拼音名称
let py_name = ''
Expand All @@ -215,7 +269,7 @@ function saveUser(msg: { [key: string]: any }, type: string) {
py_name = pinyin(item.nickname, pyConfig).join('') + ',' +
pinyin(item.remark, pyConfig).join('')
}
list[index].py_name = py_name
if(list && list[index]) list[index].py_name = py_name
// 构建分类
if (type == 'friend') {
if (item.class_id != undefined && item.class_name) {
Expand All @@ -227,8 +281,13 @@ function saveUser(msg: { [key: string]: any }, type: string) {
delete item.class_name
}
})
if (Object.keys(groupNames).length > 0) {
saveClassInfo(Array.from(Object.entries(groupNames), ([key, value]) => ({ [key]: value })))
if(Object.keys(groupNames).length > 0) {
// 把 groupNames 处理为 { class_id: number, class_name: string }[]
const groupNamesList = [] as { class_id: number, class_name: string }[]
for(const key in groupNames) {
groupNamesList.push({ class_id: Number(key), class_name: groupNames[key] })
}
saveClassInfo(groupNamesList)
}
runtimeData.userList = runtimeData.userList.concat(list)
// 刷新置顶列表
Expand All @@ -250,27 +309,7 @@ function saveUser(msg: { [key: string]: any }, type: string) {
// 给置顶的用户刷新最新一条的消息用于显示
runtimeData.userList.forEach((item) => {
if (item.always_top) {
// 发起获取历史消息请求
const type = item.user_id ? 'user' : 'group'
const id = item.user_id ? item.user_id : item.group_id
let name
if (runtimeData.jsonMap.message_list && type != 'group') {
name = runtimeData.jsonMap.message_list.private_name
} else {
name = runtimeData.jsonMap.message_list.name
}
Connector.send(
name ?? 'get_chat_history',
{
message_type: runtimeData.jsonMap.message_list.message_type[type],
group_id: id,
user_id: id,
message_seq: 0,
message_id: 0,
count: 1
},
'getChatHistoryTop_' + id
)
updateLastestHistory(item)
}
})
}
Expand All @@ -297,52 +336,41 @@ function updateTopMsg(msg: any, echoList: string[]) {
const raw = getMsgRawTxt(list[0].message)
const sender = list[0].sender
const time = list[0].time
// 更新置顶列表
// 更新消息列表
runtimeData.onMsgList.forEach((item) => {
if (item.user_id == id) {
item.raw_msg = raw
} else if(item.group_id == id) {
item.raw_msg = sender.nickname + ': ' + raw
item.time = getViewTime(Number(time))
}
item.time = getViewTime(Number(time))
})
}
}
}

function saveClassInfo(data: any) {
const list = getMsgData('class_list', data, msgPath.class_list)
if (list != undefined && (data.status == 'ok' || data.status == undefined)) {
// 对 classes 列表按拼音重新排序
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)
function saveClassInfo(list: { class_id: number, class_name: string }[]) {
// 按拼音重新排序
// const names = [] as string[]
// list.forEach((item) => {
// names.push(item.class_name)
// })
// const sortedData = names.sort(pinyin.compare)
// const back = [] as { class_id: number, class_name: string }[]
// sortedData.forEach((name) => {
// list.forEach((item) => {
// if (item.class_name == name) {
// back.push(item)
// }
// })
// })

const back = [] as any[]
sortedData.forEach((name) => {
list.forEach((item: any) => {
if ((Object.values(item)[0] as string) == name)
back.push(item)
})
})
// 按 class_id 排序
const back = list.sort((a, b) => {
return a.class_id - b.class_id
})

runtimeData.tags.classes = back
}
runtimeData.tags.classes = back
}

function saveGroupMember(data: GroupMemberInfoElem[]) {
Expand Down
19 changes: 16 additions & 3 deletions src/function/utils/appUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,23 @@ export function reloadUsers() {
// 加载用户列表
if (login.status) {
runtimeData.userList = []
Connector.send('get_friend_list', {}, 'getFriendList')
Connector.send('get_group_list', {}, 'getGroupList')
let friendName = 'get_friend_list'
let groupName = 'get_group_list'
if(runtimeData.jsonMap.user_list?.name) {
friendName = runtimeData.jsonMap.user_list.name.split('|')[0]
groupName = runtimeData.jsonMap.user_list.name.split('|')[1]
} else if(runtimeData.jsonMap.friend_list?.name &&
runtimeData.jsonMap.group_list?.name) {
friendName = runtimeData.jsonMap.friend_list.name
groupName = runtimeData.jsonMap.group_list.name
}
Connector.send(friendName, {}, 'getFriendList')
Connector.send(groupName, {}, 'getGroupList')
// 获取系统消息
Connector.send('get_system_msg', {}, 'getSystemMsg')
Connector.send(runtimeData.jsonMap.class_list.name, {}, 'getClassInfo')
// 获取最近的会话
if(runtimeData.jsonMap.recent_contact)
Connector.send(runtimeData.jsonMap.recent_contact.name, {}, 'GetRecentContact')
}
}

Expand Down
26 changes: 25 additions & 1 deletion src/function/utils/msgUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Logger } from '@/function/base'
import { runtimeData } from '@/function/msg'
import { v4 as uuid } from 'uuid'
import { Connector } from '@/function/connect'
import { BotMsgType } from '../elements/information'
import { BotMsgType, UserFriendElem, UserGroupElem } from '../elements/information'
import Umami from '@stapxs/umami-logger-typescript'

const logger = new Logger()
Expand Down Expand Up @@ -409,4 +409,28 @@ export function sendMsgRaw(id: string, type: string, msg: string | { type: strin
// UM:统计消息发送次数
Umami.trackEvent('sendMsg', { type: type })
}
}

export function updateLastestHistory(item: UserFriendElem & UserGroupElem) {
// 发起获取历史消息请求
const type = item.user_id ? 'user' : 'group'
const id = item.user_id ? item.user_id : item.group_id
let name
if (runtimeData.jsonMap.message_list && type != 'group') {
name = runtimeData.jsonMap.message_list.private_name
} else {
name = runtimeData.jsonMap.message_list.name
}
Connector.send(
name ?? 'get_chat_history',
{
message_type: runtimeData.jsonMap.message_list.message_type[type],
group_id: id,
user_id: id,
message_seq: 0,
message_id: 0,
count: 1
},
'getChatHistoryOnMsg_' + id
)
}
Loading

0 comments on commit a9e850a

Please sign in to comment.