koishi-plugin-chat-patch 5.6.1 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/web/dist/assets/Chat-BLcuHxzh.js +28 -0
- package/client/web/dist/assets/{Chat-BXVWj5Bd.css → Chat-Cee07eDL.css} +1 -1
- package/client/web/dist/assets/{MsgBody-CzrxyiFO.js → MsgBody-krZlLzRL.js} +1 -1
- package/client/web/dist/assets/MsgBody.vue_vue_type_script_setup_true_lang-CLmUjKws.js +67 -0
- package/client/web/dist/assets/{index-EJ2CcODr.js → index-DOJoilEy.js} +57 -60
- package/client/web/dist/index.html +1 -1
- package/client/web/src/assets/l10n/zh-CN.po +0 -3
- package/client/web/src/components/MsgBody.vue +29 -20
- package/client/web/src/function/connect.ts +17 -18
- package/client/web/src/function/msg.ts +2 -0
- package/client/web/src/function/satori-model.ts +2 -0
- package/client/web/src/function/satori.ts +18 -12
- package/client/web/src/function/utils/appUtil.ts +27 -6
- package/client/web/src/function/utils/msgUtil.ts +27 -21
- package/client/web/src/pages/Chat.vue +35 -32
- package/lib/database.d.ts +5 -3
- package/lib/gateway.d.ts +2 -4
- package/lib/index.d.ts +17 -0
- package/lib/index.js +5409 -473
- package/lib/media.d.ts +1 -1
- package/lib/recorder.d.ts +1 -4
- package/lib/self-message.d.ts +1 -4
- package/lib/types.d.ts +4 -0
- package/package.json +25 -10
- package/src/bootstrap.ts +3 -2
- package/src/config.ts +1 -5
- package/src/database.ts +313 -139
- package/src/gateway.ts +21 -13
- package/src/index.ts +59 -54
- package/src/media.ts +43 -12
- package/src/recorder.ts +2 -12
- package/src/self-message.ts +7 -14
- package/src/server.d.ts +17 -3
- package/src/types.ts +4 -0
- package/src/web.ts +245 -151
- package/client/web/dist/assets/Chat-m4-U5uHa.js +0 -28
- package/client/web/dist/assets/MsgBody.vue_vue_type_script_setup_true_lang-BBF1uxm6.js +0 -67
- package/lib/bootstrap.d.ts +0 -6
- package/lib/satori.d.ts +0 -3
- package/lib/web.d.ts +0 -7
|
@@ -502,13 +502,6 @@
|
|
|
502
502
|
<div><font-awesome-icon :icon="['fas', 'trash-can']" /></div>
|
|
503
503
|
<a>{{ $t('移出群聊') }}</a>
|
|
504
504
|
</div>
|
|
505
|
-
<div v-show="tags.menuDisplay.config"
|
|
506
|
-
@click="openChatInfoPan();
|
|
507
|
-
($refs.infoRef as any).openMoreConfig(selectedMsg?.sender.user_id);
|
|
508
|
-
closeMsgMenu();">
|
|
509
|
-
<div><font-awesome-icon :icon="['fas', 'cog']" /></div>
|
|
510
|
-
<a>{{ $t('成员设置') }}</a>
|
|
511
|
-
</div>
|
|
512
505
|
<div v-show="tags.menuDisplay.jumpToMsg" @click="jumpSearchMsg">
|
|
513
506
|
<div><font-awesome-icon :icon="['fas', 'arrow-up-right-from-square']" /></div>
|
|
514
507
|
<a>{{ $t('跳转到消息') }}</a>
|
|
@@ -588,7 +581,6 @@ import { v4 as uuid } from 'uuid'
|
|
|
588
581
|
import {
|
|
589
582
|
scrollToMsg,
|
|
590
583
|
downloadFile,
|
|
591
|
-
loadHistory as loadHistoryFirst,
|
|
592
584
|
shouldAutoFocus,
|
|
593
585
|
vMenu,
|
|
594
586
|
vMove,
|
|
@@ -612,7 +604,6 @@ import {
|
|
|
612
604
|
import { Logger, LogType, PopInfo, PopType } from '../function/base'
|
|
613
605
|
import { Connector, loadChatHistoryFromCache, saveSentSelfMessage, sendForwardMessage } from '../function/connect'
|
|
614
606
|
import {
|
|
615
|
-
BaseChatInfoElem,
|
|
616
607
|
MsgItemElem,
|
|
617
608
|
SQCodeElem,
|
|
618
609
|
GroupMemberInfoElem,
|
|
@@ -735,6 +726,14 @@ const forwardList = ref(contactStore.userList)
|
|
|
735
726
|
const chatImg = ref<any>(undefined)
|
|
736
727
|
const trueLang = getTrueLang()
|
|
737
728
|
|
|
729
|
+
const HISTORY_PAGE_SIZE = 50
|
|
730
|
+
const HISTORY_INITIAL_LIMIT = 100
|
|
731
|
+
|
|
732
|
+
function currentChatTargetKey(): string {
|
|
733
|
+
const show = chatStore.chatInfo.show
|
|
734
|
+
return `${String(show.type ?? '')}:${String(show.id ?? '')}:${String(show.channel_id ?? '')}`
|
|
735
|
+
}
|
|
736
|
+
|
|
738
737
|
function messageLocalTimeMs(item: any): number {
|
|
739
738
|
const local = Number(item?.local_time ?? item?.timestamp_ms ?? item?.time_ms ?? 0)
|
|
740
739
|
if (local) return local
|
|
@@ -745,6 +744,7 @@ function messageLocalTimeMs(item: any): number {
|
|
|
745
744
|
async function refreshSelfHistory() {
|
|
746
745
|
const id = chat.show.id
|
|
747
746
|
if (!id || id === 0 || details.value[3].open || tags.value.showForwardPan) return
|
|
747
|
+
const targetKey = currentChatTargetKey()
|
|
748
748
|
const channelId = chat.show.type === 'group'
|
|
749
749
|
? String(chat.show.channel_id ?? id)
|
|
750
750
|
: String(chat.show.channel_id ?? id)
|
|
@@ -754,12 +754,12 @@ async function refreshSelfHistory() {
|
|
|
754
754
|
platform: String(authStore.loginInfo.platform ?? ''),
|
|
755
755
|
selfId: String(authStore.loginInfo.uin ?? ''),
|
|
756
756
|
channelId,
|
|
757
|
-
limit:
|
|
757
|
+
limit: HISTORY_INITIAL_LIMIT,
|
|
758
758
|
})
|
|
759
759
|
} catch {
|
|
760
760
|
return
|
|
761
761
|
}
|
|
762
|
-
if (!cached.length || String(chat.show.id) !== String(id)) return
|
|
762
|
+
if (!cached.length || String(chat.show.id) !== String(id) || targetKey !== currentChatTargetKey()) return
|
|
763
763
|
|
|
764
764
|
const seen = new Set<string>()
|
|
765
765
|
const addSeen = (item: any) => {
|
|
@@ -1178,6 +1178,8 @@ async function loadMoreHistory() {
|
|
|
1178
1178
|
const firstMsg = list[0]
|
|
1179
1179
|
const firstMsgId = firstMsg.message_id
|
|
1180
1180
|
const firstMsgTime = Number(firstMsg?.time)
|
|
1181
|
+
const targetKey = currentChatTargetKey()
|
|
1182
|
+
const isStale = () => targetKey !== currentChatTargetKey()
|
|
1181
1183
|
const cacheBeforeTime = Number(
|
|
1182
1184
|
firstMsg?.local_time ?? firstMsg?.timestamp_ms ?? firstMsg?.time_ms ?? 0
|
|
1183
1185
|
) || (Number.isFinite(firstMsgTime) ? firstMsgTime * 1000 : 0)
|
|
@@ -1191,6 +1193,10 @@ async function loadMoreHistory() {
|
|
|
1191
1193
|
uiStore.historyBeforeTime = undefined
|
|
1192
1194
|
}
|
|
1193
1195
|
uiStore.loadHistoryFail = false
|
|
1196
|
+
if (isStale()) {
|
|
1197
|
+
uiStore.nowGetHistory = false
|
|
1198
|
+
return
|
|
1199
|
+
}
|
|
1194
1200
|
|
|
1195
1201
|
const channelId = String(
|
|
1196
1202
|
chatStore.chatInfo.show.channel_id
|
|
@@ -1214,6 +1220,10 @@ async function loadMoreHistory() {
|
|
|
1214
1220
|
20,
|
|
1215
1221
|
)
|
|
1216
1222
|
}
|
|
1223
|
+
if (isStale()) {
|
|
1224
|
+
uiStore.nowGetHistory = false
|
|
1225
|
+
return
|
|
1226
|
+
}
|
|
1217
1227
|
if (localMsgs.length > 0) {
|
|
1218
1228
|
const existingIds = new Set(chatStore.messageList.map((m) => String(m.message_id ?? '')))
|
|
1219
1229
|
const addList = localMsgs.filter((m) => {
|
|
@@ -1230,14 +1240,22 @@ async function loadMoreHistory() {
|
|
|
1230
1240
|
}
|
|
1231
1241
|
}
|
|
1232
1242
|
}
|
|
1243
|
+
if (isStale()) {
|
|
1244
|
+
uiStore.nowGetHistory = false
|
|
1245
|
+
return
|
|
1246
|
+
}
|
|
1233
1247
|
|
|
1234
1248
|
const cached = await loadChatHistoryFromCache({
|
|
1235
1249
|
platform: String(authStore.loginInfo.platform ?? ''),
|
|
1236
1250
|
selfId: String(authStore.loginInfo.uin ?? ''),
|
|
1237
1251
|
channelId,
|
|
1238
|
-
limit:
|
|
1252
|
+
limit: HISTORY_PAGE_SIZE,
|
|
1239
1253
|
beforeTimeMs: cacheBeforeTime > 0 ? cacheBeforeTime : undefined,
|
|
1240
1254
|
})
|
|
1255
|
+
if (isStale()) {
|
|
1256
|
+
uiStore.nowGetHistory = false
|
|
1257
|
+
return
|
|
1258
|
+
}
|
|
1241
1259
|
const existingIds = new Set(chatStore.messageList.map((m) => String(m.message_id ?? '')))
|
|
1242
1260
|
const addList = cached.filter((m) => {
|
|
1243
1261
|
const msgId = String(m.message_id ?? '')
|
|
@@ -1246,7 +1264,7 @@ async function loadMoreHistory() {
|
|
|
1246
1264
|
if (addList.length > 0) {
|
|
1247
1265
|
chatStore.messageList.splice(0, 0, ...addList)
|
|
1248
1266
|
}
|
|
1249
|
-
if (cached.length <
|
|
1267
|
+
if (cached.length < HISTORY_PAGE_SIZE) {
|
|
1250
1268
|
uiStore.canLoadHistory = false
|
|
1251
1269
|
}
|
|
1252
1270
|
uiStore.nowGetHistory = false
|
|
@@ -2064,6 +2082,8 @@ function forwardMsg(data: UserFriendElem & UserGroupElem) {
|
|
|
2064
2082
|
forwardContent: msgBody,
|
|
2065
2083
|
source: 'webui',
|
|
2066
2084
|
sentAt: sentTime,
|
|
2085
|
+
timestamp: Math.floor(sentTime / 1000),
|
|
2086
|
+
timestampMs: sentTime,
|
|
2067
2087
|
kind: 'forward',
|
|
2068
2088
|
})
|
|
2069
2089
|
}
|
|
@@ -2938,23 +2958,6 @@ function updateList(newLength: number, oldLength: number) {
|
|
|
2938
2958
|
NewMsgNum.value = Math.abs(newLength - oldLength)
|
|
2939
2959
|
}
|
|
2940
2960
|
}
|
|
2941
|
-
if (
|
|
2942
|
-
list.length > 200 &&
|
|
2943
|
-
!uiStore.nowGetHistory &&
|
|
2944
|
-
!tags.value.showBottomButton
|
|
2945
|
-
) {
|
|
2946
|
-
chatStore.messageList = []
|
|
2947
|
-
const info = {
|
|
2948
|
-
type: chat.show.type,
|
|
2949
|
-
id: chat.show.id,
|
|
2950
|
-
name: chat.show.name,
|
|
2951
|
-
avatar: chat.show.avatar,
|
|
2952
|
-
jump: chat.show.jump,
|
|
2953
|
-
} as BaseChatInfoElem
|
|
2954
|
-
loadHistoryFirst(info)
|
|
2955
|
-
uiStore.nowGetHistory = true
|
|
2956
|
-
}
|
|
2957
|
-
|
|
2958
2961
|
const pan = document.getElementById('msgPan')
|
|
2959
2962
|
if (pan !== null) {
|
|
2960
2963
|
const height = pan.scrollHeight
|
|
@@ -2968,7 +2971,7 @@ function updateList(newLength: number, oldLength: number) {
|
|
|
2968
2971
|
)
|
|
2969
2972
|
}
|
|
2970
2973
|
if (!uiStore.nowGetHistory) {
|
|
2971
|
-
if (
|
|
2974
|
+
if (shouldKeepChatAtBottom || oldLength <= 0) {
|
|
2972
2975
|
scrollTo(newPan.scrollHeight)
|
|
2973
2976
|
}
|
|
2974
2977
|
if (oldLength <= 0) {
|
|
@@ -2988,7 +2991,7 @@ function updateList(newLength: number, oldLength: number) {
|
|
|
2988
2991
|
msgItem.type === 'image' &&
|
|
2989
2992
|
msgItem.file != 'marketface'
|
|
2990
2993
|
) {
|
|
2991
|
-
getImgList.push(msgItem.url)
|
|
2994
|
+
getImgList.push(msgItem.url || msgItem.file)
|
|
2992
2995
|
}
|
|
2993
2996
|
}
|
|
2994
2997
|
}
|
package/lib/database.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export declare class ChatDatabase {
|
|
|
11
11
|
constructor(ctx: Context, config: Config, logger: PluginLogger);
|
|
12
12
|
private get db();
|
|
13
13
|
initialize(): Promise<void>;
|
|
14
|
+
private loadLevelModule;
|
|
14
15
|
dispose(): Promise<void>;
|
|
15
|
-
private ensureOpen;
|
|
16
16
|
private releaseShared;
|
|
17
17
|
clearAll(): Promise<void>;
|
|
18
18
|
appendMessage(record: MessageRecord): Promise<void>;
|
|
@@ -56,6 +56,8 @@ export declare class ChatDatabase {
|
|
|
56
56
|
type: string;
|
|
57
57
|
contacts: ContactCacheItem[];
|
|
58
58
|
}>>;
|
|
59
|
-
private
|
|
60
|
-
|
|
59
|
+
private trimChannel;
|
|
60
|
+
cleanupExcess(): Promise<void>;
|
|
61
|
+
private trimRows;
|
|
62
|
+
private extractRecordTime;
|
|
61
63
|
}
|
package/lib/gateway.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Context } from 'koishi';
|
|
2
|
-
import { Config } from './config';
|
|
3
2
|
import { ChatDatabase } from './database';
|
|
4
3
|
import { PluginLogger } from './logger';
|
|
5
4
|
import { Recorder } from './recorder';
|
|
@@ -17,7 +16,6 @@ export type SatoriGatewayPayload = {
|
|
|
17
16
|
type SatoriGatewayHandler = (payload: SatoriGatewayPayload) => void;
|
|
18
17
|
export declare class SatoriGateway {
|
|
19
18
|
private ctx;
|
|
20
|
-
private config;
|
|
21
19
|
private database;
|
|
22
20
|
private recorder;
|
|
23
21
|
private logger;
|
|
@@ -30,7 +28,8 @@ export declare class SatoriGateway {
|
|
|
30
28
|
private sequence;
|
|
31
29
|
private logins;
|
|
32
30
|
private online;
|
|
33
|
-
|
|
31
|
+
private lastPongAt;
|
|
32
|
+
constructor(ctx: Context, database: ChatDatabase, recorder: Recorder, logger: PluginLogger, onPayload: SatoriGatewayHandler);
|
|
34
33
|
start(): Promise<void>;
|
|
35
34
|
dispose(): void;
|
|
36
35
|
getLogins(): SatoriLoginInfo[];
|
|
@@ -40,7 +39,6 @@ export declare class SatoriGateway {
|
|
|
40
39
|
private scheduleReconnect;
|
|
41
40
|
private handleMessage;
|
|
42
41
|
private normalizeLogins;
|
|
43
|
-
private isBlocked;
|
|
44
42
|
private setOnline;
|
|
45
43
|
}
|
|
46
44
|
export {};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { Console } from '@koishijs/console';
|
|
3
|
+
import { Config } from './config';
|
|
4
|
+
export declare const name = "chat-patch";
|
|
5
|
+
export declare const reusable = false;
|
|
6
|
+
export declare const filter = false;
|
|
7
|
+
export declare const inject: {
|
|
8
|
+
required: string[];
|
|
9
|
+
};
|
|
10
|
+
declare module 'koishi' {
|
|
11
|
+
interface Context {
|
|
12
|
+
console: Console;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export declare const usage = "\n---\n\n\u57FA\u4E8E Satori \u534F\u8BAE\u7684 Koishi \u540E\u53F0\u804A\u5929\u5BA4\u3002\n\u9700\u8981\u5728 Koishi \u4E2D\u542F\u7528 server-satori\uFF0C\u5E76\u5728\u63D2\u4EF6\u5185\u6784\u5EFA web \u5E94\u7528\u3002\n\n---\n\n\u9700\u8981\u5B89\u88C5 w-node \u63D2\u4EF6\uFF0C\u5E76\u5F00\u542F w-node\u3001market\u3001server-satori \u63D2\u4EF6\u3002\n\n---\n";
|
|
16
|
+
export { Config } from './config';
|
|
17
|
+
export declare function apply(ctx: Context, config: Config): Promise<void>;
|