@aochuang/client-sdk 1.0.298 → 1.0.300
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/components/chat-editor/chat-editor.vue +11 -2
- package/components/chat-editor/utils.js +24 -10
- package/package.json +1 -1
- package/services/client-chat/client-chat-wechat/client-chat-session.js +3 -0
- package/services/client-chat/client-chat-wechat/client-chat.js +36 -0
- package/services/client-chat/client-chat-wechat/utils.js +2 -1
|
@@ -243,9 +243,10 @@ export default {
|
|
|
243
243
|
const cursorPos = this.cacheInputRange ? this.cacheInputRange.start : 0
|
|
244
244
|
const nearsetInfo = getNearestString(inputValue, cursorPos)
|
|
245
245
|
this.suggestionsNearsetInfo = nearsetInfo
|
|
246
|
-
const nearest = (nearsetInfo
|
|
246
|
+
const nearest = this.normalizeSuggestionsKeyword(nearsetInfo)
|
|
247
247
|
if (!nearest) {
|
|
248
248
|
this.closeSuggestions()
|
|
249
|
+
return
|
|
249
250
|
}
|
|
250
251
|
this.loadSuggestions(nearest, nearsetInfo)
|
|
251
252
|
}, 200)
|
|
@@ -254,7 +255,7 @@ export default {
|
|
|
254
255
|
if (!this.fetchSuggestionsMethod) {
|
|
255
256
|
return
|
|
256
257
|
}
|
|
257
|
-
keyword =
|
|
258
|
+
keyword = this.normalizeSuggestionsKeyword(nearestInfo, keyword)
|
|
258
259
|
this.suggestioning = true
|
|
259
260
|
this.suggestionsKeyword = keyword
|
|
260
261
|
clearTimeout(this._loadSuggestionsTimer)
|
|
@@ -268,6 +269,14 @@ export default {
|
|
|
268
269
|
this.suggestioning = false
|
|
269
270
|
})
|
|
270
271
|
},
|
|
272
|
+
normalizeSuggestionsKeyword (nearestInfo, keyword) {
|
|
273
|
+
const nearest = keyword === undefined
|
|
274
|
+
? (nearestInfo && nearestInfo.nearest) || ''
|
|
275
|
+
: keyword || ''
|
|
276
|
+
return nearestInfo && nearestInfo.isAtContext
|
|
277
|
+
? nearest.trim()
|
|
278
|
+
: nearest.replace(/^\s+/, '')
|
|
279
|
+
},
|
|
271
280
|
closeSuggestions () {
|
|
272
281
|
this.$refs.suggestions && this.$refs.suggestions.close()
|
|
273
282
|
},
|
|
@@ -38,19 +38,33 @@ export function getNearestString (inputStr, cursorPos) {
|
|
|
38
38
|
break;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
if (!isAtContext) {
|
|
43
|
+
let wordCursor = safeCursorPos - 1;
|
|
44
|
+
while (wordCursor >= 0 && /\s/.test(inputStr[wordCursor])) {
|
|
45
|
+
wordCursor--;
|
|
46
|
+
}
|
|
47
|
+
if (wordCursor < 0) {
|
|
48
|
+
return { nearest: '', start: safeCursorPos, end: safeCursorPos, isAtContext: false };
|
|
49
|
+
}
|
|
50
|
+
let start = wordCursor;
|
|
51
|
+
while (start > 0 && !/\s/.test(inputStr[start - 1])) {
|
|
52
|
+
start--;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
nearest: inputStr.slice(start, safeCursorPos),
|
|
56
|
+
start,
|
|
57
|
+
end: safeCursorPos,
|
|
58
|
+
isAtContext: false
|
|
59
|
+
};
|
|
60
|
+
}
|
|
41
61
|
|
|
42
62
|
// 2. 根据上下文选择拆分模式
|
|
43
63
|
let splitRegex, isSeparator;
|
|
44
64
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
isSeparator = (part) => part === '@';
|
|
49
|
-
} else {
|
|
50
|
-
// 普通输入场景:按空白字符拆分
|
|
51
|
-
splitRegex = /(\s+)/;
|
|
52
|
-
isSeparator = (part) => /\s+/.test(part);
|
|
53
|
-
}
|
|
65
|
+
// @ 成员场景:按 @ 字符拆分
|
|
66
|
+
splitRegex = /(@)/;
|
|
67
|
+
isSeparator = (part) => part === '@';
|
|
54
68
|
|
|
55
69
|
// 拆分字符串(保留分隔符,用于定位)
|
|
56
70
|
const parts = inputStr.split(splitRegex);
|
|
@@ -186,4 +200,4 @@ export function getNearestString (inputStr, cursorPos) {
|
|
|
186
200
|
}
|
|
187
201
|
}
|
|
188
202
|
return { nearest, start, end, isAtContext };
|
|
189
|
-
}
|
|
203
|
+
}
|
package/package.json
CHANGED
|
@@ -394,6 +394,9 @@ export default class ClientChatSession {
|
|
|
394
394
|
if (!data.wechatAccountId) {
|
|
395
395
|
throw new Error('缺少必须参数wechatAccountId')
|
|
396
396
|
}
|
|
397
|
+
if (!Array.isArray(data.lastAtMsgContent)) {
|
|
398
|
+
data.lastAtMsgContent = []
|
|
399
|
+
}
|
|
397
400
|
if (this.onBeforeAddSession && this.onBeforeAddSession({
|
|
398
401
|
data
|
|
399
402
|
}) === false) {
|
|
@@ -46,6 +46,32 @@ function isAutoReadMessage (data) {
|
|
|
46
46
|
return !!(data && data.id && data.id.indexOf('AUTO-READ-') === 0)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
function getAtMessageContent (data) {
|
|
50
|
+
if (!data || data.isSend || !data.content) {
|
|
51
|
+
return null
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const content = JSON.parse(data.content)
|
|
55
|
+
if (!content || (!Array.isArray(content.atIds) || !content.atIds.length) && (!content.text || content.text.indexOf('@所有人') < 0)) {
|
|
56
|
+
return null
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
id: data.id,
|
|
60
|
+
content: data.content
|
|
61
|
+
}
|
|
62
|
+
} catch (e) {
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function appendLastAtMsgContent (lastAtMsgContent, atMessage) {
|
|
68
|
+
const messages = Array.isArray(lastAtMsgContent) ? lastAtMsgContent : []
|
|
69
|
+
if (!atMessage || messages.some(item => item && item.id === atMessage.id)) {
|
|
70
|
+
return messages
|
|
71
|
+
}
|
|
72
|
+
return messages.concat(atMessage)
|
|
73
|
+
}
|
|
74
|
+
|
|
49
75
|
class ClientChat {
|
|
50
76
|
data = Vue.observable({
|
|
51
77
|
connectStatus: CONNECT_STATUS.Normal
|
|
@@ -252,6 +278,9 @@ class ClientChat {
|
|
|
252
278
|
// 还要更新未读消息数量
|
|
253
279
|
}
|
|
254
280
|
options.onSessionReadChange = ({ session, oldUnreadMsgCount }) => {
|
|
281
|
+
instance.updateSession(session.conversationId, {
|
|
282
|
+
lastAtMsgContent: []
|
|
283
|
+
})
|
|
255
284
|
const isMute = session.mute
|
|
256
285
|
this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
|
|
257
286
|
// 如果是免打扰的会话
|
|
@@ -514,6 +543,7 @@ class ClientChat {
|
|
|
514
543
|
onAddMessageSuccess: ({ data }) => {
|
|
515
544
|
const accountId = options.getLoginAccountIdMethod ? options.getLoginAccountIdMethod() : data.accountId
|
|
516
545
|
let sessionId = createSessionId(accountId, data.wechatChatroomId)
|
|
546
|
+
const atMessage = getAtMessageContent(data)
|
|
517
547
|
// 更新会话
|
|
518
548
|
if (!sessionId) {
|
|
519
549
|
return
|
|
@@ -550,6 +580,9 @@ class ClientChat {
|
|
|
550
580
|
rs.data.lastMsgId = data.id
|
|
551
581
|
rs.data.lastUpdateTime = data.updateDate
|
|
552
582
|
}
|
|
583
|
+
if (rs && rs.data && atMessage && !(this.sessionManage.currentSession && this.sessionManage.currentSession.conversationId === sessionId)) {
|
|
584
|
+
rs.data.lastAtMsgContent = appendLastAtMsgContent(rs.data.lastAtMsgContent, atMessage)
|
|
585
|
+
}
|
|
553
586
|
return rs
|
|
554
587
|
}).then((rs) => {
|
|
555
588
|
// 更新账号未读消息数量
|
|
@@ -596,6 +629,9 @@ class ClientChat {
|
|
|
596
629
|
this.session.setSessionRead(sessionId)
|
|
597
630
|
} else {
|
|
598
631
|
nextSession.unreadMsgCount = session.unreadMsgCount + 1
|
|
632
|
+
if (atMessage) {
|
|
633
|
+
nextSession.lastAtMsgContent = appendLastAtMsgContent(session.lastAtMsgContent, atMessage)
|
|
634
|
+
}
|
|
599
635
|
// 更新账号未读消息数量
|
|
600
636
|
this.account.updateAccountUnreadMessageNum(session.wechatAccountId, ({ unreadMesasgeNum, unreadMessageMuteNum }) => {
|
|
601
637
|
if (session.mute) {
|
|
@@ -75,8 +75,9 @@ export function createSessionData (message) {
|
|
|
75
75
|
lastMsgType: message.msgType,
|
|
76
76
|
lastUpdateTime: message.wechatTime,
|
|
77
77
|
targetId,
|
|
78
|
+
lastAtMsgContent: [],
|
|
78
79
|
unreadMsgCount: 0,
|
|
79
80
|
wechatAccountId: message.wechatAccountId
|
|
80
81
|
}
|
|
81
82
|
return nextSession
|
|
82
|
-
}
|
|
83
|
+
}
|