@onyx-p/imlib-web 1.5.4 → 1.5.6

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/index.esm.js CHANGED
@@ -18826,171 +18826,6 @@ const MessageTypes = {
18826
18826
  TRANSFER: 0x10001030
18827
18827
  };
18828
18828
 
18829
- const STATUSMESSAGE_ALIVE_TIMEMS = 6000;
18830
- function parse(orginalMsgs, callback) {
18831
- const msgs = new Map();
18832
- Object.keys(orginalMsgs).forEach(dialogId => {
18833
- const arr = orginalMsgs[dialogId].dialogMessage?.filter(m => !m.sharingGroupFlag);
18834
- if (arr?.length) {
18835
- msgs.set(dialogId, arr);
18836
- }
18837
- });
18838
- if (!msgs.size) {
18839
- callback(true, new Map());
18840
- return;
18841
- }
18842
- const remainDialogIds = new Set([...msgs.keys()]);
18843
- DialogSecretKey$1.getDialogAesKeyListInBatches([...msgs.keys()], (remote, aesKeys) => {
18844
- if (aesKeys.size) {
18845
- const dialogIds = [...aesKeys.keys()];
18846
- for (const k of dialogIds) {
18847
- remainDialogIds.delete(k);
18848
- }
18849
- callback(!remainDialogIds.size, parseDialogsMessages(dialogIds, msgs, aesKeys));
18850
- }
18851
- if (remainDialogIds.size && remote) {
18852
- callback(true, new Map());
18853
- }
18854
- });
18855
- }
18856
- const parseDialogsMessages = (dialogIdList, msgs, aesKeys) => {
18857
- const retVal = new Map();
18858
- dialogIdList.forEach(dialogId => {
18859
- const arr = parseSingleDialogMessages(dialogId, msgs.get(dialogId), aesKeys.get(dialogId));
18860
- if (arr.length) {
18861
- retVal.set(dialogId, arr);
18862
- }
18863
- });
18864
- return retVal;
18865
- };
18866
- const parseSingleDialogMessages = (dialogId, originalMessageList, aesKey) => {
18867
- const conversation = splitFullDialog(dialogId);
18868
- if (!conversation) {
18869
- return [];
18870
- }
18871
- const recallMessageUIds = new Set();
18872
- let contentList = [];
18873
- originalMessageList.forEach(item => {
18874
- const dialogMessage = item;
18875
- let mediaConstructor = dialogMessage.mediaConstructor;
18876
- let mediaAttributeJson = decodeMessageContent(dialogMessage, aesKey);
18877
- if (!mediaAttributeJson) return;
18878
- if (mediaConstructor === 0x60010012 || mediaConstructor === 0x60020021) {
18879
- const {
18880
- msgId,
18881
- sendTime
18882
- } = mediaAttributeJson;
18883
- const recallContent = {
18884
- msgId: msgId
18885
- };
18886
- mediaConstructor = MessageTypes.RECALL;
18887
- mediaAttributeJson = recallContent;
18888
- recallMessageUIds.add(msgId);
18889
- }
18890
- const messageInstance = decodeMessage(mediaConstructor, mediaAttributeJson);
18891
- if (isDef(messageInstance)) {
18892
- const receivedMessage = {
18893
- ...conversation,
18894
- senderUserId: dialogMessage.srcId.toString(),
18895
- messageDirection: dialogMessage.isOut ? MessageDirection.SEND : MessageDirection.RECEIVE,
18896
- isCounted: messageInstance.isCounted,
18897
- isMentioned: dialogMessage.atFlag,
18898
- content: messageInstance.content,
18899
- messageType: messageInstance.messageType,
18900
- isOffLineMessage: false,
18901
- isPersited: messageInstance.isPersited,
18902
- messageId: Long.isLong(dialogMessage.localId) ? dialogMessage.localId.toString() : undefined,
18903
- messageUId: dialogMessage.msgId.toString(),
18904
- sentTime: dialogMessage.seqno.toString(),
18905
- sentStatus: SentStatus.SENT,
18906
- receivedTime: getServerTime$1().toString(),
18907
- isStatusMessage: messageInstance.isStatusMessage,
18908
- receivedStatus: ReceivedStatus.READ,
18909
- disableNotification: false
18910
- };
18911
- if (receivedMessage.isStatusMessage && Long.fromNumber(getServerTime$1()).subtract(receivedMessage.sentTime).greaterThan(STATUSMESSAGE_ALIVE_TIMEMS)) {
18912
- return;
18913
- }
18914
- contentList.push(receivedMessage);
18915
- }
18916
- });
18917
- if (recallMessageUIds.size) {
18918
- contentList = contentList.filter(e => !recallMessageUIds.has(e.messageUId));
18919
- }
18920
- return contentList;
18921
- };
18922
- const decodeMessageContent = (dialogMessage, aesKey) => {
18923
- try {
18924
- let mediaAttribute;
18925
- if (dialogMessage.mediaAttribute?.length) {
18926
- mediaAttribute = aes256Decrypt(dialogMessage.mediaAttribute, aesKey);
18927
- } else {
18928
- mediaAttribute = dialogMessage.msgPreContent ?? '';
18929
- }
18930
- let msgPostContent;
18931
- if (dialogMessage.msgPostContent?.length) {
18932
- msgPostContent = aes256Decrypt(dialogMessage.msgPostContent, aesKey);
18933
- }
18934
- if (dialogMessage.mediaConstructor === 0x60010012 || dialogMessage.mediaConstructor === 0x60020021) {
18935
- mediaAttribute = transMsgIdNum64ToString(mediaAttribute);
18936
- }
18937
- return parseMediaAttributeJson(dialogMessage.mediaConstructor, mediaAttribute, msgPostContent);
18938
- } catch (error) {
18939
- logger.error('decode message content fail -> uid:', dialogMessage.msgId.toString());
18940
- return null;
18941
- }
18942
- };
18943
- const parseMediaAttributeJson = (mediaConstructor, mediaAttribute, msgPostContent) => {
18944
- let mediaAttributeJson = {};
18945
- if (mediaAttribute?.length) {
18946
- mediaAttributeJson = JSON.parse(mediaAttribute);
18947
- }
18948
- if (mediaConstructor == MessageTypes.TEXT && msgPostContent) {
18949
- mediaAttributeJson.content = msgPostContent;
18950
- }
18951
- return mediaAttributeJson;
18952
- };
18953
- const parseChatRecordMsgDetails$1 = (conversationOpt, msgDetails) => {
18954
- let contentList = [];
18955
- msgDetails.forEach(item => {
18956
- const mediaAttributeJson = parseMediaAttributeJson(item.mediaConstructor, item.mediaAttribute, item.msgPostContent);
18957
- if (!mediaAttributeJson) return;
18958
- const messageInstance = decodeMessage(item.mediaConstructor, mediaAttributeJson);
18959
- if (isDef(messageInstance)) {
18960
- const receivedMessage = {
18961
- ...conversationOpt,
18962
- senderUserId: item.srcId.toString(),
18963
- messageDirection: item.srcId == accountStore.uid ? MessageDirection.SEND : MessageDirection.RECEIVE,
18964
- isCounted: messageInstance.isCounted,
18965
- isMentioned: false,
18966
- content: messageInstance.content,
18967
- messageType: messageInstance.messageType,
18968
- isOffLineMessage: false,
18969
- isPersited: messageInstance.isPersited,
18970
- messageId: item.msgId + '',
18971
- messageUId: item.msgId + '',
18972
- sentTime: item.msgSendTime + '',
18973
- sentStatus: SentStatus.SENT,
18974
- receivedTime: item.msgSendTime + '',
18975
- isStatusMessage: messageInstance.isStatusMessage,
18976
- receivedStatus: ReceivedStatus.READ,
18977
- disableNotification: false
18978
- };
18979
- contentList.push(receivedMessage);
18980
- }
18981
- });
18982
- return contentList;
18983
- };
18984
- const transMsgIdNum64ToString = jsonString => {
18985
- const reg = /("msgId")\s*:\s*(\d+)/g;
18986
- return jsonString.replace(reg, (r1, r2, r3) => `${r2}:"${r3}"`);
18987
- };
18988
- var serverMessageParser = {
18989
- parse,
18990
- parseSingleDialogMessages,
18991
- parseChatRecordMsgDetails: parseChatRecordMsgDetails$1
18992
- };
18993
-
18994
18829
  function deepClone(obj) {
18995
18830
  if (!isDef(obj)) {
18996
18831
  return obj;
@@ -19712,6 +19547,172 @@ var ConversationManager$1 = {
19712
19547
  }
19713
19548
  };
19714
19549
 
19550
+ const STATUSMESSAGE_ALIVE_TIMEMS = 6000;
19551
+ function parse(orginalMsgs, callback) {
19552
+ const msgs = new Map();
19553
+ Object.keys(orginalMsgs).forEach(dialogId => {
19554
+ const arr = orginalMsgs[dialogId].dialogMessage?.filter(m => !m.sharingGroupFlag);
19555
+ if (arr?.length) {
19556
+ msgs.set(dialogId, arr);
19557
+ }
19558
+ });
19559
+ if (!msgs.size) {
19560
+ callback(true, new Map());
19561
+ return;
19562
+ }
19563
+ const remainDialogIds = new Set([...msgs.keys()]);
19564
+ DialogSecretKey$1.getDialogAesKeyListInBatches([...msgs.keys()], (remote, aesKeys) => {
19565
+ if (aesKeys.size) {
19566
+ const dialogIds = [...aesKeys.keys()];
19567
+ for (const k of dialogIds) {
19568
+ remainDialogIds.delete(k);
19569
+ }
19570
+ callback(!remainDialogIds.size, parseDialogsMessages(dialogIds, msgs, aesKeys));
19571
+ }
19572
+ if (remainDialogIds.size && remote) {
19573
+ callback(true, new Map());
19574
+ }
19575
+ });
19576
+ }
19577
+ const parseDialogsMessages = (dialogIdList, msgs, aesKeys) => {
19578
+ const retVal = new Map();
19579
+ dialogIdList.forEach(dialogId => {
19580
+ const arr = parseSingleDialogMessages(dialogId, msgs.get(dialogId), aesKeys.get(dialogId));
19581
+ if (arr.length) {
19582
+ retVal.set(dialogId, arr);
19583
+ }
19584
+ });
19585
+ return retVal;
19586
+ };
19587
+ const parseSingleDialogMessages = (dialogId, originalMessageList, aesKey) => {
19588
+ const conversation = splitFullDialog(dialogId);
19589
+ if (!conversation) {
19590
+ return [];
19591
+ }
19592
+ const localConversation = ConversationManager$1.get().get(conversation);
19593
+ const recallMessageUIds = new Set();
19594
+ let contentList = [];
19595
+ originalMessageList.forEach(item => {
19596
+ const dialogMessage = item;
19597
+ let mediaConstructor = dialogMessage.mediaConstructor;
19598
+ let mediaAttributeJson = decodeMessageContent(dialogMessage, aesKey);
19599
+ if (!mediaAttributeJson) return;
19600
+ if (mediaConstructor === 0x60010012 || mediaConstructor === 0x60020021) {
19601
+ const {
19602
+ msgId,
19603
+ sendTime
19604
+ } = mediaAttributeJson;
19605
+ const recallContent = {
19606
+ msgId: msgId
19607
+ };
19608
+ mediaConstructor = MessageTypes.RECALL;
19609
+ mediaAttributeJson = recallContent;
19610
+ recallMessageUIds.add(msgId);
19611
+ }
19612
+ const messageInstance = decodeMessage(mediaConstructor, mediaAttributeJson);
19613
+ if (isDef(messageInstance)) {
19614
+ const receivedMessage = {
19615
+ ...conversation,
19616
+ senderUserId: dialogMessage.srcId.toString(),
19617
+ messageDirection: dialogMessage.isOut ? MessageDirection.SEND : MessageDirection.RECEIVE,
19618
+ isCounted: messageInstance.isCounted,
19619
+ isMentioned: dialogMessage.atFlag,
19620
+ content: messageInstance.content,
19621
+ messageType: messageInstance.messageType,
19622
+ isOffLineMessage: false,
19623
+ isPersited: messageInstance.isPersited,
19624
+ messageId: Long.isLong(dialogMessage.localId) ? dialogMessage.localId.toString() : undefined,
19625
+ messageUId: dialogMessage.msgId.toString(),
19626
+ sentTime: dialogMessage.seqno.toString(),
19627
+ sentStatus: SentStatus.SENT,
19628
+ receivedTime: getServerTime$1().toString(),
19629
+ isStatusMessage: messageInstance.isStatusMessage,
19630
+ receivedStatus: ReceivedStatus.READ,
19631
+ disableNotification: localConversation?.notificationStatus === NotificationStatus.OPEN || dialogMessage.srcId.toString() == accountStore.uid
19632
+ };
19633
+ if (receivedMessage.isStatusMessage && Long.fromNumber(getServerTime$1()).subtract(receivedMessage.sentTime).greaterThan(STATUSMESSAGE_ALIVE_TIMEMS)) {
19634
+ return;
19635
+ }
19636
+ contentList.push(receivedMessage);
19637
+ }
19638
+ });
19639
+ if (recallMessageUIds.size) {
19640
+ contentList = contentList.filter(e => !recallMessageUIds.has(e.messageUId));
19641
+ }
19642
+ return contentList;
19643
+ };
19644
+ const decodeMessageContent = (dialogMessage, aesKey) => {
19645
+ try {
19646
+ let mediaAttribute;
19647
+ if (dialogMessage.mediaAttribute?.length) {
19648
+ mediaAttribute = aes256Decrypt(dialogMessage.mediaAttribute, aesKey);
19649
+ } else {
19650
+ mediaAttribute = dialogMessage.msgPreContent ?? '';
19651
+ }
19652
+ let msgPostContent;
19653
+ if (dialogMessage.msgPostContent?.length) {
19654
+ msgPostContent = aes256Decrypt(dialogMessage.msgPostContent, aesKey);
19655
+ }
19656
+ if (dialogMessage.mediaConstructor === 0x60010012 || dialogMessage.mediaConstructor === 0x60020021) {
19657
+ mediaAttribute = transMsgIdNum64ToString(mediaAttribute);
19658
+ }
19659
+ return parseMediaAttributeJson(dialogMessage.mediaConstructor, mediaAttribute, msgPostContent);
19660
+ } catch (error) {
19661
+ logger.error('decode message content fail -> uid:', dialogMessage.msgId.toString());
19662
+ return null;
19663
+ }
19664
+ };
19665
+ const parseMediaAttributeJson = (mediaConstructor, mediaAttribute, msgPostContent) => {
19666
+ let mediaAttributeJson = {};
19667
+ if (mediaAttribute?.length) {
19668
+ mediaAttributeJson = JSON.parse(mediaAttribute);
19669
+ }
19670
+ if (mediaConstructor == MessageTypes.TEXT && msgPostContent) {
19671
+ mediaAttributeJson.content = msgPostContent;
19672
+ }
19673
+ return mediaAttributeJson;
19674
+ };
19675
+ const parseChatRecordMsgDetails$1 = (conversationOpt, msgDetails) => {
19676
+ let contentList = [];
19677
+ msgDetails.forEach(item => {
19678
+ const mediaAttributeJson = parseMediaAttributeJson(item.mediaConstructor, item.mediaAttribute, item.msgPostContent);
19679
+ if (!mediaAttributeJson) return;
19680
+ const messageInstance = decodeMessage(item.mediaConstructor, mediaAttributeJson);
19681
+ if (isDef(messageInstance)) {
19682
+ const receivedMessage = {
19683
+ ...conversationOpt,
19684
+ senderUserId: item.srcId.toString(),
19685
+ messageDirection: item.srcId == accountStore.uid ? MessageDirection.SEND : MessageDirection.RECEIVE,
19686
+ isCounted: messageInstance.isCounted,
19687
+ isMentioned: false,
19688
+ content: messageInstance.content,
19689
+ messageType: messageInstance.messageType,
19690
+ isOffLineMessage: false,
19691
+ isPersited: messageInstance.isPersited,
19692
+ messageId: item.msgId + '',
19693
+ messageUId: item.msgId + '',
19694
+ sentTime: item.msgSendTime + '',
19695
+ sentStatus: SentStatus.SENT,
19696
+ receivedTime: item.msgSendTime + '',
19697
+ isStatusMessage: messageInstance.isStatusMessage,
19698
+ receivedStatus: ReceivedStatus.READ,
19699
+ disableNotification: false
19700
+ };
19701
+ contentList.push(receivedMessage);
19702
+ }
19703
+ });
19704
+ return contentList;
19705
+ };
19706
+ const transMsgIdNum64ToString = jsonString => {
19707
+ const reg = /("msgId")\s*:\s*(\d+)/g;
19708
+ return jsonString.replace(reg, (r1, r2, r3) => `${r2}:"${r3}"`);
19709
+ };
19710
+ var serverMessageParser = {
19711
+ parse,
19712
+ parseSingleDialogMessages,
19713
+ parseChatRecordMsgDetails: parseChatRecordMsgDetails$1
19714
+ };
19715
+
19715
19716
  class MessageLoader {
19716
19717
  watcher;
19717
19718
  pullingMsg = false;
@@ -19806,7 +19807,6 @@ class MessageLoader {
19806
19807
  await ConversationManager$1.get().loadConvsationsIfNotExist(cons);
19807
19808
  serverMessageParser.parse(msg, (done, outputMsgs) => {
19808
19809
  const messages = [];
19809
- const conversations = [];
19810
19810
  const isOffLineMessage = !this.pullOfflineFinished;
19811
19811
  outputMsgs.forEach((l, dialogId) => {
19812
19812
  const messageList = [];
@@ -19823,16 +19823,12 @@ class MessageLoader {
19823
19823
  });
19824
19824
  messages.push(...messageList);
19825
19825
  if (this.isExistPersistedMessage(messageList)) {
19826
- const conOpt = splitFullDialog(dialogId);
19827
- conOpt && conversations.push(conOpt);
19826
+ splitFullDialog(dialogId);
19828
19827
  }
19829
19828
  });
19830
19829
  if (messages.length) {
19831
19830
  this.watcher.batchMessage?.(messages);
19832
19831
  }
19833
- if (conversations.length) {
19834
- ConversationManager$1.get().loadConvsationsIfNotExist(conversations);
19835
- }
19836
19832
  if (done) {
19837
19833
  if (seqno.ge(this.serverMsgSeqno)) {
19838
19834
  this.serverMsgSeqno = seqno;
@@ -26670,7 +26666,7 @@ const transSentAttrs2IReceivedMessage = (message, options, sentStatus = SentStat
26670
26666
  receivedTime: '0',
26671
26667
  isStatusMessage: message.isStatusMessage,
26672
26668
  receivedStatus: ReceivedStatus.UNREAD,
26673
- disableNotification: false
26669
+ disableNotification: true
26674
26670
  });
26675
26671
 
26676
26672
  let UniqueLocalId = 0;
@@ -28615,16 +28611,7 @@ const getAllUnreadMentionedCount = () => {
28615
28611
  };
28616
28612
  const getConversationState = options => {
28617
28613
  logger.debug('getConversationState');
28618
- const state = imClient.getConversationState(options);
28619
- if (state) {
28620
- return Promise.resolve({
28621
- code: ErrorCode.SUCCESS,
28622
- data: state
28623
- });
28624
- }
28625
- return Promise.resolve({
28626
- code: ErrorCode.UNKNOWN
28627
- });
28614
+ return imClient.getConversationState(options);
28628
28615
  };
28629
28616
  const getAllConversationState = () => {
28630
28617
  logger.debug('getAllConversationState');
package/index.umd.js CHANGED
@@ -18832,171 +18832,6 @@
18832
18832
  TRANSFER: 0x10001030
18833
18833
  };
18834
18834
 
18835
- const STATUSMESSAGE_ALIVE_TIMEMS = 6000;
18836
- function parse(orginalMsgs, callback) {
18837
- const msgs = new Map();
18838
- Object.keys(orginalMsgs).forEach(dialogId => {
18839
- const arr = orginalMsgs[dialogId].dialogMessage?.filter(m => !m.sharingGroupFlag);
18840
- if (arr?.length) {
18841
- msgs.set(dialogId, arr);
18842
- }
18843
- });
18844
- if (!msgs.size) {
18845
- callback(true, new Map());
18846
- return;
18847
- }
18848
- const remainDialogIds = new Set([...msgs.keys()]);
18849
- DialogSecretKey$1.getDialogAesKeyListInBatches([...msgs.keys()], (remote, aesKeys) => {
18850
- if (aesKeys.size) {
18851
- const dialogIds = [...aesKeys.keys()];
18852
- for (const k of dialogIds) {
18853
- remainDialogIds.delete(k);
18854
- }
18855
- callback(!remainDialogIds.size, parseDialogsMessages(dialogIds, msgs, aesKeys));
18856
- }
18857
- if (remainDialogIds.size && remote) {
18858
- callback(true, new Map());
18859
- }
18860
- });
18861
- }
18862
- const parseDialogsMessages = (dialogIdList, msgs, aesKeys) => {
18863
- const retVal = new Map();
18864
- dialogIdList.forEach(dialogId => {
18865
- const arr = parseSingleDialogMessages(dialogId, msgs.get(dialogId), aesKeys.get(dialogId));
18866
- if (arr.length) {
18867
- retVal.set(dialogId, arr);
18868
- }
18869
- });
18870
- return retVal;
18871
- };
18872
- const parseSingleDialogMessages = (dialogId, originalMessageList, aesKey) => {
18873
- const conversation = splitFullDialog(dialogId);
18874
- if (!conversation) {
18875
- return [];
18876
- }
18877
- const recallMessageUIds = new Set();
18878
- let contentList = [];
18879
- originalMessageList.forEach(item => {
18880
- const dialogMessage = item;
18881
- let mediaConstructor = dialogMessage.mediaConstructor;
18882
- let mediaAttributeJson = decodeMessageContent(dialogMessage, aesKey);
18883
- if (!mediaAttributeJson) return;
18884
- if (mediaConstructor === 0x60010012 || mediaConstructor === 0x60020021) {
18885
- const {
18886
- msgId,
18887
- sendTime
18888
- } = mediaAttributeJson;
18889
- const recallContent = {
18890
- msgId: msgId
18891
- };
18892
- mediaConstructor = MessageTypes.RECALL;
18893
- mediaAttributeJson = recallContent;
18894
- recallMessageUIds.add(msgId);
18895
- }
18896
- const messageInstance = decodeMessage(mediaConstructor, mediaAttributeJson);
18897
- if (isDef(messageInstance)) {
18898
- const receivedMessage = {
18899
- ...conversation,
18900
- senderUserId: dialogMessage.srcId.toString(),
18901
- messageDirection: dialogMessage.isOut ? exports.MessageDirection.SEND : exports.MessageDirection.RECEIVE,
18902
- isCounted: messageInstance.isCounted,
18903
- isMentioned: dialogMessage.atFlag,
18904
- content: messageInstance.content,
18905
- messageType: messageInstance.messageType,
18906
- isOffLineMessage: false,
18907
- isPersited: messageInstance.isPersited,
18908
- messageId: Long.isLong(dialogMessage.localId) ? dialogMessage.localId.toString() : undefined,
18909
- messageUId: dialogMessage.msgId.toString(),
18910
- sentTime: dialogMessage.seqno.toString(),
18911
- sentStatus: exports.SentStatus.SENT,
18912
- receivedTime: getServerTime$1().toString(),
18913
- isStatusMessage: messageInstance.isStatusMessage,
18914
- receivedStatus: exports.ReceivedStatus.READ,
18915
- disableNotification: false
18916
- };
18917
- if (receivedMessage.isStatusMessage && Long.fromNumber(getServerTime$1()).subtract(receivedMessage.sentTime).greaterThan(STATUSMESSAGE_ALIVE_TIMEMS)) {
18918
- return;
18919
- }
18920
- contentList.push(receivedMessage);
18921
- }
18922
- });
18923
- if (recallMessageUIds.size) {
18924
- contentList = contentList.filter(e => !recallMessageUIds.has(e.messageUId));
18925
- }
18926
- return contentList;
18927
- };
18928
- const decodeMessageContent = (dialogMessage, aesKey) => {
18929
- try {
18930
- let mediaAttribute;
18931
- if (dialogMessage.mediaAttribute?.length) {
18932
- mediaAttribute = aes256Decrypt(dialogMessage.mediaAttribute, aesKey);
18933
- } else {
18934
- mediaAttribute = dialogMessage.msgPreContent ?? '';
18935
- }
18936
- let msgPostContent;
18937
- if (dialogMessage.msgPostContent?.length) {
18938
- msgPostContent = aes256Decrypt(dialogMessage.msgPostContent, aesKey);
18939
- }
18940
- if (dialogMessage.mediaConstructor === 0x60010012 || dialogMessage.mediaConstructor === 0x60020021) {
18941
- mediaAttribute = transMsgIdNum64ToString(mediaAttribute);
18942
- }
18943
- return parseMediaAttributeJson(dialogMessage.mediaConstructor, mediaAttribute, msgPostContent);
18944
- } catch (error) {
18945
- logger.error('decode message content fail -> uid:', dialogMessage.msgId.toString());
18946
- return null;
18947
- }
18948
- };
18949
- const parseMediaAttributeJson = (mediaConstructor, mediaAttribute, msgPostContent) => {
18950
- let mediaAttributeJson = {};
18951
- if (mediaAttribute?.length) {
18952
- mediaAttributeJson = JSON.parse(mediaAttribute);
18953
- }
18954
- if (mediaConstructor == MessageTypes.TEXT && msgPostContent) {
18955
- mediaAttributeJson.content = msgPostContent;
18956
- }
18957
- return mediaAttributeJson;
18958
- };
18959
- const parseChatRecordMsgDetails$1 = (conversationOpt, msgDetails) => {
18960
- let contentList = [];
18961
- msgDetails.forEach(item => {
18962
- const mediaAttributeJson = parseMediaAttributeJson(item.mediaConstructor, item.mediaAttribute, item.msgPostContent);
18963
- if (!mediaAttributeJson) return;
18964
- const messageInstance = decodeMessage(item.mediaConstructor, mediaAttributeJson);
18965
- if (isDef(messageInstance)) {
18966
- const receivedMessage = {
18967
- ...conversationOpt,
18968
- senderUserId: item.srcId.toString(),
18969
- messageDirection: item.srcId == accountStore.uid ? exports.MessageDirection.SEND : exports.MessageDirection.RECEIVE,
18970
- isCounted: messageInstance.isCounted,
18971
- isMentioned: false,
18972
- content: messageInstance.content,
18973
- messageType: messageInstance.messageType,
18974
- isOffLineMessage: false,
18975
- isPersited: messageInstance.isPersited,
18976
- messageId: item.msgId + '',
18977
- messageUId: item.msgId + '',
18978
- sentTime: item.msgSendTime + '',
18979
- sentStatus: exports.SentStatus.SENT,
18980
- receivedTime: item.msgSendTime + '',
18981
- isStatusMessage: messageInstance.isStatusMessage,
18982
- receivedStatus: exports.ReceivedStatus.READ,
18983
- disableNotification: false
18984
- };
18985
- contentList.push(receivedMessage);
18986
- }
18987
- });
18988
- return contentList;
18989
- };
18990
- const transMsgIdNum64ToString = jsonString => {
18991
- const reg = /("msgId")\s*:\s*(\d+)/g;
18992
- return jsonString.replace(reg, (r1, r2, r3) => `${r2}:"${r3}"`);
18993
- };
18994
- var serverMessageParser = {
18995
- parse,
18996
- parseSingleDialogMessages,
18997
- parseChatRecordMsgDetails: parseChatRecordMsgDetails$1
18998
- };
18999
-
19000
18835
  function deepClone(obj) {
19001
18836
  if (!isDef(obj)) {
19002
18837
  return obj;
@@ -19718,6 +19553,172 @@
19718
19553
  }
19719
19554
  };
19720
19555
 
19556
+ const STATUSMESSAGE_ALIVE_TIMEMS = 6000;
19557
+ function parse(orginalMsgs, callback) {
19558
+ const msgs = new Map();
19559
+ Object.keys(orginalMsgs).forEach(dialogId => {
19560
+ const arr = orginalMsgs[dialogId].dialogMessage?.filter(m => !m.sharingGroupFlag);
19561
+ if (arr?.length) {
19562
+ msgs.set(dialogId, arr);
19563
+ }
19564
+ });
19565
+ if (!msgs.size) {
19566
+ callback(true, new Map());
19567
+ return;
19568
+ }
19569
+ const remainDialogIds = new Set([...msgs.keys()]);
19570
+ DialogSecretKey$1.getDialogAesKeyListInBatches([...msgs.keys()], (remote, aesKeys) => {
19571
+ if (aesKeys.size) {
19572
+ const dialogIds = [...aesKeys.keys()];
19573
+ for (const k of dialogIds) {
19574
+ remainDialogIds.delete(k);
19575
+ }
19576
+ callback(!remainDialogIds.size, parseDialogsMessages(dialogIds, msgs, aesKeys));
19577
+ }
19578
+ if (remainDialogIds.size && remote) {
19579
+ callback(true, new Map());
19580
+ }
19581
+ });
19582
+ }
19583
+ const parseDialogsMessages = (dialogIdList, msgs, aesKeys) => {
19584
+ const retVal = new Map();
19585
+ dialogIdList.forEach(dialogId => {
19586
+ const arr = parseSingleDialogMessages(dialogId, msgs.get(dialogId), aesKeys.get(dialogId));
19587
+ if (arr.length) {
19588
+ retVal.set(dialogId, arr);
19589
+ }
19590
+ });
19591
+ return retVal;
19592
+ };
19593
+ const parseSingleDialogMessages = (dialogId, originalMessageList, aesKey) => {
19594
+ const conversation = splitFullDialog(dialogId);
19595
+ if (!conversation) {
19596
+ return [];
19597
+ }
19598
+ const localConversation = ConversationManager$1.get().get(conversation);
19599
+ const recallMessageUIds = new Set();
19600
+ let contentList = [];
19601
+ originalMessageList.forEach(item => {
19602
+ const dialogMessage = item;
19603
+ let mediaConstructor = dialogMessage.mediaConstructor;
19604
+ let mediaAttributeJson = decodeMessageContent(dialogMessage, aesKey);
19605
+ if (!mediaAttributeJson) return;
19606
+ if (mediaConstructor === 0x60010012 || mediaConstructor === 0x60020021) {
19607
+ const {
19608
+ msgId,
19609
+ sendTime
19610
+ } = mediaAttributeJson;
19611
+ const recallContent = {
19612
+ msgId: msgId
19613
+ };
19614
+ mediaConstructor = MessageTypes.RECALL;
19615
+ mediaAttributeJson = recallContent;
19616
+ recallMessageUIds.add(msgId);
19617
+ }
19618
+ const messageInstance = decodeMessage(mediaConstructor, mediaAttributeJson);
19619
+ if (isDef(messageInstance)) {
19620
+ const receivedMessage = {
19621
+ ...conversation,
19622
+ senderUserId: dialogMessage.srcId.toString(),
19623
+ messageDirection: dialogMessage.isOut ? exports.MessageDirection.SEND : exports.MessageDirection.RECEIVE,
19624
+ isCounted: messageInstance.isCounted,
19625
+ isMentioned: dialogMessage.atFlag,
19626
+ content: messageInstance.content,
19627
+ messageType: messageInstance.messageType,
19628
+ isOffLineMessage: false,
19629
+ isPersited: messageInstance.isPersited,
19630
+ messageId: Long.isLong(dialogMessage.localId) ? dialogMessage.localId.toString() : undefined,
19631
+ messageUId: dialogMessage.msgId.toString(),
19632
+ sentTime: dialogMessage.seqno.toString(),
19633
+ sentStatus: exports.SentStatus.SENT,
19634
+ receivedTime: getServerTime$1().toString(),
19635
+ isStatusMessage: messageInstance.isStatusMessage,
19636
+ receivedStatus: exports.ReceivedStatus.READ,
19637
+ disableNotification: localConversation?.notificationStatus === exports.NotificationStatus.OPEN || dialogMessage.srcId.toString() == accountStore.uid
19638
+ };
19639
+ if (receivedMessage.isStatusMessage && Long.fromNumber(getServerTime$1()).subtract(receivedMessage.sentTime).greaterThan(STATUSMESSAGE_ALIVE_TIMEMS)) {
19640
+ return;
19641
+ }
19642
+ contentList.push(receivedMessage);
19643
+ }
19644
+ });
19645
+ if (recallMessageUIds.size) {
19646
+ contentList = contentList.filter(e => !recallMessageUIds.has(e.messageUId));
19647
+ }
19648
+ return contentList;
19649
+ };
19650
+ const decodeMessageContent = (dialogMessage, aesKey) => {
19651
+ try {
19652
+ let mediaAttribute;
19653
+ if (dialogMessage.mediaAttribute?.length) {
19654
+ mediaAttribute = aes256Decrypt(dialogMessage.mediaAttribute, aesKey);
19655
+ } else {
19656
+ mediaAttribute = dialogMessage.msgPreContent ?? '';
19657
+ }
19658
+ let msgPostContent;
19659
+ if (dialogMessage.msgPostContent?.length) {
19660
+ msgPostContent = aes256Decrypt(dialogMessage.msgPostContent, aesKey);
19661
+ }
19662
+ if (dialogMessage.mediaConstructor === 0x60010012 || dialogMessage.mediaConstructor === 0x60020021) {
19663
+ mediaAttribute = transMsgIdNum64ToString(mediaAttribute);
19664
+ }
19665
+ return parseMediaAttributeJson(dialogMessage.mediaConstructor, mediaAttribute, msgPostContent);
19666
+ } catch (error) {
19667
+ logger.error('decode message content fail -> uid:', dialogMessage.msgId.toString());
19668
+ return null;
19669
+ }
19670
+ };
19671
+ const parseMediaAttributeJson = (mediaConstructor, mediaAttribute, msgPostContent) => {
19672
+ let mediaAttributeJson = {};
19673
+ if (mediaAttribute?.length) {
19674
+ mediaAttributeJson = JSON.parse(mediaAttribute);
19675
+ }
19676
+ if (mediaConstructor == MessageTypes.TEXT && msgPostContent) {
19677
+ mediaAttributeJson.content = msgPostContent;
19678
+ }
19679
+ return mediaAttributeJson;
19680
+ };
19681
+ const parseChatRecordMsgDetails$1 = (conversationOpt, msgDetails) => {
19682
+ let contentList = [];
19683
+ msgDetails.forEach(item => {
19684
+ const mediaAttributeJson = parseMediaAttributeJson(item.mediaConstructor, item.mediaAttribute, item.msgPostContent);
19685
+ if (!mediaAttributeJson) return;
19686
+ const messageInstance = decodeMessage(item.mediaConstructor, mediaAttributeJson);
19687
+ if (isDef(messageInstance)) {
19688
+ const receivedMessage = {
19689
+ ...conversationOpt,
19690
+ senderUserId: item.srcId.toString(),
19691
+ messageDirection: item.srcId == accountStore.uid ? exports.MessageDirection.SEND : exports.MessageDirection.RECEIVE,
19692
+ isCounted: messageInstance.isCounted,
19693
+ isMentioned: false,
19694
+ content: messageInstance.content,
19695
+ messageType: messageInstance.messageType,
19696
+ isOffLineMessage: false,
19697
+ isPersited: messageInstance.isPersited,
19698
+ messageId: item.msgId + '',
19699
+ messageUId: item.msgId + '',
19700
+ sentTime: item.msgSendTime + '',
19701
+ sentStatus: exports.SentStatus.SENT,
19702
+ receivedTime: item.msgSendTime + '',
19703
+ isStatusMessage: messageInstance.isStatusMessage,
19704
+ receivedStatus: exports.ReceivedStatus.READ,
19705
+ disableNotification: false
19706
+ };
19707
+ contentList.push(receivedMessage);
19708
+ }
19709
+ });
19710
+ return contentList;
19711
+ };
19712
+ const transMsgIdNum64ToString = jsonString => {
19713
+ const reg = /("msgId")\s*:\s*(\d+)/g;
19714
+ return jsonString.replace(reg, (r1, r2, r3) => `${r2}:"${r3}"`);
19715
+ };
19716
+ var serverMessageParser = {
19717
+ parse,
19718
+ parseSingleDialogMessages,
19719
+ parseChatRecordMsgDetails: parseChatRecordMsgDetails$1
19720
+ };
19721
+
19721
19722
  class MessageLoader {
19722
19723
  watcher;
19723
19724
  pullingMsg = false;
@@ -19812,7 +19813,6 @@
19812
19813
  await ConversationManager$1.get().loadConvsationsIfNotExist(cons);
19813
19814
  serverMessageParser.parse(msg, (done, outputMsgs) => {
19814
19815
  const messages = [];
19815
- const conversations = [];
19816
19816
  const isOffLineMessage = !this.pullOfflineFinished;
19817
19817
  outputMsgs.forEach((l, dialogId) => {
19818
19818
  const messageList = [];
@@ -19829,16 +19829,12 @@
19829
19829
  });
19830
19830
  messages.push(...messageList);
19831
19831
  if (this.isExistPersistedMessage(messageList)) {
19832
- const conOpt = splitFullDialog(dialogId);
19833
- conOpt && conversations.push(conOpt);
19832
+ splitFullDialog(dialogId);
19834
19833
  }
19835
19834
  });
19836
19835
  if (messages.length) {
19837
19836
  this.watcher.batchMessage?.(messages);
19838
19837
  }
19839
- if (conversations.length) {
19840
- ConversationManager$1.get().loadConvsationsIfNotExist(conversations);
19841
- }
19842
19838
  if (done) {
19843
19839
  if (seqno.ge(this.serverMsgSeqno)) {
19844
19840
  this.serverMsgSeqno = seqno;
@@ -26676,7 +26672,7 @@
26676
26672
  receivedTime: '0',
26677
26673
  isStatusMessage: message.isStatusMessage,
26678
26674
  receivedStatus: exports.ReceivedStatus.UNREAD,
26679
- disableNotification: false
26675
+ disableNotification: true
26680
26676
  });
26681
26677
 
26682
26678
  let UniqueLocalId = 0;
@@ -28621,16 +28617,7 @@
28621
28617
  };
28622
28618
  const getConversationState = options => {
28623
28619
  logger.debug('getConversationState');
28624
- const state = imClient.getConversationState(options);
28625
- if (state) {
28626
- return Promise.resolve({
28627
- code: exports.ErrorCode.SUCCESS,
28628
- data: state
28629
- });
28630
- }
28631
- return Promise.resolve({
28632
- code: exports.ErrorCode.UNKNOWN
28633
- });
28620
+ return imClient.getConversationState(options);
28634
28621
  };
28635
28622
  const getAllConversationState = () => {
28636
28623
  logger.debug('getAllConversationState');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onyx-p/imlib-web",
3
- "version": "1.5.4",
3
+ "version": "1.5.6",
4
4
  "main": "index.umd.js",
5
5
  "module": "index.esm.js",
6
6
  "types": "types/index.d.ts",
package/types/index.d.ts CHANGED
@@ -101,7 +101,7 @@ export declare const getAllUnreadMentionedCount: () => IPromiseResult<number>;
101
101
  /**
102
102
  * 获取本地单个会话的状态
103
103
  */
104
- export declare const getConversationState: (options: IConversationOption) => IPromiseResult<IConversationState>;
104
+ export declare const getConversationState: (options: IConversationOption) => IConversationState | null;
105
105
  /**
106
106
  * 获取本地全部会话的状态
107
107
  * @description