@onyx-p/imlib-web 1.3.3 → 1.3.5
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 +100 -851
- package/index.umd.js +101 -855
- 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.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,13 +13521,15 @@
|
|
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);
|
13526
13530
|
this.responseCallbacks.delete(messageSeq);
|
13527
13531
|
} else {
|
13528
|
-
logger.
|
13532
|
+
logger.info(`websocket recv -> cmd: 0x${networkResponse.cmdId.toString(16)}, messageSeq: ${messageSeq}`);
|
13529
13533
|
this.watcher?.message(networkResponse.cmdId, networkResponse.body);
|
13530
13534
|
}
|
13531
13535
|
}
|
@@ -18718,331 +18722,6 @@
|
|
18718
18722
|
}
|
18719
18723
|
};
|
18720
18724
|
|
18721
|
-
const MessageSerializers = new Map();
|
18722
|
-
function registerMessageSerializer(aSerializer) {
|
18723
|
-
MessageSerializers.set(aSerializer.getObjectId(), aSerializer.decode.bind(aSerializer));
|
18724
|
-
}
|
18725
|
-
function decodeMessage(objectId, messageData) {
|
18726
|
-
const decodeFunc = MessageSerializers.get(objectId);
|
18727
|
-
const messageObject = decodeFunc ? decodeFunc(messageData) : null;
|
18728
|
-
return messageObject;
|
18729
|
-
}
|
18730
|
-
|
18731
|
-
class BaseMessage {
|
18732
|
-
content;
|
18733
|
-
isPersited;
|
18734
|
-
isCounted;
|
18735
|
-
isStatusMessage;
|
18736
|
-
constructor(content, isPersited = true, isCounted = true, isStatusMessage = false) {
|
18737
|
-
this.content = content;
|
18738
|
-
if (isStatusMessage) {
|
18739
|
-
this.isPersited = false;
|
18740
|
-
this.isCounted = false;
|
18741
|
-
} else {
|
18742
|
-
this.isPersited = isPersited;
|
18743
|
-
this.isCounted = isCounted;
|
18744
|
-
}
|
18745
|
-
this.isStatusMessage = isStatusMessage;
|
18746
|
-
}
|
18747
|
-
get objectId() {
|
18748
|
-
return this.constructor.getObjectId();
|
18749
|
-
}
|
18750
|
-
static getObjectId() {
|
18751
|
-
throw new Error('Method not implemented.');
|
18752
|
-
}
|
18753
|
-
static decode(aDecoder) {
|
18754
|
-
throw new Error('Method not implemented.');
|
18755
|
-
}
|
18756
|
-
encode() {
|
18757
|
-
throw new Error('Method not implemented.');
|
18758
|
-
}
|
18759
|
-
}
|
18760
|
-
|
18761
|
-
const MessageObjectIds = {
|
18762
|
-
TEXT: 0x00000000,
|
18763
|
-
IMAGE: 0x10001000,
|
18764
|
-
GIF: 0x1000100b,
|
18765
|
-
FILE: 0x1000100a,
|
18766
|
-
AUDIO: 0x10001001,
|
18767
|
-
CUST_COMMAND: 0x1000101d,
|
18768
|
-
CUST_STORAGE: 0x1000102d,
|
18769
|
-
CUST_NORMAL: 0x1000103d,
|
18770
|
-
CUST_STATUS: 0x1000104d,
|
18771
|
-
RECALL: 0x6001001d,
|
18772
|
-
CMD: 0x1000105d
|
18773
|
-
};
|
18774
|
-
|
18775
|
-
class TextMessage extends BaseMessage {
|
18776
|
-
constructor(content) {
|
18777
|
-
super(content);
|
18778
|
-
}
|
18779
|
-
static getObjectId() {
|
18780
|
-
return MessageObjectIds.TEXT;
|
18781
|
-
}
|
18782
|
-
static decode(aDecoder) {
|
18783
|
-
const {
|
18784
|
-
user,
|
18785
|
-
extra,
|
18786
|
-
content
|
18787
|
-
} = aDecoder;
|
18788
|
-
return new TextMessage({
|
18789
|
-
user,
|
18790
|
-
extra,
|
18791
|
-
content
|
18792
|
-
});
|
18793
|
-
}
|
18794
|
-
encode() {
|
18795
|
-
const {
|
18796
|
-
user,
|
18797
|
-
extra,
|
18798
|
-
content
|
18799
|
-
} = this.content;
|
18800
|
-
return {
|
18801
|
-
user,
|
18802
|
-
extra,
|
18803
|
-
content
|
18804
|
-
};
|
18805
|
-
}
|
18806
|
-
}
|
18807
|
-
|
18808
|
-
class IMConfig {
|
18809
|
-
_token = '';
|
18810
|
-
_uploadUrl = '';
|
18811
|
-
_downloadUrl = '';
|
18812
|
-
_cert = '';
|
18813
|
-
set imInitToken(val) {
|
18814
|
-
this._token = val;
|
18815
|
-
}
|
18816
|
-
get imInitToken() {
|
18817
|
-
return this._token;
|
18818
|
-
}
|
18819
|
-
get fileUploadUrl() {
|
18820
|
-
return this._uploadUrl;
|
18821
|
-
}
|
18822
|
-
get cert() {
|
18823
|
-
return this._cert;
|
18824
|
-
}
|
18825
|
-
get fileDownloadUrl() {
|
18826
|
-
return this._downloadUrl;
|
18827
|
-
}
|
18828
|
-
setFileServerInfo(uploadUrl, downloadUrl, cert) {
|
18829
|
-
this._uploadUrl = uploadUrl;
|
18830
|
-
this._downloadUrl = downloadUrl;
|
18831
|
-
this._cert = cert;
|
18832
|
-
}
|
18833
|
-
getFileAbsoluteUri(u) {
|
18834
|
-
if (!notEmptyString(u)) {
|
18835
|
-
return u;
|
18836
|
-
}
|
18837
|
-
if (u.startsWith('http')) {
|
18838
|
-
return u;
|
18839
|
-
}
|
18840
|
-
return this.fileDownloadUrl + u;
|
18841
|
-
}
|
18842
|
-
try2ExtractFileRelativeUri(u) {
|
18843
|
-
if (!notEmptyString(u)) {
|
18844
|
-
return u;
|
18845
|
-
}
|
18846
|
-
if (!u.startsWith(this.fileDownloadUrl)) {
|
18847
|
-
return u;
|
18848
|
-
}
|
18849
|
-
return u.substring(this.fileDownloadUrl.length);
|
18850
|
-
}
|
18851
|
-
}
|
18852
|
-
var imConfig = new IMConfig();
|
18853
|
-
|
18854
|
-
class ImageMessage extends BaseMessage {
|
18855
|
-
constructor(content) {
|
18856
|
-
super(content);
|
18857
|
-
}
|
18858
|
-
static getObjectId() {
|
18859
|
-
return MessageObjectIds.IMAGE;
|
18860
|
-
}
|
18861
|
-
static decode(aDecoder) {
|
18862
|
-
const {
|
18863
|
-
user,
|
18864
|
-
extra,
|
18865
|
-
thumbnailObjectKey,
|
18866
|
-
originalObjectKey,
|
18867
|
-
width,
|
18868
|
-
height
|
18869
|
-
} = aDecoder;
|
18870
|
-
return new ImageMessage({
|
18871
|
-
user,
|
18872
|
-
extra,
|
18873
|
-
content: thumbnailObjectKey,
|
18874
|
-
imageUri: imConfig.getFileAbsoluteUri(originalObjectKey),
|
18875
|
-
width,
|
18876
|
-
height
|
18877
|
-
});
|
18878
|
-
}
|
18879
|
-
encode() {
|
18880
|
-
const {
|
18881
|
-
user,
|
18882
|
-
extra,
|
18883
|
-
content,
|
18884
|
-
imageUri,
|
18885
|
-
width,
|
18886
|
-
height
|
18887
|
-
} = this.content;
|
18888
|
-
return {
|
18889
|
-
user,
|
18890
|
-
extra,
|
18891
|
-
thumbnailObjectKey: content,
|
18892
|
-
originalObjectKey: imConfig.try2ExtractFileRelativeUri(imageUri),
|
18893
|
-
width: width && Math.floor(width),
|
18894
|
-
height: height && Math.floor(height)
|
18895
|
-
};
|
18896
|
-
}
|
18897
|
-
}
|
18898
|
-
|
18899
|
-
class GIFMessage extends BaseMessage {
|
18900
|
-
constructor(content) {
|
18901
|
-
super(content);
|
18902
|
-
}
|
18903
|
-
static getObjectId() {
|
18904
|
-
return MessageObjectIds.GIF;
|
18905
|
-
}
|
18906
|
-
static decode(aDecoder) {
|
18907
|
-
const {
|
18908
|
-
user,
|
18909
|
-
extra,
|
18910
|
-
size,
|
18911
|
-
originalObjectKey,
|
18912
|
-
width,
|
18913
|
-
height
|
18914
|
-
} = aDecoder;
|
18915
|
-
return new GIFMessage({
|
18916
|
-
user,
|
18917
|
-
extra,
|
18918
|
-
gifDataSize: size,
|
18919
|
-
remoteUrl: imConfig.getFileAbsoluteUri(originalObjectKey),
|
18920
|
-
width,
|
18921
|
-
height
|
18922
|
-
});
|
18923
|
-
}
|
18924
|
-
encode() {
|
18925
|
-
const {
|
18926
|
-
user,
|
18927
|
-
extra,
|
18928
|
-
gifDataSize,
|
18929
|
-
remoteUrl,
|
18930
|
-
width,
|
18931
|
-
height
|
18932
|
-
} = this.content;
|
18933
|
-
return {
|
18934
|
-
user,
|
18935
|
-
extra,
|
18936
|
-
size: gifDataSize,
|
18937
|
-
originalObjectKey: imConfig.try2ExtractFileRelativeUri(remoteUrl),
|
18938
|
-
width: width && Math.floor(width),
|
18939
|
-
height: height && Math.floor(height),
|
18940
|
-
extension: 'gif'
|
18941
|
-
};
|
18942
|
-
}
|
18943
|
-
}
|
18944
|
-
|
18945
|
-
class HQVoiceMessage extends BaseMessage {
|
18946
|
-
constructor(content) {
|
18947
|
-
super(content);
|
18948
|
-
}
|
18949
|
-
static getObjectId() {
|
18950
|
-
return MessageObjectIds.AUDIO;
|
18951
|
-
}
|
18952
|
-
static decode(aDecoder) {
|
18953
|
-
const {
|
18954
|
-
user,
|
18955
|
-
extra,
|
18956
|
-
length,
|
18957
|
-
audioObjectKey,
|
18958
|
-
extension
|
18959
|
-
} = aDecoder;
|
18960
|
-
return new HQVoiceMessage({
|
18961
|
-
user,
|
18962
|
-
extra,
|
18963
|
-
remoteUrl: imConfig.getFileAbsoluteUri(audioObjectKey),
|
18964
|
-
duration: length,
|
18965
|
-
type: extension
|
18966
|
-
});
|
18967
|
-
}
|
18968
|
-
encode() {
|
18969
|
-
const {
|
18970
|
-
user,
|
18971
|
-
extra,
|
18972
|
-
remoteUrl,
|
18973
|
-
duration,
|
18974
|
-
type
|
18975
|
-
} = this.content;
|
18976
|
-
return {
|
18977
|
-
user,
|
18978
|
-
extra,
|
18979
|
-
length: duration,
|
18980
|
-
audioObjectKey: imConfig.try2ExtractFileRelativeUri(remoteUrl),
|
18981
|
-
extension: type
|
18982
|
-
};
|
18983
|
-
}
|
18984
|
-
}
|
18985
|
-
|
18986
|
-
class FileMessage extends BaseMessage {
|
18987
|
-
constructor(content) {
|
18988
|
-
super(content);
|
18989
|
-
}
|
18990
|
-
static getObjectId() {
|
18991
|
-
return MessageObjectIds.FILE;
|
18992
|
-
}
|
18993
|
-
static decode(aDecoder) {
|
18994
|
-
const {
|
18995
|
-
user,
|
18996
|
-
extra,
|
18997
|
-
title,
|
18998
|
-
extension,
|
18999
|
-
size,
|
19000
|
-
originalObjectKey
|
19001
|
-
} = aDecoder;
|
19002
|
-
return new FileMessage({
|
19003
|
-
user,
|
19004
|
-
extra,
|
19005
|
-
name: title,
|
19006
|
-
size,
|
19007
|
-
type: extension,
|
19008
|
-
fileUrl: imConfig.getFileAbsoluteUri(originalObjectKey)
|
19009
|
-
});
|
19010
|
-
}
|
19011
|
-
encode() {
|
19012
|
-
const {
|
19013
|
-
user,
|
19014
|
-
extra,
|
19015
|
-
name,
|
19016
|
-
size,
|
19017
|
-
type,
|
19018
|
-
fileUrl
|
19019
|
-
} = this.content;
|
19020
|
-
return {
|
19021
|
-
user,
|
19022
|
-
extra,
|
19023
|
-
title: name,
|
19024
|
-
originalObjectKey: imConfig.try2ExtractFileRelativeUri(fileUrl),
|
19025
|
-
extension: type,
|
19026
|
-
size
|
19027
|
-
};
|
19028
|
-
}
|
19029
|
-
}
|
19030
|
-
|
19031
|
-
class RecallCommandMessage extends BaseMessage {
|
19032
|
-
constructor(content) {
|
19033
|
-
super(content, true, false, false);
|
19034
|
-
}
|
19035
|
-
static getObjectId() {
|
19036
|
-
return MessageObjectIds.RECALL;
|
19037
|
-
}
|
19038
|
-
static decode(aDecoder) {
|
19039
|
-
return new RecallCommandMessage(aDecoder);
|
19040
|
-
}
|
19041
|
-
encode() {
|
19042
|
-
return this.content;
|
19043
|
-
}
|
19044
|
-
}
|
19045
|
-
|
19046
18725
|
class DialogSecretKey {
|
19047
18726
|
aesKeyRecord = new Map();
|
19048
18727
|
async getDialogAesKey(dialogId) {
|
@@ -19192,6 +18871,27 @@
|
|
19192
18871
|
return new Uint8Array(array);
|
19193
18872
|
};
|
19194
18873
|
|
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
|
+
const MessageTypes = {
|
18882
|
+
TEXT: 0x00000000,
|
18883
|
+
IMAGE: 0x10001000,
|
18884
|
+
GIF: 0x1000100b,
|
18885
|
+
FILE: 0x1000100a,
|
18886
|
+
AUDIO: 0x10001001,
|
18887
|
+
CUST_COMMAND: 0x1000101d,
|
18888
|
+
CUST_STORAGE: 0x1000102d,
|
18889
|
+
CUST_NORMAL: 0x1000103d,
|
18890
|
+
CUST_STATUS: 0x1000104d,
|
18891
|
+
RECALL: 0x6001001d,
|
18892
|
+
CMD: 0x1000105d
|
18893
|
+
};
|
18894
|
+
|
19195
18895
|
const STATUSMESSAGE_ALIVE_TIMEMS = 6000;
|
19196
18896
|
function parse(orginalMsgs, callback) {
|
19197
18897
|
const msgs = new Map();
|
@@ -19247,12 +18947,9 @@
|
|
19247
18947
|
sendTime
|
19248
18948
|
} = mediaAttributeJson;
|
19249
18949
|
const recallContent = {
|
19250
|
-
|
19251
|
-
messageUId: msgId,
|
19252
|
-
conversationType: conversation.conversationType,
|
19253
|
-
targetId: dialogMessage.isOut ? conversation.targetId : accountStore.uid
|
18950
|
+
msgId: msgId
|
19254
18951
|
};
|
19255
|
-
mediaConstructor =
|
18952
|
+
mediaConstructor = MessageTypes.RECALL;
|
19256
18953
|
mediaAttributeJson = recallContent;
|
19257
18954
|
recallMessageUIds.add(msgId);
|
19258
18955
|
}
|
@@ -19398,7 +19095,7 @@
|
|
19398
19095
|
messageDirection
|
19399
19096
|
} = message;
|
19400
19097
|
const isSelfSend = messageDirection === exports.MessageDirection.SEND;
|
19401
|
-
const isRecall = messageType ===
|
19098
|
+
const isRecall = messageType === MessageTypes.RECALL;
|
19402
19099
|
const hasContent = isObject(content);
|
19403
19100
|
const key = {
|
19404
19101
|
conversationType,
|
@@ -19432,7 +19129,7 @@
|
|
19432
19129
|
messageDirection,
|
19433
19130
|
content
|
19434
19131
|
} = message;
|
19435
|
-
if (messageDirection === exports.MessageDirection.SEND || !isMentioned && messageType !==
|
19132
|
+
if (messageDirection === exports.MessageDirection.SEND || !isMentioned && messageType !== MessageTypes.RECALL) {
|
19436
19133
|
return;
|
19437
19134
|
}
|
19438
19135
|
const key = this.getStoreKey({
|
@@ -19447,9 +19144,9 @@
|
|
19447
19144
|
localMentionedUIdList.push(messageUId.toString());
|
19448
19145
|
}
|
19449
19146
|
}
|
19450
|
-
if (messageType ===
|
19147
|
+
if (messageType === MessageTypes.RECALL && conversationType === exports.ConversationType.GROUP) {
|
19451
19148
|
const recallContent = content;
|
19452
|
-
const index = localMentionedUIdList.indexOf(recallContent.
|
19149
|
+
const index = localMentionedUIdList.indexOf(recallContent.msgId.toString());
|
19453
19150
|
if (index >= 0) {
|
19454
19151
|
localMentionedUIdList.splice(index, 1);
|
19455
19152
|
}
|
@@ -19571,7 +19268,7 @@
|
|
19571
19268
|
data
|
19572
19269
|
} = await getDialogChangedStatus(offset);
|
19573
19270
|
if (code === exports.ErrorCode.SUCCESS) {
|
19574
|
-
if (data.setTime.toNumber() > 0) {
|
19271
|
+
if (Long.isLong(data.setTime) && data.setTime.toNumber() > 0) {
|
19575
19272
|
SecureStorageService.set(this.storageKey, data.setTime.toNumber());
|
19576
19273
|
}
|
19577
19274
|
if (data.briefDialog) {
|
@@ -20065,7 +19762,6 @@
|
|
20065
19762
|
};
|
20066
19763
|
});
|
20067
19764
|
ConversationManager$1.get().loadConvsationsIfNotExist(cons);
|
20068
|
-
debugger;
|
20069
19765
|
ServerMessageParser.parse(msg, (done, outputMsgs) => {
|
20070
19766
|
const messages = [];
|
20071
19767
|
const conversations = [];
|
@@ -20075,7 +19771,7 @@
|
|
20075
19771
|
l.forEach(m => {
|
20076
19772
|
if (m.messageDirection === exports.MessageDirection.SEND && m.messageId && SentMessageStore.has(m.messageId)) {
|
20077
19773
|
SentMessageStore.remove(m.messageId);
|
20078
|
-
} else if (m.messageType ===
|
19774
|
+
} else if (m.messageType === MessageTypes.RECALL && RecallMessageStore.has(m.content.messageUId)) {
|
20079
19775
|
RecallMessageStore.remove(m.content.messageUId);
|
20080
19776
|
} else {
|
20081
19777
|
m.isOffLineMessage = isOffLineMessage;
|
@@ -20118,7 +19814,7 @@
|
|
20118
19814
|
}
|
20119
19815
|
}
|
20120
19816
|
|
20121
|
-
const DEFAULT_SOCKET_URI = 'wss://
|
19817
|
+
const DEFAULT_SOCKET_URI = 'wss://imweb.mp.net:6443';
|
20122
19818
|
class LibLoader {
|
20123
19819
|
options;
|
20124
19820
|
connectionStatus = exports.ConnectionStatus.DISCONNECTED;
|
@@ -20144,7 +19840,8 @@
|
|
20144
19840
|
onSuspend: undefined,
|
20145
19841
|
pullFinished: undefined,
|
20146
19842
|
batchMessage: undefined,
|
20147
|
-
conversationState: undefined
|
19843
|
+
conversationState: undefined,
|
19844
|
+
onPush: undefined
|
20148
19845
|
};
|
20149
19846
|
webSocketServer.setServerInfo(this.getWebSocketUrl());
|
20150
19847
|
webSocketServer.setCallback({
|
@@ -20163,14 +19860,7 @@
|
|
20163
19860
|
}
|
20164
19861
|
return DEFAULT_SOCKET_URI;
|
20165
19862
|
}
|
20166
|
-
registerMessage() {
|
20167
|
-
registerMessageSerializer(TextMessage);
|
20168
|
-
registerMessageSerializer(ImageMessage);
|
20169
|
-
registerMessageSerializer(GIFMessage);
|
20170
|
-
registerMessageSerializer(HQVoiceMessage);
|
20171
|
-
registerMessageSerializer(RecallCommandMessage);
|
20172
|
-
registerMessageSerializer(FileMessage);
|
20173
|
-
}
|
19863
|
+
registerMessage() {}
|
20174
19864
|
async connect() {
|
20175
19865
|
if (this.connectionStatus === exports.ConnectionStatus.CONNECTED) {
|
20176
19866
|
return {
|
@@ -26850,6 +26540,56 @@
|
|
26850
26540
|
var protobufjsExports = requireProtobufjs();
|
26851
26541
|
var protobuf = /*@__PURE__*/getDefaultExportFromCjs(protobufjsExports);
|
26852
26542
|
|
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
|
+
|
26853
26593
|
const transSentAttrs2IReceivedMessage = (message, options, sentStatus = exports.SentStatus.SENDING) => ({
|
26854
26594
|
conversationType: options.conversation.conversationType,
|
26855
26595
|
targetId: options.conversation.targetId,
|
@@ -26881,411 +26621,10 @@
|
|
26881
26621
|
return 230000000000000 + UniqueLocalId;
|
26882
26622
|
}
|
26883
26623
|
|
26884
|
-
const getBlobUrl = blob => {
|
26885
|
-
const URL = window.URL || window.webkitURL;
|
26886
|
-
return URL ? URL.createObjectURL(blob) : '';
|
26887
|
-
};
|
26888
|
-
const getBlobExtension = blob => {
|
26889
|
-
const name = blob.name;
|
26890
|
-
if (notEmptyString(name)) {
|
26891
|
-
return name.substring(name.lastIndexOf('.') + 1);
|
26892
|
-
}
|
26893
|
-
return blob.type.indexOf('/') > 0 ? blob.type.substring(blob.type.lastIndexOf('/') + 1) : '';
|
26894
|
-
};
|
26895
|
-
const blob2ArrayBuffer = blob => {
|
26896
|
-
if (isPromise(blob.arrayBuffer)) {
|
26897
|
-
return blob.arrayBuffer();
|
26898
|
-
}
|
26899
|
-
return new Promise((resolve, reject) => {
|
26900
|
-
const reader = new FileReader();
|
26901
|
-
reader.addEventListener('load', event => {
|
26902
|
-
if (event.target) {
|
26903
|
-
resolve(event.target.result);
|
26904
|
-
} else {
|
26905
|
-
reject('null');
|
26906
|
-
}
|
26907
|
-
});
|
26908
|
-
reader.addEventListener('error', error => reject(error));
|
26909
|
-
reader.readAsArrayBuffer(blob);
|
26910
|
-
});
|
26911
|
-
};
|
26912
|
-
const revokeBlobUrl = url => {
|
26913
|
-
const URL = window.URL || window.webkitURL;
|
26914
|
-
URL.revokeObjectURL(url);
|
26915
|
-
};
|
26916
|
-
const dataURL2Blob = url => {
|
26917
|
-
const type = url.match(/data:([^;]+)/)[1];
|
26918
|
-
const base64 = url.replace(/^[^,]+,/, '');
|
26919
|
-
const bstr = window.atob(base64);
|
26920
|
-
let n = bstr.length;
|
26921
|
-
const u8arr = new Uint8Array(bstr.length);
|
26922
|
-
while (n--) {
|
26923
|
-
u8arr[n] = bstr.charCodeAt(n);
|
26924
|
-
}
|
26925
|
-
return new Blob([u8arr], {
|
26926
|
-
type
|
26927
|
-
});
|
26928
|
-
};
|
26929
|
-
|
26930
|
-
const COMPRESS_LENGTH_MAX = 1680;
|
26931
|
-
const COMPRESS_LENGTH_MIN = 160;
|
26932
|
-
const getImageObj = link => {
|
26933
|
-
return new Promise((resolve, reject) => {
|
26934
|
-
const handle = image => {
|
26935
|
-
if (image.width !== 0 || image.height !== 0) {
|
26936
|
-
resolve(image);
|
26937
|
-
} else {
|
26938
|
-
reject();
|
26939
|
-
}
|
26940
|
-
};
|
26941
|
-
const image = new Image();
|
26942
|
-
image.addEventListener('load', event => handle(event.target));
|
26943
|
-
image.addEventListener('error', reject);
|
26944
|
-
image.src = link;
|
26945
|
-
if (image.complete) {
|
26946
|
-
handle(image);
|
26947
|
-
return;
|
26948
|
-
}
|
26949
|
-
const intervalId = setInterval(() => {
|
26950
|
-
if (image.complete) {
|
26951
|
-
handle(image);
|
26952
|
-
clearInterval(intervalId);
|
26953
|
-
}
|
26954
|
-
}, 40);
|
26955
|
-
});
|
26956
|
-
};
|
26957
|
-
const compress = (image, quality = 1, mineType = 'image/jpeg') => {
|
26958
|
-
quality = Math.min(1, quality);
|
26959
|
-
const width = image.width;
|
26960
|
-
const height = image.height;
|
26961
|
-
let compressWidth = width;
|
26962
|
-
let compressHeight = height;
|
26963
|
-
if (quality < 1) {
|
26964
|
-
const isheight = width < height;
|
26965
|
-
const zoom = isheight ? height / COMPRESS_LENGTH_MAX : width / COMPRESS_LENGTH_MAX;
|
26966
|
-
if (width > COMPRESS_LENGTH_MAX && height > COMPRESS_LENGTH_MAX) {
|
26967
|
-
if (isheight) {
|
26968
|
-
compressHeight = COMPRESS_LENGTH_MAX;
|
26969
|
-
compressWidth = compressWidth / zoom;
|
26970
|
-
} else {
|
26971
|
-
compressWidth = COMPRESS_LENGTH_MAX;
|
26972
|
-
compressHeight = compressHeight / zoom;
|
26973
|
-
}
|
26974
|
-
} else if (width > COMPRESS_LENGTH_MAX && height > COMPRESS_LENGTH_MIN) {
|
26975
|
-
compressWidth = COMPRESS_LENGTH_MAX;
|
26976
|
-
compressHeight = compressHeight / zoom;
|
26977
|
-
if (compressHeight < COMPRESS_LENGTH_MIN) {
|
26978
|
-
compressHeight = COMPRESS_LENGTH_MIN;
|
26979
|
-
compressWidth = width / (height / COMPRESS_LENGTH_MIN);
|
26980
|
-
}
|
26981
|
-
} else if (height > COMPRESS_LENGTH_MAX && width > COMPRESS_LENGTH_MIN) {
|
26982
|
-
compressHeight = COMPRESS_LENGTH_MAX;
|
26983
|
-
compressWidth = compressWidth / zoom;
|
26984
|
-
if (compressWidth < COMPRESS_LENGTH_MIN) {
|
26985
|
-
compressWidth = COMPRESS_LENGTH_MIN;
|
26986
|
-
compressHeight = height / (width / COMPRESS_LENGTH_MIN);
|
26987
|
-
}
|
26988
|
-
}
|
26989
|
-
}
|
26990
|
-
compressWidth = Math.floor(compressWidth);
|
26991
|
-
compressHeight = Math.floor(compressHeight);
|
26992
|
-
const canvas = document.createElement('canvas');
|
26993
|
-
canvas.width = compressWidth;
|
26994
|
-
canvas.height = compressHeight;
|
26995
|
-
const ctx = canvas.getContext('2d');
|
26996
|
-
ctx.fillStyle = '#FFF';
|
26997
|
-
ctx.fillRect(0, 0, compressWidth, compressHeight);
|
26998
|
-
ctx.drawImage(image, 0, 0, width, height, 0, 0, compressWidth, compressHeight);
|
26999
|
-
if (!mineType || mineType == 'image/png') {
|
27000
|
-
mineType = 'image/jpeg';
|
27001
|
-
}
|
27002
|
-
return {
|
27003
|
-
imageFile: dataURL2Blob(canvas.toDataURL(mineType, Math.min(0.92, quality))),
|
27004
|
-
compressWidth,
|
27005
|
-
compressHeight
|
27006
|
-
};
|
27007
|
-
};
|
27008
|
-
const getThumbnail = (img, thumbnailConfig) => {
|
27009
|
-
const canvas = document.createElement('canvas');
|
27010
|
-
const context = canvas.getContext('2d');
|
27011
|
-
const pos = calcPosition(img.width, img.height, thumbnailConfig);
|
27012
|
-
canvas.width = pos.w > thumbnailConfig.maxWidth ? thumbnailConfig.maxWidth : pos.w;
|
27013
|
-
canvas.height = pos.h > thumbnailConfig.maxHeight ? thumbnailConfig.maxHeight : pos.h;
|
27014
|
-
context?.drawImage(img, pos.x, pos.y, pos.w, pos.h);
|
27015
|
-
try {
|
27016
|
-
let base64 = canvas.toDataURL('image/jpeg', thumbnailConfig.quality);
|
27017
|
-
const reg = new RegExp('^data:image/[^;]+;base64,');
|
27018
|
-
base64 = base64.replace(reg, '');
|
27019
|
-
return base64;
|
27020
|
-
} catch (e) {
|
27021
|
-
throw new Error(e);
|
27022
|
-
}
|
27023
|
-
};
|
27024
|
-
function calcPosition(width, height, thumbnailConfig) {
|
27025
|
-
const isheight = width < height;
|
27026
|
-
const scale = isheight ? height / width : width / height;
|
27027
|
-
let zoom;
|
27028
|
-
let x = 0;
|
27029
|
-
let y = 0;
|
27030
|
-
let w;
|
27031
|
-
let h;
|
27032
|
-
const gtScale = function () {
|
27033
|
-
if (isheight) {
|
27034
|
-
zoom = width / 100;
|
27035
|
-
w = 100;
|
27036
|
-
h = height / zoom;
|
27037
|
-
y = (h - thumbnailConfig.maxHeight) / 2;
|
27038
|
-
} else {
|
27039
|
-
zoom = height / 100;
|
27040
|
-
h = 100;
|
27041
|
-
w = width / zoom;
|
27042
|
-
x = (w - thumbnailConfig.maxWidth) / 2;
|
27043
|
-
}
|
27044
|
-
return {
|
27045
|
-
w: w,
|
27046
|
-
h: h,
|
27047
|
-
x: -x,
|
27048
|
-
y: -y
|
27049
|
-
};
|
27050
|
-
};
|
27051
|
-
const ltScale = function () {
|
27052
|
-
if (isheight) {
|
27053
|
-
zoom = height / thumbnailConfig.maxHeight;
|
27054
|
-
h = thumbnailConfig.maxHeight;
|
27055
|
-
w = width / zoom;
|
27056
|
-
} else {
|
27057
|
-
zoom = width / thumbnailConfig.maxWidth;
|
27058
|
-
w = thumbnailConfig.maxWidth;
|
27059
|
-
h = height / zoom;
|
27060
|
-
}
|
27061
|
-
return {
|
27062
|
-
w: w,
|
27063
|
-
h: h,
|
27064
|
-
x: -x,
|
27065
|
-
y: -y
|
27066
|
-
};
|
27067
|
-
};
|
27068
|
-
return scale > thumbnailConfig.scale ? gtScale() : ltScale();
|
27069
|
-
}
|
27070
|
-
|
27071
|
-
class Img {
|
27072
|
-
async create(file) {
|
27073
|
-
try {
|
27074
|
-
const blobUrl = getBlobUrl(file);
|
27075
|
-
const image = await getImageObj(blobUrl);
|
27076
|
-
revokeBlobUrl(blobUrl);
|
27077
|
-
const {
|
27078
|
-
imageFile: sentImageFile,
|
27079
|
-
compressWidth,
|
27080
|
-
compressHeight
|
27081
|
-
} = compress(image, 0.85, file.type);
|
27082
|
-
const config = {
|
27083
|
-
maxHeight: 160,
|
27084
|
-
maxWidth: 160,
|
27085
|
-
quality: 0.6,
|
27086
|
-
scale: 2.4
|
27087
|
-
};
|
27088
|
-
const thumbnail = getThumbnail(image, config);
|
27089
|
-
return {
|
27090
|
-
success: true,
|
27091
|
-
message: new ImageMessage({
|
27092
|
-
content: thumbnail,
|
27093
|
-
imageUri: getBlobUrl(sentImageFile),
|
27094
|
-
width: compressWidth,
|
27095
|
-
height: compressHeight
|
27096
|
-
}),
|
27097
|
-
file: sentImageFile
|
27098
|
-
};
|
27099
|
-
} catch (error) {
|
27100
|
-
return {
|
27101
|
-
success: false
|
27102
|
-
};
|
27103
|
-
}
|
27104
|
-
}
|
27105
|
-
updateMessageRemoteUrlProperty(msg, remoteUrl) {
|
27106
|
-
msg.content.imageUri = remoteUrl;
|
27107
|
-
}
|
27108
|
-
}
|
27109
|
-
class GIF {
|
27110
|
-
async create(file) {
|
27111
|
-
if (file.size > 2 * 1024 * 1024) {
|
27112
|
-
return {
|
27113
|
-
success: false
|
27114
|
-
};
|
27115
|
-
}
|
27116
|
-
try {
|
27117
|
-
const blobUrl = getBlobUrl(file);
|
27118
|
-
const image = await getImageObj(blobUrl);
|
27119
|
-
return {
|
27120
|
-
success: true,
|
27121
|
-
message: new GIFMessage({
|
27122
|
-
gifDataSize: file.size,
|
27123
|
-
remoteUrl: blobUrl,
|
27124
|
-
width: image.width,
|
27125
|
-
height: image.height
|
27126
|
-
}),
|
27127
|
-
file: file
|
27128
|
-
};
|
27129
|
-
} catch {
|
27130
|
-
return {
|
27131
|
-
success: false
|
27132
|
-
};
|
27133
|
-
}
|
27134
|
-
}
|
27135
|
-
updateMessageRemoteUrlProperty(message, remoteUrl) {
|
27136
|
-
message.content.remoteUrl = remoteUrl;
|
27137
|
-
}
|
27138
|
-
}
|
27139
|
-
let audioCtx;
|
27140
|
-
class Audio {
|
27141
|
-
create(file) {
|
27142
|
-
return blob2ArrayBuffer(file).then(this.getAudioInfo).then(info => {
|
27143
|
-
return {
|
27144
|
-
success: true,
|
27145
|
-
message: new HQVoiceMessage({
|
27146
|
-
remoteUrl: '',
|
27147
|
-
duration: info.duration,
|
27148
|
-
type: getBlobExtension(file)
|
27149
|
-
}),
|
27150
|
-
file
|
27151
|
-
};
|
27152
|
-
}).catch(() => {
|
27153
|
-
return {
|
27154
|
-
success: false
|
27155
|
-
};
|
27156
|
-
});
|
27157
|
-
}
|
27158
|
-
updateMessageRemoteUrlProperty(message, remoteUrl) {
|
27159
|
-
message.content.remoteUrl = remoteUrl;
|
27160
|
-
}
|
27161
|
-
getAudioInfo(buffer) {
|
27162
|
-
const ctx = audioCtx || new AudioContext();
|
27163
|
-
audioCtx = ctx;
|
27164
|
-
return new Promise((resolve, reject) => {
|
27165
|
-
ctx.decodeAudioData(buffer, function (audioBuffer) {
|
27166
|
-
resolve({
|
27167
|
-
duration: audioBuffer.duration,
|
27168
|
-
length: audioBuffer.length
|
27169
|
-
});
|
27170
|
-
}, reject);
|
27171
|
-
});
|
27172
|
-
}
|
27173
|
-
}
|
27174
|
-
class File {
|
27175
|
-
async create(file) {
|
27176
|
-
if (file.size > 100 * 1024 * 1024) {
|
27177
|
-
return {
|
27178
|
-
success: false
|
27179
|
-
};
|
27180
|
-
}
|
27181
|
-
return {
|
27182
|
-
success: true,
|
27183
|
-
message: new FileMessage({
|
27184
|
-
fileUrl: '',
|
27185
|
-
name: file.name,
|
27186
|
-
type: getBlobExtension(file),
|
27187
|
-
size: file.size
|
27188
|
-
}),
|
27189
|
-
file
|
27190
|
-
};
|
27191
|
-
}
|
27192
|
-
updateMessageRemoteUrlProperty(message, remoteUrl) {
|
27193
|
-
message.content.fileUrl = remoteUrl;
|
27194
|
-
}
|
27195
|
-
}
|
27196
|
-
var FileType;
|
27197
|
-
(function (FileType) {
|
27198
|
-
FileType[FileType["IMAGE"] = 1] = "IMAGE";
|
27199
|
-
FileType[FileType["GIF"] = 2] = "GIF";
|
27200
|
-
FileType[FileType["AUDIO"] = 3] = "AUDIO";
|
27201
|
-
FileType[FileType["VIDEO"] = 4] = "VIDEO";
|
27202
|
-
FileType[FileType["FILE"] = 5] = "FILE";
|
27203
|
-
FileType[FileType["SIGHT"] = 6] = "SIGHT";
|
27204
|
-
})(FileType || (FileType = {}));
|
27205
|
-
const getMediaMessageCreator = fileType => {
|
27206
|
-
let creator;
|
27207
|
-
switch (fileType) {
|
27208
|
-
case FileType.IMAGE:
|
27209
|
-
creator = new Img();
|
27210
|
-
break;
|
27211
|
-
case FileType.AUDIO:
|
27212
|
-
creator = new Audio();
|
27213
|
-
break;
|
27214
|
-
case FileType.GIF:
|
27215
|
-
creator = new GIF();
|
27216
|
-
break;
|
27217
|
-
case FileType.FILE:
|
27218
|
-
creator = new File();
|
27219
|
-
break;
|
27220
|
-
}
|
27221
|
-
return creator;
|
27222
|
-
};
|
27223
|
-
|
27224
|
-
class Upload {
|
27225
|
-
options;
|
27226
|
-
xhr;
|
27227
|
-
constructor(options) {
|
27228
|
-
this.options = options;
|
27229
|
-
}
|
27230
|
-
upload(file, callback) {
|
27231
|
-
const xhr = new XMLHttpRequest();
|
27232
|
-
xhr.timeout = (30 + file.size / 1024 / 512) * 1000;
|
27233
|
-
xhr.upload.onprogress = event => {
|
27234
|
-
callback.onProgress?.(event.loaded, event.total);
|
27235
|
-
};
|
27236
|
-
xhr.onreadystatechange = () => {
|
27237
|
-
if (xhr.readyState === 4) {
|
27238
|
-
const responseText = xhr.responseText || '{}';
|
27239
|
-
const responseData = JSON.parse(responseText);
|
27240
|
-
if (xhr.status === 200 && responseData.code === 200) {
|
27241
|
-
let result = {
|
27242
|
-
url: responseData.url
|
27243
|
-
};
|
27244
|
-
if (this.options.transformer) {
|
27245
|
-
result = this.options.transformer(result);
|
27246
|
-
}
|
27247
|
-
callback.onCompleted?.(result);
|
27248
|
-
} else {
|
27249
|
-
callback.onError?.('upload fail');
|
27250
|
-
}
|
27251
|
-
}
|
27252
|
-
};
|
27253
|
-
xhr.open('POST', this.options.uploadUrl, true);
|
27254
|
-
xhr.setRequestHeader('device', '7');
|
27255
|
-
xhr.setRequestHeader('cert', this.options.cert ?? '');
|
27256
|
-
const type = getBlobExtension(file);
|
27257
|
-
const fileName = genUId() + (type.length ? `.${type}` : '');
|
27258
|
-
const formData = new FormData();
|
27259
|
-
formData.append('file', file);
|
27260
|
-
formData.append('name', 'file');
|
27261
|
-
formData.append('fileName', fileName);
|
27262
|
-
formData.append('token', this.options.token);
|
27263
|
-
xhr.send(formData);
|
27264
|
-
this.xhr = xhr;
|
27265
|
-
}
|
27266
|
-
cancel() {
|
27267
|
-
this.xhr?.abort();
|
27268
|
-
}
|
27269
|
-
}
|
27270
|
-
function genUId() {
|
27271
|
-
let date = new Date().getTime();
|
27272
|
-
const uuid = 'xxxxxx4xxxyxxxxxxx'.replace(/[xy]/g, function (c) {
|
27273
|
-
const r = (date + Math.random() * 16) % 16 | 0;
|
27274
|
-
date = Math.floor(date / 16);
|
27275
|
-
return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
|
27276
|
-
});
|
27277
|
-
return uuid;
|
27278
|
-
}
|
27279
|
-
|
27280
26624
|
const MAX_MESSAGE_CONTENT_BYTES = 80 * 1024;
|
27281
|
-
const MEDIA_MESSAGES = [MessageObjectIds.IMAGE, MessageObjectIds.AUDIO, MessageObjectIds.GIF, MessageObjectIds.FILE];
|
27282
26625
|
async function sendMessage$1(conversation, message, options) {
|
27283
26626
|
return internal_sendMessage(conversation, message, options);
|
27284
26627
|
}
|
27285
|
-
const sendImageMessage$1 = createSendFunction.bind(null, FileType.IMAGE);
|
27286
|
-
const sendGIFMessage$1 = createSendFunction.bind(null, FileType.GIF);
|
27287
|
-
const sendHQVoiceMessage$1 = createSendFunction.bind(null, FileType.AUDIO);
|
27288
|
-
const sendFileMessage$1 = createSendFunction.bind(null, FileType.FILE);
|
27289
26628
|
const sendRecallMessage = async (conversation, options) => {
|
27290
26629
|
const dialogId = getFullDialogId(conversation);
|
27291
26630
|
RecallMessageStore.addMessage(options.messageUId);
|
@@ -27296,9 +26635,7 @@
|
|
27296
26635
|
};
|
27297
26636
|
}
|
27298
26637
|
const recallCommandMessage = new RecallCommandMessage({
|
27299
|
-
|
27300
|
-
messageUId: options.messageUId,
|
27301
|
-
...conversation
|
26638
|
+
msgId: options.messageUId
|
27302
26639
|
});
|
27303
26640
|
const sentAttris = {
|
27304
26641
|
conversation,
|
@@ -27313,58 +26650,6 @@
|
|
27313
26650
|
data: receivedMessage
|
27314
26651
|
};
|
27315
26652
|
};
|
27316
|
-
async function createSendFunction(fileType, conversation, msgBody, hooks, sendOptions) {
|
27317
|
-
const mediaMessageCreator = getMediaMessageCreator(fileType);
|
27318
|
-
if (!mediaMessageCreator) return {
|
27319
|
-
code: exports.ErrorCode.NOT_SUPPORT
|
27320
|
-
};
|
27321
|
-
const {
|
27322
|
-
success,
|
27323
|
-
message: message1,
|
27324
|
-
file
|
27325
|
-
} = await mediaMessageCreator.create(msgBody.file);
|
27326
|
-
if (!success || !message1 || !file) {
|
27327
|
-
return {
|
27328
|
-
code: exports.ErrorCode.MEDIA_EXCEPTION
|
27329
|
-
};
|
27330
|
-
}
|
27331
|
-
message1.content.user = msgBody.user;
|
27332
|
-
message1.content.extra = msgBody.extra;
|
27333
|
-
return internal_sendMessage(conversation, message1, sendOptions, {
|
27334
|
-
file,
|
27335
|
-
task: (message2, toBeUploadedFile) => {
|
27336
|
-
return new Promise(resolve => {
|
27337
|
-
const uploader = new Upload({
|
27338
|
-
token: imConfig.imInitToken,
|
27339
|
-
uploadUrl: imConfig.fileUploadUrl,
|
27340
|
-
cert: imConfig.cert,
|
27341
|
-
transformer: result => ({
|
27342
|
-
...result,
|
27343
|
-
url: imConfig.getFileAbsoluteUri(result.url)
|
27344
|
-
})
|
27345
|
-
});
|
27346
|
-
uploader.upload(toBeUploadedFile, {
|
27347
|
-
onProgress: (loaded, total) => hooks?.onProgress?.(Math.floor(loaded / total * 100)),
|
27348
|
-
onError: () => {
|
27349
|
-
resolve({
|
27350
|
-
finished: false,
|
27351
|
-
message: message2
|
27352
|
-
});
|
27353
|
-
},
|
27354
|
-
onCompleted: result => {
|
27355
|
-
mediaMessageCreator.updateMessageRemoteUrlProperty(message2, result.url);
|
27356
|
-
resolve({
|
27357
|
-
finished: true,
|
27358
|
-
message: hooks?.onComplete?.({
|
27359
|
-
url: result.url
|
27360
|
-
}) ?? message2
|
27361
|
-
});
|
27362
|
-
}
|
27363
|
-
});
|
27364
|
-
});
|
27365
|
-
}
|
27366
|
-
});
|
27367
|
-
}
|
27368
26653
|
async function internal_sendMessage(conversation, message, options, uploadOptions) {
|
27369
26654
|
const checkResult = beforeSend(conversation, message, options);
|
27370
26655
|
if (checkResult.code !== exports.ErrorCode.SUCCESS || !checkResult.message || !checkResult.sentArgs) {
|
@@ -27436,7 +26721,7 @@
|
|
27436
26721
|
SentMessageStore.addMessage(sentArgs.messageId);
|
27437
26722
|
const baseParams = {
|
27438
26723
|
localId: sentArgs.messageId,
|
27439
|
-
mediaFlag:
|
26724
|
+
mediaFlag: false,
|
27440
26725
|
mediaConstructor: message.objectId,
|
27441
26726
|
mediaAttribute: '',
|
27442
26727
|
msgPreContent: '',
|
@@ -27592,10 +26877,6 @@
|
|
27592
26877
|
}
|
27593
26878
|
getServerTime = getServerTime$1;
|
27594
26879
|
sendMessage = sendMessage$1;
|
27595
|
-
sendImageMessage = sendImageMessage$1;
|
27596
|
-
sendGIFMessage = sendGIFMessage$1;
|
27597
|
-
sendHQVoiceMessage = sendHQVoiceMessage$1;
|
27598
|
-
sendFileMessage = sendFileMessage$1;
|
27599
26880
|
recallMsg = sendRecallMessage;
|
27600
26881
|
async getRemoteHistoryMessages(conversation, options) {
|
27601
26882
|
const dialogId = getFullDialogId(conversation);
|
@@ -28893,6 +28174,12 @@
|
|
28893
28174
|
const getTopConversationList = () => {
|
28894
28175
|
return imClient.getTopConversationList();
|
28895
28176
|
};
|
28177
|
+
const registerMessageType = (messageType, isPersited, isCounted, isStatusMessage) => {
|
28178
|
+
const defined = function (content) {
|
28179
|
+
return new BaseMessage(messageType, content, isPersited, isCounted, isStatusMessage);
|
28180
|
+
};
|
28181
|
+
return defined;
|
28182
|
+
};
|
28896
28183
|
const sendMessage = async (conversation, message, options) => {
|
28897
28184
|
if (message instanceof BaseMessage === false) {
|
28898
28185
|
logger.warn('send message fail -> message parameter is not an instance of BaseMessage');
|
@@ -28910,44 +28197,6 @@
|
|
28910
28197
|
const message = new TextMessage(messageBody);
|
28911
28198
|
return sendMessage(conversation, message, options);
|
28912
28199
|
};
|
28913
|
-
const sendImageMessage = async (conversation, msgBody, hooks, sendOptions) => {
|
28914
|
-
assert('conversation', conversation, AssertRules.CONVERSATION, true);
|
28915
|
-
assert('msgBody.file', msgBody.file, file => file instanceof Blob && file.type.startsWith('image/'), true);
|
28916
|
-
const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
|
28917
|
-
logger.debug('send message ->' + paramsStr);
|
28918
|
-
_logSendBefore(conversation);
|
28919
|
-
const response = await imClient.sendImageMessage(conversation, msgBody, hooks, sendOptions);
|
28920
|
-
_logSendError(conversation, response.code);
|
28921
|
-
return response;
|
28922
|
-
};
|
28923
|
-
const sendGIFMessage = async (conversation, msgBody, hooks, sendOptions) => {
|
28924
|
-
assert('conversation', conversation, AssertRules.CONVERSATION, true);
|
28925
|
-
assert('msgBody.file', msgBody.file, file => file instanceof Blob && file.type.endsWith('image/gif'), true);
|
28926
|
-
const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
|
28927
|
-
logger.debug('send message ->' + paramsStr);
|
28928
|
-
_logSendBefore(conversation);
|
28929
|
-
const response = await imClient.sendGIFMessage(conversation, msgBody, hooks, sendOptions);
|
28930
|
-
_logSendError(conversation, response.code);
|
28931
|
-
return response;
|
28932
|
-
};
|
28933
|
-
const sendHQVoiceMessage = async (conversation, msgBody, hooks, sendOptions) => {
|
28934
|
-
assert('conversation', conversation, AssertRules.CONVERSATION, true);
|
28935
|
-
assert('msgBody.file', msgBody.file, file => file instanceof Blob, true);
|
28936
|
-
_logSendBefore(conversation);
|
28937
|
-
const response = await imClient.sendHQVoiceMessage(conversation, msgBody, hooks, sendOptions);
|
28938
|
-
_logSendError(conversation, response.code);
|
28939
|
-
return response;
|
28940
|
-
};
|
28941
|
-
const sendFileMessage = async (conversation, msgBody, hooks, sendOptions) => {
|
28942
|
-
assert('conversation', conversation, AssertRules.CONVERSATION, true);
|
28943
|
-
assert('msgBody.file', msgBody.file, file => file instanceof Blob, true);
|
28944
|
-
const paramsStr = 'conversationType:' + conversation.conversationType + ',targetId:' + conversation.targetId;
|
28945
|
-
logger.debug('send message ->' + paramsStr);
|
28946
|
-
_logSendBefore(conversation);
|
28947
|
-
const response = await imClient.sendFileMessage(conversation, msgBody, hooks, sendOptions);
|
28948
|
-
_logSendError(conversation, response.code);
|
28949
|
-
return response;
|
28950
|
-
};
|
28951
28200
|
const recallMessage = async (conversation, options) => {
|
28952
28201
|
assert('options.messageUId', options.messageUId, AssertRules.STRING, true);
|
28953
28202
|
assert('options.sentTime', options.sentTime, AssertRules.NUMBER, true);
|
@@ -29050,7 +28299,7 @@
|
|
29050
28299
|
exports.ErrorDesc = ErrorDesc;
|
29051
28300
|
exports.FileMessage = FileMessage;
|
29052
28301
|
exports.GIFMessage = GIFMessage;
|
29053
|
-
exports.HQVoiceMessage =
|
28302
|
+
exports.HQVoiceMessage = VoiceMessage;
|
29054
28303
|
exports.ImageMessage = ImageMessage;
|
29055
28304
|
exports.TextMessage = TextMessage;
|
29056
28305
|
exports.addEventListener = addEventListener;
|
@@ -29082,14 +28331,11 @@
|
|
29082
28331
|
exports.mockLogin = mockLogin;
|
29083
28332
|
exports.onceEventListener = onceEventListener;
|
29084
28333
|
exports.recallMessage = recallMessage;
|
28334
|
+
exports.registerMessageType = registerMessageType;
|
29085
28335
|
exports.removeConversation = removeConversation;
|
29086
28336
|
exports.removeEventListener = removeEventListener;
|
29087
28337
|
exports.request = request;
|
29088
28338
|
exports.saveTextMessageDraft = saveTextMessageDraft;
|
29089
|
-
exports.sendFileMessage = sendFileMessage;
|
29090
|
-
exports.sendGIFMessage = sendGIFMessage;
|
29091
|
-
exports.sendHQVoiceMessage = sendHQVoiceMessage;
|
29092
|
-
exports.sendImageMessage = sendImageMessage;
|
29093
28339
|
exports.sendMessage = sendMessage;
|
29094
28340
|
exports.sendTextMessage = sendTextMessage;
|
29095
28341
|
exports.setConversationNotificationStatus = setConversationNotificationStatus;
|