@onyx-p/imlib-web 1.3.4 → 1.3.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 +123 -196
- package/index.umd.js +123 -196
- package/package.json +1 -1
- package/types/model/baseMessage.d.ts +0 -4
- package/types/types.d.ts +0 -4
package/index.esm.js
CHANGED
@@ -8017,9 +8017,9 @@ var CmdIds;
|
|
8017
8017
|
CmdIds[CmdIds["DeletePrivateDialog"] = 1610682372] = "DeletePrivateDialog";
|
8018
8018
|
CmdIds[CmdIds["DeleteGroupDialog"] = 1610747908] = "DeleteGroupDialog";
|
8019
8019
|
CmdIds[CmdIds["GetDialogChangedStatus"] = 1610711094] = "GetDialogChangedStatus";
|
8020
|
+
CmdIds[CmdIds["HeartbeanResp"] = 268468225] = "HeartbeanResp";
|
8020
8021
|
CmdIds[CmdIds["NewMessagePush"] = 1610711040] = "NewMessagePush";
|
8021
8022
|
CmdIds[CmdIds["DialogChangedPush"] = 1610711096] = "DialogChangedPush";
|
8022
|
-
CmdIds[CmdIds["AppAllowLoginPush"] = 806453286] = "AppAllowLoginPush";
|
8023
8023
|
CmdIds[CmdIds["SessionKilledPush"] = 268468229] = "SessionKilledPush";
|
8024
8024
|
CmdIds[CmdIds["SignOutPish"] = 268439559] = "SignOutPish";
|
8025
8025
|
CmdIds[CmdIds["SignOutPish2"] = 268468231] = "SignOutPish2";
|
@@ -13394,7 +13394,9 @@ class WebSocketServer {
|
|
13394
13394
|
body: body,
|
13395
13395
|
deviceType: 7
|
13396
13396
|
};
|
13397
|
-
|
13397
|
+
if (cmdId !== CmdIds$1.Heartbean) {
|
13398
|
+
logger.info(`websocket send -> cmd: 0x${cmdId.toString(16)}, messageSeq: ${messageSeq}`);
|
13399
|
+
}
|
13398
13400
|
this.socket.send(buildWsPacketData(rpc_baseExports.NetworkRequest.encode(networkReq).finish()));
|
13399
13401
|
const respData = await new Promise(resolve => {
|
13400
13402
|
this.responseCallbacks.set(messageSeq, resolve);
|
@@ -13513,7 +13515,9 @@ class WebSocketServer {
|
|
13513
13515
|
return;
|
13514
13516
|
}
|
13515
13517
|
const messageSeq = Long.isLong(networkResponse.messageSeq) ? networkResponse.messageSeq.toNumber() : 0;
|
13516
|
-
|
13518
|
+
if (networkResponse.cmdId !== CmdIds$1.HeartbeanResp) {
|
13519
|
+
logger.info(`websocket recv ack -> messageSeq: ${messageSeq}`);
|
13520
|
+
}
|
13517
13521
|
const resolve = this.responseCallbacks.get(messageSeq);
|
13518
13522
|
if (isDef(resolve)) {
|
13519
13523
|
resolve(networkResponse.body);
|
@@ -17556,11 +17560,6 @@ const SendGroupChatMessageReq = $root.SendGroupChatMessageReq = (() => {
|
|
17556
17560
|
* @property {number|null} [mediaConstructor] SendGroupChatMessageReq mediaConstructor
|
17557
17561
|
* @property {string|null} [mediaAttribute] SendGroupChatMessageReq mediaAttribute
|
17558
17562
|
* @property {Array.<Long>|null} [at] SendGroupChatMessageReq at
|
17559
|
-
* @property {string|null} [extra] SendGroupChatMessageReq extra
|
17560
|
-
* @property {string|null} [assign] SendGroupChatMessageReq assign
|
17561
|
-
* @property {boolean|null} [atAll] SendGroupChatMessageReq atAll
|
17562
|
-
* @property {Uint8Array|null} [msgContent] SendGroupChatMessageReq msgContent
|
17563
|
-
* @property {string|null} [pushContent] SendGroupChatMessageReq pushContent
|
17564
17563
|
*/
|
17565
17564
|
|
17566
17565
|
/**
|
@@ -17640,46 +17639,6 @@ const SendGroupChatMessageReq = $root.SendGroupChatMessageReq = (() => {
|
|
17640
17639
|
*/
|
17641
17640
|
SendGroupChatMessageReq.prototype.at = $util.emptyArray;
|
17642
17641
|
|
17643
|
-
/**
|
17644
|
-
* SendGroupChatMessageReq extra.
|
17645
|
-
* @member {string} extra
|
17646
|
-
* @memberof SendGroupChatMessageReq
|
17647
|
-
* @instance
|
17648
|
-
*/
|
17649
|
-
SendGroupChatMessageReq.prototype.extra = "";
|
17650
|
-
|
17651
|
-
/**
|
17652
|
-
* SendGroupChatMessageReq assign.
|
17653
|
-
* @member {string} assign
|
17654
|
-
* @memberof SendGroupChatMessageReq
|
17655
|
-
* @instance
|
17656
|
-
*/
|
17657
|
-
SendGroupChatMessageReq.prototype.assign = "";
|
17658
|
-
|
17659
|
-
/**
|
17660
|
-
* SendGroupChatMessageReq atAll.
|
17661
|
-
* @member {boolean} atAll
|
17662
|
-
* @memberof SendGroupChatMessageReq
|
17663
|
-
* @instance
|
17664
|
-
*/
|
17665
|
-
SendGroupChatMessageReq.prototype.atAll = false;
|
17666
|
-
|
17667
|
-
/**
|
17668
|
-
* SendGroupChatMessageReq msgContent.
|
17669
|
-
* @member {Uint8Array} msgContent
|
17670
|
-
* @memberof SendGroupChatMessageReq
|
17671
|
-
* @instance
|
17672
|
-
*/
|
17673
|
-
SendGroupChatMessageReq.prototype.msgContent = $util.newBuffer([]);
|
17674
|
-
|
17675
|
-
/**
|
17676
|
-
* SendGroupChatMessageReq pushContent.
|
17677
|
-
* @member {string} pushContent
|
17678
|
-
* @memberof SendGroupChatMessageReq
|
17679
|
-
* @instance
|
17680
|
-
*/
|
17681
|
-
SendGroupChatMessageReq.prototype.pushContent = "";
|
17682
|
-
|
17683
17642
|
/**
|
17684
17643
|
* Encodes the specified SendGroupChatMessageReq message. Does not implicitly {@link SendGroupChatMessageReq.verify|verify} messages.
|
17685
17644
|
* @function encode
|
@@ -17703,11 +17662,6 @@ const SendGroupChatMessageReq = $root.SendGroupChatMessageReq = (() => {
|
|
17703
17662
|
for (let i = 0; i < message.at.length; ++i) writer.int64(message.at[i]);
|
17704
17663
|
writer.ldelim();
|
17705
17664
|
}
|
17706
|
-
if (message.extra != null && Object.hasOwnProperty.call(message, "extra")) writer.uint32(/* id 9, wireType 2 =*/74).string(message.extra);
|
17707
|
-
if (message.assign != null && Object.hasOwnProperty.call(message, "assign")) writer.uint32(/* id 10, wireType 2 =*/82).string(message.assign);
|
17708
|
-
if (message.atAll != null && Object.hasOwnProperty.call(message, "atAll")) writer.uint32(/* id 11, wireType 0 =*/88).bool(message.atAll);
|
17709
|
-
if (message.msgContent != null && Object.hasOwnProperty.call(message, "msgContent")) writer.uint32(/* id 12, wireType 2 =*/98).bytes(message.msgContent);
|
17710
|
-
if (message.pushContent != null && Object.hasOwnProperty.call(message, "pushContent")) writer.uint32(/* id 13, wireType 2 =*/106).string(message.pushContent);
|
17711
17665
|
return writer;
|
17712
17666
|
};
|
17713
17667
|
|
@@ -17773,31 +17727,6 @@ const SendGroupChatMessageReq = $root.SendGroupChatMessageReq = (() => {
|
|
17773
17727
|
} else message.at.push(reader.int64());
|
17774
17728
|
break;
|
17775
17729
|
}
|
17776
|
-
case 9:
|
17777
|
-
{
|
17778
|
-
message.extra = reader.string();
|
17779
|
-
break;
|
17780
|
-
}
|
17781
|
-
case 10:
|
17782
|
-
{
|
17783
|
-
message.assign = reader.string();
|
17784
|
-
break;
|
17785
|
-
}
|
17786
|
-
case 11:
|
17787
|
-
{
|
17788
|
-
message.atAll = reader.bool();
|
17789
|
-
break;
|
17790
|
-
}
|
17791
|
-
case 12:
|
17792
|
-
{
|
17793
|
-
message.msgContent = reader.bytes();
|
17794
|
-
break;
|
17795
|
-
}
|
17796
|
-
case 13:
|
17797
|
-
{
|
17798
|
-
message.pushContent = reader.string();
|
17799
|
-
break;
|
17800
|
-
}
|
17801
17730
|
default:
|
17802
17731
|
reader.skipType(tag & 7);
|
17803
17732
|
break;
|
@@ -18712,6 +18641,24 @@ var RecallMessageStore = {
|
|
18712
18641
|
}
|
18713
18642
|
};
|
18714
18643
|
|
18644
|
+
const MessageStores = new Map();
|
18645
|
+
function registerMessage(messageType, messageConstructor) {
|
18646
|
+
MessageStores.set(messageType, messageConstructor);
|
18647
|
+
}
|
18648
|
+
function decodeMessage(messageType, messageData) {
|
18649
|
+
const MessageConstructor = MessageStores.get(messageType);
|
18650
|
+
if (!MessageConstructor) {
|
18651
|
+
console.warn(`No message constructor found for type: ${messageType}`);
|
18652
|
+
return null;
|
18653
|
+
}
|
18654
|
+
try {
|
18655
|
+
return new MessageConstructor(messageData);
|
18656
|
+
} catch (error) {
|
18657
|
+
console.error(`Failed to decode message type ${messageType}:`, error);
|
18658
|
+
return null;
|
18659
|
+
}
|
18660
|
+
}
|
18661
|
+
|
18715
18662
|
class DialogSecretKey {
|
18716
18663
|
aesKeyRecord = new Map();
|
18717
18664
|
async getDialogAesKey(dialogId) {
|
@@ -18776,7 +18723,7 @@ class DialogSecretKey {
|
|
18776
18723
|
const {
|
18777
18724
|
code,
|
18778
18725
|
data
|
18779
|
-
} = await getDialogKey(dialogIdList);
|
18726
|
+
} = await getDialogKey(dialogIdList.map(e => Long.fromString(e)));
|
18780
18727
|
if (code === ErrorCode.SUCCESS) {
|
18781
18728
|
const content = new Map();
|
18782
18729
|
for (const k in data.entry) {
|
@@ -18786,9 +18733,8 @@ class DialogSecretKey {
|
|
18786
18733
|
key: v.aesKey,
|
18787
18734
|
iv: v.aesIV
|
18788
18735
|
};
|
18789
|
-
|
18790
|
-
|
18791
|
-
this.aesKeyRecord.set(kLong, keyItem);
|
18736
|
+
content.set(k, keyItem);
|
18737
|
+
this.aesKeyRecord.set(k, keyItem);
|
18792
18738
|
}
|
18793
18739
|
}
|
18794
18740
|
return content;
|
@@ -18835,15 +18781,16 @@ class Letterbox {
|
|
18835
18781
|
|
18836
18782
|
const aes256Encrypt = (message, secretKey) => {
|
18837
18783
|
if (!notEmptyString(message)) {
|
18838
|
-
return
|
18784
|
+
return '';
|
18839
18785
|
}
|
18840
18786
|
const encryptedData = CryptoJS.AES.encrypt(message, CryptoJS.enc.Utf8.parse(secretKey.key), {
|
18841
18787
|
iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
|
18842
18788
|
});
|
18843
|
-
return wordToUInt8Array(encryptedData.ciphertext.words);
|
18789
|
+
return Array.from(wordToUInt8Array(encryptedData.ciphertext.words)).map(byte => byte.toString(16).padStart(2, '0')).join('');
|
18844
18790
|
};
|
18845
|
-
const aes256Decrypt = (
|
18846
|
-
const
|
18791
|
+
const aes256Decrypt = (cipherHex, secretKey) => {
|
18792
|
+
const cipherData = new Uint8Array(cipherHex.match(/.{1,2}/g)?.map(byte => parseInt(byte, 16)) || []);
|
18793
|
+
const srcs = window.btoa(String.fromCharCode(...cipherData));
|
18847
18794
|
const decrypt = CryptoJS.AES.decrypt(srcs, CryptoJS.enc.Utf8.parse(secretKey.key), {
|
18848
18795
|
iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
|
18849
18796
|
});
|
@@ -18861,13 +18808,6 @@ const wordToUInt8Array = wordArray => {
|
|
18861
18808
|
return new Uint8Array(array);
|
18862
18809
|
};
|
18863
18810
|
|
18864
|
-
const MessageSerializers = new Map();
|
18865
|
-
function decodeMessage(objectId, messageData) {
|
18866
|
-
const decodeFunc = MessageSerializers.get(objectId);
|
18867
|
-
const messageObject = decodeFunc ? decodeFunc(messageData) : null;
|
18868
|
-
return messageObject;
|
18869
|
-
}
|
18870
|
-
|
18871
18811
|
const MessageTypes = {
|
18872
18812
|
TEXT: 0x00000000,
|
18873
18813
|
IMAGE: 0x10001000,
|
@@ -18888,7 +18828,7 @@ function parse(orginalMsgs, callback) {
|
|
18888
18828
|
Object.keys(orginalMsgs).forEach(dialogId => {
|
18889
18829
|
const arr = orginalMsgs[dialogId].dialogMessage?.filter(m => !m.sharingGroupFlag);
|
18890
18830
|
if (arr?.length) {
|
18891
|
-
msgs.set(
|
18831
|
+
msgs.set(dialogId, arr);
|
18892
18832
|
}
|
18893
18833
|
});
|
18894
18834
|
if (!msgs.size) {
|
@@ -18952,7 +18892,7 @@ const parseSingleDialogMessages = (dialogId, originalMessageList, aesKey) => {
|
|
18952
18892
|
isCounted: messageInstance.isCounted,
|
18953
18893
|
isMentioned: dialogMessage.atFlag,
|
18954
18894
|
content: messageInstance.content,
|
18955
|
-
messageType: messageInstance.
|
18895
|
+
messageType: messageInstance.messageType,
|
18956
18896
|
isOffLineMessage: false,
|
18957
18897
|
isPersited: messageInstance.isPersited,
|
18958
18898
|
messageId: Long.isLong(dialogMessage.localId) ? dialogMessage.localId : undefined,
|
@@ -18978,11 +18918,15 @@ const parseSingleDialogMessages = (dialogId, originalMessageList, aesKey) => {
|
|
18978
18918
|
const decodeMessageContent = (dialogMessage, aesKey) => {
|
18979
18919
|
try {
|
18980
18920
|
let mediaAttribute;
|
18981
|
-
if (dialogMessage.
|
18921
|
+
if (dialogMessage.mediaAttribute?.length) {
|
18982
18922
|
mediaAttribute = aes256Decrypt(dialogMessage.mediaAttribute, aesKey);
|
18983
18923
|
} else {
|
18984
18924
|
mediaAttribute = dialogMessage.msgPreContent ?? '';
|
18985
18925
|
}
|
18926
|
+
let msgPostContent;
|
18927
|
+
if (dialogMessage.msgPostContent?.length) {
|
18928
|
+
msgPostContent = aes256Decrypt(dialogMessage.msgPostContent, aesKey);
|
18929
|
+
}
|
18986
18930
|
if (dialogMessage.mediaConstructor === 0x60010012 || dialogMessage.mediaConstructor === 0x60020021) {
|
18987
18931
|
mediaAttribute = transMsgIdNum64ToString(mediaAttribute);
|
18988
18932
|
}
|
@@ -18990,6 +18934,9 @@ const decodeMessageContent = (dialogMessage, aesKey) => {
|
|
18990
18934
|
if (mediaAttribute?.length) {
|
18991
18935
|
mediaAttributeJson = JSON.parse(mediaAttribute);
|
18992
18936
|
}
|
18937
|
+
if (dialogMessage.mediaConstructor == MessageTypes.TEXT && msgPostContent) {
|
18938
|
+
mediaAttributeJson.content = msgPostContent;
|
18939
|
+
}
|
18993
18940
|
return mediaAttributeJson;
|
18994
18941
|
} catch (error) {
|
18995
18942
|
logger.error('decode message content fail -> uid:', dialogMessage.msgId.toString());
|
@@ -19258,7 +19205,7 @@ class ConversationStatus {
|
|
19258
19205
|
data
|
19259
19206
|
} = await getDialogChangedStatus(offset);
|
19260
19207
|
if (code === ErrorCode.SUCCESS) {
|
19261
|
-
if (data.setTime.toNumber() > 0) {
|
19208
|
+
if (Long.isLong(data.setTime) && data.setTime.toNumber() > 0) {
|
19262
19209
|
SecureStorageService.set(this.storageKey, data.setTime.toNumber());
|
19263
19210
|
}
|
19264
19211
|
if (data.briefDialog) {
|
@@ -19752,7 +19699,6 @@ class MessageLoader {
|
|
19752
19699
|
};
|
19753
19700
|
});
|
19754
19701
|
ConversationManager$1.get().loadConvsationsIfNotExist(cons);
|
19755
|
-
debugger;
|
19756
19702
|
ServerMessageParser.parse(msg, (done, outputMsgs) => {
|
19757
19703
|
const messages = [];
|
19758
19704
|
const conversations = [];
|
@@ -19805,7 +19751,45 @@ class MessageLoader {
|
|
19805
19751
|
}
|
19806
19752
|
}
|
19807
19753
|
|
19808
|
-
|
19754
|
+
class BaseMessage {
|
19755
|
+
messageType;
|
19756
|
+
content;
|
19757
|
+
isPersited;
|
19758
|
+
isCounted;
|
19759
|
+
isStatusMessage;
|
19760
|
+
constructor(messageType, content, isPersited = true, isCounted = true, isStatusMessage = false) {
|
19761
|
+
this.messageType = messageType;
|
19762
|
+
this.content = content;
|
19763
|
+
if (isStatusMessage) {
|
19764
|
+
this.isPersited = false;
|
19765
|
+
this.isCounted = false;
|
19766
|
+
} else {
|
19767
|
+
this.isPersited = isPersited;
|
19768
|
+
this.isCounted = isCounted;
|
19769
|
+
}
|
19770
|
+
this.isStatusMessage = isStatusMessage;
|
19771
|
+
}
|
19772
|
+
}
|
19773
|
+
const registerMessageType$1 = (messageType, isPersited, isCounted, isStatusMessage) => {
|
19774
|
+
const defined = function (content) {
|
19775
|
+
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
19776
|
+
};
|
19777
|
+
return defined;
|
19778
|
+
};
|
19779
|
+
|
19780
|
+
const TextMessage = registerMessageType$1(MessageTypes.TEXT, true, true, false);
|
19781
|
+
|
19782
|
+
const ImageMessage = registerMessageType$1(MessageTypes.IMAGE, true, true, false);
|
19783
|
+
|
19784
|
+
const GIFMessage = registerMessageType$1(MessageTypes.GIF, true, true, false);
|
19785
|
+
|
19786
|
+
const VoiceMessage = registerMessageType$1(MessageTypes.AUDIO, true, true, false);
|
19787
|
+
|
19788
|
+
const FileMessage = registerMessageType$1(MessageTypes.FILE, true, true, false);
|
19789
|
+
|
19790
|
+
const RecallCommandMessage = registerMessageType$1(MessageTypes.RECALL, true, false, false);
|
19791
|
+
|
19792
|
+
const DEFAULT_SOCKET_URI = 'wss://imweb.mp.net:6443';
|
19809
19793
|
class LibLoader {
|
19810
19794
|
options;
|
19811
19795
|
connectionStatus = ConnectionStatus.DISCONNECTED;
|
@@ -19831,7 +19815,8 @@ class LibLoader {
|
|
19831
19815
|
onSuspend: undefined,
|
19832
19816
|
pullFinished: undefined,
|
19833
19817
|
batchMessage: undefined,
|
19834
|
-
conversationState: undefined
|
19818
|
+
conversationState: undefined,
|
19819
|
+
onPush: undefined
|
19835
19820
|
};
|
19836
19821
|
webSocketServer.setServerInfo(this.getWebSocketUrl());
|
19837
19822
|
webSocketServer.setCallback({
|
@@ -19850,7 +19835,13 @@ class LibLoader {
|
|
19850
19835
|
}
|
19851
19836
|
return DEFAULT_SOCKET_URI;
|
19852
19837
|
}
|
19853
|
-
registerMessage() {
|
19838
|
+
registerMessage() {
|
19839
|
+
registerMessage(MessageTypes.TEXT, TextMessage);
|
19840
|
+
registerMessage(MessageTypes.IMAGE, ImageMessage);
|
19841
|
+
registerMessage(MessageTypes.GIF, GIFMessage);
|
19842
|
+
registerMessage(MessageTypes.AUDIO, VoiceMessage);
|
19843
|
+
registerMessage(MessageTypes.FILE, FileMessage);
|
19844
|
+
}
|
19854
19845
|
async connect() {
|
19855
19846
|
if (this.connectionStatus === ConnectionStatus.CONNECTED) {
|
19856
19847
|
return {
|
@@ -19960,7 +19951,6 @@ class LibLoader {
|
|
19960
19951
|
}, 2000);
|
19961
19952
|
}
|
19962
19953
|
messageListener(cmdId, body) {
|
19963
|
-
logger.info(`libLoader messageListener -> cmdId: ${cmdId}, body: ${body}`);
|
19964
19954
|
if (cmdId === CmdIds$1.NewMessagePush) {
|
19965
19955
|
const newMsgNotiResp = NewMessageNotificationResp.decode(body);
|
19966
19956
|
this.messageLoader?.syncMsg(newMsgNotiResp.seqno);
|
@@ -26531,56 +26521,6 @@ function requireProtobufjs () {
|
|
26531
26521
|
var protobufjsExports = requireProtobufjs();
|
26532
26522
|
var protobuf = /*@__PURE__*/getDefaultExportFromCjs(protobufjsExports);
|
26533
26523
|
|
26534
|
-
class BaseMessage {
|
26535
|
-
messageType;
|
26536
|
-
content;
|
26537
|
-
isPersited;
|
26538
|
-
isCounted;
|
26539
|
-
isStatusMessage;
|
26540
|
-
constructor(messageType, content, isPersited = true, isCounted = true, isStatusMessage = false) {
|
26541
|
-
this.messageType = messageType;
|
26542
|
-
this.content = content;
|
26543
|
-
if (isStatusMessage) {
|
26544
|
-
this.isPersited = false;
|
26545
|
-
this.isCounted = false;
|
26546
|
-
} else {
|
26547
|
-
this.isPersited = isPersited;
|
26548
|
-
this.isCounted = isCounted;
|
26549
|
-
}
|
26550
|
-
this.isStatusMessage = isStatusMessage;
|
26551
|
-
}
|
26552
|
-
get objectId() {
|
26553
|
-
return this.constructor.getObjectId();
|
26554
|
-
}
|
26555
|
-
static getObjectId() {
|
26556
|
-
throw new Error('Method not implemented.');
|
26557
|
-
}
|
26558
|
-
static decode(aDecoder) {
|
26559
|
-
throw new Error('Method not implemented.');
|
26560
|
-
}
|
26561
|
-
encode() {
|
26562
|
-
throw new Error('Method not implemented.');
|
26563
|
-
}
|
26564
|
-
}
|
26565
|
-
const registerMessageType$1 = (messageType, isPersited, isCounted, isStatusMessage) => {
|
26566
|
-
const defined = function (content) {
|
26567
|
-
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
26568
|
-
};
|
26569
|
-
return defined;
|
26570
|
-
};
|
26571
|
-
|
26572
|
-
const TextMessage = registerMessageType$1(MessageTypes.TEXT, true, true, false);
|
26573
|
-
|
26574
|
-
const ImageMessage = registerMessageType$1(MessageTypes.IMAGE, true, true, false);
|
26575
|
-
|
26576
|
-
const GIFMessage = registerMessageType$1(MessageTypes.GIF, true, true, false);
|
26577
|
-
|
26578
|
-
const VoiceMessage = registerMessageType$1(MessageTypes.AUDIO, true, true, false);
|
26579
|
-
|
26580
|
-
const FileMessage = registerMessageType$1(MessageTypes.FILE, true, true, false);
|
26581
|
-
|
26582
|
-
const RecallCommandMessage = registerMessageType$1(MessageTypes.RECALL, true, false, false);
|
26583
|
-
|
26584
26524
|
const transSentAttrs2IReceivedMessage = (message, options, sentStatus = SentStatus.SENDING) => ({
|
26585
26525
|
conversationType: options.conversation.conversationType,
|
26586
26526
|
targetId: options.conversation.targetId,
|
@@ -26589,7 +26529,7 @@ const transSentAttrs2IReceivedMessage = (message, options, sentStatus = SentStat
|
|
26589
26529
|
isCounted: message.isCounted,
|
26590
26530
|
isMentioned: false,
|
26591
26531
|
content: message.content,
|
26592
|
-
messageType: message.
|
26532
|
+
messageType: message.messageType,
|
26593
26533
|
isOffLineMessage: false,
|
26594
26534
|
isPersited: message.isPersited,
|
26595
26535
|
messageId: options.messageId,
|
@@ -26614,7 +26554,11 @@ function generateMessageId() {
|
|
26614
26554
|
|
26615
26555
|
const MAX_MESSAGE_CONTENT_BYTES = 80 * 1024;
|
26616
26556
|
async function sendMessage$1(conversation, message, options) {
|
26617
|
-
|
26557
|
+
let tmpConversation = conversation;
|
26558
|
+
if (typeof tmpConversation.targetId === 'string') {
|
26559
|
+
tmpConversation.targetId = Long.fromString(tmpConversation.targetId);
|
26560
|
+
}
|
26561
|
+
return internal_sendMessage(tmpConversation, message, options);
|
26618
26562
|
}
|
26619
26563
|
const sendRecallMessage = async (conversation, options) => {
|
26620
26564
|
const dialogId = getFullDialogId(conversation);
|
@@ -26670,7 +26614,7 @@ function beforeSend(conversation, message, options) {
|
|
26670
26614
|
code: ErrorCode.RC_NET_CHANNEL_INVALID
|
26671
26615
|
};
|
26672
26616
|
}
|
26673
|
-
const mediaAttribute = JSON.stringify(filterNullProperty(message.
|
26617
|
+
const mediaAttribute = JSON.stringify(filterNullProperty(message.content));
|
26674
26618
|
if (getByteLength(mediaAttribute) > MAX_MESSAGE_CONTENT_BYTES) {
|
26675
26619
|
return {
|
26676
26620
|
code: ErrorCode.RC_MSG_CONTENT_EXCEED_LIMIT
|
@@ -26681,7 +26625,6 @@ function beforeSend(conversation, message, options) {
|
|
26681
26625
|
senderUserId: accountStore.uid,
|
26682
26626
|
messageId: options?.messageId ?? Long.fromNumber(generateMessageId()),
|
26683
26627
|
sentTime: Long.fromNumber(getMessageSentTime()),
|
26684
|
-
directionalUserIdList: options?.directionalUserIdList,
|
26685
26628
|
pushConfig: options?.pushConfig
|
26686
26629
|
};
|
26687
26630
|
if (options?.onSendBefore) {
|
@@ -26698,7 +26641,7 @@ async function send(message, sentArgs) {
|
|
26698
26641
|
const dialogId = getFullDialogId(sentArgs.conversation);
|
26699
26642
|
const receivedMessage = transSentAttrs2IReceivedMessage(message, sentArgs);
|
26700
26643
|
message.isPersited && ConversationManager$1.get().loadConvsationsIfNotExist([sentArgs.conversation]);
|
26701
|
-
const secretKey = await DialogSecretKey$1.getDialogAesKey(dialogId);
|
26644
|
+
const secretKey = await DialogSecretKey$1.getDialogAesKey(dialogId.toString());
|
26702
26645
|
if (!secretKey) {
|
26703
26646
|
receivedMessage.sentStatus = SentStatus.FAILED;
|
26704
26647
|
return {
|
@@ -26706,19 +26649,26 @@ async function send(message, sentArgs) {
|
|
26706
26649
|
data: receivedMessage
|
26707
26650
|
};
|
26708
26651
|
}
|
26709
|
-
|
26710
|
-
|
26711
|
-
|
26652
|
+
let postEncryptedString;
|
26653
|
+
let mediaAttribute;
|
26654
|
+
if (message.messageType === MessageTypes.TEXT) {
|
26655
|
+
let content = message.content;
|
26656
|
+
let textContent = message.content.content;
|
26657
|
+
delete content.content;
|
26658
|
+
postEncryptedString = aes256Encrypt(textContent, secretKey);
|
26659
|
+
mediaAttribute = JSON.stringify(filterNullProperty(content));
|
26660
|
+
} else {
|
26661
|
+
mediaAttribute = JSON.stringify(filterNullProperty(message.content));
|
26662
|
+
}
|
26663
|
+
const mediaEncryptedString = aes256Encrypt(mediaAttribute, secretKey);
|
26712
26664
|
SentMessageStore.addMessage(sentArgs.messageId);
|
26713
26665
|
const baseParams = {
|
26714
26666
|
localId: sentArgs.messageId,
|
26715
26667
|
mediaFlag: false,
|
26716
|
-
mediaConstructor: message.
|
26717
|
-
mediaAttribute: '',
|
26668
|
+
mediaConstructor: message.messageType,
|
26718
26669
|
msgPreContent: '',
|
26719
|
-
msgPostContent:
|
26720
|
-
|
26721
|
-
pushContent: pushConfig
|
26670
|
+
msgPostContent: postEncryptedString,
|
26671
|
+
mediaAttribute: mediaEncryptedString
|
26722
26672
|
};
|
26723
26673
|
let response;
|
26724
26674
|
if (sentArgs.conversation.conversationType === ConversationType.GROUP) {
|
@@ -26726,14 +26676,9 @@ async function send(message, sentArgs) {
|
|
26726
26676
|
...baseParams,
|
26727
26677
|
groupId: dialogId
|
26728
26678
|
};
|
26729
|
-
if (sentArgs?.directionalUserIdList?.length) {
|
26730
|
-
groupParams.assign = sentArgs.directionalUserIdList.join(',');
|
26731
|
-
}
|
26732
26679
|
if (isDef(message.content.mentionedInfo)) {
|
26733
26680
|
const mentionedInfo = message.content.mentionedInfo;
|
26734
|
-
if (mentionedInfo.type === MentionedType.ALL) {
|
26735
|
-
groupParams.atAll = true;
|
26736
|
-
} else if (mentionedInfo.type === MentionedType.SINGAL && mentionedInfo.userIdList?.length) {
|
26681
|
+
if (mentionedInfo.type === MentionedType.ALL) ; else if (mentionedInfo.type === MentionedType.SINGAL && mentionedInfo.userIdList?.length) {
|
26737
26682
|
groupParams.at = mentionedInfo.userIdList.map(e => Long.fromString(e));
|
26738
26683
|
}
|
26739
26684
|
}
|
@@ -26767,25 +26712,6 @@ function getMessageSentTime() {
|
|
26767
26712
|
}
|
26768
26713
|
return UniqueSentTime;
|
26769
26714
|
}
|
26770
|
-
function encodePushConfig(config) {
|
26771
|
-
if (!isDef(config)) return null;
|
26772
|
-
const obj = {};
|
26773
|
-
if (notEmptyString(config.pushTitle)) {
|
26774
|
-
obj.pushExt = {
|
26775
|
-
title: config.pushTitle
|
26776
|
-
};
|
26777
|
-
}
|
26778
|
-
if (notEmptyString(config.pushContent)) {
|
26779
|
-
obj.pushContent = config.pushContent;
|
26780
|
-
}
|
26781
|
-
if (notEmptyString(config.pushData)) {
|
26782
|
-
obj.pushData = config.pushData;
|
26783
|
-
}
|
26784
|
-
if (Object.keys(obj).length) {
|
26785
|
-
return JSON.stringify(obj);
|
26786
|
-
}
|
26787
|
-
return null;
|
26788
|
-
}
|
26789
26715
|
|
26790
26716
|
class IMClient extends EventEmitter {
|
26791
26717
|
options;
|
@@ -26842,7 +26768,6 @@ class IMClient extends EventEmitter {
|
|
26842
26768
|
});
|
26843
26769
|
},
|
26844
26770
|
onPush: (cmdId, body) => {
|
26845
|
-
logger.info(`client onPush -> cmdId: ${cmdId}, body: ${body}`);
|
26846
26771
|
this.emit(Events.PUSH, {
|
26847
26772
|
cmdId,
|
26848
26773
|
body
|
@@ -26892,7 +26817,7 @@ class IMClient extends EventEmitter {
|
|
26892
26817
|
ServerMessageParser.parse({
|
26893
26818
|
[dialogId.toString()]: data.msg ?? {}
|
26894
26819
|
}, (_, outputMsgs) => {
|
26895
|
-
const messageList = outputMsgs.get(dialogId) ?? [];
|
26820
|
+
const messageList = outputMsgs.get(dialogId.toString()) ?? [];
|
26896
26821
|
messageList.sort((e1, e2) => e1.sentTime.lessThan(e2.sentTime) ? -1 : 1);
|
26897
26822
|
resolve({
|
26898
26823
|
code: ErrorCode.SUCCESS,
|
@@ -26928,7 +26853,7 @@ class IMClient extends EventEmitter {
|
|
26928
26853
|
};
|
26929
26854
|
}
|
26930
26855
|
const dialogIdList = data.fullDialog.map(item => item.dialog?.destId).filter(isDef);
|
26931
|
-
await DialogSecretKey$1.getDialogAesKeyList(dialogIdList);
|
26856
|
+
await DialogSecretKey$1.getDialogAesKeyList(dialogIdList.map(e => e.toString()));
|
26932
26857
|
const contentList = [];
|
26933
26858
|
for (const dialogInfo of data.fullDialog) {
|
26934
26859
|
const conversationObj = this.formatConversation(dialogInfo);
|
@@ -27069,11 +26994,11 @@ class IMClient extends EventEmitter {
|
|
27069
26994
|
if (!conversationObj) {
|
27070
26995
|
return;
|
27071
26996
|
}
|
27072
|
-
const aesKey = DialogSecretKey$1.getDialogAesKeyFromLocal(dialogId);
|
26997
|
+
const aesKey = DialogSecretKey$1.getDialogAesKeyFromLocal(dialogId.toString());
|
27073
26998
|
if (!aesKey) {
|
27074
26999
|
return;
|
27075
27000
|
}
|
27076
|
-
const latestMessage = ServerMessageParser.parseSingleDialogMessages(dialogId, [msg], aesKey)[0];
|
27001
|
+
const latestMessage = ServerMessageParser.parseSingleDialogMessages(dialogId.toString(), [msg], aesKey)[0];
|
27077
27002
|
if (!latestMessage) {
|
27078
27003
|
return;
|
27079
27004
|
}
|
@@ -28170,7 +28095,9 @@ const registerMessageType = (messageType, isPersited, isCounted, isStatusMessage
|
|
28170
28095
|
const defined = function (content) {
|
28171
28096
|
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
28172
28097
|
};
|
28173
|
-
|
28098
|
+
let messageConstructor = defined;
|
28099
|
+
registerMessage(messageType, messageConstructor);
|
28100
|
+
return messageConstructor;
|
28174
28101
|
};
|
28175
28102
|
const sendMessage = async (conversation, message, options) => {
|
28176
28103
|
if (message instanceof BaseMessage === false) {
|
package/index.umd.js
CHANGED
@@ -8023,9 +8023,9 @@
|
|
8023
8023
|
CmdIds[CmdIds["DeletePrivateDialog"] = 1610682372] = "DeletePrivateDialog";
|
8024
8024
|
CmdIds[CmdIds["DeleteGroupDialog"] = 1610747908] = "DeleteGroupDialog";
|
8025
8025
|
CmdIds[CmdIds["GetDialogChangedStatus"] = 1610711094] = "GetDialogChangedStatus";
|
8026
|
+
CmdIds[CmdIds["HeartbeanResp"] = 268468225] = "HeartbeanResp";
|
8026
8027
|
CmdIds[CmdIds["NewMessagePush"] = 1610711040] = "NewMessagePush";
|
8027
8028
|
CmdIds[CmdIds["DialogChangedPush"] = 1610711096] = "DialogChangedPush";
|
8028
|
-
CmdIds[CmdIds["AppAllowLoginPush"] = 806453286] = "AppAllowLoginPush";
|
8029
8029
|
CmdIds[CmdIds["SessionKilledPush"] = 268468229] = "SessionKilledPush";
|
8030
8030
|
CmdIds[CmdIds["SignOutPish"] = 268439559] = "SignOutPish";
|
8031
8031
|
CmdIds[CmdIds["SignOutPish2"] = 268468231] = "SignOutPish2";
|
@@ -13400,7 +13400,9 @@
|
|
13400
13400
|
body: body,
|
13401
13401
|
deviceType: 7
|
13402
13402
|
};
|
13403
|
-
|
13403
|
+
if (cmdId !== CmdIds$1.Heartbean) {
|
13404
|
+
logger.info(`websocket send -> cmd: 0x${cmdId.toString(16)}, messageSeq: ${messageSeq}`);
|
13405
|
+
}
|
13404
13406
|
this.socket.send(buildWsPacketData(rpc_baseExports.NetworkRequest.encode(networkReq).finish()));
|
13405
13407
|
const respData = await new Promise(resolve => {
|
13406
13408
|
this.responseCallbacks.set(messageSeq, resolve);
|
@@ -13519,7 +13521,9 @@
|
|
13519
13521
|
return;
|
13520
13522
|
}
|
13521
13523
|
const messageSeq = Long.isLong(networkResponse.messageSeq) ? networkResponse.messageSeq.toNumber() : 0;
|
13522
|
-
|
13524
|
+
if (networkResponse.cmdId !== CmdIds$1.HeartbeanResp) {
|
13525
|
+
logger.info(`websocket recv ack -> messageSeq: ${messageSeq}`);
|
13526
|
+
}
|
13523
13527
|
const resolve = this.responseCallbacks.get(messageSeq);
|
13524
13528
|
if (isDef(resolve)) {
|
13525
13529
|
resolve(networkResponse.body);
|
@@ -17562,11 +17566,6 @@
|
|
17562
17566
|
* @property {number|null} [mediaConstructor] SendGroupChatMessageReq mediaConstructor
|
17563
17567
|
* @property {string|null} [mediaAttribute] SendGroupChatMessageReq mediaAttribute
|
17564
17568
|
* @property {Array.<Long>|null} [at] SendGroupChatMessageReq at
|
17565
|
-
* @property {string|null} [extra] SendGroupChatMessageReq extra
|
17566
|
-
* @property {string|null} [assign] SendGroupChatMessageReq assign
|
17567
|
-
* @property {boolean|null} [atAll] SendGroupChatMessageReq atAll
|
17568
|
-
* @property {Uint8Array|null} [msgContent] SendGroupChatMessageReq msgContent
|
17569
|
-
* @property {string|null} [pushContent] SendGroupChatMessageReq pushContent
|
17570
17569
|
*/
|
17571
17570
|
|
17572
17571
|
/**
|
@@ -17646,46 +17645,6 @@
|
|
17646
17645
|
*/
|
17647
17646
|
SendGroupChatMessageReq.prototype.at = $util.emptyArray;
|
17648
17647
|
|
17649
|
-
/**
|
17650
|
-
* SendGroupChatMessageReq extra.
|
17651
|
-
* @member {string} extra
|
17652
|
-
* @memberof SendGroupChatMessageReq
|
17653
|
-
* @instance
|
17654
|
-
*/
|
17655
|
-
SendGroupChatMessageReq.prototype.extra = "";
|
17656
|
-
|
17657
|
-
/**
|
17658
|
-
* SendGroupChatMessageReq assign.
|
17659
|
-
* @member {string} assign
|
17660
|
-
* @memberof SendGroupChatMessageReq
|
17661
|
-
* @instance
|
17662
|
-
*/
|
17663
|
-
SendGroupChatMessageReq.prototype.assign = "";
|
17664
|
-
|
17665
|
-
/**
|
17666
|
-
* SendGroupChatMessageReq atAll.
|
17667
|
-
* @member {boolean} atAll
|
17668
|
-
* @memberof SendGroupChatMessageReq
|
17669
|
-
* @instance
|
17670
|
-
*/
|
17671
|
-
SendGroupChatMessageReq.prototype.atAll = false;
|
17672
|
-
|
17673
|
-
/**
|
17674
|
-
* SendGroupChatMessageReq msgContent.
|
17675
|
-
* @member {Uint8Array} msgContent
|
17676
|
-
* @memberof SendGroupChatMessageReq
|
17677
|
-
* @instance
|
17678
|
-
*/
|
17679
|
-
SendGroupChatMessageReq.prototype.msgContent = $util.newBuffer([]);
|
17680
|
-
|
17681
|
-
/**
|
17682
|
-
* SendGroupChatMessageReq pushContent.
|
17683
|
-
* @member {string} pushContent
|
17684
|
-
* @memberof SendGroupChatMessageReq
|
17685
|
-
* @instance
|
17686
|
-
*/
|
17687
|
-
SendGroupChatMessageReq.prototype.pushContent = "";
|
17688
|
-
|
17689
17648
|
/**
|
17690
17649
|
* Encodes the specified SendGroupChatMessageReq message. Does not implicitly {@link SendGroupChatMessageReq.verify|verify} messages.
|
17691
17650
|
* @function encode
|
@@ -17709,11 +17668,6 @@
|
|
17709
17668
|
for (let i = 0; i < message.at.length; ++i) writer.int64(message.at[i]);
|
17710
17669
|
writer.ldelim();
|
17711
17670
|
}
|
17712
|
-
if (message.extra != null && Object.hasOwnProperty.call(message, "extra")) writer.uint32(/* id 9, wireType 2 =*/74).string(message.extra);
|
17713
|
-
if (message.assign != null && Object.hasOwnProperty.call(message, "assign")) writer.uint32(/* id 10, wireType 2 =*/82).string(message.assign);
|
17714
|
-
if (message.atAll != null && Object.hasOwnProperty.call(message, "atAll")) writer.uint32(/* id 11, wireType 0 =*/88).bool(message.atAll);
|
17715
|
-
if (message.msgContent != null && Object.hasOwnProperty.call(message, "msgContent")) writer.uint32(/* id 12, wireType 2 =*/98).bytes(message.msgContent);
|
17716
|
-
if (message.pushContent != null && Object.hasOwnProperty.call(message, "pushContent")) writer.uint32(/* id 13, wireType 2 =*/106).string(message.pushContent);
|
17717
17671
|
return writer;
|
17718
17672
|
};
|
17719
17673
|
|
@@ -17779,31 +17733,6 @@
|
|
17779
17733
|
} else message.at.push(reader.int64());
|
17780
17734
|
break;
|
17781
17735
|
}
|
17782
|
-
case 9:
|
17783
|
-
{
|
17784
|
-
message.extra = reader.string();
|
17785
|
-
break;
|
17786
|
-
}
|
17787
|
-
case 10:
|
17788
|
-
{
|
17789
|
-
message.assign = reader.string();
|
17790
|
-
break;
|
17791
|
-
}
|
17792
|
-
case 11:
|
17793
|
-
{
|
17794
|
-
message.atAll = reader.bool();
|
17795
|
-
break;
|
17796
|
-
}
|
17797
|
-
case 12:
|
17798
|
-
{
|
17799
|
-
message.msgContent = reader.bytes();
|
17800
|
-
break;
|
17801
|
-
}
|
17802
|
-
case 13:
|
17803
|
-
{
|
17804
|
-
message.pushContent = reader.string();
|
17805
|
-
break;
|
17806
|
-
}
|
17807
17736
|
default:
|
17808
17737
|
reader.skipType(tag & 7);
|
17809
17738
|
break;
|
@@ -18718,6 +18647,24 @@
|
|
18718
18647
|
}
|
18719
18648
|
};
|
18720
18649
|
|
18650
|
+
const MessageStores = new Map();
|
18651
|
+
function registerMessage(messageType, messageConstructor) {
|
18652
|
+
MessageStores.set(messageType, messageConstructor);
|
18653
|
+
}
|
18654
|
+
function decodeMessage(messageType, messageData) {
|
18655
|
+
const MessageConstructor = MessageStores.get(messageType);
|
18656
|
+
if (!MessageConstructor) {
|
18657
|
+
console.warn(`No message constructor found for type: ${messageType}`);
|
18658
|
+
return null;
|
18659
|
+
}
|
18660
|
+
try {
|
18661
|
+
return new MessageConstructor(messageData);
|
18662
|
+
} catch (error) {
|
18663
|
+
console.error(`Failed to decode message type ${messageType}:`, error);
|
18664
|
+
return null;
|
18665
|
+
}
|
18666
|
+
}
|
18667
|
+
|
18721
18668
|
class DialogSecretKey {
|
18722
18669
|
aesKeyRecord = new Map();
|
18723
18670
|
async getDialogAesKey(dialogId) {
|
@@ -18782,7 +18729,7 @@
|
|
18782
18729
|
const {
|
18783
18730
|
code,
|
18784
18731
|
data
|
18785
|
-
} = await getDialogKey(dialogIdList);
|
18732
|
+
} = await getDialogKey(dialogIdList.map(e => Long.fromString(e)));
|
18786
18733
|
if (code === exports.ErrorCode.SUCCESS) {
|
18787
18734
|
const content = new Map();
|
18788
18735
|
for (const k in data.entry) {
|
@@ -18792,9 +18739,8 @@
|
|
18792
18739
|
key: v.aesKey,
|
18793
18740
|
iv: v.aesIV
|
18794
18741
|
};
|
18795
|
-
|
18796
|
-
|
18797
|
-
this.aesKeyRecord.set(kLong, keyItem);
|
18742
|
+
content.set(k, keyItem);
|
18743
|
+
this.aesKeyRecord.set(k, keyItem);
|
18798
18744
|
}
|
18799
18745
|
}
|
18800
18746
|
return content;
|
@@ -18841,15 +18787,16 @@
|
|
18841
18787
|
|
18842
18788
|
const aes256Encrypt = (message, secretKey) => {
|
18843
18789
|
if (!notEmptyString(message)) {
|
18844
|
-
return
|
18790
|
+
return '';
|
18845
18791
|
}
|
18846
18792
|
const encryptedData = CryptoJS.AES.encrypt(message, CryptoJS.enc.Utf8.parse(secretKey.key), {
|
18847
18793
|
iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
|
18848
18794
|
});
|
18849
|
-
return wordToUInt8Array(encryptedData.ciphertext.words);
|
18795
|
+
return Array.from(wordToUInt8Array(encryptedData.ciphertext.words)).map(byte => byte.toString(16).padStart(2, '0')).join('');
|
18850
18796
|
};
|
18851
|
-
const aes256Decrypt = (
|
18852
|
-
const
|
18797
|
+
const aes256Decrypt = (cipherHex, secretKey) => {
|
18798
|
+
const cipherData = new Uint8Array(cipherHex.match(/.{1,2}/g)?.map(byte => parseInt(byte, 16)) || []);
|
18799
|
+
const srcs = window.btoa(String.fromCharCode(...cipherData));
|
18853
18800
|
const decrypt = CryptoJS.AES.decrypt(srcs, CryptoJS.enc.Utf8.parse(secretKey.key), {
|
18854
18801
|
iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
|
18855
18802
|
});
|
@@ -18867,13 +18814,6 @@
|
|
18867
18814
|
return new Uint8Array(array);
|
18868
18815
|
};
|
18869
18816
|
|
18870
|
-
const MessageSerializers = new Map();
|
18871
|
-
function decodeMessage(objectId, messageData) {
|
18872
|
-
const decodeFunc = MessageSerializers.get(objectId);
|
18873
|
-
const messageObject = decodeFunc ? decodeFunc(messageData) : null;
|
18874
|
-
return messageObject;
|
18875
|
-
}
|
18876
|
-
|
18877
18817
|
const MessageTypes = {
|
18878
18818
|
TEXT: 0x00000000,
|
18879
18819
|
IMAGE: 0x10001000,
|
@@ -18894,7 +18834,7 @@
|
|
18894
18834
|
Object.keys(orginalMsgs).forEach(dialogId => {
|
18895
18835
|
const arr = orginalMsgs[dialogId].dialogMessage?.filter(m => !m.sharingGroupFlag);
|
18896
18836
|
if (arr?.length) {
|
18897
|
-
msgs.set(
|
18837
|
+
msgs.set(dialogId, arr);
|
18898
18838
|
}
|
18899
18839
|
});
|
18900
18840
|
if (!msgs.size) {
|
@@ -18958,7 +18898,7 @@
|
|
18958
18898
|
isCounted: messageInstance.isCounted,
|
18959
18899
|
isMentioned: dialogMessage.atFlag,
|
18960
18900
|
content: messageInstance.content,
|
18961
|
-
messageType: messageInstance.
|
18901
|
+
messageType: messageInstance.messageType,
|
18962
18902
|
isOffLineMessage: false,
|
18963
18903
|
isPersited: messageInstance.isPersited,
|
18964
18904
|
messageId: Long.isLong(dialogMessage.localId) ? dialogMessage.localId : undefined,
|
@@ -18984,11 +18924,15 @@
|
|
18984
18924
|
const decodeMessageContent = (dialogMessage, aesKey) => {
|
18985
18925
|
try {
|
18986
18926
|
let mediaAttribute;
|
18987
|
-
if (dialogMessage.
|
18927
|
+
if (dialogMessage.mediaAttribute?.length) {
|
18988
18928
|
mediaAttribute = aes256Decrypt(dialogMessage.mediaAttribute, aesKey);
|
18989
18929
|
} else {
|
18990
18930
|
mediaAttribute = dialogMessage.msgPreContent ?? '';
|
18991
18931
|
}
|
18932
|
+
let msgPostContent;
|
18933
|
+
if (dialogMessage.msgPostContent?.length) {
|
18934
|
+
msgPostContent = aes256Decrypt(dialogMessage.msgPostContent, aesKey);
|
18935
|
+
}
|
18992
18936
|
if (dialogMessage.mediaConstructor === 0x60010012 || dialogMessage.mediaConstructor === 0x60020021) {
|
18993
18937
|
mediaAttribute = transMsgIdNum64ToString(mediaAttribute);
|
18994
18938
|
}
|
@@ -18996,6 +18940,9 @@
|
|
18996
18940
|
if (mediaAttribute?.length) {
|
18997
18941
|
mediaAttributeJson = JSON.parse(mediaAttribute);
|
18998
18942
|
}
|
18943
|
+
if (dialogMessage.mediaConstructor == MessageTypes.TEXT && msgPostContent) {
|
18944
|
+
mediaAttributeJson.content = msgPostContent;
|
18945
|
+
}
|
18999
18946
|
return mediaAttributeJson;
|
19000
18947
|
} catch (error) {
|
19001
18948
|
logger.error('decode message content fail -> uid:', dialogMessage.msgId.toString());
|
@@ -19264,7 +19211,7 @@
|
|
19264
19211
|
data
|
19265
19212
|
} = await getDialogChangedStatus(offset);
|
19266
19213
|
if (code === exports.ErrorCode.SUCCESS) {
|
19267
|
-
if (data.setTime.toNumber() > 0) {
|
19214
|
+
if (Long.isLong(data.setTime) && data.setTime.toNumber() > 0) {
|
19268
19215
|
SecureStorageService.set(this.storageKey, data.setTime.toNumber());
|
19269
19216
|
}
|
19270
19217
|
if (data.briefDialog) {
|
@@ -19758,7 +19705,6 @@
|
|
19758
19705
|
};
|
19759
19706
|
});
|
19760
19707
|
ConversationManager$1.get().loadConvsationsIfNotExist(cons);
|
19761
|
-
debugger;
|
19762
19708
|
ServerMessageParser.parse(msg, (done, outputMsgs) => {
|
19763
19709
|
const messages = [];
|
19764
19710
|
const conversations = [];
|
@@ -19811,7 +19757,45 @@
|
|
19811
19757
|
}
|
19812
19758
|
}
|
19813
19759
|
|
19814
|
-
|
19760
|
+
class BaseMessage {
|
19761
|
+
messageType;
|
19762
|
+
content;
|
19763
|
+
isPersited;
|
19764
|
+
isCounted;
|
19765
|
+
isStatusMessage;
|
19766
|
+
constructor(messageType, content, isPersited = true, isCounted = true, isStatusMessage = false) {
|
19767
|
+
this.messageType = messageType;
|
19768
|
+
this.content = content;
|
19769
|
+
if (isStatusMessage) {
|
19770
|
+
this.isPersited = false;
|
19771
|
+
this.isCounted = false;
|
19772
|
+
} else {
|
19773
|
+
this.isPersited = isPersited;
|
19774
|
+
this.isCounted = isCounted;
|
19775
|
+
}
|
19776
|
+
this.isStatusMessage = isStatusMessage;
|
19777
|
+
}
|
19778
|
+
}
|
19779
|
+
const registerMessageType$1 = (messageType, isPersited, isCounted, isStatusMessage) => {
|
19780
|
+
const defined = function (content) {
|
19781
|
+
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
19782
|
+
};
|
19783
|
+
return defined;
|
19784
|
+
};
|
19785
|
+
|
19786
|
+
const TextMessage = registerMessageType$1(MessageTypes.TEXT, true, true, false);
|
19787
|
+
|
19788
|
+
const ImageMessage = registerMessageType$1(MessageTypes.IMAGE, true, true, false);
|
19789
|
+
|
19790
|
+
const GIFMessage = registerMessageType$1(MessageTypes.GIF, true, true, false);
|
19791
|
+
|
19792
|
+
const VoiceMessage = registerMessageType$1(MessageTypes.AUDIO, true, true, false);
|
19793
|
+
|
19794
|
+
const FileMessage = registerMessageType$1(MessageTypes.FILE, true, true, false);
|
19795
|
+
|
19796
|
+
const RecallCommandMessage = registerMessageType$1(MessageTypes.RECALL, true, false, false);
|
19797
|
+
|
19798
|
+
const DEFAULT_SOCKET_URI = 'wss://imweb.mp.net:6443';
|
19815
19799
|
class LibLoader {
|
19816
19800
|
options;
|
19817
19801
|
connectionStatus = exports.ConnectionStatus.DISCONNECTED;
|
@@ -19837,7 +19821,8 @@
|
|
19837
19821
|
onSuspend: undefined,
|
19838
19822
|
pullFinished: undefined,
|
19839
19823
|
batchMessage: undefined,
|
19840
|
-
conversationState: undefined
|
19824
|
+
conversationState: undefined,
|
19825
|
+
onPush: undefined
|
19841
19826
|
};
|
19842
19827
|
webSocketServer.setServerInfo(this.getWebSocketUrl());
|
19843
19828
|
webSocketServer.setCallback({
|
@@ -19856,7 +19841,13 @@
|
|
19856
19841
|
}
|
19857
19842
|
return DEFAULT_SOCKET_URI;
|
19858
19843
|
}
|
19859
|
-
registerMessage() {
|
19844
|
+
registerMessage() {
|
19845
|
+
registerMessage(MessageTypes.TEXT, TextMessage);
|
19846
|
+
registerMessage(MessageTypes.IMAGE, ImageMessage);
|
19847
|
+
registerMessage(MessageTypes.GIF, GIFMessage);
|
19848
|
+
registerMessage(MessageTypes.AUDIO, VoiceMessage);
|
19849
|
+
registerMessage(MessageTypes.FILE, FileMessage);
|
19850
|
+
}
|
19860
19851
|
async connect() {
|
19861
19852
|
if (this.connectionStatus === exports.ConnectionStatus.CONNECTED) {
|
19862
19853
|
return {
|
@@ -19966,7 +19957,6 @@
|
|
19966
19957
|
}, 2000);
|
19967
19958
|
}
|
19968
19959
|
messageListener(cmdId, body) {
|
19969
|
-
logger.info(`libLoader messageListener -> cmdId: ${cmdId}, body: ${body}`);
|
19970
19960
|
if (cmdId === CmdIds$1.NewMessagePush) {
|
19971
19961
|
const newMsgNotiResp = NewMessageNotificationResp.decode(body);
|
19972
19962
|
this.messageLoader?.syncMsg(newMsgNotiResp.seqno);
|
@@ -26537,56 +26527,6 @@
|
|
26537
26527
|
var protobufjsExports = requireProtobufjs();
|
26538
26528
|
var protobuf = /*@__PURE__*/getDefaultExportFromCjs(protobufjsExports);
|
26539
26529
|
|
26540
|
-
class BaseMessage {
|
26541
|
-
messageType;
|
26542
|
-
content;
|
26543
|
-
isPersited;
|
26544
|
-
isCounted;
|
26545
|
-
isStatusMessage;
|
26546
|
-
constructor(messageType, content, isPersited = true, isCounted = true, isStatusMessage = false) {
|
26547
|
-
this.messageType = messageType;
|
26548
|
-
this.content = content;
|
26549
|
-
if (isStatusMessage) {
|
26550
|
-
this.isPersited = false;
|
26551
|
-
this.isCounted = false;
|
26552
|
-
} else {
|
26553
|
-
this.isPersited = isPersited;
|
26554
|
-
this.isCounted = isCounted;
|
26555
|
-
}
|
26556
|
-
this.isStatusMessage = isStatusMessage;
|
26557
|
-
}
|
26558
|
-
get objectId() {
|
26559
|
-
return this.constructor.getObjectId();
|
26560
|
-
}
|
26561
|
-
static getObjectId() {
|
26562
|
-
throw new Error('Method not implemented.');
|
26563
|
-
}
|
26564
|
-
static decode(aDecoder) {
|
26565
|
-
throw new Error('Method not implemented.');
|
26566
|
-
}
|
26567
|
-
encode() {
|
26568
|
-
throw new Error('Method not implemented.');
|
26569
|
-
}
|
26570
|
-
}
|
26571
|
-
const registerMessageType$1 = (messageType, isPersited, isCounted, isStatusMessage) => {
|
26572
|
-
const defined = function (content) {
|
26573
|
-
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
26574
|
-
};
|
26575
|
-
return defined;
|
26576
|
-
};
|
26577
|
-
|
26578
|
-
const TextMessage = registerMessageType$1(MessageTypes.TEXT, true, true, false);
|
26579
|
-
|
26580
|
-
const ImageMessage = registerMessageType$1(MessageTypes.IMAGE, true, true, false);
|
26581
|
-
|
26582
|
-
const GIFMessage = registerMessageType$1(MessageTypes.GIF, true, true, false);
|
26583
|
-
|
26584
|
-
const VoiceMessage = registerMessageType$1(MessageTypes.AUDIO, true, true, false);
|
26585
|
-
|
26586
|
-
const FileMessage = registerMessageType$1(MessageTypes.FILE, true, true, false);
|
26587
|
-
|
26588
|
-
const RecallCommandMessage = registerMessageType$1(MessageTypes.RECALL, true, false, false);
|
26589
|
-
|
26590
26530
|
const transSentAttrs2IReceivedMessage = (message, options, sentStatus = exports.SentStatus.SENDING) => ({
|
26591
26531
|
conversationType: options.conversation.conversationType,
|
26592
26532
|
targetId: options.conversation.targetId,
|
@@ -26595,7 +26535,7 @@
|
|
26595
26535
|
isCounted: message.isCounted,
|
26596
26536
|
isMentioned: false,
|
26597
26537
|
content: message.content,
|
26598
|
-
messageType: message.
|
26538
|
+
messageType: message.messageType,
|
26599
26539
|
isOffLineMessage: false,
|
26600
26540
|
isPersited: message.isPersited,
|
26601
26541
|
messageId: options.messageId,
|
@@ -26620,7 +26560,11 @@
|
|
26620
26560
|
|
26621
26561
|
const MAX_MESSAGE_CONTENT_BYTES = 80 * 1024;
|
26622
26562
|
async function sendMessage$1(conversation, message, options) {
|
26623
|
-
|
26563
|
+
let tmpConversation = conversation;
|
26564
|
+
if (typeof tmpConversation.targetId === 'string') {
|
26565
|
+
tmpConversation.targetId = Long.fromString(tmpConversation.targetId);
|
26566
|
+
}
|
26567
|
+
return internal_sendMessage(tmpConversation, message, options);
|
26624
26568
|
}
|
26625
26569
|
const sendRecallMessage = async (conversation, options) => {
|
26626
26570
|
const dialogId = getFullDialogId(conversation);
|
@@ -26676,7 +26620,7 @@
|
|
26676
26620
|
code: exports.ErrorCode.RC_NET_CHANNEL_INVALID
|
26677
26621
|
};
|
26678
26622
|
}
|
26679
|
-
const mediaAttribute = JSON.stringify(filterNullProperty(message.
|
26623
|
+
const mediaAttribute = JSON.stringify(filterNullProperty(message.content));
|
26680
26624
|
if (getByteLength(mediaAttribute) > MAX_MESSAGE_CONTENT_BYTES) {
|
26681
26625
|
return {
|
26682
26626
|
code: exports.ErrorCode.RC_MSG_CONTENT_EXCEED_LIMIT
|
@@ -26687,7 +26631,6 @@
|
|
26687
26631
|
senderUserId: accountStore.uid,
|
26688
26632
|
messageId: options?.messageId ?? Long.fromNumber(generateMessageId()),
|
26689
26633
|
sentTime: Long.fromNumber(getMessageSentTime()),
|
26690
|
-
directionalUserIdList: options?.directionalUserIdList,
|
26691
26634
|
pushConfig: options?.pushConfig
|
26692
26635
|
};
|
26693
26636
|
if (options?.onSendBefore) {
|
@@ -26704,7 +26647,7 @@
|
|
26704
26647
|
const dialogId = getFullDialogId(sentArgs.conversation);
|
26705
26648
|
const receivedMessage = transSentAttrs2IReceivedMessage(message, sentArgs);
|
26706
26649
|
message.isPersited && ConversationManager$1.get().loadConvsationsIfNotExist([sentArgs.conversation]);
|
26707
|
-
const secretKey = await DialogSecretKey$1.getDialogAesKey(dialogId);
|
26650
|
+
const secretKey = await DialogSecretKey$1.getDialogAesKey(dialogId.toString());
|
26708
26651
|
if (!secretKey) {
|
26709
26652
|
receivedMessage.sentStatus = exports.SentStatus.FAILED;
|
26710
26653
|
return {
|
@@ -26712,19 +26655,26 @@
|
|
26712
26655
|
data: receivedMessage
|
26713
26656
|
};
|
26714
26657
|
}
|
26715
|
-
|
26716
|
-
|
26717
|
-
|
26658
|
+
let postEncryptedString;
|
26659
|
+
let mediaAttribute;
|
26660
|
+
if (message.messageType === MessageTypes.TEXT) {
|
26661
|
+
let content = message.content;
|
26662
|
+
let textContent = message.content.content;
|
26663
|
+
delete content.content;
|
26664
|
+
postEncryptedString = aes256Encrypt(textContent, secretKey);
|
26665
|
+
mediaAttribute = JSON.stringify(filterNullProperty(content));
|
26666
|
+
} else {
|
26667
|
+
mediaAttribute = JSON.stringify(filterNullProperty(message.content));
|
26668
|
+
}
|
26669
|
+
const mediaEncryptedString = aes256Encrypt(mediaAttribute, secretKey);
|
26718
26670
|
SentMessageStore.addMessage(sentArgs.messageId);
|
26719
26671
|
const baseParams = {
|
26720
26672
|
localId: sentArgs.messageId,
|
26721
26673
|
mediaFlag: false,
|
26722
|
-
mediaConstructor: message.
|
26723
|
-
mediaAttribute: '',
|
26674
|
+
mediaConstructor: message.messageType,
|
26724
26675
|
msgPreContent: '',
|
26725
|
-
msgPostContent:
|
26726
|
-
|
26727
|
-
pushContent: pushConfig
|
26676
|
+
msgPostContent: postEncryptedString,
|
26677
|
+
mediaAttribute: mediaEncryptedString
|
26728
26678
|
};
|
26729
26679
|
let response;
|
26730
26680
|
if (sentArgs.conversation.conversationType === exports.ConversationType.GROUP) {
|
@@ -26732,14 +26682,9 @@
|
|
26732
26682
|
...baseParams,
|
26733
26683
|
groupId: dialogId
|
26734
26684
|
};
|
26735
|
-
if (sentArgs?.directionalUserIdList?.length) {
|
26736
|
-
groupParams.assign = sentArgs.directionalUserIdList.join(',');
|
26737
|
-
}
|
26738
26685
|
if (isDef(message.content.mentionedInfo)) {
|
26739
26686
|
const mentionedInfo = message.content.mentionedInfo;
|
26740
|
-
if (mentionedInfo.type === exports.MentionedType.ALL) {
|
26741
|
-
groupParams.atAll = true;
|
26742
|
-
} else if (mentionedInfo.type === exports.MentionedType.SINGAL && mentionedInfo.userIdList?.length) {
|
26687
|
+
if (mentionedInfo.type === exports.MentionedType.ALL) ; else if (mentionedInfo.type === exports.MentionedType.SINGAL && mentionedInfo.userIdList?.length) {
|
26743
26688
|
groupParams.at = mentionedInfo.userIdList.map(e => Long.fromString(e));
|
26744
26689
|
}
|
26745
26690
|
}
|
@@ -26773,25 +26718,6 @@
|
|
26773
26718
|
}
|
26774
26719
|
return UniqueSentTime;
|
26775
26720
|
}
|
26776
|
-
function encodePushConfig(config) {
|
26777
|
-
if (!isDef(config)) return null;
|
26778
|
-
const obj = {};
|
26779
|
-
if (notEmptyString(config.pushTitle)) {
|
26780
|
-
obj.pushExt = {
|
26781
|
-
title: config.pushTitle
|
26782
|
-
};
|
26783
|
-
}
|
26784
|
-
if (notEmptyString(config.pushContent)) {
|
26785
|
-
obj.pushContent = config.pushContent;
|
26786
|
-
}
|
26787
|
-
if (notEmptyString(config.pushData)) {
|
26788
|
-
obj.pushData = config.pushData;
|
26789
|
-
}
|
26790
|
-
if (Object.keys(obj).length) {
|
26791
|
-
return JSON.stringify(obj);
|
26792
|
-
}
|
26793
|
-
return null;
|
26794
|
-
}
|
26795
26721
|
|
26796
26722
|
class IMClient extends EventEmitter {
|
26797
26723
|
options;
|
@@ -26848,7 +26774,6 @@
|
|
26848
26774
|
});
|
26849
26775
|
},
|
26850
26776
|
onPush: (cmdId, body) => {
|
26851
|
-
logger.info(`client onPush -> cmdId: ${cmdId}, body: ${body}`);
|
26852
26777
|
this.emit(exports.Events.PUSH, {
|
26853
26778
|
cmdId,
|
26854
26779
|
body
|
@@ -26898,7 +26823,7 @@
|
|
26898
26823
|
ServerMessageParser.parse({
|
26899
26824
|
[dialogId.toString()]: data.msg ?? {}
|
26900
26825
|
}, (_, outputMsgs) => {
|
26901
|
-
const messageList = outputMsgs.get(dialogId) ?? [];
|
26826
|
+
const messageList = outputMsgs.get(dialogId.toString()) ?? [];
|
26902
26827
|
messageList.sort((e1, e2) => e1.sentTime.lessThan(e2.sentTime) ? -1 : 1);
|
26903
26828
|
resolve({
|
26904
26829
|
code: exports.ErrorCode.SUCCESS,
|
@@ -26934,7 +26859,7 @@
|
|
26934
26859
|
};
|
26935
26860
|
}
|
26936
26861
|
const dialogIdList = data.fullDialog.map(item => item.dialog?.destId).filter(isDef);
|
26937
|
-
await DialogSecretKey$1.getDialogAesKeyList(dialogIdList);
|
26862
|
+
await DialogSecretKey$1.getDialogAesKeyList(dialogIdList.map(e => e.toString()));
|
26938
26863
|
const contentList = [];
|
26939
26864
|
for (const dialogInfo of data.fullDialog) {
|
26940
26865
|
const conversationObj = this.formatConversation(dialogInfo);
|
@@ -27075,11 +27000,11 @@
|
|
27075
27000
|
if (!conversationObj) {
|
27076
27001
|
return;
|
27077
27002
|
}
|
27078
|
-
const aesKey = DialogSecretKey$1.getDialogAesKeyFromLocal(dialogId);
|
27003
|
+
const aesKey = DialogSecretKey$1.getDialogAesKeyFromLocal(dialogId.toString());
|
27079
27004
|
if (!aesKey) {
|
27080
27005
|
return;
|
27081
27006
|
}
|
27082
|
-
const latestMessage = ServerMessageParser.parseSingleDialogMessages(dialogId, [msg], aesKey)[0];
|
27007
|
+
const latestMessage = ServerMessageParser.parseSingleDialogMessages(dialogId.toString(), [msg], aesKey)[0];
|
27083
27008
|
if (!latestMessage) {
|
27084
27009
|
return;
|
27085
27010
|
}
|
@@ -28176,7 +28101,9 @@
|
|
28176
28101
|
const defined = function (content) {
|
28177
28102
|
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
28178
28103
|
};
|
28179
|
-
|
28104
|
+
let messageConstructor = defined;
|
28105
|
+
registerMessage(messageType, messageConstructor);
|
28106
|
+
return messageConstructor;
|
28180
28107
|
};
|
28181
28108
|
const sendMessage = async (conversation, message, options) => {
|
28182
28109
|
if (message instanceof BaseMessage === false) {
|
package/package.json
CHANGED
@@ -44,9 +44,5 @@ export declare class BaseMessage<T extends IBaseMessageBody = any> {
|
|
44
44
|
readonly isCounted: boolean;
|
45
45
|
readonly isStatusMessage: boolean;
|
46
46
|
constructor(messageType: number, content: T, isPersited?: boolean, isCounted?: boolean, isStatusMessage?: boolean);
|
47
|
-
get objectId(): number;
|
48
|
-
static getObjectId(): number;
|
49
|
-
static decode(aDecoder: MessageCodingData): BaseMessage<any>;
|
50
|
-
encode(): MessageCodingData;
|
51
47
|
}
|
52
48
|
export declare const registerMessageType: <T extends IBaseMessageBody>(messageType: number, isPersited: boolean, isCounted: boolean, isStatusMessage?: boolean) => new (content: T) => BaseMessage<T>;
|
package/types/types.d.ts
CHANGED
@@ -109,10 +109,6 @@ export type IPushConfig = {
|
|
109
109
|
* 发送消息时的可选项信息
|
110
110
|
*/
|
111
111
|
export interface ISendMessageOptions {
|
112
|
-
/**
|
113
|
-
* 用于发送群定向消息,只当 conversationType 值为 `ConversationType.GROUP` 时有效
|
114
|
-
*/
|
115
|
-
directionalUserIdList?: string[];
|
116
112
|
/**
|
117
113
|
* 消息发送之前的回调
|
118
114
|
*/
|