@onyx-p/imlib-web 1.3.5 → 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 +112 -187
- package/index.umd.js +112 -187
- 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
@@ -17560,11 +17560,6 @@ const SendGroupChatMessageReq = $root.SendGroupChatMessageReq = (() => {
|
|
17560
17560
|
* @property {number|null} [mediaConstructor] SendGroupChatMessageReq mediaConstructor
|
17561
17561
|
* @property {string|null} [mediaAttribute] SendGroupChatMessageReq mediaAttribute
|
17562
17562
|
* @property {Array.<Long>|null} [at] SendGroupChatMessageReq at
|
17563
|
-
* @property {string|null} [extra] SendGroupChatMessageReq extra
|
17564
|
-
* @property {string|null} [assign] SendGroupChatMessageReq assign
|
17565
|
-
* @property {boolean|null} [atAll] SendGroupChatMessageReq atAll
|
17566
|
-
* @property {Uint8Array|null} [msgContent] SendGroupChatMessageReq msgContent
|
17567
|
-
* @property {string|null} [pushContent] SendGroupChatMessageReq pushContent
|
17568
17563
|
*/
|
17569
17564
|
|
17570
17565
|
/**
|
@@ -17644,46 +17639,6 @@ const SendGroupChatMessageReq = $root.SendGroupChatMessageReq = (() => {
|
|
17644
17639
|
*/
|
17645
17640
|
SendGroupChatMessageReq.prototype.at = $util.emptyArray;
|
17646
17641
|
|
17647
|
-
/**
|
17648
|
-
* SendGroupChatMessageReq extra.
|
17649
|
-
* @member {string} extra
|
17650
|
-
* @memberof SendGroupChatMessageReq
|
17651
|
-
* @instance
|
17652
|
-
*/
|
17653
|
-
SendGroupChatMessageReq.prototype.extra = "";
|
17654
|
-
|
17655
|
-
/**
|
17656
|
-
* SendGroupChatMessageReq assign.
|
17657
|
-
* @member {string} assign
|
17658
|
-
* @memberof SendGroupChatMessageReq
|
17659
|
-
* @instance
|
17660
|
-
*/
|
17661
|
-
SendGroupChatMessageReq.prototype.assign = "";
|
17662
|
-
|
17663
|
-
/**
|
17664
|
-
* SendGroupChatMessageReq atAll.
|
17665
|
-
* @member {boolean} atAll
|
17666
|
-
* @memberof SendGroupChatMessageReq
|
17667
|
-
* @instance
|
17668
|
-
*/
|
17669
|
-
SendGroupChatMessageReq.prototype.atAll = false;
|
17670
|
-
|
17671
|
-
/**
|
17672
|
-
* SendGroupChatMessageReq msgContent.
|
17673
|
-
* @member {Uint8Array} msgContent
|
17674
|
-
* @memberof SendGroupChatMessageReq
|
17675
|
-
* @instance
|
17676
|
-
*/
|
17677
|
-
SendGroupChatMessageReq.prototype.msgContent = $util.newBuffer([]);
|
17678
|
-
|
17679
|
-
/**
|
17680
|
-
* SendGroupChatMessageReq pushContent.
|
17681
|
-
* @member {string} pushContent
|
17682
|
-
* @memberof SendGroupChatMessageReq
|
17683
|
-
* @instance
|
17684
|
-
*/
|
17685
|
-
SendGroupChatMessageReq.prototype.pushContent = "";
|
17686
|
-
|
17687
17642
|
/**
|
17688
17643
|
* Encodes the specified SendGroupChatMessageReq message. Does not implicitly {@link SendGroupChatMessageReq.verify|verify} messages.
|
17689
17644
|
* @function encode
|
@@ -17707,11 +17662,6 @@ const SendGroupChatMessageReq = $root.SendGroupChatMessageReq = (() => {
|
|
17707
17662
|
for (let i = 0; i < message.at.length; ++i) writer.int64(message.at[i]);
|
17708
17663
|
writer.ldelim();
|
17709
17664
|
}
|
17710
|
-
if (message.extra != null && Object.hasOwnProperty.call(message, "extra")) writer.uint32(/* id 9, wireType 2 =*/74).string(message.extra);
|
17711
|
-
if (message.assign != null && Object.hasOwnProperty.call(message, "assign")) writer.uint32(/* id 10, wireType 2 =*/82).string(message.assign);
|
17712
|
-
if (message.atAll != null && Object.hasOwnProperty.call(message, "atAll")) writer.uint32(/* id 11, wireType 0 =*/88).bool(message.atAll);
|
17713
|
-
if (message.msgContent != null && Object.hasOwnProperty.call(message, "msgContent")) writer.uint32(/* id 12, wireType 2 =*/98).bytes(message.msgContent);
|
17714
|
-
if (message.pushContent != null && Object.hasOwnProperty.call(message, "pushContent")) writer.uint32(/* id 13, wireType 2 =*/106).string(message.pushContent);
|
17715
17665
|
return writer;
|
17716
17666
|
};
|
17717
17667
|
|
@@ -17777,31 +17727,6 @@ const SendGroupChatMessageReq = $root.SendGroupChatMessageReq = (() => {
|
|
17777
17727
|
} else message.at.push(reader.int64());
|
17778
17728
|
break;
|
17779
17729
|
}
|
17780
|
-
case 9:
|
17781
|
-
{
|
17782
|
-
message.extra = reader.string();
|
17783
|
-
break;
|
17784
|
-
}
|
17785
|
-
case 10:
|
17786
|
-
{
|
17787
|
-
message.assign = reader.string();
|
17788
|
-
break;
|
17789
|
-
}
|
17790
|
-
case 11:
|
17791
|
-
{
|
17792
|
-
message.atAll = reader.bool();
|
17793
|
-
break;
|
17794
|
-
}
|
17795
|
-
case 12:
|
17796
|
-
{
|
17797
|
-
message.msgContent = reader.bytes();
|
17798
|
-
break;
|
17799
|
-
}
|
17800
|
-
case 13:
|
17801
|
-
{
|
17802
|
-
message.pushContent = reader.string();
|
17803
|
-
break;
|
17804
|
-
}
|
17805
17730
|
default:
|
17806
17731
|
reader.skipType(tag & 7);
|
17807
17732
|
break;
|
@@ -18716,6 +18641,24 @@ var RecallMessageStore = {
|
|
18716
18641
|
}
|
18717
18642
|
};
|
18718
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
|
+
|
18719
18662
|
class DialogSecretKey {
|
18720
18663
|
aesKeyRecord = new Map();
|
18721
18664
|
async getDialogAesKey(dialogId) {
|
@@ -18780,7 +18723,7 @@ class DialogSecretKey {
|
|
18780
18723
|
const {
|
18781
18724
|
code,
|
18782
18725
|
data
|
18783
|
-
} = await getDialogKey(dialogIdList);
|
18726
|
+
} = await getDialogKey(dialogIdList.map(e => Long.fromString(e)));
|
18784
18727
|
if (code === ErrorCode.SUCCESS) {
|
18785
18728
|
const content = new Map();
|
18786
18729
|
for (const k in data.entry) {
|
@@ -18790,9 +18733,8 @@ class DialogSecretKey {
|
|
18790
18733
|
key: v.aesKey,
|
18791
18734
|
iv: v.aesIV
|
18792
18735
|
};
|
18793
|
-
|
18794
|
-
|
18795
|
-
this.aesKeyRecord.set(kLong, keyItem);
|
18736
|
+
content.set(k, keyItem);
|
18737
|
+
this.aesKeyRecord.set(k, keyItem);
|
18796
18738
|
}
|
18797
18739
|
}
|
18798
18740
|
return content;
|
@@ -18839,15 +18781,16 @@ class Letterbox {
|
|
18839
18781
|
|
18840
18782
|
const aes256Encrypt = (message, secretKey) => {
|
18841
18783
|
if (!notEmptyString(message)) {
|
18842
|
-
return
|
18784
|
+
return '';
|
18843
18785
|
}
|
18844
18786
|
const encryptedData = CryptoJS.AES.encrypt(message, CryptoJS.enc.Utf8.parse(secretKey.key), {
|
18845
18787
|
iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
|
18846
18788
|
});
|
18847
|
-
return wordToUInt8Array(encryptedData.ciphertext.words);
|
18789
|
+
return Array.from(wordToUInt8Array(encryptedData.ciphertext.words)).map(byte => byte.toString(16).padStart(2, '0')).join('');
|
18848
18790
|
};
|
18849
|
-
const aes256Decrypt = (
|
18850
|
-
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));
|
18851
18794
|
const decrypt = CryptoJS.AES.decrypt(srcs, CryptoJS.enc.Utf8.parse(secretKey.key), {
|
18852
18795
|
iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
|
18853
18796
|
});
|
@@ -18865,13 +18808,6 @@ const wordToUInt8Array = wordArray => {
|
|
18865
18808
|
return new Uint8Array(array);
|
18866
18809
|
};
|
18867
18810
|
|
18868
|
-
const MessageSerializers = new Map();
|
18869
|
-
function decodeMessage(objectId, messageData) {
|
18870
|
-
const decodeFunc = MessageSerializers.get(objectId);
|
18871
|
-
const messageObject = decodeFunc ? decodeFunc(messageData) : null;
|
18872
|
-
return messageObject;
|
18873
|
-
}
|
18874
|
-
|
18875
18811
|
const MessageTypes = {
|
18876
18812
|
TEXT: 0x00000000,
|
18877
18813
|
IMAGE: 0x10001000,
|
@@ -18892,7 +18828,7 @@ function parse(orginalMsgs, callback) {
|
|
18892
18828
|
Object.keys(orginalMsgs).forEach(dialogId => {
|
18893
18829
|
const arr = orginalMsgs[dialogId].dialogMessage?.filter(m => !m.sharingGroupFlag);
|
18894
18830
|
if (arr?.length) {
|
18895
|
-
msgs.set(
|
18831
|
+
msgs.set(dialogId, arr);
|
18896
18832
|
}
|
18897
18833
|
});
|
18898
18834
|
if (!msgs.size) {
|
@@ -18956,7 +18892,7 @@ const parseSingleDialogMessages = (dialogId, originalMessageList, aesKey) => {
|
|
18956
18892
|
isCounted: messageInstance.isCounted,
|
18957
18893
|
isMentioned: dialogMessage.atFlag,
|
18958
18894
|
content: messageInstance.content,
|
18959
|
-
messageType: messageInstance.
|
18895
|
+
messageType: messageInstance.messageType,
|
18960
18896
|
isOffLineMessage: false,
|
18961
18897
|
isPersited: messageInstance.isPersited,
|
18962
18898
|
messageId: Long.isLong(dialogMessage.localId) ? dialogMessage.localId : undefined,
|
@@ -18982,11 +18918,15 @@ const parseSingleDialogMessages = (dialogId, originalMessageList, aesKey) => {
|
|
18982
18918
|
const decodeMessageContent = (dialogMessage, aesKey) => {
|
18983
18919
|
try {
|
18984
18920
|
let mediaAttribute;
|
18985
|
-
if (dialogMessage.
|
18921
|
+
if (dialogMessage.mediaAttribute?.length) {
|
18986
18922
|
mediaAttribute = aes256Decrypt(dialogMessage.mediaAttribute, aesKey);
|
18987
18923
|
} else {
|
18988
18924
|
mediaAttribute = dialogMessage.msgPreContent ?? '';
|
18989
18925
|
}
|
18926
|
+
let msgPostContent;
|
18927
|
+
if (dialogMessage.msgPostContent?.length) {
|
18928
|
+
msgPostContent = aes256Decrypt(dialogMessage.msgPostContent, aesKey);
|
18929
|
+
}
|
18990
18930
|
if (dialogMessage.mediaConstructor === 0x60010012 || dialogMessage.mediaConstructor === 0x60020021) {
|
18991
18931
|
mediaAttribute = transMsgIdNum64ToString(mediaAttribute);
|
18992
18932
|
}
|
@@ -18994,6 +18934,9 @@ const decodeMessageContent = (dialogMessage, aesKey) => {
|
|
18994
18934
|
if (mediaAttribute?.length) {
|
18995
18935
|
mediaAttributeJson = JSON.parse(mediaAttribute);
|
18996
18936
|
}
|
18937
|
+
if (dialogMessage.mediaConstructor == MessageTypes.TEXT && msgPostContent) {
|
18938
|
+
mediaAttributeJson.content = msgPostContent;
|
18939
|
+
}
|
18997
18940
|
return mediaAttributeJson;
|
18998
18941
|
} catch (error) {
|
18999
18942
|
logger.error('decode message content fail -> uid:', dialogMessage.msgId.toString());
|
@@ -19808,6 +19751,44 @@ class MessageLoader {
|
|
19808
19751
|
}
|
19809
19752
|
}
|
19810
19753
|
|
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
|
+
|
19811
19792
|
const DEFAULT_SOCKET_URI = 'wss://imweb.mp.net:6443';
|
19812
19793
|
class LibLoader {
|
19813
19794
|
options;
|
@@ -19854,7 +19835,13 @@ class LibLoader {
|
|
19854
19835
|
}
|
19855
19836
|
return DEFAULT_SOCKET_URI;
|
19856
19837
|
}
|
19857
|
-
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
|
+
}
|
19858
19845
|
async connect() {
|
19859
19846
|
if (this.connectionStatus === ConnectionStatus.CONNECTED) {
|
19860
19847
|
return {
|
@@ -26534,56 +26521,6 @@ function requireProtobufjs () {
|
|
26534
26521
|
var protobufjsExports = requireProtobufjs();
|
26535
26522
|
var protobuf = /*@__PURE__*/getDefaultExportFromCjs(protobufjsExports);
|
26536
26523
|
|
26537
|
-
class BaseMessage {
|
26538
|
-
messageType;
|
26539
|
-
content;
|
26540
|
-
isPersited;
|
26541
|
-
isCounted;
|
26542
|
-
isStatusMessage;
|
26543
|
-
constructor(messageType, content, isPersited = true, isCounted = true, isStatusMessage = false) {
|
26544
|
-
this.messageType = messageType;
|
26545
|
-
this.content = content;
|
26546
|
-
if (isStatusMessage) {
|
26547
|
-
this.isPersited = false;
|
26548
|
-
this.isCounted = false;
|
26549
|
-
} else {
|
26550
|
-
this.isPersited = isPersited;
|
26551
|
-
this.isCounted = isCounted;
|
26552
|
-
}
|
26553
|
-
this.isStatusMessage = isStatusMessage;
|
26554
|
-
}
|
26555
|
-
get objectId() {
|
26556
|
-
return this.constructor.getObjectId();
|
26557
|
-
}
|
26558
|
-
static getObjectId() {
|
26559
|
-
throw new Error('Method not implemented.');
|
26560
|
-
}
|
26561
|
-
static decode(aDecoder) {
|
26562
|
-
throw new Error('Method not implemented.');
|
26563
|
-
}
|
26564
|
-
encode() {
|
26565
|
-
throw new Error('Method not implemented.');
|
26566
|
-
}
|
26567
|
-
}
|
26568
|
-
const registerMessageType$1 = (messageType, isPersited, isCounted, isStatusMessage) => {
|
26569
|
-
const defined = function (content) {
|
26570
|
-
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
26571
|
-
};
|
26572
|
-
return defined;
|
26573
|
-
};
|
26574
|
-
|
26575
|
-
const TextMessage = registerMessageType$1(MessageTypes.TEXT, true, true, false);
|
26576
|
-
|
26577
|
-
const ImageMessage = registerMessageType$1(MessageTypes.IMAGE, true, true, false);
|
26578
|
-
|
26579
|
-
const GIFMessage = registerMessageType$1(MessageTypes.GIF, true, true, false);
|
26580
|
-
|
26581
|
-
const VoiceMessage = registerMessageType$1(MessageTypes.AUDIO, true, true, false);
|
26582
|
-
|
26583
|
-
const FileMessage = registerMessageType$1(MessageTypes.FILE, true, true, false);
|
26584
|
-
|
26585
|
-
const RecallCommandMessage = registerMessageType$1(MessageTypes.RECALL, true, false, false);
|
26586
|
-
|
26587
26524
|
const transSentAttrs2IReceivedMessage = (message, options, sentStatus = SentStatus.SENDING) => ({
|
26588
26525
|
conversationType: options.conversation.conversationType,
|
26589
26526
|
targetId: options.conversation.targetId,
|
@@ -26592,7 +26529,7 @@ const transSentAttrs2IReceivedMessage = (message, options, sentStatus = SentStat
|
|
26592
26529
|
isCounted: message.isCounted,
|
26593
26530
|
isMentioned: false,
|
26594
26531
|
content: message.content,
|
26595
|
-
messageType: message.
|
26532
|
+
messageType: message.messageType,
|
26596
26533
|
isOffLineMessage: false,
|
26597
26534
|
isPersited: message.isPersited,
|
26598
26535
|
messageId: options.messageId,
|
@@ -26617,7 +26554,11 @@ function generateMessageId() {
|
|
26617
26554
|
|
26618
26555
|
const MAX_MESSAGE_CONTENT_BYTES = 80 * 1024;
|
26619
26556
|
async function sendMessage$1(conversation, message, options) {
|
26620
|
-
|
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);
|
26621
26562
|
}
|
26622
26563
|
const sendRecallMessage = async (conversation, options) => {
|
26623
26564
|
const dialogId = getFullDialogId(conversation);
|
@@ -26673,7 +26614,7 @@ function beforeSend(conversation, message, options) {
|
|
26673
26614
|
code: ErrorCode.RC_NET_CHANNEL_INVALID
|
26674
26615
|
};
|
26675
26616
|
}
|
26676
|
-
const mediaAttribute = JSON.stringify(filterNullProperty(message.
|
26617
|
+
const mediaAttribute = JSON.stringify(filterNullProperty(message.content));
|
26677
26618
|
if (getByteLength(mediaAttribute) > MAX_MESSAGE_CONTENT_BYTES) {
|
26678
26619
|
return {
|
26679
26620
|
code: ErrorCode.RC_MSG_CONTENT_EXCEED_LIMIT
|
@@ -26684,7 +26625,6 @@ function beforeSend(conversation, message, options) {
|
|
26684
26625
|
senderUserId: accountStore.uid,
|
26685
26626
|
messageId: options?.messageId ?? Long.fromNumber(generateMessageId()),
|
26686
26627
|
sentTime: Long.fromNumber(getMessageSentTime()),
|
26687
|
-
directionalUserIdList: options?.directionalUserIdList,
|
26688
26628
|
pushConfig: options?.pushConfig
|
26689
26629
|
};
|
26690
26630
|
if (options?.onSendBefore) {
|
@@ -26701,7 +26641,7 @@ async function send(message, sentArgs) {
|
|
26701
26641
|
const dialogId = getFullDialogId(sentArgs.conversation);
|
26702
26642
|
const receivedMessage = transSentAttrs2IReceivedMessage(message, sentArgs);
|
26703
26643
|
message.isPersited && ConversationManager$1.get().loadConvsationsIfNotExist([sentArgs.conversation]);
|
26704
|
-
const secretKey = await DialogSecretKey$1.getDialogAesKey(dialogId);
|
26644
|
+
const secretKey = await DialogSecretKey$1.getDialogAesKey(dialogId.toString());
|
26705
26645
|
if (!secretKey) {
|
26706
26646
|
receivedMessage.sentStatus = SentStatus.FAILED;
|
26707
26647
|
return {
|
@@ -26709,19 +26649,26 @@ async function send(message, sentArgs) {
|
|
26709
26649
|
data: receivedMessage
|
26710
26650
|
};
|
26711
26651
|
}
|
26712
|
-
|
26713
|
-
|
26714
|
-
|
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);
|
26715
26664
|
SentMessageStore.addMessage(sentArgs.messageId);
|
26716
26665
|
const baseParams = {
|
26717
26666
|
localId: sentArgs.messageId,
|
26718
26667
|
mediaFlag: false,
|
26719
|
-
mediaConstructor: message.
|
26720
|
-
mediaAttribute: '',
|
26668
|
+
mediaConstructor: message.messageType,
|
26721
26669
|
msgPreContent: '',
|
26722
|
-
msgPostContent:
|
26723
|
-
|
26724
|
-
pushContent: pushConfig
|
26670
|
+
msgPostContent: postEncryptedString,
|
26671
|
+
mediaAttribute: mediaEncryptedString
|
26725
26672
|
};
|
26726
26673
|
let response;
|
26727
26674
|
if (sentArgs.conversation.conversationType === ConversationType.GROUP) {
|
@@ -26729,14 +26676,9 @@ async function send(message, sentArgs) {
|
|
26729
26676
|
...baseParams,
|
26730
26677
|
groupId: dialogId
|
26731
26678
|
};
|
26732
|
-
if (sentArgs?.directionalUserIdList?.length) {
|
26733
|
-
groupParams.assign = sentArgs.directionalUserIdList.join(',');
|
26734
|
-
}
|
26735
26679
|
if (isDef(message.content.mentionedInfo)) {
|
26736
26680
|
const mentionedInfo = message.content.mentionedInfo;
|
26737
|
-
if (mentionedInfo.type === MentionedType.ALL) {
|
26738
|
-
groupParams.atAll = true;
|
26739
|
-
} else if (mentionedInfo.type === MentionedType.SINGAL && mentionedInfo.userIdList?.length) {
|
26681
|
+
if (mentionedInfo.type === MentionedType.ALL) ; else if (mentionedInfo.type === MentionedType.SINGAL && mentionedInfo.userIdList?.length) {
|
26740
26682
|
groupParams.at = mentionedInfo.userIdList.map(e => Long.fromString(e));
|
26741
26683
|
}
|
26742
26684
|
}
|
@@ -26770,25 +26712,6 @@ function getMessageSentTime() {
|
|
26770
26712
|
}
|
26771
26713
|
return UniqueSentTime;
|
26772
26714
|
}
|
26773
|
-
function encodePushConfig(config) {
|
26774
|
-
if (!isDef(config)) return null;
|
26775
|
-
const obj = {};
|
26776
|
-
if (notEmptyString(config.pushTitle)) {
|
26777
|
-
obj.pushExt = {
|
26778
|
-
title: config.pushTitle
|
26779
|
-
};
|
26780
|
-
}
|
26781
|
-
if (notEmptyString(config.pushContent)) {
|
26782
|
-
obj.pushContent = config.pushContent;
|
26783
|
-
}
|
26784
|
-
if (notEmptyString(config.pushData)) {
|
26785
|
-
obj.pushData = config.pushData;
|
26786
|
-
}
|
26787
|
-
if (Object.keys(obj).length) {
|
26788
|
-
return JSON.stringify(obj);
|
26789
|
-
}
|
26790
|
-
return null;
|
26791
|
-
}
|
26792
26715
|
|
26793
26716
|
class IMClient extends EventEmitter {
|
26794
26717
|
options;
|
@@ -26894,7 +26817,7 @@ class IMClient extends EventEmitter {
|
|
26894
26817
|
ServerMessageParser.parse({
|
26895
26818
|
[dialogId.toString()]: data.msg ?? {}
|
26896
26819
|
}, (_, outputMsgs) => {
|
26897
|
-
const messageList = outputMsgs.get(dialogId) ?? [];
|
26820
|
+
const messageList = outputMsgs.get(dialogId.toString()) ?? [];
|
26898
26821
|
messageList.sort((e1, e2) => e1.sentTime.lessThan(e2.sentTime) ? -1 : 1);
|
26899
26822
|
resolve({
|
26900
26823
|
code: ErrorCode.SUCCESS,
|
@@ -26930,7 +26853,7 @@ class IMClient extends EventEmitter {
|
|
26930
26853
|
};
|
26931
26854
|
}
|
26932
26855
|
const dialogIdList = data.fullDialog.map(item => item.dialog?.destId).filter(isDef);
|
26933
|
-
await DialogSecretKey$1.getDialogAesKeyList(dialogIdList);
|
26856
|
+
await DialogSecretKey$1.getDialogAesKeyList(dialogIdList.map(e => e.toString()));
|
26934
26857
|
const contentList = [];
|
26935
26858
|
for (const dialogInfo of data.fullDialog) {
|
26936
26859
|
const conversationObj = this.formatConversation(dialogInfo);
|
@@ -27071,11 +26994,11 @@ class IMClient extends EventEmitter {
|
|
27071
26994
|
if (!conversationObj) {
|
27072
26995
|
return;
|
27073
26996
|
}
|
27074
|
-
const aesKey = DialogSecretKey$1.getDialogAesKeyFromLocal(dialogId);
|
26997
|
+
const aesKey = DialogSecretKey$1.getDialogAesKeyFromLocal(dialogId.toString());
|
27075
26998
|
if (!aesKey) {
|
27076
26999
|
return;
|
27077
27000
|
}
|
27078
|
-
const latestMessage = ServerMessageParser.parseSingleDialogMessages(dialogId, [msg], aesKey)[0];
|
27001
|
+
const latestMessage = ServerMessageParser.parseSingleDialogMessages(dialogId.toString(), [msg], aesKey)[0];
|
27079
27002
|
if (!latestMessage) {
|
27080
27003
|
return;
|
27081
27004
|
}
|
@@ -28172,7 +28095,9 @@ const registerMessageType = (messageType, isPersited, isCounted, isStatusMessage
|
|
28172
28095
|
const defined = function (content) {
|
28173
28096
|
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
28174
28097
|
};
|
28175
|
-
|
28098
|
+
let messageConstructor = defined;
|
28099
|
+
registerMessage(messageType, messageConstructor);
|
28100
|
+
return messageConstructor;
|
28176
28101
|
};
|
28177
28102
|
const sendMessage = async (conversation, message, options) => {
|
28178
28103
|
if (message instanceof BaseMessage === false) {
|
package/index.umd.js
CHANGED
@@ -17566,11 +17566,6 @@
|
|
17566
17566
|
* @property {number|null} [mediaConstructor] SendGroupChatMessageReq mediaConstructor
|
17567
17567
|
* @property {string|null} [mediaAttribute] SendGroupChatMessageReq mediaAttribute
|
17568
17568
|
* @property {Array.<Long>|null} [at] SendGroupChatMessageReq at
|
17569
|
-
* @property {string|null} [extra] SendGroupChatMessageReq extra
|
17570
|
-
* @property {string|null} [assign] SendGroupChatMessageReq assign
|
17571
|
-
* @property {boolean|null} [atAll] SendGroupChatMessageReq atAll
|
17572
|
-
* @property {Uint8Array|null} [msgContent] SendGroupChatMessageReq msgContent
|
17573
|
-
* @property {string|null} [pushContent] SendGroupChatMessageReq pushContent
|
17574
17569
|
*/
|
17575
17570
|
|
17576
17571
|
/**
|
@@ -17650,46 +17645,6 @@
|
|
17650
17645
|
*/
|
17651
17646
|
SendGroupChatMessageReq.prototype.at = $util.emptyArray;
|
17652
17647
|
|
17653
|
-
/**
|
17654
|
-
* SendGroupChatMessageReq extra.
|
17655
|
-
* @member {string} extra
|
17656
|
-
* @memberof SendGroupChatMessageReq
|
17657
|
-
* @instance
|
17658
|
-
*/
|
17659
|
-
SendGroupChatMessageReq.prototype.extra = "";
|
17660
|
-
|
17661
|
-
/**
|
17662
|
-
* SendGroupChatMessageReq assign.
|
17663
|
-
* @member {string} assign
|
17664
|
-
* @memberof SendGroupChatMessageReq
|
17665
|
-
* @instance
|
17666
|
-
*/
|
17667
|
-
SendGroupChatMessageReq.prototype.assign = "";
|
17668
|
-
|
17669
|
-
/**
|
17670
|
-
* SendGroupChatMessageReq atAll.
|
17671
|
-
* @member {boolean} atAll
|
17672
|
-
* @memberof SendGroupChatMessageReq
|
17673
|
-
* @instance
|
17674
|
-
*/
|
17675
|
-
SendGroupChatMessageReq.prototype.atAll = false;
|
17676
|
-
|
17677
|
-
/**
|
17678
|
-
* SendGroupChatMessageReq msgContent.
|
17679
|
-
* @member {Uint8Array} msgContent
|
17680
|
-
* @memberof SendGroupChatMessageReq
|
17681
|
-
* @instance
|
17682
|
-
*/
|
17683
|
-
SendGroupChatMessageReq.prototype.msgContent = $util.newBuffer([]);
|
17684
|
-
|
17685
|
-
/**
|
17686
|
-
* SendGroupChatMessageReq pushContent.
|
17687
|
-
* @member {string} pushContent
|
17688
|
-
* @memberof SendGroupChatMessageReq
|
17689
|
-
* @instance
|
17690
|
-
*/
|
17691
|
-
SendGroupChatMessageReq.prototype.pushContent = "";
|
17692
|
-
|
17693
17648
|
/**
|
17694
17649
|
* Encodes the specified SendGroupChatMessageReq message. Does not implicitly {@link SendGroupChatMessageReq.verify|verify} messages.
|
17695
17650
|
* @function encode
|
@@ -17713,11 +17668,6 @@
|
|
17713
17668
|
for (let i = 0; i < message.at.length; ++i) writer.int64(message.at[i]);
|
17714
17669
|
writer.ldelim();
|
17715
17670
|
}
|
17716
|
-
if (message.extra != null && Object.hasOwnProperty.call(message, "extra")) writer.uint32(/* id 9, wireType 2 =*/74).string(message.extra);
|
17717
|
-
if (message.assign != null && Object.hasOwnProperty.call(message, "assign")) writer.uint32(/* id 10, wireType 2 =*/82).string(message.assign);
|
17718
|
-
if (message.atAll != null && Object.hasOwnProperty.call(message, "atAll")) writer.uint32(/* id 11, wireType 0 =*/88).bool(message.atAll);
|
17719
|
-
if (message.msgContent != null && Object.hasOwnProperty.call(message, "msgContent")) writer.uint32(/* id 12, wireType 2 =*/98).bytes(message.msgContent);
|
17720
|
-
if (message.pushContent != null && Object.hasOwnProperty.call(message, "pushContent")) writer.uint32(/* id 13, wireType 2 =*/106).string(message.pushContent);
|
17721
17671
|
return writer;
|
17722
17672
|
};
|
17723
17673
|
|
@@ -17783,31 +17733,6 @@
|
|
17783
17733
|
} else message.at.push(reader.int64());
|
17784
17734
|
break;
|
17785
17735
|
}
|
17786
|
-
case 9:
|
17787
|
-
{
|
17788
|
-
message.extra = reader.string();
|
17789
|
-
break;
|
17790
|
-
}
|
17791
|
-
case 10:
|
17792
|
-
{
|
17793
|
-
message.assign = reader.string();
|
17794
|
-
break;
|
17795
|
-
}
|
17796
|
-
case 11:
|
17797
|
-
{
|
17798
|
-
message.atAll = reader.bool();
|
17799
|
-
break;
|
17800
|
-
}
|
17801
|
-
case 12:
|
17802
|
-
{
|
17803
|
-
message.msgContent = reader.bytes();
|
17804
|
-
break;
|
17805
|
-
}
|
17806
|
-
case 13:
|
17807
|
-
{
|
17808
|
-
message.pushContent = reader.string();
|
17809
|
-
break;
|
17810
|
-
}
|
17811
17736
|
default:
|
17812
17737
|
reader.skipType(tag & 7);
|
17813
17738
|
break;
|
@@ -18722,6 +18647,24 @@
|
|
18722
18647
|
}
|
18723
18648
|
};
|
18724
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
|
+
|
18725
18668
|
class DialogSecretKey {
|
18726
18669
|
aesKeyRecord = new Map();
|
18727
18670
|
async getDialogAesKey(dialogId) {
|
@@ -18786,7 +18729,7 @@
|
|
18786
18729
|
const {
|
18787
18730
|
code,
|
18788
18731
|
data
|
18789
|
-
} = await getDialogKey(dialogIdList);
|
18732
|
+
} = await getDialogKey(dialogIdList.map(e => Long.fromString(e)));
|
18790
18733
|
if (code === exports.ErrorCode.SUCCESS) {
|
18791
18734
|
const content = new Map();
|
18792
18735
|
for (const k in data.entry) {
|
@@ -18796,9 +18739,8 @@
|
|
18796
18739
|
key: v.aesKey,
|
18797
18740
|
iv: v.aesIV
|
18798
18741
|
};
|
18799
|
-
|
18800
|
-
|
18801
|
-
this.aesKeyRecord.set(kLong, keyItem);
|
18742
|
+
content.set(k, keyItem);
|
18743
|
+
this.aesKeyRecord.set(k, keyItem);
|
18802
18744
|
}
|
18803
18745
|
}
|
18804
18746
|
return content;
|
@@ -18845,15 +18787,16 @@
|
|
18845
18787
|
|
18846
18788
|
const aes256Encrypt = (message, secretKey) => {
|
18847
18789
|
if (!notEmptyString(message)) {
|
18848
|
-
return
|
18790
|
+
return '';
|
18849
18791
|
}
|
18850
18792
|
const encryptedData = CryptoJS.AES.encrypt(message, CryptoJS.enc.Utf8.parse(secretKey.key), {
|
18851
18793
|
iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
|
18852
18794
|
});
|
18853
|
-
return wordToUInt8Array(encryptedData.ciphertext.words);
|
18795
|
+
return Array.from(wordToUInt8Array(encryptedData.ciphertext.words)).map(byte => byte.toString(16).padStart(2, '0')).join('');
|
18854
18796
|
};
|
18855
|
-
const aes256Decrypt = (
|
18856
|
-
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));
|
18857
18800
|
const decrypt = CryptoJS.AES.decrypt(srcs, CryptoJS.enc.Utf8.parse(secretKey.key), {
|
18858
18801
|
iv: isDef(secretKey.iv) ? CryptoJS.enc.Utf8.parse(secretKey.iv) : undefined
|
18859
18802
|
});
|
@@ -18871,13 +18814,6 @@
|
|
18871
18814
|
return new Uint8Array(array);
|
18872
18815
|
};
|
18873
18816
|
|
18874
|
-
const MessageSerializers = new Map();
|
18875
|
-
function decodeMessage(objectId, messageData) {
|
18876
|
-
const decodeFunc = MessageSerializers.get(objectId);
|
18877
|
-
const messageObject = decodeFunc ? decodeFunc(messageData) : null;
|
18878
|
-
return messageObject;
|
18879
|
-
}
|
18880
|
-
|
18881
18817
|
const MessageTypes = {
|
18882
18818
|
TEXT: 0x00000000,
|
18883
18819
|
IMAGE: 0x10001000,
|
@@ -18898,7 +18834,7 @@
|
|
18898
18834
|
Object.keys(orginalMsgs).forEach(dialogId => {
|
18899
18835
|
const arr = orginalMsgs[dialogId].dialogMessage?.filter(m => !m.sharingGroupFlag);
|
18900
18836
|
if (arr?.length) {
|
18901
|
-
msgs.set(
|
18837
|
+
msgs.set(dialogId, arr);
|
18902
18838
|
}
|
18903
18839
|
});
|
18904
18840
|
if (!msgs.size) {
|
@@ -18962,7 +18898,7 @@
|
|
18962
18898
|
isCounted: messageInstance.isCounted,
|
18963
18899
|
isMentioned: dialogMessage.atFlag,
|
18964
18900
|
content: messageInstance.content,
|
18965
|
-
messageType: messageInstance.
|
18901
|
+
messageType: messageInstance.messageType,
|
18966
18902
|
isOffLineMessage: false,
|
18967
18903
|
isPersited: messageInstance.isPersited,
|
18968
18904
|
messageId: Long.isLong(dialogMessage.localId) ? dialogMessage.localId : undefined,
|
@@ -18988,11 +18924,15 @@
|
|
18988
18924
|
const decodeMessageContent = (dialogMessage, aesKey) => {
|
18989
18925
|
try {
|
18990
18926
|
let mediaAttribute;
|
18991
|
-
if (dialogMessage.
|
18927
|
+
if (dialogMessage.mediaAttribute?.length) {
|
18992
18928
|
mediaAttribute = aes256Decrypt(dialogMessage.mediaAttribute, aesKey);
|
18993
18929
|
} else {
|
18994
18930
|
mediaAttribute = dialogMessage.msgPreContent ?? '';
|
18995
18931
|
}
|
18932
|
+
let msgPostContent;
|
18933
|
+
if (dialogMessage.msgPostContent?.length) {
|
18934
|
+
msgPostContent = aes256Decrypt(dialogMessage.msgPostContent, aesKey);
|
18935
|
+
}
|
18996
18936
|
if (dialogMessage.mediaConstructor === 0x60010012 || dialogMessage.mediaConstructor === 0x60020021) {
|
18997
18937
|
mediaAttribute = transMsgIdNum64ToString(mediaAttribute);
|
18998
18938
|
}
|
@@ -19000,6 +18940,9 @@
|
|
19000
18940
|
if (mediaAttribute?.length) {
|
19001
18941
|
mediaAttributeJson = JSON.parse(mediaAttribute);
|
19002
18942
|
}
|
18943
|
+
if (dialogMessage.mediaConstructor == MessageTypes.TEXT && msgPostContent) {
|
18944
|
+
mediaAttributeJson.content = msgPostContent;
|
18945
|
+
}
|
19003
18946
|
return mediaAttributeJson;
|
19004
18947
|
} catch (error) {
|
19005
18948
|
logger.error('decode message content fail -> uid:', dialogMessage.msgId.toString());
|
@@ -19814,6 +19757,44 @@
|
|
19814
19757
|
}
|
19815
19758
|
}
|
19816
19759
|
|
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
|
+
|
19817
19798
|
const DEFAULT_SOCKET_URI = 'wss://imweb.mp.net:6443';
|
19818
19799
|
class LibLoader {
|
19819
19800
|
options;
|
@@ -19860,7 +19841,13 @@
|
|
19860
19841
|
}
|
19861
19842
|
return DEFAULT_SOCKET_URI;
|
19862
19843
|
}
|
19863
|
-
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
|
+
}
|
19864
19851
|
async connect() {
|
19865
19852
|
if (this.connectionStatus === exports.ConnectionStatus.CONNECTED) {
|
19866
19853
|
return {
|
@@ -26540,56 +26527,6 @@
|
|
26540
26527
|
var protobufjsExports = requireProtobufjs();
|
26541
26528
|
var protobuf = /*@__PURE__*/getDefaultExportFromCjs(protobufjsExports);
|
26542
26529
|
|
26543
|
-
class BaseMessage {
|
26544
|
-
messageType;
|
26545
|
-
content;
|
26546
|
-
isPersited;
|
26547
|
-
isCounted;
|
26548
|
-
isStatusMessage;
|
26549
|
-
constructor(messageType, content, isPersited = true, isCounted = true, isStatusMessage = false) {
|
26550
|
-
this.messageType = messageType;
|
26551
|
-
this.content = content;
|
26552
|
-
if (isStatusMessage) {
|
26553
|
-
this.isPersited = false;
|
26554
|
-
this.isCounted = false;
|
26555
|
-
} else {
|
26556
|
-
this.isPersited = isPersited;
|
26557
|
-
this.isCounted = isCounted;
|
26558
|
-
}
|
26559
|
-
this.isStatusMessage = isStatusMessage;
|
26560
|
-
}
|
26561
|
-
get objectId() {
|
26562
|
-
return this.constructor.getObjectId();
|
26563
|
-
}
|
26564
|
-
static getObjectId() {
|
26565
|
-
throw new Error('Method not implemented.');
|
26566
|
-
}
|
26567
|
-
static decode(aDecoder) {
|
26568
|
-
throw new Error('Method not implemented.');
|
26569
|
-
}
|
26570
|
-
encode() {
|
26571
|
-
throw new Error('Method not implemented.');
|
26572
|
-
}
|
26573
|
-
}
|
26574
|
-
const registerMessageType$1 = (messageType, isPersited, isCounted, isStatusMessage) => {
|
26575
|
-
const defined = function (content) {
|
26576
|
-
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
26577
|
-
};
|
26578
|
-
return defined;
|
26579
|
-
};
|
26580
|
-
|
26581
|
-
const TextMessage = registerMessageType$1(MessageTypes.TEXT, true, true, false);
|
26582
|
-
|
26583
|
-
const ImageMessage = registerMessageType$1(MessageTypes.IMAGE, true, true, false);
|
26584
|
-
|
26585
|
-
const GIFMessage = registerMessageType$1(MessageTypes.GIF, true, true, false);
|
26586
|
-
|
26587
|
-
const VoiceMessage = registerMessageType$1(MessageTypes.AUDIO, true, true, false);
|
26588
|
-
|
26589
|
-
const FileMessage = registerMessageType$1(MessageTypes.FILE, true, true, false);
|
26590
|
-
|
26591
|
-
const RecallCommandMessage = registerMessageType$1(MessageTypes.RECALL, true, false, false);
|
26592
|
-
|
26593
26530
|
const transSentAttrs2IReceivedMessage = (message, options, sentStatus = exports.SentStatus.SENDING) => ({
|
26594
26531
|
conversationType: options.conversation.conversationType,
|
26595
26532
|
targetId: options.conversation.targetId,
|
@@ -26598,7 +26535,7 @@
|
|
26598
26535
|
isCounted: message.isCounted,
|
26599
26536
|
isMentioned: false,
|
26600
26537
|
content: message.content,
|
26601
|
-
messageType: message.
|
26538
|
+
messageType: message.messageType,
|
26602
26539
|
isOffLineMessage: false,
|
26603
26540
|
isPersited: message.isPersited,
|
26604
26541
|
messageId: options.messageId,
|
@@ -26623,7 +26560,11 @@
|
|
26623
26560
|
|
26624
26561
|
const MAX_MESSAGE_CONTENT_BYTES = 80 * 1024;
|
26625
26562
|
async function sendMessage$1(conversation, message, options) {
|
26626
|
-
|
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);
|
26627
26568
|
}
|
26628
26569
|
const sendRecallMessage = async (conversation, options) => {
|
26629
26570
|
const dialogId = getFullDialogId(conversation);
|
@@ -26679,7 +26620,7 @@
|
|
26679
26620
|
code: exports.ErrorCode.RC_NET_CHANNEL_INVALID
|
26680
26621
|
};
|
26681
26622
|
}
|
26682
|
-
const mediaAttribute = JSON.stringify(filterNullProperty(message.
|
26623
|
+
const mediaAttribute = JSON.stringify(filterNullProperty(message.content));
|
26683
26624
|
if (getByteLength(mediaAttribute) > MAX_MESSAGE_CONTENT_BYTES) {
|
26684
26625
|
return {
|
26685
26626
|
code: exports.ErrorCode.RC_MSG_CONTENT_EXCEED_LIMIT
|
@@ -26690,7 +26631,6 @@
|
|
26690
26631
|
senderUserId: accountStore.uid,
|
26691
26632
|
messageId: options?.messageId ?? Long.fromNumber(generateMessageId()),
|
26692
26633
|
sentTime: Long.fromNumber(getMessageSentTime()),
|
26693
|
-
directionalUserIdList: options?.directionalUserIdList,
|
26694
26634
|
pushConfig: options?.pushConfig
|
26695
26635
|
};
|
26696
26636
|
if (options?.onSendBefore) {
|
@@ -26707,7 +26647,7 @@
|
|
26707
26647
|
const dialogId = getFullDialogId(sentArgs.conversation);
|
26708
26648
|
const receivedMessage = transSentAttrs2IReceivedMessage(message, sentArgs);
|
26709
26649
|
message.isPersited && ConversationManager$1.get().loadConvsationsIfNotExist([sentArgs.conversation]);
|
26710
|
-
const secretKey = await DialogSecretKey$1.getDialogAesKey(dialogId);
|
26650
|
+
const secretKey = await DialogSecretKey$1.getDialogAesKey(dialogId.toString());
|
26711
26651
|
if (!secretKey) {
|
26712
26652
|
receivedMessage.sentStatus = exports.SentStatus.FAILED;
|
26713
26653
|
return {
|
@@ -26715,19 +26655,26 @@
|
|
26715
26655
|
data: receivedMessage
|
26716
26656
|
};
|
26717
26657
|
}
|
26718
|
-
|
26719
|
-
|
26720
|
-
|
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);
|
26721
26670
|
SentMessageStore.addMessage(sentArgs.messageId);
|
26722
26671
|
const baseParams = {
|
26723
26672
|
localId: sentArgs.messageId,
|
26724
26673
|
mediaFlag: false,
|
26725
|
-
mediaConstructor: message.
|
26726
|
-
mediaAttribute: '',
|
26674
|
+
mediaConstructor: message.messageType,
|
26727
26675
|
msgPreContent: '',
|
26728
|
-
msgPostContent:
|
26729
|
-
|
26730
|
-
pushContent: pushConfig
|
26676
|
+
msgPostContent: postEncryptedString,
|
26677
|
+
mediaAttribute: mediaEncryptedString
|
26731
26678
|
};
|
26732
26679
|
let response;
|
26733
26680
|
if (sentArgs.conversation.conversationType === exports.ConversationType.GROUP) {
|
@@ -26735,14 +26682,9 @@
|
|
26735
26682
|
...baseParams,
|
26736
26683
|
groupId: dialogId
|
26737
26684
|
};
|
26738
|
-
if (sentArgs?.directionalUserIdList?.length) {
|
26739
|
-
groupParams.assign = sentArgs.directionalUserIdList.join(',');
|
26740
|
-
}
|
26741
26685
|
if (isDef(message.content.mentionedInfo)) {
|
26742
26686
|
const mentionedInfo = message.content.mentionedInfo;
|
26743
|
-
if (mentionedInfo.type === exports.MentionedType.ALL) {
|
26744
|
-
groupParams.atAll = true;
|
26745
|
-
} 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) {
|
26746
26688
|
groupParams.at = mentionedInfo.userIdList.map(e => Long.fromString(e));
|
26747
26689
|
}
|
26748
26690
|
}
|
@@ -26776,25 +26718,6 @@
|
|
26776
26718
|
}
|
26777
26719
|
return UniqueSentTime;
|
26778
26720
|
}
|
26779
|
-
function encodePushConfig(config) {
|
26780
|
-
if (!isDef(config)) return null;
|
26781
|
-
const obj = {};
|
26782
|
-
if (notEmptyString(config.pushTitle)) {
|
26783
|
-
obj.pushExt = {
|
26784
|
-
title: config.pushTitle
|
26785
|
-
};
|
26786
|
-
}
|
26787
|
-
if (notEmptyString(config.pushContent)) {
|
26788
|
-
obj.pushContent = config.pushContent;
|
26789
|
-
}
|
26790
|
-
if (notEmptyString(config.pushData)) {
|
26791
|
-
obj.pushData = config.pushData;
|
26792
|
-
}
|
26793
|
-
if (Object.keys(obj).length) {
|
26794
|
-
return JSON.stringify(obj);
|
26795
|
-
}
|
26796
|
-
return null;
|
26797
|
-
}
|
26798
26721
|
|
26799
26722
|
class IMClient extends EventEmitter {
|
26800
26723
|
options;
|
@@ -26900,7 +26823,7 @@
|
|
26900
26823
|
ServerMessageParser.parse({
|
26901
26824
|
[dialogId.toString()]: data.msg ?? {}
|
26902
26825
|
}, (_, outputMsgs) => {
|
26903
|
-
const messageList = outputMsgs.get(dialogId) ?? [];
|
26826
|
+
const messageList = outputMsgs.get(dialogId.toString()) ?? [];
|
26904
26827
|
messageList.sort((e1, e2) => e1.sentTime.lessThan(e2.sentTime) ? -1 : 1);
|
26905
26828
|
resolve({
|
26906
26829
|
code: exports.ErrorCode.SUCCESS,
|
@@ -26936,7 +26859,7 @@
|
|
26936
26859
|
};
|
26937
26860
|
}
|
26938
26861
|
const dialogIdList = data.fullDialog.map(item => item.dialog?.destId).filter(isDef);
|
26939
|
-
await DialogSecretKey$1.getDialogAesKeyList(dialogIdList);
|
26862
|
+
await DialogSecretKey$1.getDialogAesKeyList(dialogIdList.map(e => e.toString()));
|
26940
26863
|
const contentList = [];
|
26941
26864
|
for (const dialogInfo of data.fullDialog) {
|
26942
26865
|
const conversationObj = this.formatConversation(dialogInfo);
|
@@ -27077,11 +27000,11 @@
|
|
27077
27000
|
if (!conversationObj) {
|
27078
27001
|
return;
|
27079
27002
|
}
|
27080
|
-
const aesKey = DialogSecretKey$1.getDialogAesKeyFromLocal(dialogId);
|
27003
|
+
const aesKey = DialogSecretKey$1.getDialogAesKeyFromLocal(dialogId.toString());
|
27081
27004
|
if (!aesKey) {
|
27082
27005
|
return;
|
27083
27006
|
}
|
27084
|
-
const latestMessage = ServerMessageParser.parseSingleDialogMessages(dialogId, [msg], aesKey)[0];
|
27007
|
+
const latestMessage = ServerMessageParser.parseSingleDialogMessages(dialogId.toString(), [msg], aesKey)[0];
|
27085
27008
|
if (!latestMessage) {
|
27086
27009
|
return;
|
27087
27010
|
}
|
@@ -28178,7 +28101,9 @@
|
|
28178
28101
|
const defined = function (content) {
|
28179
28102
|
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
28180
28103
|
};
|
28181
|
-
|
28104
|
+
let messageConstructor = defined;
|
28105
|
+
registerMessage(messageType, messageConstructor);
|
28106
|
+
return messageConstructor;
|
28182
28107
|
};
|
28183
28108
|
const sendMessage = async (conversation, message, options) => {
|
28184
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
|
*/
|