@onyx-p/imlib-web 1.3.3 → 1.3.4
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 +92 -845
- package/index.umd.js +93 -849
- package/package.json +1 -1
- package/types/index.d.ts +2 -5
- package/types/model/baseMessage.d.ts +4 -2
- package/types/model/messages/fileMessage.d.ts +12 -13
- package/types/model/messages/gifMessage.d.ts +11 -12
- package/types/model/messages/imageMessage.d.ts +16 -16
- package/types/model/messages/recallCommandMessage.d.ts +5 -13
- package/types/model/messages/textMessage.d.ts +4 -8
- package/types/model/messages/voiceMessage.d.ts +9 -12
package/index.esm.js
CHANGED
@@ -13513,13 +13513,13 @@ class WebSocketServer {
|
|
13513
13513
|
return;
|
13514
13514
|
}
|
13515
13515
|
const messageSeq = Long.isLong(networkResponse.messageSeq) ? networkResponse.messageSeq.toNumber() : 0;
|
13516
|
-
logger.
|
13516
|
+
logger.info(`websocket recv ack -> messageSeq: ${messageSeq}`);
|
13517
13517
|
const resolve = this.responseCallbacks.get(messageSeq);
|
13518
13518
|
if (isDef(resolve)) {
|
13519
13519
|
resolve(networkResponse.body);
|
13520
13520
|
this.responseCallbacks.delete(messageSeq);
|
13521
13521
|
} else {
|
13522
|
-
logger.
|
13522
|
+
logger.info(`websocket recv -> cmd: 0x${networkResponse.cmdId.toString(16)}, messageSeq: ${messageSeq}`);
|
13523
13523
|
this.watcher?.message(networkResponse.cmdId, networkResponse.body);
|
13524
13524
|
}
|
13525
13525
|
}
|
@@ -18712,331 +18712,6 @@ var RecallMessageStore = {
|
|
18712
18712
|
}
|
18713
18713
|
};
|
18714
18714
|
|
18715
|
-
const MessageSerializers = new Map();
|
18716
|
-
function registerMessageSerializer(aSerializer) {
|
18717
|
-
MessageSerializers.set(aSerializer.getObjectId(), aSerializer.decode.bind(aSerializer));
|
18718
|
-
}
|
18719
|
-
function decodeMessage(objectId, messageData) {
|
18720
|
-
const decodeFunc = MessageSerializers.get(objectId);
|
18721
|
-
const messageObject = decodeFunc ? decodeFunc(messageData) : null;
|
18722
|
-
return messageObject;
|
18723
|
-
}
|
18724
|
-
|
18725
|
-
class BaseMessage {
|
18726
|
-
content;
|
18727
|
-
isPersited;
|
18728
|
-
isCounted;
|
18729
|
-
isStatusMessage;
|
18730
|
-
constructor(content, isPersited = true, isCounted = true, isStatusMessage = false) {
|
18731
|
-
this.content = content;
|
18732
|
-
if (isStatusMessage) {
|
18733
|
-
this.isPersited = false;
|
18734
|
-
this.isCounted = false;
|
18735
|
-
} else {
|
18736
|
-
this.isPersited = isPersited;
|
18737
|
-
this.isCounted = isCounted;
|
18738
|
-
}
|
18739
|
-
this.isStatusMessage = isStatusMessage;
|
18740
|
-
}
|
18741
|
-
get objectId() {
|
18742
|
-
return this.constructor.getObjectId();
|
18743
|
-
}
|
18744
|
-
static getObjectId() {
|
18745
|
-
throw new Error('Method not implemented.');
|
18746
|
-
}
|
18747
|
-
static decode(aDecoder) {
|
18748
|
-
throw new Error('Method not implemented.');
|
18749
|
-
}
|
18750
|
-
encode() {
|
18751
|
-
throw new Error('Method not implemented.');
|
18752
|
-
}
|
18753
|
-
}
|
18754
|
-
|
18755
|
-
const MessageObjectIds = {
|
18756
|
-
TEXT: 0x00000000,
|
18757
|
-
IMAGE: 0x10001000,
|
18758
|
-
GIF: 0x1000100b,
|
18759
|
-
FILE: 0x1000100a,
|
18760
|
-
AUDIO: 0x10001001,
|
18761
|
-
CUST_COMMAND: 0x1000101d,
|
18762
|
-
CUST_STORAGE: 0x1000102d,
|
18763
|
-
CUST_NORMAL: 0x1000103d,
|
18764
|
-
CUST_STATUS: 0x1000104d,
|
18765
|
-
RECALL: 0x6001001d,
|
18766
|
-
CMD: 0x1000105d
|
18767
|
-
};
|
18768
|
-
|
18769
|
-
class TextMessage extends BaseMessage {
|
18770
|
-
constructor(content) {
|
18771
|
-
super(content);
|
18772
|
-
}
|
18773
|
-
static getObjectId() {
|
18774
|
-
return MessageObjectIds.TEXT;
|
18775
|
-
}
|
18776
|
-
static decode(aDecoder) {
|
18777
|
-
const {
|
18778
|
-
user,
|
18779
|
-
extra,
|
18780
|
-
content
|
18781
|
-
} = aDecoder;
|
18782
|
-
return new TextMessage({
|
18783
|
-
user,
|
18784
|
-
extra,
|
18785
|
-
content
|
18786
|
-
});
|
18787
|
-
}
|
18788
|
-
encode() {
|
18789
|
-
const {
|
18790
|
-
user,
|
18791
|
-
extra,
|
18792
|
-
content
|
18793
|
-
} = this.content;
|
18794
|
-
return {
|
18795
|
-
user,
|
18796
|
-
extra,
|
18797
|
-
content
|
18798
|
-
};
|
18799
|
-
}
|
18800
|
-
}
|
18801
|
-
|
18802
|
-
class IMConfig {
|
18803
|
-
_token = '';
|
18804
|
-
_uploadUrl = '';
|
18805
|
-
_downloadUrl = '';
|
18806
|
-
_cert = '';
|
18807
|
-
set imInitToken(val) {
|
18808
|
-
this._token = val;
|
18809
|
-
}
|
18810
|
-
get imInitToken() {
|
18811
|
-
return this._token;
|
18812
|
-
}
|
18813
|
-
get fileUploadUrl() {
|
18814
|
-
return this._uploadUrl;
|
18815
|
-
}
|
18816
|
-
get cert() {
|
18817
|
-
return this._cert;
|
18818
|
-
}
|
18819
|
-
get fileDownloadUrl() {
|
18820
|
-
return this._downloadUrl;
|
18821
|
-
}
|
18822
|
-
setFileServerInfo(uploadUrl, downloadUrl, cert) {
|
18823
|
-
this._uploadUrl = uploadUrl;
|
18824
|
-
this._downloadUrl = downloadUrl;
|
18825
|
-
this._cert = cert;
|
18826
|
-
}
|
18827
|
-
getFileAbsoluteUri(u) {
|
18828
|
-
if (!notEmptyString(u)) {
|
18829
|
-
return u;
|
18830
|
-
}
|
18831
|
-
if (u.startsWith('http')) {
|
18832
|
-
return u;
|
18833
|
-
}
|
18834
|
-
return this.fileDownloadUrl + u;
|
18835
|
-
}
|
18836
|
-
try2ExtractFileRelativeUri(u) {
|
18837
|
-
if (!notEmptyString(u)) {
|
18838
|
-
return u;
|
18839
|
-
}
|
18840
|
-
if (!u.startsWith(this.fileDownloadUrl)) {
|
18841
|
-
return u;
|
18842
|
-
}
|
18843
|
-
return u.substring(this.fileDownloadUrl.length);
|
18844
|
-
}
|
18845
|
-
}
|
18846
|
-
var imConfig = new IMConfig();
|
18847
|
-
|
18848
|
-
class ImageMessage extends BaseMessage {
|
18849
|
-
constructor(content) {
|
18850
|
-
super(content);
|
18851
|
-
}
|
18852
|
-
static getObjectId() {
|
18853
|
-
return MessageObjectIds.IMAGE;
|
18854
|
-
}
|
18855
|
-
static decode(aDecoder) {
|
18856
|
-
const {
|
18857
|
-
user,
|
18858
|
-
extra,
|
18859
|
-
thumbnailObjectKey,
|
18860
|
-
originalObjectKey,
|
18861
|
-
width,
|
18862
|
-
height
|
18863
|
-
} = aDecoder;
|
18864
|
-
return new ImageMessage({
|
18865
|
-
user,
|
18866
|
-
extra,
|
18867
|
-
content: thumbnailObjectKey,
|
18868
|
-
imageUri: imConfig.getFileAbsoluteUri(originalObjectKey),
|
18869
|
-
width,
|
18870
|
-
height
|
18871
|
-
});
|
18872
|
-
}
|
18873
|
-
encode() {
|
18874
|
-
const {
|
18875
|
-
user,
|
18876
|
-
extra,
|
18877
|
-
content,
|
18878
|
-
imageUri,
|
18879
|
-
width,
|
18880
|
-
height
|
18881
|
-
} = this.content;
|
18882
|
-
return {
|
18883
|
-
user,
|
18884
|
-
extra,
|
18885
|
-
thumbnailObjectKey: content,
|
18886
|
-
originalObjectKey: imConfig.try2ExtractFileRelativeUri(imageUri),
|
18887
|
-
width: width && Math.floor(width),
|
18888
|
-
height: height && Math.floor(height)
|
18889
|
-
};
|
18890
|
-
}
|
18891
|
-
}
|
18892
|
-
|
18893
|
-
class GIFMessage extends BaseMessage {
|
18894
|
-
constructor(content) {
|
18895
|
-
super(content);
|
18896
|
-
}
|
18897
|
-
static getObjectId() {
|
18898
|
-
return MessageObjectIds.GIF;
|
18899
|
-
}
|
18900
|
-
static decode(aDecoder) {
|
18901
|
-
const {
|
18902
|
-
user,
|
18903
|
-
extra,
|
18904
|
-
size,
|
18905
|
-
originalObjectKey,
|
18906
|
-
width,
|
18907
|
-
height
|
18908
|
-
} = aDecoder;
|
18909
|
-
return new GIFMessage({
|
18910
|
-
user,
|
18911
|
-
extra,
|
18912
|
-
gifDataSize: size,
|
18913
|
-
remoteUrl: imConfig.getFileAbsoluteUri(originalObjectKey),
|
18914
|
-
width,
|
18915
|
-
height
|
18916
|
-
});
|
18917
|
-
}
|
18918
|
-
encode() {
|
18919
|
-
const {
|
18920
|
-
user,
|
18921
|
-
extra,
|
18922
|
-
gifDataSize,
|
18923
|
-
remoteUrl,
|
18924
|
-
width,
|
18925
|
-
height
|
18926
|
-
} = this.content;
|
18927
|
-
return {
|
18928
|
-
user,
|
18929
|
-
extra,
|
18930
|
-
size: gifDataSize,
|
18931
|
-
originalObjectKey: imConfig.try2ExtractFileRelativeUri(remoteUrl),
|
18932
|
-
width: width && Math.floor(width),
|
18933
|
-
height: height && Math.floor(height),
|
18934
|
-
extension: 'gif'
|
18935
|
-
};
|
18936
|
-
}
|
18937
|
-
}
|
18938
|
-
|
18939
|
-
class HQVoiceMessage extends BaseMessage {
|
18940
|
-
constructor(content) {
|
18941
|
-
super(content);
|
18942
|
-
}
|
18943
|
-
static getObjectId() {
|
18944
|
-
return MessageObjectIds.AUDIO;
|
18945
|
-
}
|
18946
|
-
static decode(aDecoder) {
|
18947
|
-
const {
|
18948
|
-
user,
|
18949
|
-
extra,
|
18950
|
-
length,
|
18951
|
-
audioObjectKey,
|
18952
|
-
extension
|
18953
|
-
} = aDecoder;
|
18954
|
-
return new HQVoiceMessage({
|
18955
|
-
user,
|
18956
|
-
extra,
|
18957
|
-
remoteUrl: imConfig.getFileAbsoluteUri(audioObjectKey),
|
18958
|
-
duration: length,
|
18959
|
-
type: extension
|
18960
|
-
});
|
18961
|
-
}
|
18962
|
-
encode() {
|
18963
|
-
const {
|
18964
|
-
user,
|
18965
|
-
extra,
|
18966
|
-
remoteUrl,
|
18967
|
-
duration,
|
18968
|
-
type
|
18969
|
-
} = this.content;
|
18970
|
-
return {
|
18971
|
-
user,
|
18972
|
-
extra,
|
18973
|
-
length: duration,
|
18974
|
-
audioObjectKey: imConfig.try2ExtractFileRelativeUri(remoteUrl),
|
18975
|
-
extension: type
|
18976
|
-
};
|
18977
|
-
}
|
18978
|
-
}
|
18979
|
-
|
18980
|
-
class FileMessage extends BaseMessage {
|
18981
|
-
constructor(content) {
|
18982
|
-
super(content);
|
18983
|
-
}
|
18984
|
-
static getObjectId() {
|
18985
|
-
return MessageObjectIds.FILE;
|
18986
|
-
}
|
18987
|
-
static decode(aDecoder) {
|
18988
|
-
const {
|
18989
|
-
user,
|
18990
|
-
extra,
|
18991
|
-
title,
|
18992
|
-
extension,
|
18993
|
-
size,
|
18994
|
-
originalObjectKey
|
18995
|
-
} = aDecoder;
|
18996
|
-
return new FileMessage({
|
18997
|
-
user,
|
18998
|
-
extra,
|
18999
|
-
name: title,
|
19000
|
-
size,
|
19001
|
-
type: extension,
|
19002
|
-
fileUrl: imConfig.getFileAbsoluteUri(originalObjectKey)
|
19003
|
-
});
|
19004
|
-
}
|
19005
|
-
encode() {
|
19006
|
-
const {
|
19007
|
-
user,
|
19008
|
-
extra,
|
19009
|
-
name,
|
19010
|
-
size,
|
19011
|
-
type,
|
19012
|
-
fileUrl
|
19013
|
-
} = this.content;
|
19014
|
-
return {
|
19015
|
-
user,
|
19016
|
-
extra,
|
19017
|
-
title: name,
|
19018
|
-
originalObjectKey: imConfig.try2ExtractFileRelativeUri(fileUrl),
|
19019
|
-
extension: type,
|
19020
|
-
size
|
19021
|
-
};
|
19022
|
-
}
|
19023
|
-
}
|
19024
|
-
|
19025
|
-
class RecallCommandMessage extends BaseMessage {
|
19026
|
-
constructor(content) {
|
19027
|
-
super(content, true, false, false);
|
19028
|
-
}
|
19029
|
-
static getObjectId() {
|
19030
|
-
return MessageObjectIds.RECALL;
|
19031
|
-
}
|
19032
|
-
static decode(aDecoder) {
|
19033
|
-
return new RecallCommandMessage(aDecoder);
|
19034
|
-
}
|
19035
|
-
encode() {
|
19036
|
-
return this.content;
|
19037
|
-
}
|
19038
|
-
}
|
19039
|
-
|
19040
18715
|
class DialogSecretKey {
|
19041
18716
|
aesKeyRecord = new Map();
|
19042
18717
|
async getDialogAesKey(dialogId) {
|
@@ -19186,6 +18861,27 @@ const wordToUInt8Array = wordArray => {
|
|
19186
18861
|
return new Uint8Array(array);
|
19187
18862
|
};
|
19188
18863
|
|
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
|
+
const MessageTypes = {
|
18872
|
+
TEXT: 0x00000000,
|
18873
|
+
IMAGE: 0x10001000,
|
18874
|
+
GIF: 0x1000100b,
|
18875
|
+
FILE: 0x1000100a,
|
18876
|
+
AUDIO: 0x10001001,
|
18877
|
+
CUST_COMMAND: 0x1000101d,
|
18878
|
+
CUST_STORAGE: 0x1000102d,
|
18879
|
+
CUST_NORMAL: 0x1000103d,
|
18880
|
+
CUST_STATUS: 0x1000104d,
|
18881
|
+
RECALL: 0x6001001d,
|
18882
|
+
CMD: 0x1000105d
|
18883
|
+
};
|
18884
|
+
|
19189
18885
|
const STATUSMESSAGE_ALIVE_TIMEMS = 6000;
|
19190
18886
|
function parse(orginalMsgs, callback) {
|
19191
18887
|
const msgs = new Map();
|
@@ -19241,12 +18937,9 @@ const parseSingleDialogMessages = (dialogId, originalMessageList, aesKey) => {
|
|
19241
18937
|
sendTime
|
19242
18938
|
} = mediaAttributeJson;
|
19243
18939
|
const recallContent = {
|
19244
|
-
|
19245
|
-
messageUId: msgId,
|
19246
|
-
conversationType: conversation.conversationType,
|
19247
|
-
targetId: dialogMessage.isOut ? conversation.targetId : accountStore.uid
|
18940
|
+
msgId: msgId
|
19248
18941
|
};
|
19249
|
-
mediaConstructor =
|
18942
|
+
mediaConstructor = MessageTypes.RECALL;
|
19250
18943
|
mediaAttributeJson = recallContent;
|
19251
18944
|
recallMessageUIds.add(msgId);
|
19252
18945
|
}
|
@@ -19392,7 +19085,7 @@ class ConversationStore {
|
|
19392
19085
|
messageDirection
|
19393
19086
|
} = message;
|
19394
19087
|
const isSelfSend = messageDirection === MessageDirection.SEND;
|
19395
|
-
const isRecall = messageType ===
|
19088
|
+
const isRecall = messageType === MessageTypes.RECALL;
|
19396
19089
|
const hasContent = isObject(content);
|
19397
19090
|
const key = {
|
19398
19091
|
conversationType,
|
@@ -19426,7 +19119,7 @@ class ConversationStore {
|
|
19426
19119
|
messageDirection,
|
19427
19120
|
content
|
19428
19121
|
} = message;
|
19429
|
-
if (messageDirection === MessageDirection.SEND || !isMentioned && messageType !==
|
19122
|
+
if (messageDirection === MessageDirection.SEND || !isMentioned && messageType !== MessageTypes.RECALL) {
|
19430
19123
|
return;
|
19431
19124
|
}
|
19432
19125
|
const key = this.getStoreKey({
|
@@ -19441,9 +19134,9 @@ class ConversationStore {
|
|
19441
19134
|
localMentionedUIdList.push(messageUId.toString());
|
19442
19135
|
}
|
19443
19136
|
}
|
19444
|
-
if (messageType ===
|
19137
|
+
if (messageType === MessageTypes.RECALL && conversationType === ConversationType.GROUP) {
|
19445
19138
|
const recallContent = content;
|
19446
|
-
const index = localMentionedUIdList.indexOf(recallContent.
|
19139
|
+
const index = localMentionedUIdList.indexOf(recallContent.msgId.toString());
|
19447
19140
|
if (index >= 0) {
|
19448
19141
|
localMentionedUIdList.splice(index, 1);
|
19449
19142
|
}
|
@@ -20069,7 +19762,7 @@ class MessageLoader {
|
|
20069
19762
|
l.forEach(m => {
|
20070
19763
|
if (m.messageDirection === MessageDirection.SEND && m.messageId && SentMessageStore.has(m.messageId)) {
|
20071
19764
|
SentMessageStore.remove(m.messageId);
|
20072
|
-
} else if (m.messageType ===
|
19765
|
+
} else if (m.messageType === MessageTypes.RECALL && RecallMessageStore.has(m.content.messageUId)) {
|
20073
19766
|
RecallMessageStore.remove(m.content.messageUId);
|
20074
19767
|
} else {
|
20075
19768
|
m.isOffLineMessage = isOffLineMessage;
|
@@ -20157,14 +19850,7 @@ class LibLoader {
|
|
20157
19850
|
}
|
20158
19851
|
return DEFAULT_SOCKET_URI;
|
20159
19852
|
}
|
20160
|
-
registerMessage() {
|
20161
|
-
registerMessageSerializer(TextMessage);
|
20162
|
-
registerMessageSerializer(ImageMessage);
|
20163
|
-
registerMessageSerializer(GIFMessage);
|
20164
|
-
registerMessageSerializer(HQVoiceMessage);
|
20165
|
-
registerMessageSerializer(RecallCommandMessage);
|
20166
|
-
registerMessageSerializer(FileMessage);
|
20167
|
-
}
|
19853
|
+
registerMessage() {}
|
20168
19854
|
async connect() {
|
20169
19855
|
if (this.connectionStatus === ConnectionStatus.CONNECTED) {
|
20170
19856
|
return {
|
@@ -20274,6 +19960,7 @@ class LibLoader {
|
|
20274
19960
|
}, 2000);
|
20275
19961
|
}
|
20276
19962
|
messageListener(cmdId, body) {
|
19963
|
+
logger.info(`libLoader messageListener -> cmdId: ${cmdId}, body: ${body}`);
|
20277
19964
|
if (cmdId === CmdIds$1.NewMessagePush) {
|
20278
19965
|
const newMsgNotiResp = NewMessageNotificationResp.decode(body);
|
20279
19966
|
this.messageLoader?.syncMsg(newMsgNotiResp.seqno);
|
@@ -26844,6 +26531,56 @@ function requireProtobufjs () {
|
|
26844
26531
|
var protobufjsExports = requireProtobufjs();
|
26845
26532
|
var protobuf = /*@__PURE__*/getDefaultExportFromCjs(protobufjsExports);
|
26846
26533
|
|
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
|
+
|
26847
26584
|
const transSentAttrs2IReceivedMessage = (message, options, sentStatus = SentStatus.SENDING) => ({
|
26848
26585
|
conversationType: options.conversation.conversationType,
|
26849
26586
|
targetId: options.conversation.targetId,
|
@@ -26875,411 +26612,10 @@ function generateMessageId() {
|
|
26875
26612
|
return 230000000000000 + UniqueLocalId;
|
26876
26613
|
}
|
26877
26614
|
|
26878
|
-
const getBlobUrl = blob => {
|
26879
|
-
const URL = window.URL || window.webkitURL;
|
26880
|
-
return URL ? URL.createObjectURL(blob) : '';
|
26881
|
-
};
|
26882
|
-
const getBlobExtension = blob => {
|
26883
|
-
const name = blob.name;
|
26884
|
-
if (notEmptyString(name)) {
|
26885
|
-
return name.substring(name.lastIndexOf('.') + 1);
|
26886
|
-
}
|
26887
|
-
return blob.type.indexOf('/') > 0 ? blob.type.substring(blob.type.lastIndexOf('/') + 1) : '';
|
26888
|
-
};
|
26889
|
-
const blob2ArrayBuffer = blob => {
|
26890
|
-
if (isPromise(blob.arrayBuffer)) {
|
26891
|
-
return blob.arrayBuffer();
|
26892
|
-
}
|
26893
|
-
return new Promise((resolve, reject) => {
|
26894
|
-
const reader = new FileReader();
|
26895
|
-
reader.addEventListener('load', event => {
|
26896
|
-
if (event.target) {
|
26897
|
-
resolve(event.target.result);
|
26898
|
-
} else {
|
26899
|
-
reject('null');
|
26900
|
-
}
|
26901
|
-
});
|
26902
|
-
reader.addEventListener('error', error => reject(error));
|
26903
|
-
reader.readAsArrayBuffer(blob);
|
26904
|
-
});
|
26905
|
-
};
|
26906
|
-
const revokeBlobUrl = url => {
|
26907
|
-
const URL = window.URL || window.webkitURL;
|
26908
|
-
URL.revokeObjectURL(url);
|
26909
|
-
};
|
26910
|
-
const dataURL2Blob = url => {
|
26911
|
-
const type = url.match(/data:([^;]+)/)[1];
|
26912
|
-
const base64 = url.replace(/^[^,]+,/, '');
|
26913
|
-
const bstr = window.atob(base64);
|
26914
|
-
let n = bstr.length;
|
26915
|
-
const u8arr = new Uint8Array(bstr.length);
|
26916
|
-
while (n--) {
|
26917
|
-
u8arr[n] = bstr.charCodeAt(n);
|
26918
|
-
}
|
26919
|
-
return new Blob([u8arr], {
|
26920
|
-
type
|
26921
|
-
});
|
26922
|
-
};
|
26923
|
-
|
26924
|
-
const COMPRESS_LENGTH_MAX = 1680;
|
26925
|
-
const COMPRESS_LENGTH_MIN = 160;
|
26926
|
-
const getImageObj = link => {
|
26927
|
-
return new Promise((resolve, reject) => {
|
26928
|
-
const handle = image => {
|
26929
|
-
if (image.width !== 0 || image.height !== 0) {
|
26930
|
-
resolve(image);
|
26931
|
-
} else {
|
26932
|
-
reject();
|
26933
|
-
}
|
26934
|
-
};
|
26935
|
-
const image = new Image();
|
26936
|
-
image.addEventListener('load', event => handle(event.target));
|
26937
|
-
image.addEventListener('error', reject);
|
26938
|
-
image.src = link;
|
26939
|
-
if (image.complete) {
|
26940
|
-
handle(image);
|
26941
|
-
return;
|
26942
|
-
}
|
26943
|
-
const intervalId = setInterval(() => {
|
26944
|
-
if (image.complete) {
|
26945
|
-
handle(image);
|
26946
|
-
clearInterval(intervalId);
|
26947
|
-
}
|
26948
|
-
}, 40);
|
26949
|
-
});
|
26950
|
-
};
|
26951
|
-
const compress = (image, quality = 1, mineType = 'image/jpeg') => {
|
26952
|
-
quality = Math.min(1, quality);
|
26953
|
-
const width = image.width;
|
26954
|
-
const height = image.height;
|
26955
|
-
let compressWidth = width;
|
26956
|
-
let compressHeight = height;
|
26957
|
-
if (quality < 1) {
|
26958
|
-
const isheight = width < height;
|
26959
|
-
const zoom = isheight ? height / COMPRESS_LENGTH_MAX : width / COMPRESS_LENGTH_MAX;
|
26960
|
-
if (width > COMPRESS_LENGTH_MAX && height > COMPRESS_LENGTH_MAX) {
|
26961
|
-
if (isheight) {
|
26962
|
-
compressHeight = COMPRESS_LENGTH_MAX;
|
26963
|
-
compressWidth = compressWidth / zoom;
|
26964
|
-
} else {
|
26965
|
-
compressWidth = COMPRESS_LENGTH_MAX;
|
26966
|
-
compressHeight = compressHeight / zoom;
|
26967
|
-
}
|
26968
|
-
} else if (width > COMPRESS_LENGTH_MAX && height > COMPRESS_LENGTH_MIN) {
|
26969
|
-
compressWidth = COMPRESS_LENGTH_MAX;
|
26970
|
-
compressHeight = compressHeight / zoom;
|
26971
|
-
if (compressHeight < COMPRESS_LENGTH_MIN) {
|
26972
|
-
compressHeight = COMPRESS_LENGTH_MIN;
|
26973
|
-
compressWidth = width / (height / COMPRESS_LENGTH_MIN);
|
26974
|
-
}
|
26975
|
-
} else if (height > COMPRESS_LENGTH_MAX && width > COMPRESS_LENGTH_MIN) {
|
26976
|
-
compressHeight = COMPRESS_LENGTH_MAX;
|
26977
|
-
compressWidth = compressWidth / zoom;
|
26978
|
-
if (compressWidth < COMPRESS_LENGTH_MIN) {
|
26979
|
-
compressWidth = COMPRESS_LENGTH_MIN;
|
26980
|
-
compressHeight = height / (width / COMPRESS_LENGTH_MIN);
|
26981
|
-
}
|
26982
|
-
}
|
26983
|
-
}
|
26984
|
-
compressWidth = Math.floor(compressWidth);
|
26985
|
-
compressHeight = Math.floor(compressHeight);
|
26986
|
-
const canvas = document.createElement('canvas');
|
26987
|
-
canvas.width = compressWidth;
|
26988
|
-
canvas.height = compressHeight;
|
26989
|
-
const ctx = canvas.getContext('2d');
|
26990
|
-
ctx.fillStyle = '#FFF';
|
26991
|
-
ctx.fillRect(0, 0, compressWidth, compressHeight);
|
26992
|
-
ctx.drawImage(image, 0, 0, width, height, 0, 0, compressWidth, compressHeight);
|
26993
|
-
if (!mineType || mineType == 'image/png') {
|
26994
|
-
mineType = 'image/jpeg';
|
26995
|
-
}
|
26996
|
-
return {
|
26997
|
-
imageFile: dataURL2Blob(canvas.toDataURL(mineType, Math.min(0.92, quality))),
|
26998
|
-
compressWidth,
|
26999
|
-
compressHeight
|
27000
|
-
};
|
27001
|
-
};
|
27002
|
-
const getThumbnail = (img, thumbnailConfig) => {
|
27003
|
-
const canvas = document.createElement('canvas');
|
27004
|
-
const context = canvas.getContext('2d');
|
27005
|
-
const pos = calcPosition(img.width, img.height, thumbnailConfig);
|
27006
|
-
canvas.width = pos.w > thumbnailConfig.maxWidth ? thumbnailConfig.maxWidth : pos.w;
|
27007
|
-
canvas.height = pos.h > thumbnailConfig.maxHeight ? thumbnailConfig.maxHeight : pos.h;
|
27008
|
-
context?.drawImage(img, pos.x, pos.y, pos.w, pos.h);
|
27009
|
-
try {
|
27010
|
-
let base64 = canvas.toDataURL('image/jpeg', thumbnailConfig.quality);
|
27011
|
-
const reg = new RegExp('^data:image/[^;]+;base64,');
|
27012
|
-
base64 = base64.replace(reg, '');
|
27013
|
-
return base64;
|
27014
|
-
} catch (e) {
|
27015
|
-
throw new Error(e);
|
27016
|
-
}
|
27017
|
-
};
|
27018
|
-
function calcPosition(width, height, thumbnailConfig) {
|
27019
|
-
const isheight = width < height;
|
27020
|
-
const scale = isheight ? height / width : width / height;
|
27021
|
-
let zoom;
|
27022
|
-
let x = 0;
|
27023
|
-
let y = 0;
|
27024
|
-
let w;
|
27025
|
-
let h;
|
27026
|
-
const gtScale = function () {
|
27027
|
-
if (isheight) {
|
27028
|
-
zoom = width / 100;
|
27029
|
-
w = 100;
|
27030
|
-
h = height / zoom;
|
27031
|
-
y = (h - thumbnailConfig.maxHeight) / 2;
|
27032
|
-
} else {
|
27033
|
-
zoom = height / 100;
|
27034
|
-
h = 100;
|
27035
|
-
w = width / zoom;
|
27036
|
-
x = (w - thumbnailConfig.maxWidth) / 2;
|
27037
|
-
}
|
27038
|
-
return {
|
27039
|
-
w: w,
|
27040
|
-
h: h,
|
27041
|
-
x: -x,
|
27042
|
-
y: -y
|
27043
|
-
};
|
27044
|
-
};
|
27045
|
-
const ltScale = function () {
|
27046
|
-
if (isheight) {
|
27047
|
-
zoom = height / thumbnailConfig.maxHeight;
|
27048
|
-
h = thumbnailConfig.maxHeight;
|
27049
|
-
w = width / zoom;
|
27050
|
-
} else {
|
27051
|
-
zoom = width / thumbnailConfig.maxWidth;
|
27052
|
-
w = thumbnailConfig.maxWidth;
|
27053
|
-
h = height / zoom;
|
27054
|
-
}
|
27055
|
-
return {
|
27056
|
-
w: w,
|
27057
|
-
h: h,
|
27058
|
-
x: -x,
|
27059
|
-
y: -y
|
27060
|
-
};
|
27061
|
-
};
|
27062
|
-
return scale > thumbnailConfig.scale ? gtScale() : ltScale();
|
27063
|
-
}
|
27064
|
-
|
27065
|
-
class Img {
|
27066
|
-
async create(file) {
|
27067
|
-
try {
|
27068
|
-
const blobUrl = getBlobUrl(file);
|
27069
|
-
const image = await getImageObj(blobUrl);
|
27070
|
-
revokeBlobUrl(blobUrl);
|
27071
|
-
const {
|
27072
|
-
imageFile: sentImageFile,
|
27073
|
-
compressWidth,
|
27074
|
-
compressHeight
|
27075
|
-
} = compress(image, 0.85, file.type);
|
27076
|
-
const config = {
|
27077
|
-
maxHeight: 160,
|
27078
|
-
maxWidth: 160,
|
27079
|
-
quality: 0.6,
|
27080
|
-
scale: 2.4
|
27081
|
-
};
|
27082
|
-
const thumbnail = getThumbnail(image, config);
|
27083
|
-
return {
|
27084
|
-
success: true,
|
27085
|
-
message: new ImageMessage({
|
27086
|
-
content: thumbnail,
|
27087
|
-
imageUri: getBlobUrl(sentImageFile),
|
27088
|
-
width: compressWidth,
|
27089
|
-
height: compressHeight
|
27090
|
-
}),
|
27091
|
-
file: sentImageFile
|
27092
|
-
};
|
27093
|
-
} catch (error) {
|
27094
|
-
return {
|
27095
|
-
success: false
|
27096
|
-
};
|
27097
|
-
}
|
27098
|
-
}
|
27099
|
-
updateMessageRemoteUrlProperty(msg, remoteUrl) {
|
27100
|
-
msg.content.imageUri = remoteUrl;
|
27101
|
-
}
|
27102
|
-
}
|
27103
|
-
class GIF {
|
27104
|
-
async create(file) {
|
27105
|
-
if (file.size > 2 * 1024 * 1024) {
|
27106
|
-
return {
|
27107
|
-
success: false
|
27108
|
-
};
|
27109
|
-
}
|
27110
|
-
try {
|
27111
|
-
const blobUrl = getBlobUrl(file);
|
27112
|
-
const image = await getImageObj(blobUrl);
|
27113
|
-
return {
|
27114
|
-
success: true,
|
27115
|
-
message: new GIFMessage({
|
27116
|
-
gifDataSize: file.size,
|
27117
|
-
remoteUrl: blobUrl,
|
27118
|
-
width: image.width,
|
27119
|
-
height: image.height
|
27120
|
-
}),
|
27121
|
-
file: file
|
27122
|
-
};
|
27123
|
-
} catch {
|
27124
|
-
return {
|
27125
|
-
success: false
|
27126
|
-
};
|
27127
|
-
}
|
27128
|
-
}
|
27129
|
-
updateMessageRemoteUrlProperty(message, remoteUrl) {
|
27130
|
-
message.content.remoteUrl = remoteUrl;
|
27131
|
-
}
|
27132
|
-
}
|
27133
|
-
let audioCtx;
|
27134
|
-
class Audio {
|
27135
|
-
create(file) {
|
27136
|
-
return blob2ArrayBuffer(file).then(this.getAudioInfo).then(info => {
|
27137
|
-
return {
|
27138
|
-
success: true,
|
27139
|
-
message: new HQVoiceMessage({
|
27140
|
-
remoteUrl: '',
|
27141
|
-
duration: info.duration,
|
27142
|
-
type: getBlobExtension(file)
|
27143
|
-
}),
|
27144
|
-
file
|
27145
|
-
};
|
27146
|
-
}).catch(() => {
|
27147
|
-
return {
|
27148
|
-
success: false
|
27149
|
-
};
|
27150
|
-
});
|
27151
|
-
}
|
27152
|
-
updateMessageRemoteUrlProperty(message, remoteUrl) {
|
27153
|
-
message.content.remoteUrl = remoteUrl;
|
27154
|
-
}
|
27155
|
-
getAudioInfo(buffer) {
|
27156
|
-
const ctx = audioCtx || new AudioContext();
|
27157
|
-
audioCtx = ctx;
|
27158
|
-
return new Promise((resolve, reject) => {
|
27159
|
-
ctx.decodeAudioData(buffer, function (audioBuffer) {
|
27160
|
-
resolve({
|
27161
|
-
duration: audioBuffer.duration,
|
27162
|
-
length: audioBuffer.length
|
27163
|
-
});
|
27164
|
-
}, reject);
|
27165
|
-
});
|
27166
|
-
}
|
27167
|
-
}
|
27168
|
-
class File {
|
27169
|
-
async create(file) {
|
27170
|
-
if (file.size > 100 * 1024 * 1024) {
|
27171
|
-
return {
|
27172
|
-
success: false
|
27173
|
-
};
|
27174
|
-
}
|
27175
|
-
return {
|
27176
|
-
success: true,
|
27177
|
-
message: new FileMessage({
|
27178
|
-
fileUrl: '',
|
27179
|
-
name: file.name,
|
27180
|
-
type: getBlobExtension(file),
|
27181
|
-
size: file.size
|
27182
|
-
}),
|
27183
|
-
file
|
27184
|
-
};
|
27185
|
-
}
|
27186
|
-
updateMessageRemoteUrlProperty(message, remoteUrl) {
|
27187
|
-
message.content.fileUrl = remoteUrl;
|
27188
|
-
}
|
27189
|
-
}
|
27190
|
-
var FileType;
|
27191
|
-
(function (FileType) {
|
27192
|
-
FileType[FileType["IMAGE"] = 1] = "IMAGE";
|
27193
|
-
FileType[FileType["GIF"] = 2] = "GIF";
|
27194
|
-
FileType[FileType["AUDIO"] = 3] = "AUDIO";
|
27195
|
-
FileType[FileType["VIDEO"] = 4] = "VIDEO";
|
27196
|
-
FileType[FileType["FILE"] = 5] = "FILE";
|
27197
|
-
FileType[FileType["SIGHT"] = 6] = "SIGHT";
|
27198
|
-
})(FileType || (FileType = {}));
|
27199
|
-
const getMediaMessageCreator = fileType => {
|
27200
|
-
let creator;
|
27201
|
-
switch (fileType) {
|
27202
|
-
case FileType.IMAGE:
|
27203
|
-
creator = new Img();
|
27204
|
-
break;
|
27205
|
-
case FileType.AUDIO:
|
27206
|
-
creator = new Audio();
|
27207
|
-
break;
|
27208
|
-
case FileType.GIF:
|
27209
|
-
creator = new GIF();
|
27210
|
-
break;
|
27211
|
-
case FileType.FILE:
|
27212
|
-
creator = new File();
|
27213
|
-
break;
|
27214
|
-
}
|
27215
|
-
return creator;
|
27216
|
-
};
|
27217
|
-
|
27218
|
-
class Upload {
|
27219
|
-
options;
|
27220
|
-
xhr;
|
27221
|
-
constructor(options) {
|
27222
|
-
this.options = options;
|
27223
|
-
}
|
27224
|
-
upload(file, callback) {
|
27225
|
-
const xhr = new XMLHttpRequest();
|
27226
|
-
xhr.timeout = (30 + file.size / 1024 / 512) * 1000;
|
27227
|
-
xhr.upload.onprogress = event => {
|
27228
|
-
callback.onProgress?.(event.loaded, event.total);
|
27229
|
-
};
|
27230
|
-
xhr.onreadystatechange = () => {
|
27231
|
-
if (xhr.readyState === 4) {
|
27232
|
-
const responseText = xhr.responseText || '{}';
|
27233
|
-
const responseData = JSON.parse(responseText);
|
27234
|
-
if (xhr.status === 200 && responseData.code === 200) {
|
27235
|
-
let result = {
|
27236
|
-
url: responseData.url
|
27237
|
-
};
|
27238
|
-
if (this.options.transformer) {
|
27239
|
-
result = this.options.transformer(result);
|
27240
|
-
}
|
27241
|
-
callback.onCompleted?.(result);
|
27242
|
-
} else {
|
27243
|
-
callback.onError?.('upload fail');
|
27244
|
-
}
|
27245
|
-
}
|
27246
|
-
};
|
27247
|
-
xhr.open('POST', this.options.uploadUrl, true);
|
27248
|
-
xhr.setRequestHeader('device', '7');
|
27249
|
-
xhr.setRequestHeader('cert', this.options.cert ?? '');
|
27250
|
-
const type = getBlobExtension(file);
|
27251
|
-
const fileName = genUId() + (type.length ? `.${type}` : '');
|
27252
|
-
const formData = new FormData();
|
27253
|
-
formData.append('file', file);
|
27254
|
-
formData.append('name', 'file');
|
27255
|
-
formData.append('fileName', fileName);
|
27256
|
-
formData.append('token', this.options.token);
|
27257
|
-
xhr.send(formData);
|
27258
|
-
this.xhr = xhr;
|
27259
|
-
}
|
27260
|
-
cancel() {
|
27261
|
-
this.xhr?.abort();
|
27262
|
-
}
|
27263
|
-
}
|
27264
|
-
function genUId() {
|
27265
|
-
let date = new Date().getTime();
|
27266
|
-
const uuid = 'xxxxxx4xxxyxxxxxxx'.replace(/[xy]/g, function (c) {
|
27267
|
-
const r = (date + Math.random() * 16) % 16 | 0;
|
27268
|
-
date = Math.floor(date / 16);
|
27269
|
-
return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
|
27270
|
-
});
|
27271
|
-
return uuid;
|
27272
|
-
}
|
27273
|
-
|
27274
26615
|
const MAX_MESSAGE_CONTENT_BYTES = 80 * 1024;
|
27275
|
-
const MEDIA_MESSAGES = [MessageObjectIds.IMAGE, MessageObjectIds.AUDIO, MessageObjectIds.GIF, MessageObjectIds.FILE];
|
27276
26616
|
async function sendMessage$1(conversation, message, options) {
|
27277
26617
|
return internal_sendMessage(conversation, message, options);
|
27278
26618
|
}
|
27279
|
-
const sendImageMessage$1 = createSendFunction.bind(null, FileType.IMAGE);
|
27280
|
-
const sendGIFMessage$1 = createSendFunction.bind(null, FileType.GIF);
|
27281
|
-
const sendHQVoiceMessage$1 = createSendFunction.bind(null, FileType.AUDIO);
|
27282
|
-
const sendFileMessage$1 = createSendFunction.bind(null, FileType.FILE);
|
27283
26619
|
const sendRecallMessage = async (conversation, options) => {
|
27284
26620
|
const dialogId = getFullDialogId(conversation);
|
27285
26621
|
RecallMessageStore.addMessage(options.messageUId);
|
@@ -27290,9 +26626,7 @@ const sendRecallMessage = async (conversation, options) => {
|
|
27290
26626
|
};
|
27291
26627
|
}
|
27292
26628
|
const recallCommandMessage = new RecallCommandMessage({
|
27293
|
-
|
27294
|
-
messageUId: options.messageUId,
|
27295
|
-
...conversation
|
26629
|
+
msgId: options.messageUId
|
27296
26630
|
});
|
27297
26631
|
const sentAttris = {
|
27298
26632
|
conversation,
|
@@ -27307,58 +26641,6 @@ const sendRecallMessage = async (conversation, options) => {
|
|
27307
26641
|
data: receivedMessage
|
27308
26642
|
};
|
27309
26643
|
};
|
27310
|
-
async function createSendFunction(fileType, conversation, msgBody, hooks, sendOptions) {
|
27311
|
-
const mediaMessageCreator = getMediaMessageCreator(fileType);
|
27312
|
-
if (!mediaMessageCreator) return {
|
27313
|
-
code: ErrorCode.NOT_SUPPORT
|
27314
|
-
};
|
27315
|
-
const {
|
27316
|
-
success,
|
27317
|
-
message: message1,
|
27318
|
-
file
|
27319
|
-
} = await mediaMessageCreator.create(msgBody.file);
|
27320
|
-
if (!success || !message1 || !file) {
|
27321
|
-
return {
|
27322
|
-
code: ErrorCode.MEDIA_EXCEPTION
|
27323
|
-
};
|
27324
|
-
}
|
27325
|
-
message1.content.user = msgBody.user;
|
27326
|
-
message1.content.extra = msgBody.extra;
|
27327
|
-
return internal_sendMessage(conversation, message1, sendOptions, {
|
27328
|
-
file,
|
27329
|
-
task: (message2, toBeUploadedFile) => {
|
27330
|
-
return new Promise(resolve => {
|
27331
|
-
const uploader = new Upload({
|
27332
|
-
token: imConfig.imInitToken,
|
27333
|
-
uploadUrl: imConfig.fileUploadUrl,
|
27334
|
-
cert: imConfig.cert,
|
27335
|
-
transformer: result => ({
|
27336
|
-
...result,
|
27337
|
-
url: imConfig.getFileAbsoluteUri(result.url)
|
27338
|
-
})
|
27339
|
-
});
|
27340
|
-
uploader.upload(toBeUploadedFile, {
|
27341
|
-
onProgress: (loaded, total) => hooks?.onProgress?.(Math.floor(loaded / total * 100)),
|
27342
|
-
onError: () => {
|
27343
|
-
resolve({
|
27344
|
-
finished: false,
|
27345
|
-
message: message2
|
27346
|
-
});
|
27347
|
-
},
|
27348
|
-
onCompleted: result => {
|
27349
|
-
mediaMessageCreator.updateMessageRemoteUrlProperty(message2, result.url);
|
27350
|
-
resolve({
|
27351
|
-
finished: true,
|
27352
|
-
message: hooks?.onComplete?.({
|
27353
|
-
url: result.url
|
27354
|
-
}) ?? message2
|
27355
|
-
});
|
27356
|
-
}
|
27357
|
-
});
|
27358
|
-
});
|
27359
|
-
}
|
27360
|
-
});
|
27361
|
-
}
|
27362
26644
|
async function internal_sendMessage(conversation, message, options, uploadOptions) {
|
27363
26645
|
const checkResult = beforeSend(conversation, message, options);
|
27364
26646
|
if (checkResult.code !== ErrorCode.SUCCESS || !checkResult.message || !checkResult.sentArgs) {
|
@@ -27430,7 +26712,7 @@ async function send(message, sentArgs) {
|
|
27430
26712
|
SentMessageStore.addMessage(sentArgs.messageId);
|
27431
26713
|
const baseParams = {
|
27432
26714
|
localId: sentArgs.messageId,
|
27433
|
-
mediaFlag:
|
26715
|
+
mediaFlag: false,
|
27434
26716
|
mediaConstructor: message.objectId,
|
27435
26717
|
mediaAttribute: '',
|
27436
26718
|
msgPreContent: '',
|
@@ -27560,6 +26842,7 @@ class IMClient extends EventEmitter {
|
|
27560
26842
|
});
|
27561
26843
|
},
|
27562
26844
|
onPush: (cmdId, body) => {
|
26845
|
+
logger.info(`client onPush -> cmdId: ${cmdId}, body: ${body}`);
|
27563
26846
|
this.emit(Events.PUSH, {
|
27564
26847
|
cmdId,
|
27565
26848
|
body
|
@@ -27586,10 +26869,6 @@ class IMClient extends EventEmitter {
|
|
27586
26869
|
}
|
27587
26870
|
getServerTime = getServerTime$1;
|
27588
26871
|
sendMessage = sendMessage$1;
|
27589
|
-
sendImageMessage = sendImageMessage$1;
|
27590
|
-
sendGIFMessage = sendGIFMessage$1;
|
27591
|
-
sendHQVoiceMessage = sendHQVoiceMessage$1;
|
27592
|
-
sendFileMessage = sendFileMessage$1;
|
27593
26872
|
recallMsg = sendRecallMessage;
|
27594
26873
|
async getRemoteHistoryMessages(conversation, options) {
|
27595
26874
|
const dialogId = getFullDialogId(conversation);
|
@@ -28887,6 +28166,12 @@ const setConversationToTop = async (options, isTop = true) => {
|
|
28887
28166
|
const getTopConversationList = () => {
|
28888
28167
|
return imClient.getTopConversationList();
|
28889
28168
|
};
|
28169
|
+
const registerMessageType = (messageType, isPersited, isCounted, isStatusMessage) => {
|
28170
|
+
const defined = function (content) {
|
28171
|
+
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
28172
|
+
};
|
28173
|
+
return defined;
|
28174
|
+
};
|
28890
28175
|
const sendMessage = async (conversation, message, options) => {
|
28891
28176
|
if (message instanceof BaseMessage === false) {
|
28892
28177
|
logger.warn('send message fail -> message parameter is not an instance of BaseMessage');
|
@@ -28904,44 +28189,6 @@ const sendTextMessage = (conversation, messageBody, options) => {
|
|
28904
28189
|
const message = new TextMessage(messageBody);
|
28905
28190
|
return sendMessage(conversation, message, options);
|
28906
28191
|
};
|
28907
|
-
const sendImageMessage = async (conversation, msgBody, hooks, sendOptions) => {
|
28908
|
-
assert('conversation', conversation, AssertRules.CONVERSATION, true);
|
28909
|
-
assert('msgBody.file', msgBody.file, file => file instanceof Blob && file.type.startsWith('image/'), true);
|
28910
|
-
const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
|
28911
|
-
logger.debug('send message ->' + paramsStr);
|
28912
|
-
_logSendBefore(conversation);
|
28913
|
-
const response = await imClient.sendImageMessage(conversation, msgBody, hooks, sendOptions);
|
28914
|
-
_logSendError(conversation, response.code);
|
28915
|
-
return response;
|
28916
|
-
};
|
28917
|
-
const sendGIFMessage = async (conversation, msgBody, hooks, sendOptions) => {
|
28918
|
-
assert('conversation', conversation, AssertRules.CONVERSATION, true);
|
28919
|
-
assert('msgBody.file', msgBody.file, file => file instanceof Blob && file.type.endsWith('image/gif'), true);
|
28920
|
-
const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
|
28921
|
-
logger.debug('send message ->' + paramsStr);
|
28922
|
-
_logSendBefore(conversation);
|
28923
|
-
const response = await imClient.sendGIFMessage(conversation, msgBody, hooks, sendOptions);
|
28924
|
-
_logSendError(conversation, response.code);
|
28925
|
-
return response;
|
28926
|
-
};
|
28927
|
-
const sendHQVoiceMessage = async (conversation, msgBody, hooks, sendOptions) => {
|
28928
|
-
assert('conversation', conversation, AssertRules.CONVERSATION, true);
|
28929
|
-
assert('msgBody.file', msgBody.file, file => file instanceof Blob, true);
|
28930
|
-
_logSendBefore(conversation);
|
28931
|
-
const response = await imClient.sendHQVoiceMessage(conversation, msgBody, hooks, sendOptions);
|
28932
|
-
_logSendError(conversation, response.code);
|
28933
|
-
return response;
|
28934
|
-
};
|
28935
|
-
const sendFileMessage = async (conversation, msgBody, hooks, sendOptions) => {
|
28936
|
-
assert('conversation', conversation, AssertRules.CONVERSATION, true);
|
28937
|
-
assert('msgBody.file', msgBody.file, file => file instanceof Blob, true);
|
28938
|
-
const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
|
28939
|
-
logger.debug('send message ->' + paramsStr);
|
28940
|
-
_logSendBefore(conversation);
|
28941
|
-
const response = await imClient.sendFileMessage(conversation, msgBody, hooks, sendOptions);
|
28942
|
-
_logSendError(conversation, response.code);
|
28943
|
-
return response;
|
28944
|
-
};
|
28945
28192
|
const recallMessage = async (conversation, options) => {
|
28946
28193
|
assert('options.messageUId', options.messageUId, AssertRules.STRING, true);
|
28947
28194
|
assert('options.sentTime', options.sentTime, AssertRules.NUMBER, true);
|
@@ -29041,4 +28288,4 @@ const _logSendError = (conversation, errorCode) => {
|
|
29041
28288
|
}
|
29042
28289
|
};
|
29043
28290
|
|
29044
|
-
export { ConnectionStatus, ConversationType, ErrorCode, ErrorDesc, Events, FileMessage, GIFMessage, HQVoiceMessage, ImageMessage, LogLevel, MentionedType, MessageDirection, NotificationLevel, NotificationStatus, ReceivedStatus, SentStatus, TextMessage, addEventListener, clearAllMessagesUnreadStatus, clearHistoryMessages, clearMessagesUnreadStatus, clearTextMessageDraft, connect, deleteMessages, disconnect, getAllConversationState, getAllUnreadMentionedCount, getBlockedConversationList, getConnectionStatus, getConversation, getConversationList, getConversationNotificationLevel, getConversationNotificationStatus, getHistoryMessages, getRemoteHistoryMessages, getServerTime, getTextMessageDraft, getTopConversationList, getTotalUnreadCount, getUnreadCount, getUnreadMentionedCount, init, logOut, mockLogin, onceEventListener, recallMessage, removeConversation, removeEventListener, request, saveTextMessageDraft,
|
28291
|
+
export { ConnectionStatus, ConversationType, ErrorCode, ErrorDesc, Events, FileMessage, GIFMessage, VoiceMessage as HQVoiceMessage, ImageMessage, LogLevel, MentionedType, MessageDirection, NotificationLevel, NotificationStatus, ReceivedStatus, SentStatus, TextMessage, addEventListener, clearAllMessagesUnreadStatus, clearHistoryMessages, clearMessagesUnreadStatus, clearTextMessageDraft, connect, deleteMessages, disconnect, getAllConversationState, getAllUnreadMentionedCount, getBlockedConversationList, getConnectionStatus, getConversation, getConversationList, getConversationNotificationLevel, getConversationNotificationStatus, getHistoryMessages, getRemoteHistoryMessages, getServerTime, getTextMessageDraft, getTopConversationList, getTotalUnreadCount, getUnreadCount, getUnreadMentionedCount, init, logOut, mockLogin, onceEventListener, recallMessage, registerMessageType, removeConversation, removeEventListener, request, saveTextMessageDraft, sendMessage, sendTextMessage, setConversationNotificationStatus, setConversationToTop, setUserLogged };
|