Skip to content

Commit

Permalink
永远的分页
Browse files Browse the repository at this point in the history
✨ 支持非分页模式加载消息 <- #120
🐛 修正后端连接模式 SSL 协议错误的问题
  • Loading branch information
Stapxs committed Aug 27, 2024
1 parent 84a0bb3 commit b949123
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/assets/pathMap/NapCat.Onebot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ message_list:
name: get_group_msg_history
private_name: get_friend_msg_history
source: $.data.messages[*]
pageed: false # 是否支持分页(id + count 获取)
type: $.data
message_type:
user: private
Expand Down
3 changes: 3 additions & 0 deletions src/function/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ export class Connector {
static send(name: string, value: {[key: string]: any}, echo: string = name) {
// 构建 JSON
const json = JSON.stringify({ action: name, params: value, echo: echo } as BotActionElem)
this.sendRaw(json)
}
static sendRaw(json: string) {
// 发送
if(runtimeData.tags.isElectron) {
const reader = runtimeData.reader
Expand Down
4 changes: 4 additions & 0 deletions src/function/msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ function saveMsg(msg: any, append = undefined as undefined | string) {
let list = getMsgData('message_list', msg, msgPath.message_list)
list = getMessageList(list)
if (list != undefined) {
// 在加载历史消息的时候判断是否支持分页追加
if(append == 'top' && runtimeData.jsonMap.message_list?.pageed == false) {
append = undefined
}
// 追加处理
if (append != undefined) {
// 没有更旧的消息能加载了,禁用允许加载标志
Expand Down
5 changes: 2 additions & 3 deletions src/function/utils/appUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export function loadHistory(info: BaseChatInfoElem) {
}
export function loadHistoryMessage(id: number, type: string, count = 20, echo = 'getChatHistoryFist') {
let name
const pageed = !(runtimeData.jsonMap.message_list?.pageed == false)
if(runtimeData.jsonMap.message_list && type != 'group') {
name = runtimeData.jsonMap.message_list.private_name
} else {
Expand All @@ -122,12 +123,10 @@ export function loadHistoryMessage(id: number, type: string, count = 20, echo =
Connector.send(
name ?? 'get_chat_history',
{
message_type: runtimeData.jsonMap.message_list.message_type[type],
group_id: type == 'group' ? id : undefined,
user_id: type != 'group' ? id : undefined,
message_seq: 0,
message_id: 0,
count: count
count: !pageed ? runtimeData.messageList.length + count : count
},
echo
)
Expand Down
5 changes: 2 additions & 3 deletions src/pages/Chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ export default defineComponent({
// 锁定加载防止反复触发
this.tags.nowGetHistroy = true
// 发起获取历史消息请求
const pageed = !(runtimeData.jsonMap.message_list.pageed == false)
const type = runtimeData.chatInfo.show.type
const id = runtimeData.chatInfo.show.id
let name
Expand All @@ -533,12 +534,10 @@ export default defineComponent({
Connector.send(
name ?? 'get_chat_history',
{
message_type: runtimeData.jsonMap.message_list.message_type[type],
group_id: type == 'group' ? id : undefined,
user_id: type != 'group' ? id : undefined,
message_seq: firstMsgId,
message_id: firstMsgId,
count: 20
count: !pageed ? runtimeData.messageList.length + 20 : 20
},
'getChatHistory'
)
Expand Down
5 changes: 2 additions & 3 deletions src/pages/chat-view/Chat弹幕.vue
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export default defineComponent({
const id = runtimeData.chatInfo.show.id
const firstMsgId = this.list[0].message_id ?? 0
let name
const pageed = !(runtimeData.jsonMap.message_list?.pageed == false)
if(runtimeData.jsonMap.message_list && type != 'group') {
name = runtimeData.jsonMap.message_list.private_name
} else {
Expand All @@ -319,12 +320,10 @@ export default defineComponent({
Connector.send(
name ?? 'get_chat_history',
{
message_type: runtimeData.jsonMap.message_list.message_type[type],
group_id: type == 'group' ? id : undefined,
user_id: type != 'group' ? id : undefined,
message_seq: firstMsgId,
message_id: firstMsgId,
count: 10
count: !pageed ? runtimeData.messageList.length + 10 : 10
},
'getChatHistory'
)
Expand Down
5 changes: 2 additions & 3 deletions src/pages/chat-view/Chat终端.vue
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ export default defineComponent({
const type = runtimeData.chatInfo.show.type
const id = runtimeData.chatInfo.show.id
let name
const pageed = !(runtimeData.jsonMap.message_list?.pageed == false)
if(runtimeData.jsonMap.message_list && type != 'group') {
name = runtimeData.jsonMap.message_list.private_name
} else {
Expand All @@ -497,12 +498,10 @@ export default defineComponent({
Connector.send(
name ?? 'get_chat_history',
{
message_type: runtimeData.jsonMap.message_list.message_type[type],
group_id: type == 'group' ? id : undefined,
user_id: type != 'group' ? id : undefined,
message_seq: firstMsgId,
message_id: firstMsgId,
count: 20
count: !pageed ? runtimeData.messageList.length + 20 : 20
},
'getChatHistory'
)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/options/OptDev.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
<script lang="ts">
import { defineComponent } from 'vue'
import { runASWEvent as save, saveAll } from '@/function/option'
import { websocket as ws } from '@/function/connect'
import { Connector, websocket as ws } from '@/function/connect'

Check warning on line 201 in src/pages/options/OptDev.vue

View workflow job for this annotation

GitHub Actions / lint

'ws' is defined but never used
import { PopInfo, PopType } from '@/function/base'
import { runtimeData } from '@/function/msg'
import app from '@/main'
Expand Down Expand Up @@ -229,7 +229,7 @@ export default defineComponent({
this.ws_text = ''
// 修改 echo 防止被消息处理机处理
info.echo = 'websocketTest'
if(ws) ws.send(JSON.stringify(info))
Connector.sendRaw(JSON.stringify(info))
}
},
sendTestAppmsg (event: KeyboardEvent) {
Expand Down

0 comments on commit b949123

Please sign in to comment.