wfc.js 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148
  1. /*
  2. * Copyright (c) 2020 WildFireChat. All rights reserved.
  3. */
  4. import {EventEmitter} from 'events';
  5. import {atob, btoa} from '../util/base64.min.js';
  6. import Long from 'long';
  7. import impl from '../proto/proto.min';
  8. import Config from "../../config";
  9. import EventType from "./wfcEvent";
  10. import ConnectionStatus from "./connectionStatus";
  11. import NullUserInfo from "../model/nullUserInfo";
  12. //import avenginekit from "../av/engine/avenginekitproxy";
  13. export class WfcManager {
  14. /**
  15. * 事件通知,{@link EventType}中定义的事件,都会采用本{@link eventEmitter} 通知
  16. * @type {module:events.internal.EventEmitter}
  17. */
  18. eventEmitter = new EventEmitter();
  19. constructor() {
  20. impl.eventEmitter = {
  21. emit: (ev, ...args) => {
  22. if (ev === EventType.ConnectionStatusChanged || ev === EventType.UserOnlineEvent) {
  23. self.eventEmitter.emit(ev, ...args)
  24. } else {
  25. if (impl.connectionStatus === ConnectionStatus.ConnectionStatusConnected) {
  26. self.eventEmitter.emit(ev, ...args)
  27. } else {
  28. // ignore
  29. }
  30. }
  31. }
  32. };
  33. }
  34. /**
  35. * 初始化,请参考本demo的用法
  36. * @param {[]} args,pc 时,传入[node实例]; web 时,可以传入Config配置对象,配置项,请参考{@link Config}
  37. */
  38. init(args = []) {
  39. console.log('wfc init');
  40. impl.init(args);
  41. //avenginekit.setup(self);
  42. //self.setProxyInfo("", "192.168.1.80", 1080, "", "");
  43. console.log('wfc init end')
  44. }
  45. /**
  46. * 注册新的自定义消息
  47. *
  48. * @param {string} name
  49. * @param {number} flag 用来标识本消息是否需要存储、计数等,{@link PersistFlag}
  50. * @param {number} type 消息类型,{@link MessageContentType}
  51. * @param {class} clazz 消息对应的class
  52. */
  53. registerMessageContent(name, flag, type, clazz) {
  54. impl.registerMessageContent(name, flag, type, clazz);
  55. }
  56. /**
  57. * 获取clientId,获取用户token时,一定要通过调用此方法获取clientId,否则会连接失败。
  58. * @returns {string} clientId
  59. */
  60. getClientId() {
  61. return impl.getClientId();
  62. }
  63. /*
  64. * 启用国密加密。注意需要服务器端同步开启国密配置
  65. */
  66. useSM4() {
  67. impl.useSM4();
  68. }
  69. /**
  70. * 连接服务器
  71. * @param {string} userId 用户id
  72. * @param {string} token 用户token,生成token时,所使用的clientId,一定要通过{@link getClientId}获取
  73. * @return {number} 返回上一次活动时间。如果间隔时间较长,可以加个第一次登录的等待提示界面,在等待时同步所有的用户信息/群组信息/频道信息等。
  74. */
  75. connect(userId, token) {
  76. return impl.connect(userId, token);
  77. }
  78. /**
  79. * 设置代理,只支持socks5代理
  80. *
  81. * @param {String} host 代理host,host和ip必须至少有一个。
  82. * @param {String} ip 代理IP,host和ip必须至少有一个。
  83. * @param {number} port 代理端口
  84. * @param {String} username username
  85. * @param {String} password password
  86. */
  87. setProxyInfo(host, ip, port, username, password) {
  88. impl.setProxyInfo(host, ip, port, username, password);
  89. }
  90. /**
  91. * 设置第三方推送设备token
  92. * @param {number} pushType 推送类型,0-5 移动端已经使用了。
  93. * @param {String} token 设备token
  94. */
  95. setDeviceToken(pushType, token) {
  96. impl.setDeviceToken(pushType, token);
  97. }
  98. disconnect() {
  99. impl.disconnect();
  100. }
  101. setPackageName(packageName) {
  102. impl.setPackageName(packageName);
  103. }
  104. /**
  105. * 获取当前用户的id
  106. * @returns {string} 当前用户的id
  107. */
  108. getUserId() {
  109. return impl.getUserId();
  110. }
  111. /**
  112. * 服务器时间和本地时间的差值
  113. * @returns {number} 服务器时间和本地时间的差值
  114. */
  115. getServerDeltaTime() {
  116. return impl.getServerDeltaTime();
  117. }
  118. /**
  119. * 截图,
  120. * @returns {string} 成功返回'done',同时,图片保存到了系统剪贴板
  121. */
  122. screenShot() {
  123. return impl.screenShot();
  124. }
  125. /**
  126. * 是否成功登录
  127. * @returns {boolean}
  128. */
  129. isLogin() {
  130. return impl.isLogin();
  131. }
  132. /**
  133. * 获取连接状态
  134. * @returns {number} 连接状态,参考{@link ConnectionStatus}
  135. */
  136. getConnectionStatus() {
  137. return impl.getConnectionStatus();
  138. }
  139. /**
  140. * 设置网络策略,仅专业版支持
  141. * @param {int} strategy 网络策略。0 是自动选择;1 选择主网络;2选择备用网络
  142. *
  143. */
  144. setBackupAddressStrategy(strategy) {
  145. impl.setBackupAddressStrategy(strategy);
  146. }
  147. /**
  148. * 设置备选网络信息,仅专业版支持
  149. * @param {String} backupHost 备选网络主机地址
  150. * @param {int} backupPort 备选网络主机端口
  151. */
  152. setBackupAddress(backupHost, backupPort) {
  153. impl.setBackupAddress(backupHost, backupPort);
  154. }
  155. /**
  156. * 设置协议栈短连接UA。
  157. *
  158. * @param {string} userAgent 协议栈短连接使用的UA
  159. */
  160. setProtoUserAgent(userAgent) {
  161. impl.setProtoUserAgent(userAgent);
  162. }
  163. /**
  164. * 添加协议栈短连接自定义Header
  165. *
  166. * @param {string} header 协议栈短连接使用的UA
  167. * @param {string} value 协议栈短连接使用的UA
  168. */
  169. addHttpHeader(header, value) {
  170. impl.addHttpHeader(header, value)
  171. }
  172. /**
  173. * 设备从睡眠中恢复
  174. */
  175. onAppResume() {
  176. impl.onAppResume();
  177. }
  178. /**
  179. * 设备进入睡眠状态
  180. */
  181. onAppSuspend() {
  182. impl.onAppSuspend();
  183. }
  184. /**
  185. * 已废弃,请使用{@link getFavGroupList}
  186. * 获取我保存到通讯录的群组信息列表
  187. * @returns {[GroupInfo]} 参考{@link GroupInfo}
  188. */
  189. getMyGroupList() {
  190. return impl.getMyGroupList();
  191. }
  192. /**
  193. * 获取我保存到通讯录的群组信息列表
  194. * @returns {[GroupInfo]} 参考{@link GroupInfo}
  195. */
  196. getFavGroupList() {
  197. let groupInfos = impl.getMyGroupList();
  198. groupInfos.map(info => {
  199. if (!info.portrait || info.portrait.startsWith(Config.APP_SERVER)) {
  200. info.portrait = this.defaultGroupPortrait(info);
  201. }
  202. return info;
  203. })
  204. return groupInfos;
  205. }
  206. /**
  207. * 获取用户的displayName
  208. * @param {string} userId 用户id
  209. * @returns {string} 用户displayName
  210. */
  211. getUserDisplayName(userId) {
  212. let userInfo = this.getUserInfo(userId, false);
  213. if (!userInfo) {
  214. return '<' + userId + '>';
  215. }
  216. return userInfo.friendAlias ? userInfo.friendAlias : (userInfo.displayName ? userInfo.displayName : '<' + userId + '>');
  217. }
  218. /**
  219. * 获取用户在群里面的displayName
  220. * @param {string} groupId 群id
  221. * @param {string} userId 用户id
  222. * @returns {string} 用户在群里面的displayName
  223. */
  224. getGroupMemberDisplayName(groupId, userId) {
  225. let userInfo = this.getUserInfo(userId, false, groupId);
  226. if (!userInfo) {
  227. return '<' + userId + '>';
  228. }
  229. return userInfo.groupAlias ? userInfo.groupAlias : (userInfo.friendAlias ? userInfo.friendAlias : (userInfo.displayName ? userInfo.displayName : '<' + userId + '>'))
  230. }
  231. getUserDisplayNameEx(userInfo) {
  232. return userInfo.friendAlias ? userInfo.friendAlias : (userInfo.displayName ? userInfo.displayName : '<' + userInfo.uid + '>');
  233. }
  234. getGroupMemberDisplayNameEx(userInfo) {
  235. return userInfo.groupAlias ? userInfo.groupAlias : (userInfo.friendAlias ? userInfo.friendAlias : (userInfo.displayName ? userInfo.displayName : '<' + userInfo.uid + '>'))
  236. }
  237. /**
  238. * 获取用户信息
  239. * @param {string} userId 用户id
  240. * @param {boolean} refresh 是否刷新用户信息,如果刷新的话,且用户信息有更新,会通过{@link eventEmitter}进行通知,事件的名字是{@link EventType.UserInfosUpdate }
  241. * @param {string} groupId
  242. * @returns {UserInfo}
  243. */
  244. getUserInfo(userId, refresh = false, groupId = '') {
  245. let userInfo = impl.getUserInfo(userId, refresh, groupId);
  246. if (!userInfo.portrait || userInfo.portrait.startsWith(Config.APP_SERVER)) {
  247. userInfo.portrait = this.defaultUserPortrait(userInfo);
  248. }
  249. return userInfo;
  250. }
  251. /**
  252. * 获取用户信息
  253. * @param {string} userId 用户ID
  254. * @param {boolean} refresh 是否强制从服务器更新,如果本地没有或者强制,会从服务器刷新
  255. * @param {function (UserInfo)} success 成功回调,如果本地有该用户信息,则通过回调返回本地的用户信息;如果本地没有,则从服务端拉取该用户信息,并通过回调返回
  256. * @param {function (number)} fail 失败回调
  257. */
  258. getUserInfoEx(userId, refresh, success, fail) {
  259. impl.getUserInfoEx(userId, refresh, success, fail);
  260. }
  261. /**
  262. * 批量从服务端拉取用户信息
  263. * @param {[string]} userIds 用户ids
  264. * @param {function ([UserInfo])} successCB 成功回调
  265. * @param {function (Number)} failCB 失败回调
  266. */
  267. getUserInfosEx(userIds, successCB, failCB) {
  268. impl.getUserInfosEx(userIds, userInfos => {
  269. userInfos.forEach((u) => {
  270. if (!u.portrait || u.portrait.startsWith(Config.APP_SERVER)) {
  271. u.portrait = this.defaultUserPortrait(u);
  272. }
  273. });
  274. successCB && successCB(userInfos);
  275. }, err => {
  276. failCB && failCB(err);
  277. });
  278. }
  279. /**
  280. * 批量获取用户信息
  281. * @param {[string]} userIds 用户ids
  282. * @param {string} groupId 群组id
  283. * @returns {[UserInfo]}
  284. */
  285. getUserInfos(userIds, groupId) {
  286. let userInfos = impl.getUserInfos(userIds, groupId);
  287. userInfos.forEach((u) => {
  288. if (!u.portrait || u.portrait.startsWith(Config.APP_SERVER)) {
  289. u.portrait = this.defaultUserPortrait(u)
  290. }
  291. });
  292. return userInfos;
  293. }
  294. /**
  295. * 服务端搜索用户
  296. * @param {string} keyword 搜索关键字
  297. * @param {number} searchType 搜索类型,可选值参考{@link SearchType}
  298. * @param {number} page 页数,如果searchType是0,每次搜索20个,可以指定page。如果searchType非0,只能搜索一个,page无意义
  299. * @param {function (keyword, [UserInfo])} successCB
  300. * @param {function (number)}failCB
  301. * @returns {Promise<void>}
  302. */
  303. async searchUser(keyword, searchType, page, successCB, failCB) {
  304. impl.searchUser(keyword, searchType, page, (keyword, userInfos) => {
  305. userInfos.forEach((u) => {
  306. if (!u.portrait || u.portrait.startsWith(Config.APP_SERVER)) {
  307. u.portrait = this.defaultUserPortrait(u)
  308. }
  309. });
  310. successCB && successCB(keyword, userInfos);
  311. }, failCB);
  312. }
  313. /**
  314. * 本地搜索好友
  315. * @param keyword 搜索关键字
  316. * @returns {[UserInfo]}
  317. */
  318. searchFriends(keyword) {
  319. let userInfos = impl.searchFriends(keyword);
  320. userInfos.forEach((u) => {
  321. if (!u.portrait || u.portrait.startsWith(Config.APP_SERVER)) {
  322. u.portrait = this.defaultUserPortrait(u)
  323. }
  324. });
  325. return userInfos;
  326. }
  327. /**
  328. * 本地搜索群组
  329. * @param keyword 搜索关键字
  330. * @returns {[GroupSearchResult]}
  331. */
  332. searchGroups(keyword) {
  333. let results = impl.searchGroups(keyword);
  334. results.forEach(r => {
  335. let info = r.groupInfo;
  336. if (!info.portrait || info.portrait.startsWith(Config.APP_SERVER)) {
  337. info.portrait = this.defaultGroupPortrait(info);
  338. }
  339. })
  340. return results;
  341. }
  342. /**
  343. * 获取收到的好友请求
  344. * @returns {[FriendRequest]}
  345. */
  346. getIncommingFriendRequest() {
  347. return impl.getIncommingFriendRequest();
  348. }
  349. /**
  350. * 获取发送出去的好友请求
  351. * @returns {[FriendRequest]}
  352. */
  353. getOutgoingFriendRequest() {
  354. return impl.getOutgoingFriendRequest();
  355. }
  356. /**
  357. * 获取单条好友请求
  358. * @param {string} userId 对方的用户id
  359. * @param {boolean} incoming 是否是收到的好友请求
  360. * @return {FriendRequest|null}
  361. */
  362. getOneFriendRequest(userId, incoming = true) {
  363. return impl.getOneFriendRequest(userId, incoming);
  364. }
  365. /**
  366. * 从服务端加载好友请求,如果有更新,会通过{@link eventEmitter}通知
  367. */
  368. loadFriendRequestFromRemote() {
  369. impl.loadFriendRequestFromRemote(Long.ZERO);
  370. }
  371. /**
  372. * 获取未读的好友请求数
  373. * @returns {number}
  374. */
  375. getUnreadFriendRequestCount() {
  376. return impl.getUnreadFriendRequestCount();
  377. }
  378. /**
  379. * 清除好友请求未读状态
  380. */
  381. clearUnreadFriendRequestStatus() {
  382. impl.clearUnreadFriendRequestStatus();
  383. }
  384. /**
  385. * 删除好友
  386. * @param {string} userId 好友id
  387. * @param {function ()} successCB
  388. * @param {function (number) }failCB
  389. * @returns {Promise<void>}
  390. */
  391. async deleteFriend(userId, successCB, failCB) {
  392. impl.deleteFriend(userId, successCB, failCB);
  393. }
  394. /**
  395. * 处理好友请求
  396. * @param {string} userId 发送好友请求的用户的id
  397. * @param {boolean} accept true,接受好友请求;false,拒绝好友请求
  398. * @param {string} extra 一些额外信息,可用来实现好友来源等,推荐使用json格式
  399. * @param {function ()} successCB
  400. * @param {function (number)} failCB
  401. * @returns {Promise<void>}
  402. */
  403. async handleFriendRequest(userId, accept, extra, successCB, failCB) {
  404. impl.handleFriendRequest(userId, accept, extra, successCB, failCB);
  405. }
  406. /**
  407. * 判断用户是否被加入了黑名单
  408. * @param userId
  409. * @returns {boolean}
  410. */
  411. isBlackListed(userId) {
  412. return impl.isBlackListed(userId);
  413. }
  414. /**
  415. * 获取黑名单
  416. * @returns {[string]}
  417. */
  418. getBlackList() {
  419. return impl.getBlackList();
  420. }
  421. /**
  422. * 设置黑名单
  423. * @param {string} userId 用户id
  424. * @param {boolean} block true,加入黑名单;false,移除黑名单
  425. * @param {function ()} successCB
  426. * @param {function (number)} failCB
  427. */
  428. setBlackList(userId, block, successCB, failCB) {
  429. impl.setBlackList(userId, block, successCB, failCB);
  430. }
  431. /**
  432. * 获取好友列表,返回的时好友id数组
  433. * @param {boolean} fresh 是否刷新好友信息,如果刷新,且有更新的话,会通过{@link eventEmitter}通知
  434. * @returns {[string]}
  435. */
  436. getMyFriendList(fresh = false) {
  437. return impl.getMyFriendList(fresh);
  438. }
  439. /**
  440. * 好友列表
  441. * @returns {[Friend]}
  442. */
  443. getFriendList(fresh = false) {
  444. return impl.getFriendList(fresh);
  445. }
  446. /**
  447. * 获取好友别名
  448. * @param {string} userId
  449. * @returns {string}
  450. */
  451. getFriendAlias(userId) {
  452. return impl.getFriendAlias(userId);
  453. }
  454. getFriendExtra(userId) {
  455. return impl.getFriendExtra(userId);
  456. }
  457. /**
  458. * 设置好友别名
  459. * @param {string} userId 用户id
  460. * @param {string} alias 别名
  461. * @param {function ()} successCB
  462. * @param {function (number)} failCB
  463. * @returns {Promise<void>}
  464. */
  465. async setFriendAlias(userId, alias, successCB, failCB) {
  466. impl.setFriendAlias(userId, alias, successCB, failCB);
  467. }
  468. /**
  469. * 创建群组
  470. * @param {string | null} groupId 群组id,一般情况下,传null;如果有自己的用户系统,自己维护群信息,那么可以传群id
  471. * @param {number} groupType 群类型,可参考 {@link GroupType }
  472. * @param {string} name 群名称
  473. * @param {string} portrait 群头像的链接
  474. * @param {string} groupExtra 群组扩展信息
  475. * @param {[string]} memberIds 群成员id列表
  476. * @param {string} memberExtra 群组成员扩展信息
  477. * @param {[number]} lines 会话线路,默认传[0]即可
  478. * @param {CreateGroupNotification} notifyContent 通知信息,默认传null,服务端会生成默认通知
  479. * @param {function (string)} successCB 回调通知群id
  480. * @param {function (number)} failCB
  481. * @returns {Promise<void>}
  482. */
  483. async createGroup(groupId, groupType, name, portrait, groupExtra, memberIds = [], memberExtra = '', lines = [0], notifyContent, successCB, failCB) {
  484. impl.createGroup(groupId, groupType, name, portrait == null ? "" : portrait, groupExtra, memberIds, memberExtra, lines, notifyContent, successCB, failCB);
  485. }
  486. /**
  487. * 设置群管理员
  488. * @param {string} groupId 群id
  489. * @param {boolean} isSet true,设置;false,取消设置
  490. * @param {[string]} memberIds 将被设置为管理或取消管理远的群成员的用户id
  491. * @param {[number]} lines 默认传[0]即可
  492. * @param {Object} notifyContent 默认传null即可
  493. * @param {function ()} successCB
  494. * @param {function (number)} failCB
  495. * @returns {Promise<void>}
  496. */
  497. async setGroupManager(groupId, isSet, memberIds, lines, notifyContent, successCB, failCB) {
  498. impl.setGroupManager(groupId, isSet, memberIds, lines, notifyContent, successCB, failCB);
  499. }
  500. /**
  501. * 获取群信息
  502. * @param {string} groupId 群id
  503. * @param {boolean} refresh 是否刷新,如果刷新,且有更新的话,会通过{@link eventEmitter}通知
  504. * @returns {GroupInfo}
  505. */
  506. getGroupInfo(groupId, refresh = false) {
  507. let info = impl.getGroupInfo(groupId, refresh);
  508. if (!info.portrait || info.portrait.startsWith(Config.APP_SERVER)) {
  509. info.portrait = this.defaultGroupPortrait(info);
  510. }
  511. return info;
  512. }
  513. /**
  514. * 批量获取群信息
  515. * @param {[string]} groupIds 群id
  516. * @param {boolean} refresh 是否刷新,如果刷新,且有更新的话,会通过{@link eventEmitter}通知
  517. * @returns {[GroupInfo]}
  518. */
  519. getGroupInfos(groupIds, refresh = false) {
  520. let infos = impl.getGroupInfos(groupIds, refresh);
  521. infos.forEach(info => {
  522. if (!info.portrait || info.portrait.startsWith(Config.APP_SERVER)) {
  523. info.portrait = this.defaultGroupPortrait(info);
  524. }
  525. })
  526. return infos;
  527. }
  528. /**
  529. * 获取群信息
  530. * @param {string} groupId 群id
  531. * @param {boolean} refresh 是否刷新,如果刷新,且有更新的话,会通过{@link eventEmitter}通知
  532. * @param {function (GroupInfo)} successCB 成功回调
  533. * @param {function (number)} failCB 失败回调
  534. */
  535. getGroupInfoEx(groupId, refresh = false, successCB, failCB) {
  536. impl.getGroupInfoEx(groupId, refresh, info => {
  537. if (!info.portrait || info.portrait.startsWith(Config.APP_SERVER)) {
  538. info.portrait = this.defaultGroupPortrait(info);
  539. }
  540. successCB && successCB(info);
  541. }, failCB);
  542. }
  543. /**
  544. * 添加群成员
  545. * @param {string} groupId 群组id
  546. * @param {[string]} memberIds 新添加的群成员id
  547. * @param {string} extra 群成员扩展信息
  548. * @param {[number]} notifyLines
  549. * @param {AddGroupMemberNotification} notifyMessageContent
  550. * @param successCB
  551. * @param failCB
  552. */
  553. addGroupMembers(groupId, memberIds, extra, notifyLines, notifyMessageContent, successCB, failCB) {
  554. impl.addGroupMembers(groupId, memberIds, extra, notifyLines, notifyMessageContent, successCB, failCB);
  555. }
  556. /**
  557. * 获取群成员id列表
  558. * @param {string} groupId 群id
  559. * @param {boolean} fresh 是否刷新,刷新时,如果有更新,会通过{@link eventEmitter}通知
  560. * @returns {[string]} 群成员用户id列表
  561. */
  562. getGroupMemberIds(groupId, fresh = false) {
  563. return impl.getGroupMemberIds(groupId, fresh);
  564. }
  565. /**
  566. * 获取群成员信息
  567. * @param {string} groupId 群id
  568. * @param {boolean} fresh 是否刷新
  569. * @returns {[GroupMember]} 群成员信息
  570. */
  571. getGroupMembers(groupId, fresh = false) {
  572. return impl.getGroupMembers(groupId, fresh);
  573. }
  574. /**
  575. * 根据群成员类型获取群成员列表
  576. * @param {string} groupId
  577. * @param {number} memberType,可选值参考{@link GroupMemberType}
  578. * @return {[GroupMember]} 群成员列表
  579. */
  580. getGroupMembersByType(groupId, memberType) {
  581. return impl.getGroupMembersByType(groupId, memberType);
  582. }
  583. /**
  584. * 获取群成员信息
  585. * @param {string} groupId 群id
  586. * @param {boolean} fresh 是否强制从服务器更新,如果不刷新则从本地缓存中读取
  587. * @param {function ([GroupMember])} successCB
  588. * @param {function (number)} failCB
  589. */
  590. getGroupMembersEx(groupId, fresh = false, successCB, failCB) {
  591. impl.getGroupMembersEx(groupId, fresh, successCB, failCB);
  592. }
  593. /**
  594. * 获取单个群成员信息
  595. * @param {string} groupId 群id
  596. * @param {string} memberId 群成员id
  597. * @returns {GroupMember} 群成员信息
  598. */
  599. getGroupMember(groupId, memberId) {
  600. return impl.getGroupMember(groupId, memberId);
  601. }
  602. /**
  603. * 将用户从群里移除
  604. * @param {string} groupId 群id
  605. * @param {[string]} memberIds 将要被移除的群成员id列表
  606. * @param {[]} notifyLines 默认传[0]即可
  607. * @param {KickoffGroupMemberNotification} notifyMsg 默认传null即可
  608. * @param {function ()} successCB
  609. * @param {function (number)} failCB
  610. */
  611. kickoffGroupMembers(groupId, memberIds, notifyLines, notifyMsg, successCB, failCB) {
  612. impl.kickoffGroupMembers(groupId, memberIds, notifyLines, notifyMsg, successCB, failCB);
  613. }
  614. /**
  615. * 对群成员禁言
  616. * @param {string} groupId 群id
  617. * @param {boolean} isSet true,禁言;false,取消禁言
  618. * @param {[string]} memberIds 群成员id列表
  619. * @param {[number]} notifyLines 默认传[0]即可
  620. * @param {MessageContent} notifyMsg 默认传null即可
  621. * @param {function ()} successCB 成功回调
  622. * @param {function (number)} failCB 失败回调
  623. */
  624. muteGroupMembers(groupId, isSet, memberIds = [], notifyLines = [], notifyMsg, successCB, failCB) {
  625. impl.muteOrAllowGroupMembers(groupId, isSet, false, memberIds, notifyLines, notifyMsg, successCB, failCB);
  626. }
  627. /**
  628. * 群全局禁言之后,允许白名单成员发言
  629. * @param {string} groupId 群id
  630. * @param {boolean} isSet true,加入白名单,允许发言;false,移除白名单,禁止发言
  631. * @param {[string]} memberIds 群成员id列表
  632. * @param {[number]} notifyLines 默认传[0]即可
  633. * @param {MessageContent} notifyMsg 默认传null即可
  634. * @param {function ()} successCB 成功回调
  635. * @param {function (number)} failCB 失败回调
  636. */
  637. allowGroupMembers(groupId, isSet, memberIds = [], notifyLines = [], notifyMsg, successCB, failCB) {
  638. impl.muteOrAllowGroupMembers(groupId, isSet, true, memberIds, notifyLines, notifyMsg, successCB, failCB);
  639. }
  640. /**
  641. * 退出群组
  642. * @param groupId 群id
  643. * @param {[]} lines 默认传[0]即可
  644. * @param {KickoffGroupMemberNotification} notifyMessageContent 默认传null即可
  645. * @param successCB
  646. * @param failCB
  647. * @returns {Promise<void>}
  648. */
  649. async quitGroup(groupId, lines, notifyMessageContent, successCB, failCB) {
  650. impl.quitGroup(groupId, lines, notifyMessageContent, successCB, failCB);
  651. }
  652. /**
  653. * 解散群组
  654. * @param {string} groupId 群组id
  655. * @param {[]} lines 默认传[0]即可
  656. * @param {KickoffGroupMemberNotification} notifyMessageContent 默认传null即可
  657. * @param {function ()} successCB
  658. * @param {function (number)} failCB
  659. * @returns {Promise<void>}
  660. */
  661. async dismissGroup(groupId, lines, notifyMessageContent, successCB, failCB) {
  662. impl.dismissGroup(groupId, lines, notifyMessageContent, successCB, failCB);
  663. }
  664. /**
  665. * 修改群信息
  666. * @param {string} groupId 群id
  667. * @param {number} type 修改信息所属类型,可选值参考{@link ModifyGroupInfoType}
  668. * @param {string} newValue 准备修改成什么
  669. * @param {[number]} lines
  670. * @param {GroupNotificationContent} notifyMessageContent
  671. * @param successCB
  672. * @param failCB
  673. * @returns {Promise<void>}
  674. */
  675. async modifyGroupInfo(groupId, type, newValue, lines, notifyMessageContent, successCB, failCB) {
  676. impl.modifyGroupInfo(groupId, type, newValue, lines, notifyMessageContent, successCB, failCB);
  677. }
  678. /**
  679. * 修改我在群组的别名
  680. * @param {string} groupId 群id
  681. * @param {string} alias 别名
  682. * @param lines
  683. * @param notifyMessageContent
  684. * @param successCB
  685. * @param failCB
  686. * @returns {Promise<void>}
  687. */
  688. async modifyGroupAlias(groupId, alias, lines, notifyMessageContent, successCB, failCB) {
  689. impl.modifyGroupAlias(groupId, alias, lines, notifyMessageContent, successCB, failCB);
  690. }
  691. /**
  692. * 修改群成员在群组的别名
  693. * @param {string} groupId 群id
  694. * @param {string} memberId 群成员id
  695. * @param {string} alias 别名
  696. * @param lines
  697. * @param notifyMessageContent
  698. * @param successCB
  699. * @param failCB
  700. * @returns {Promise<void>}
  701. */
  702. async modifyGroupMemberAlias(groupId, memberId, alias, lines, notifyMessageContent, successCB, failCB) {
  703. impl.modifyGroupMemberAlias(groupId, memberId, alias, lines, notifyMessageContent, successCB, failCB);
  704. }
  705. /**
  706. * 修改群成员在群组的附加信息
  707. * @param {string} groupId 群id
  708. * @param {string} memberId 群成员id
  709. * @param {string} extra 群成员附加信息
  710. * @param lines
  711. * @param notifyMessageContent
  712. * @param successCB
  713. * @param failCB
  714. * @returns {Promise<void>}
  715. */
  716. async modifyGroupMemberExtra(groupId, memberId, extra, lines, notifyMessageContent, successCB, failCB) {
  717. impl.modifyGroupMemberExtra(groupId, memberId, extra, lines, notifyMessageContent, successCB, failCB);
  718. }
  719. /**
  720. * 转移群主
  721. * @param {string} groupId 群id
  722. * @param {string} newOwner 新群主的id
  723. * @param lines
  724. * @param notifyMessageContent
  725. * @param successCB
  726. * @param failCB
  727. */
  728. transferGroup(groupId, newOwner, lines, notifyMessageContent, successCB, failCB) {
  729. impl.transferGroup(groupId, newOwner, lines, notifyMessageContent, successCB, failCB);
  730. }
  731. /**
  732. * 获取保存到通讯录的群id列表
  733. * @returns {[string]}
  734. */
  735. getFavGroups() {
  736. return impl.getFavGroups();
  737. }
  738. /**
  739. * 判断群是否保存到了通讯录
  740. * @param {string} groupId
  741. * @returns {boolean}
  742. */
  743. isFavGroup(groupId) {
  744. return impl.isFavGroup(groupId);
  745. }
  746. /**
  747. * 将群保存到通讯录或移除通讯录
  748. * @param {string} groupId 群id
  749. * @param {boolean} fav true,保存到通讯录;false,从通讯录移除
  750. * @param {function ()} successCB
  751. * @param {function (number)} failCB
  752. * @returns {Promise<void>}
  753. */
  754. async setFavGroup(groupId, fav, successCB, failCB) {
  755. impl.setFavGroup(groupId, fav, successCB, failCB);
  756. }
  757. /**
  758. * 获取用户设置,保存格式可以理解为:scope + key => value
  759. * @param {number} scope 命名空间,可选值参考{@link UserSettingScope}
  760. * @param {string} key key
  761. * @returns {string} 设置的key对应的value
  762. */
  763. getUserSetting(scope, key) {
  764. return impl.getUserSetting(scope, key);
  765. }
  766. /**
  767. * 获取某个命名空间下的所有设置
  768. * @param scope 命名空间,可选值参考{@link UserSettingScope}
  769. * @returns {Map} key-value
  770. */
  771. getUserSettings(scope) {
  772. return impl.getUserSettings(scope);
  773. }
  774. /**
  775. * 设置或更新用户设置
  776. * @param {number} scope 命名空间
  777. * @param {string} key 设置的key
  778. * @param {string} value 设置的value
  779. * @param {function ()} successCB 成功回调
  780. * @param {function (number)} failCB 失败回调
  781. * @returns {Promise<void>}
  782. */
  783. async setUserSetting(scope, key, value, successCB, failCB) {
  784. impl.setUserSetting(scope, key, value, successCB, failCB);
  785. }
  786. /**
  787. * 修改个人信息
  788. * @param {[ModifyMyInfoEntry]} modifyMyInfoEntries 需要修改的信息列表,pc端,一次只允许修改一个项。
  789. * @param successCB
  790. * @param failCB
  791. */
  792. modifyMyInfo(modifyMyInfoEntries, successCB, failCB) {
  793. impl.modifyMyInfo(modifyMyInfoEntries, successCB, failCB);
  794. }
  795. /**
  796. * 是否全局免打扰
  797. * @returns {boolean}
  798. */
  799. isGlobalSlient() {
  800. return impl.isGlobalSlient();
  801. }
  802. /**
  803. * 设置全局免打扰
  804. * @param {boolean} silent
  805. * @param {function ()} successCB
  806. * @param failCB
  807. */
  808. setGlobalSlient(silent, successCB, failCB) {
  809. impl.setGlobalSlient(silent, successCB, failCB);
  810. }
  811. /**
  812. * 是否隐藏通知详情
  813. * @returns {boolean}
  814. */
  815. isHiddenNotificationDetail() {
  816. return impl.isHiddenNotificationDetail();
  817. }
  818. /**
  819. * 设置或取消设置隐藏通知详情
  820. * @param {boolean} hide 是否隐藏通知详情
  821. * @param {function ()} successCB
  822. * @param {function (number)} failCB
  823. * @returns {Promise<void>}
  824. */
  825. async setHiddenNotificationDetail(hide, successCB, failCB) {
  826. impl.setHiddenNotificationDetail(hide, successCB, failCB);
  827. }
  828. /**
  829. * 是否隐藏群成员昵称
  830. * @param {string} groupId 群id
  831. * @returns {boolean}
  832. */
  833. isHiddenGroupMemberName(groupId) {
  834. return impl.isHiddenGroupMemberName(groupId);
  835. }
  836. /**
  837. * 设置或取消设置隐藏群成员昵称
  838. * @param {string} groupId 群id
  839. * @param {boolean} hide 是否隐藏
  840. * @param {function ()} successCB
  841. * @param {function (number)} failCB
  842. * @returns {Promise<void>}
  843. */
  844. async setHiddenGroupMemberName(groupId, hide, successCB, failCB) {
  845. impl.setHiddenGroupMemberName(groupId, hide, successCB, failCB);
  846. }
  847. /**
  848. * 加入聊天室
  849. * @param {string} chatroomId 聊天室id
  850. * @param {function ()} successCB
  851. * @param {function (number)} failCB
  852. * @returns {Promise<void>}
  853. */
  854. async joinChatroom(chatroomId, successCB, failCB) {
  855. impl.joinChatroom(chatroomId, successCB, failCB);
  856. }
  857. /**
  858. * 退出聊天室
  859. * @param {string} chatroomId 聊天室id
  860. * @param {function ()} successCB
  861. * @param {function (number)} failCB
  862. * @returns {Promise<void>}
  863. */
  864. async quitChatroom(chatroomId, successCB, failCB) {
  865. impl.quitChatroom(chatroomId, successCB, failCB);
  866. }
  867. /**
  868. * 获取聊天室信息
  869. * @param {string} chatroomId 聊天是id
  870. * @param {number} updateDt 传当前时间对应的毫秒数
  871. * @param {function (ChatRoomInfo)} successCB
  872. * @param failCB
  873. * @returns {Promise<void>}
  874. */
  875. async getChatroomInfo(chatroomId, updateDt, successCB, failCB) {
  876. return impl.getChatroomInfo(chatroomId, updateDt, successCB, failCB);
  877. }
  878. /**
  879. * 获取聊天室成员信息
  880. * @param {string} chatroomId 聊天室id
  881. * @param {number} maxCount 最多获取多少个聊天室成员信息
  882. * @param {function (ChatRoomMemberInfo)} successCB
  883. * @param {function (number)} failCB
  884. * @returns {Promise<void>}
  885. */
  886. async getChatroomMemberInfo(chatroomId, maxCount, successCB, failCB) {
  887. impl.getChatroomMemberInfo(chatroomId, maxCount, successCB, failCB);
  888. }
  889. /**
  890. * 创建频道
  891. * @param {string} name 频道名称
  892. * @param {string} portrait 频道头像的链接地址
  893. * @param {string} desc 描述
  894. * @param {string} extra 额外信息
  895. * @param {function (string)} successCB 创建成功,会回调通知channelId
  896. * @param {function (number)} failCB
  897. */
  898. createChannel(name, portrait, desc, extra, successCB, failCB) {
  899. impl.createChannel(name, portrait, desc, extra, successCB, failCB);
  900. }
  901. /**
  902. * 获取频道信息
  903. * @param {string} channelId 频道id
  904. * @param {boolean} refresh 是否强制刷新
  905. * @returns {ChannelInfo|NullChannelInfo}
  906. */
  907. getChannelInfo(channelId, refresh) {
  908. return impl.getChannelInfo(channelId, refresh);
  909. }
  910. /**
  911. * 修改频道信息
  912. * @param {string} channelId 频道id
  913. * @param {number} type 修改什么,可选值参考{@link ModifyChannelInfoType}
  914. * @param {string} newValue 修改后的值
  915. * @param {function ()} successCB
  916. * @param {function (number)} failCB
  917. * @returns {Promise<void>}
  918. */
  919. async modifyChannelInfo(channelId, type, newValue, successCB, failCB) {
  920. impl.modifyChannelInfo(channelId, type, newValue, successCB, failCB);
  921. }
  922. /**
  923. * 搜索频道
  924. * @param {string} keyword 关键字
  925. * @param {boolean} fuzzy 是否模糊搜索
  926. * @param {function (keyword, [ChannelInfo])} successCB
  927. * @param {function (number)} failCB
  928. */
  929. searchChannel(keyword, fuzzy, successCB, failCB) {
  930. impl.searchChannel(keyword, successCB, failCB);
  931. }
  932. /**
  933. * 是否已收听/关注某个频道
  934. * @param {string} channelId 频道id
  935. * @returns {boolean}
  936. */
  937. isListenedChannel(channelId) {
  938. return impl.isListenedChannel(channelId);
  939. }
  940. /**
  941. * 收听或取消收听频道
  942. * @param {string} channelId 频道id
  943. * @param {boolean} listen true,收听;false,取消收听
  944. * @param {function ()} successCB
  945. * @param {function (number)} failCB
  946. * @returns {Promise<void>}
  947. */
  948. async listenChannel(channelId, listen, successCB, failCB) {
  949. impl.listenChannel(channelId, listen, successCB, failCB);
  950. }
  951. /**
  952. * 获取自己创建的频道id列表
  953. * @returns {[string]}
  954. */
  955. getMyChannels() {
  956. return impl.getMyChannels();
  957. }
  958. /**
  959. * 获取所收听的频道id列表
  960. * @returns {[string]}
  961. */
  962. getListenedChannels() {
  963. return impl.getListenedChannels();
  964. }
  965. /**
  966. * 销毁频道
  967. * @param {string} channelId 频道id
  968. * @param {function ()} successCB
  969. * @param {function (number)} failCB
  970. * @returns {Promise<void>}
  971. */
  972. async destoryChannel(channelId, successCB, failCB) {
  973. impl.destoryChannel(channelId, successCB, failCB);
  974. }
  975. /**
  976. * 获取会话列表
  977. * @param {[number]} types 想获取的会话类型,可选值参考{@link ConversationType}
  978. * @param {[0]} lines 想获取哪些会话线路的会话,默认传[0]即可
  979. * @returns {[ConversationInfo]}
  980. */
  981. getConversationList(types, lines) {
  982. return impl.getConversationList(types, lines);
  983. }
  984. /**
  985. * 获取会话详情
  986. * @param {Conversation} conversation
  987. * @returns {ConversationInfo}
  988. */
  989. getConversationInfo(conversation) {
  990. return impl.getConversationInfo(conversation);
  991. }
  992. /**
  993. * 搜索会话
  994. * @param {string} keyword 关键字
  995. * @param {[number]} types 从哪些类型的会话中进行搜索,可选值可参考{@link ConversationType}
  996. * @param {[number]} lines 从哪些会话线路进行搜索,默认传[0]即可
  997. * @returns {[ConversationSearchResult]}
  998. */
  999. searchConversation(keyword, types = [0, 1, 2], lines = [0, 1, 2]) {
  1000. return impl.searchConversation(keyword, types, lines);
  1001. }
  1002. /**
  1003. * 删除会话
  1004. * @param {Conversation} conversation 想删除的目标会话
  1005. * @param {boolean} clearMsg 是否已删除的会话的消息
  1006. * @returns {Promise<void>}
  1007. */
  1008. async removeConversation(conversation, clearMsg) {
  1009. impl.removeConversation(conversation, clearMsg);
  1010. }
  1011. /**
  1012. * 会话置顶或取消置顶
  1013. * @param {Conversation} conversation 需要置顶或取消置顶的会话
  1014. * @param {number} top > 0, 置顶,可以根据这个值进行置顶排序;0,取消置顶
  1015. * @param {function ()} successCB
  1016. * @param {function (number)} failCB
  1017. */
  1018. setConversationTop(conversation, top, successCB, failCB) {
  1019. impl.setConversationTop(conversation, top, successCB, failCB);
  1020. }
  1021. /**
  1022. * 会话免打扰或取消免打扰
  1023. * @param {Conversation} conversation 目标会话
  1024. * @param {boolean} silent true,设置为免打扰;false,取消免打扰
  1025. * @param {function ()} successCB
  1026. * @param {function (number)} failCB
  1027. */
  1028. setConversationSlient(conversation, silent, successCB, failCB) {
  1029. impl.setConversationSlient(conversation, silent, successCB, failCB);
  1030. }
  1031. /**
  1032. * 保存会话草稿
  1033. * @param {Conversation} conversation 目标会话
  1034. * @param {string} draft 草稿,传''时,相当于清楚会话草稿
  1035. */
  1036. setConversationDraft(conversation, draft = '') {
  1037. impl.setConversationDraft(conversation, draft);
  1038. }
  1039. /**
  1040. * 设置会话时间错,当会话不存在时,会创建一个新的会话。
  1041. * @param {Conversation} conversation
  1042. * @param {number} timestamp
  1043. */
  1044. setConversationTimestamp(conversation, timestamp) {
  1045. impl.setConversationTimestamp(conversation, timestamp);
  1046. }
  1047. /**
  1048. * 获取未读消息数
  1049. * @param {[number]} types 获取未读数时,包含哪些类型的会话,可选值参考{@link ConversationType}
  1050. * @param {[number]} lines 获取未读数时,包含哪些会话线路,默认传[0]即可
  1051. * @returns {UnreadCount}
  1052. */
  1053. getUnreadCount(types = [0, 1, 2], lines = [0]) {
  1054. return impl.getUnreadCount(types, lines);
  1055. }
  1056. /**
  1057. * 获取某个会话的未读消息数
  1058. * @param {Conversation} conversation 目标会话
  1059. * @returns {UnreadCount}
  1060. */
  1061. getConversationUnreadCount(conversation) {
  1062. return impl.getConversationUnreadCount(conversation);
  1063. }
  1064. /**
  1065. * 清楚会话消息未读状态
  1066. * @param {Conversation} conversation 目标会话
  1067. */
  1068. clearConversationUnreadStatus(conversation) {
  1069. impl.clearConversationUnreadStatus(conversation);
  1070. }
  1071. /**
  1072. * 将会话最后一条消息置为未读
  1073. * @param {Conversation} conversation 会话
  1074. * @param {boolean} syncToOtherClient 是否同步给其他端
  1075. * @return {boolean} 是否操作成功
  1076. */
  1077. markConversationAsUnread(conversation, syncToOtherClient) {
  1078. return impl.markConversationAsUnread(conversation, syncToOtherClient);
  1079. }
  1080. /**
  1081. * 清除单条消息的未读状态
  1082. * @param messageId
  1083. */
  1084. clearMessageUnreadStatus(messageId) {
  1085. impl.clearMessageUnreadStatus(messageId);
  1086. }
  1087. /**
  1088. * 清除所有消息的未读状态
  1089. *
  1090. * 特别注意1:本方法只清除了底层数据库中的未读状态,并未清理 UI 层会话列表中的未读状态,UI 层会话列表中的未读状态,需要手动重置。
  1091. * 特别注意2:本方法不会触发{@link ConversationInfoUpdate} 事件
  1092. */
  1093. clearAllUnreadStatus() {
  1094. impl.clearAllUnreadStatus();
  1095. }
  1096. /**
  1097. * 设置媒体消息的状态为已播放
  1098. * @param {number} messageId 消息id,不是消息uid!
  1099. */
  1100. setMediaMessagePlayed(messageId) {
  1101. impl.setMediaMessagePlayed(messageId);
  1102. }
  1103. /**
  1104. * 设置消息本地扩展信息
  1105. * @param {number} messageId 消息id,不是消息uid!
  1106. * @param {string} extra 扩展信息
  1107. */
  1108. setMessageLocalExtra(messageId, extra) {
  1109. impl.setMessageLocalExtra(messageId, extra);
  1110. }
  1111. /**
  1112. * 判断是否是好友
  1113. * @param {string} userId 用户id
  1114. * @returns {boolean}
  1115. */
  1116. isMyFriend(userId) {
  1117. return impl.isMyFriend(userId);
  1118. }
  1119. /**
  1120. * 获取星标用户id列表
  1121. * @returns {[string]}
  1122. */
  1123. getFavUsers() {
  1124. return impl.getFavUsers();
  1125. }
  1126. /**
  1127. * 判断用户是否是星标用户
  1128. * @param {string} userId
  1129. * @returns {boolean}
  1130. */
  1131. isFavUser(userId) {
  1132. return impl.isFavUser(userId);
  1133. }
  1134. /**
  1135. * 设置或取消星标用户
  1136. * @param {string} userId 用户id
  1137. * @param {boolean} fav true,保存到通讯录;false,从通讯录移除
  1138. * @param {function ()} successCB
  1139. * @param {function (number)} failCB
  1140. * @returns {Promise<void>}
  1141. */
  1142. async setFavUser(userId, fav, successCB, failCB) {
  1143. impl.setFavUser(userId, fav, successCB, failCB);
  1144. }
  1145. /**
  1146. * 发送好友请求
  1147. * @param {string} userId 目标用户id
  1148. * @param {string} reason 发送好友请求的原因
  1149. * @param {string} extra 请求的扩展信息
  1150. * @param {function ()} successCB
  1151. * @param {function (number)} failCB
  1152. * @returns {Promise<void>}
  1153. */
  1154. async sendFriendRequest(userId, reason, extra, successCB, failCB) {
  1155. impl.sendFriendRequest(userId, reason, extra, successCB, failCB);
  1156. }
  1157. /**
  1158. * 获取会话消息
  1159. * @deprecated 请使用{@link getMessagesV2}
  1160. * @param {Conversation} conversation 目标会话
  1161. * @param {number} fromIndex messageId,表示从那一条消息开始获取
  1162. * @param {boolean} before true, 获取fromIndex之前的消息,即更旧的消息;false,获取fromIndex之后的消息,即更新的消息。都不包含fromIndex对应的消息
  1163. * @param {number} count 获取多少条消息
  1164. * @param {string} withUser 只有会话类型为{@link ConversationType#Channel}时生效, channel主用来查询和某个用户的所有消息
  1165. * @return {[Message]} 会话消息列表,参考{@link Message}
  1166. */
  1167. getMessages(conversation, fromIndex = 0, before = true, count = 20, withUser = '') {
  1168. return impl.getMessages(conversation, fromIndex, before, count, withUser);
  1169. }
  1170. /**
  1171. * 获取消息
  1172. * @deprecated 请使用{@link getMessagesExV2}
  1173. * @param {[number]} conversationTypes 会话类型列表,可选值参考{@link ConversationType}
  1174. * @param {[number]} lines 会话线路列表
  1175. * @param {number} fromIndex 本参数暂时无效! messageId,表示从那一条消息开始获取
  1176. * @param {boolean} before 本参数暂时无效! true, 获取fromIndex之前的消息,即更旧的消息;false,获取fromIndex之后的消息,即更新的消息。都不包含fromIndex对应的消息
  1177. * @param {number} count 本参数暂时无效! 获取多少条消息
  1178. * @param {string} withUser 只有会话类型为{@link ConversationType#Channel}时生效, channel主用来查询和某个用户的所有消息
  1179. * @param {[number]} contentTypes 消息类型列表,可选值参考{@link MessageContentType}
  1180. * @return {[Message]} 会话消息列表,参考{@link Message}
  1181. */
  1182. getMessagesEx(conversationTypes, lines, fromIndex = 0, before = true, count = 20, withUser = '', contentTypes = []) {
  1183. return impl.getMessagesEx(conversationTypes, lines, contentTypes, fromIndex, before, count, withUser);
  1184. }
  1185. /**
  1186. * 获取消息
  1187. * @deprecated 请使用{@link getMessagesEx2V2}
  1188. * @param {[number]} conversationTypes 会话类型列表,可选值参考{@link ConversationType}
  1189. * @param {[number]} lines 会话线路列表
  1190. * @param {[number]} messageStatus 消息状态,可选值参考{@link MessageStatus}
  1191. * @param {number} fromIndex 本参数暂时无效! messageId,表示从那一条消息开始获取
  1192. * @param {boolean} before 本参数暂时无效! true, 获取fromIndex之前的消息,即更旧的消息;false,获取fromIndex之后的消息,即更新的消息。都不包含fromIndex对应的消息
  1193. * @param {number} count 本参数暂时无效! 获取多少条消息
  1194. * @param {string} withUser 只有会话类型为{@link ConversationType#Channel}时生效, channel主用来查询和某个用户的所有消息
  1195. * @return {[Message]} 会话消息列表,参考{@link Message}
  1196. */
  1197. getMessagesEx2(conversationTypes, lines, messageStatus, fromIndex = 0, before = true, count = 20, withUser = '') {
  1198. return impl.getMessagesEx2(conversationTypes, lines, messageStatus, fromIndex, before, count, withUser);
  1199. }
  1200. /**
  1201. * 获取会话消息
  1202. * @deprecated 请使用{@link getMessagesByTimestampV2}
  1203. * @param {Conversation} conversation 目标会话
  1204. * @param {[number]} contentTypes 消息类型,可选值参考{@link MessageContentType}
  1205. * @param {number} timestamp 时间戳
  1206. * @param {boolean} before true, 获取timestamp之前的消息,即更旧的消息;false,获取timestamp之后的消息,即更新的消息。都不包含timestamp对应的消息
  1207. * @param {number} count 获取多少条消息
  1208. * @param {string} withUser 只有会话类型为{@link ConversationType#Channel}时生效, channel主用来查询和某个用户的所有消息
  1209. * @return {[Message]} 会话消息列表,参考{@link Message}
  1210. */
  1211. getMessagesByTimestamp(conversation, contentTypes, timestamp, before = true, count = 20, withUser = '') {
  1212. return impl.getMessagesByTimestamp(conversation, contentTypes, timestamp, before, count, withUser);
  1213. }
  1214. /**
  1215. * 获取用户会话消息
  1216. * @deprecated 请使用{@link getUserMessagesV2}
  1217. * @param {string} userId 用户id
  1218. * @param {Conversation} conversation 目标会话
  1219. * @param {number} fromIndex 本参数暂时无效! messageId,表示从那一条消息开始获取
  1220. * @param {boolean} before 本参数暂时无效! true, 获取fromIndex之前的消息,即更旧的消息;false,获取fromIndex之后的消息,即更新的消息。都不包含fromIndex对应的消息
  1221. * @param {number} count 本参数暂时无效! 获取多少条消息
  1222. * @return
  1223. */
  1224. getUserMessages(userId, conversation, fromIndex, before = true, count = 20) {
  1225. return impl.getUserMessages(userId, conversation, fromIndex, before, count);
  1226. }
  1227. /**
  1228. * 获取用户消息
  1229. * @deprecated 请使用{@link getUserMessagesExV2}
  1230. * @param {string} userId 用户id
  1231. * @param {[number]} conversationTypes 想获取的会话类型,可选值参考{@link ConversationType}
  1232. * @param {[0]} lines 想获取哪些会话线路的会话,默认传[0]即可
  1233. * @param {number} fromIndex 本参数暂时无效! messageId,表示从那一条消息开始获取
  1234. * @param {boolean} before 本参数暂时无效! true, 获取fromIndex之前的消息,即更旧的消息;false,获取fromIndex之后的消息,即更新的消息。都不包含fromIndex对应的消息
  1235. * @param {number} count 本参数暂时无效! 获取多少条消息
  1236. * @param {[number]} contentTypes 消息类型,可选值参考{@link MessageContentType}
  1237. * @return
  1238. */
  1239. getUserMessagesEx(userId, conversationTypes, lines, fromIndex, before = true, count = 20, contentTypes = []) {
  1240. return impl.getUserMessagesEx(userId, conversationTypes, lines, fromIndex, before, count, contentTypes);
  1241. }
  1242. /**
  1243. * 获取会话消息
  1244. * @param {Conversation} conversation 目标会话
  1245. * @param {number} fromIndex messageId,表示从那一条消息开始获取
  1246. * @param {boolean} before true, 获取fromIndex之前的消息,即更旧的消息;false,获取fromIndex之后的消息,即更新的消息。都不包含fromIndex对应的消息
  1247. * @param {number} count 获取多少条消息
  1248. * @param {string} withUser 只有会话类型为{@link ConversationType#Channel}时生效, channel主用来查询和某个用户的所有消息
  1249. * @param {function (Message)} successCB
  1250. * @param failCB
  1251. */
  1252. getMessagesV2(conversation, fromIndex, before, count, withUser, successCB, failCB) {
  1253. impl.getMessagesV2(conversation, fromIndex, before, count, withUser, successCB, failCB);
  1254. }
  1255. /**
  1256. * 获取消息
  1257. * @param {[number]} conversationTypes 会话类型列表,可选值参考{@link ConversationType}
  1258. * @param {[number]} lines 会话线路列表
  1259. * @param {number} fromIndex 本参数暂时无效! messageId,表示从那一条消息开始获取
  1260. * @param {boolean} before 本参数暂时无效! true, 获取fromIndex之前的消息,即更旧的消息;false,获取fromIndex之后的消息,即更新的消息。都不包含fromIndex对应的消息
  1261. * @param {number} count 本参数暂时无效! 获取多少条消息
  1262. * @param {string} withUser 只有会话类型为{@link ConversationType#Channel}时生效, channel主用来查询和某个用户的所有消息
  1263. * @param {[number]} contentTypes 消息类型列表,可选值参考{@link MessageContentType}
  1264. * @param {function (Message)} successCB
  1265. * @param failCB
  1266. */
  1267. getMessagesExV2(conversationTypes, lines, fromIndex, before, count, withUser, contentTypes, successCB, failCB) {
  1268. impl.getMessagesExV2(conversationTypes, lines, contentTypes, fromIndex, before, count, withUser, successCB, failCB);
  1269. }
  1270. /**
  1271. *
  1272. * @param {[number]} conversationTypes 会话类型列表,可选值参考{@link ConversationType}
  1273. * @param {[number]} lines 会话线路列表
  1274. * @param {[number]} messageStatuses 消息状态,可选值参考{@link MessageStatus}
  1275. * @param {number} fromIndex 本参数暂时无效! messageId,表示从那一条消息开始获取
  1276. * @param {boolean} before 本参数暂时无效! true, 获取fromIndex之前的消息,即更旧的消息;false,获取fromIndex之后的消息,即更新的消息。都不包含fromIndex对应的消息
  1277. * @param {number} count 本参数暂时无效! 获取多少条消息
  1278. * @param {string} withUser 只有会话类型为{@link ConversationType#Channel}时生效, channel主用来查询和某个用户的所有消息
  1279. * @param {function (Message)} successCB
  1280. * @param failCB
  1281. */
  1282. getMessagesEx2V2(conversationTypes, lines, messageStatuses, fromIndex, before, count, withUser, successCB, failCB) {
  1283. impl.getMessagesEx2V2(conversationTypes, lines, messageStatuses, fromIndex, before, count, withUser, successCB, failCB);
  1284. }
  1285. /**
  1286. * 获取会话消息
  1287. * @param {Conversation} conversation 目标会话
  1288. * @param {[number]} contentTypes 消息类型,可选值参考{@link MessageContentType}
  1289. * @param {number} timestamp 时间戳
  1290. * @param {boolean} before true, 获取timestamp之前的消息,即更旧的消息;false,获取timestamp之后的消息,即更新的消息。都不包含timestamp对应的消息
  1291. * @param {number} count 获取多少条消息
  1292. * @param {string} withUser 只有会话类型为{@link ConversationType#Channel}时生效, channel主用来查询和某个用户的所有消息
  1293. * @param {function (Message)} successCB
  1294. * @param failCB
  1295. */
  1296. getMessagesByTimestampV2(conversation, contentTypes, timestamp, before, count, withUser, successCB, failCB) {
  1297. impl.getMessagesByTimestampV2(conversation, contentTypes, timestamp, before, count, withUser, successCB, failCB);
  1298. }
  1299. /**
  1300. * 获取用户会话消息
  1301. * @param {string} userId 用户id
  1302. * @param {Conversation} conversation 目标会话
  1303. * @param {number} fromIndex 本参数暂时无效! messageId,表示从那一条消息开始获取
  1304. * @param {boolean} before 本参数暂时无效! true, 获取fromIndex之前的消息,即更旧的消息;false,获取fromIndex之后的消息,即更新的消息。都不包含fromIndex对应的消息
  1305. * @param {number} count 本参数暂时无效! 获取多少条消息
  1306. * @param {function (Message)} successCB
  1307. * @param failCB
  1308. */
  1309. getUserMessagesV2(userId, conversation, fromIndex, before, count, successCB, failCB) {
  1310. impl.getUserMessagesV2(userId, conversation, fromIndex, before, count, successCB, failCB);
  1311. }
  1312. /**
  1313. * 获取用户消息
  1314. * @param {string} userId 用户id
  1315. * @param {[number]} conversationTypes 想获取的会话类型,可选值参考{@link ConversationType}
  1316. * @param {[0]} lines 想获取哪些会话线路的会话,默认传[0]即可
  1317. * @param {number} fromIndex 本参数暂时无效! messageId,表示从那一条消息开始获取
  1318. * @param {boolean} before 本参数暂时无效! true, 获取fromIndex之前的消息,即更旧的消息;false,获取fromIndex之后的消息,即更新的消息。都不包含fromIndex对应的消息
  1319. * @param {number} count 本参数暂时无效! 获取多少条消息
  1320. * @param {[number]} contentTypes 消息类型,可选值参考{@link MessageContentType}
  1321. * @param {function (Message)} successCB
  1322. * @param failCB
  1323. */
  1324. getUserMessagesExV2(userId, conversationTypes, lines, fromIndex, before, count, contentTypes, successCB, failCB) {
  1325. impl.getUserMessagesExV2(userId, conversationTypes, lines, fromIndex, before, count, contentTypes, successCB, failCB);
  1326. }
  1327. /**
  1328. * 获取会话第一条未读消息的消息id
  1329. * @param {Conversation} conversation
  1330. * @return {number}
  1331. */
  1332. getFirstUnreadMessageId(conversation) {
  1333. return impl.getFirstUnreadMessageId(conversation);
  1334. }
  1335. /**
  1336. * 已废弃,请使用{@link loadRemoteConversationMessages}
  1337. * 获取会还的远程历史消息
  1338. * @param {Conversation} conversation 目标会话
  1339. * @param {[number]} contentTypes 消息类型列表,可选值参考{@link MessageContentType}
  1340. * @param {number | Long} beforeUid 消息uid,表示拉取本条消息之前的消息
  1341. * @param {number} count
  1342. * @param {function (Message)} successCB
  1343. * @param failCB
  1344. */
  1345. loadRemoteMessages(conversation, contentTypes, beforeUid, count, successCB, failCB) {
  1346. impl.loadRemoteMessages(conversation, contentTypes, beforeUid, count, successCB, failCB);
  1347. }
  1348. /**
  1349. * 获取会话的远程历史消息
  1350. * @param {Conversation} conversation 目标会话
  1351. * @param {[number]} contentTypes 消息类型列表,可选值参考{@link MessageContentType}
  1352. * @param {number | Long} beforeUid 消息uid,表示拉取本条消息之前的消息
  1353. * @param {number} count
  1354. * @param {function ([Message])} successCB
  1355. * @param failCB
  1356. */
  1357. loadRemoteConversationMessages(conversation, contentTypes, beforeUid, count, successCB, failCB) {
  1358. impl.loadRemoteMessages(conversation, contentTypes, beforeUid, count, successCB, failCB);
  1359. }
  1360. /**
  1361. * 获取会话的远程历史消息,仅 web 有效
  1362. * @param {Conversation} conversation 目标会话
  1363. * @param {[number]} contentTypes 消息类型列表,可选值参考{@link MessageContentType}
  1364. * @param {number | Long} beforeUid 消息uid,表示拉取本条消息之前的消息
  1365. * @param {number} count
  1366. * @param {boolean} filterLocalMessage 是否过滤本地已经存在的消息
  1367. * @param {function ([Message])} successCB
  1368. * @param failCB
  1369. */
  1370. loadRemoteConversationMessagesEx(conversation, contentTypes, beforeUid, count, filterLocalMessage, successCB, failCB) {
  1371. impl.loadRemoteMessages(conversation, contentTypes, beforeUid, count, successCB, failCB, filterLocalMessage);
  1372. }
  1373. /**
  1374. * 根据会话线路,获取远程历史消息
  1375. * @param {number} line 会话线路
  1376. * @param {number | Long} beforeUid 消息uid,表示拉取本条消息之前的消息
  1377. * @param {[number]} contentTypes 消息类型列表,可选值参考{@link MessageContentType}
  1378. * @param {number} count
  1379. * @param {function ([Message])} successCB
  1380. * @param failCB
  1381. */
  1382. loadRemoteLineMessages(line, contentTypes, beforeUid, count, successCB, failCB) {
  1383. impl.loadRemoteLineMessages(line, contentTypes, beforeUid, count, successCB, failCB)
  1384. }
  1385. /**
  1386. * 根据会话线路,获取远程历史消息,仅 web 端有效
  1387. * @param {number} line 会话线路
  1388. * @param {number | Long} beforeUid 消息uid,表示拉取本条消息之前的消息
  1389. * @param {[number]} contentTypes 消息类型列表,可选值参考{@link MessageContentType}
  1390. * @param {number} count
  1391. * @param {boolean} filterLocalMessage 是否过滤本地已经存在的消息
  1392. * @param {function ([Message])} successCB
  1393. * @param failCB
  1394. */
  1395. loadRemoteLineMessages(line, contentTypes, beforeUid, count, filterLocalMessage, successCB, failCB) {
  1396. impl.loadRemoteLineMessages(line, contentTypes, beforeUid, count, successCB, failCB, filterLocalMessage)
  1397. }
  1398. /**
  1399. * 根据消息 uid,获取远程消息
  1400. * @param {Long} messageUid 消息uid
  1401. * @param {function ([Message])} successCB
  1402. * @param failCB
  1403. */
  1404. loadRemoteMessage(messageUid, successCB, failCB) {
  1405. impl.loadRemoteMessage(messageUid, successCB, failCB);
  1406. }
  1407. /**
  1408. * 获取消息
  1409. * @param {number} messageId 消息id
  1410. * @returns {null|Message}
  1411. */
  1412. getMessageById(messageId) {
  1413. return impl.getMessageById(messageId);
  1414. }
  1415. /**
  1416. * 获取消息
  1417. * @param {Long|string|number} messageUid
  1418. * @returns {null|Message}
  1419. */
  1420. getMessageByUid(messageUid) {
  1421. return impl.getMessageByUid(messageUid);
  1422. }
  1423. /**
  1424. * 搜索消息
  1425. * @param {Conversation} conversation 目标会话
  1426. * @param {string} keyword 关键字
  1427. * @param {string} withUser 目标用户
  1428. * @returns {[Message]}
  1429. */
  1430. searchMessage(conversation, keyword, withUser = '') {
  1431. return impl.searchMessage(conversation, keyword, withUser);
  1432. }
  1433. /**
  1434. * 搜索消息
  1435. * @param {Conversation} conversation 目标会话,如果为空搜索所有会话
  1436. * @param {string} keyword 关键字
  1437. * @param {boolean} desc 逆序排列
  1438. * @param {int} limit 返回数量
  1439. * @param {int} offset 偏移
  1440. * @param {string} withUser 目标用户
  1441. * @returns {Message[]}
  1442. */
  1443. searchMessageEx(conversation, keyword, desc, limit, offset, withUser = '') {
  1444. return impl.searchMessageEx(conversation, keyword, desc, limit, offset, withUser);
  1445. }
  1446. /**
  1447. * 搜索消息
  1448. * @param {Conversation} conversation 目标会话,如果为空搜索所有会话
  1449. * @param {string} keyword 关键字
  1450. * @param {[number]} contentTypes 消息类型列表,可选值参考{@link MessageContentType}
  1451. * @param {boolean} desc 逆序排列
  1452. * @param {int} limit 返回数量
  1453. * @param {int} offset 偏移
  1454. * @param {string} withUser 目标用户
  1455. * @returns {Message[]}
  1456. */
  1457. searchMessageByTypes(conversation, keyword, contentTypes, desc, limit, offset, withUser = '') {
  1458. return impl.searchMessageByTypes(conversation, keyword, contentTypes, desc, limit, offset, withUser);
  1459. }
  1460. /**
  1461. * 搜索消息
  1462. * @param {Conversation} conversation 目标会话,如果为空搜索所有会话
  1463. * @param {string} keyword 关键字
  1464. * @param {[number]} contentTypes 消息类型列表,可选值参考{@link MessageContentType}
  1465. * @param {Long} 消息起始时间,如果为0,则忽略起始时间。
  1466. * @param {Long} 消息结束时间,如果为0,测忽略结束时间。
  1467. * @param {boolean} desc 逆序排列
  1468. * @param {int} limit 返回数量
  1469. * @param {int} offset 偏移
  1470. * @param {string} withUser 目标用户
  1471. * @returns {Message[]}
  1472. */
  1473. searchMessageByTypesAndTimes(conversation, keyword, contentTypes, startTime, endTime, desc, limit, offset, withUser = '') {
  1474. return impl.searchMessageByTypesAndTimes(conversation, keyword, contentTypes, startTime, endTime, desc, limit, offset, withUser);
  1475. }
  1476. /**
  1477. * 搜索消息
  1478. * @param {[number]} conversationTypes 会话类型列表,可选值参考{@link ConversationType}
  1479. * @param {[number]} lines 会话线路列表
  1480. * @param {[number]} contentTypes 消息类型列表,可选值参考{@link MessageContentType}
  1481. * @param {string} keyword 关键字
  1482. * @param {number} fromIndex messageId,表示从那一条消息开始获取
  1483. * @param {boolean} desc 逆序排列
  1484. * @param {number} count 最大数量
  1485. * @param {string} withUser 目标用户
  1486. * @returns {[Message]}
  1487. */
  1488. searchMessageEx2(conversationTypes, lines, contentTypes, keyword, fromIndex, desc, count, withUser = '') {
  1489. return impl.searchMessageEx2(conversationTypes, lines, contentTypes, keyword, fromIndex, desc, count, withUser);
  1490. }
  1491. /**
  1492. * 发送消息
  1493. * @param {Conversation} conversation 目标会话
  1494. * @param {MessageContent} messageContent 具体的消息内容,一定要求是{@link MessageContent} 的子类,不能是普通的object
  1495. * @param {[string]} toUsers 定向发送给会话中的某些用户;为空,则发给所有人;另外对单聊会话,本参数无效
  1496. * @param {function (number, number)} preparedCB 消息已插入本地数据的回调,回调的两个参数表示:messageId, timestamp
  1497. * @param {function (number, number)} progressCB 媒体上传进度回调,针对媒体消息,且媒体大于100K时有效,回调参数表示:uploaded, total
  1498. * @param {function (number, number)} successCB 发送成功回调,回调参数表示:messageUid, timestamp
  1499. * @param {function (number)} failCB
  1500. * @returns {Promise<void>}
  1501. */
  1502. async sendConversationMessage(conversation, messageContent, toUsers = [], preparedCB = null, progressCB = null, successCB = null, failCB = null) {
  1503. impl.sendConversationMessage(conversation, messageContent, toUsers, preparedCB, progressCB, successCB, failCB);
  1504. }
  1505. /**
  1506. * 发送消息,参考{@link sendConversationMessage}
  1507. * @param {Message} message 一定要求是{@link Message}类型
  1508. * @param preparedCB
  1509. * @param progressCB
  1510. * @param successCB
  1511. * @param failCB
  1512. * @returns {Promise<void>}
  1513. */
  1514. async sendMessage(message, preparedCB, progressCB, successCB, failCB) {
  1515. impl.sendMessage(message, preparedCB, progressCB, successCB, failCB);
  1516. }
  1517. /**
  1518. * 发送消息,参考{@link sendMessage}
  1519. * @param message
  1520. * @param toUsers
  1521. * @param preparedCB
  1522. * @param progressCB
  1523. * @param successCB
  1524. * @param failCB
  1525. * @returns {Promise<void>}
  1526. */
  1527. async sendMessageEx(message, toUsers = [], preparedCB, progressCB, successCB, failCB) {
  1528. impl.sendMessageEx(message, toUsers, preparedCB, progressCB, successCB, failCB);
  1529. }
  1530. // 更新了原始消息的内容
  1531. /**
  1532. * 撤回消息
  1533. * @param {Long} messageUid
  1534. * @param {function ()} successCB
  1535. * @param {function (number)} failCB
  1536. * @returns {Promise<void>}
  1537. */
  1538. async recallMessage(messageUid, successCB, failCB) {
  1539. impl.recallMessage(messageUid, successCB, failCB);
  1540. }
  1541. /**
  1542. * 删除消息
  1543. * @param {number} messageId 消息id
  1544. * @returns {*}
  1545. */
  1546. deleteMessage(messageId) {
  1547. return impl.deleteMessageById(messageId);
  1548. }
  1549. /**
  1550. * 删除远程消息
  1551. * @param {Long | string} msgUid 消息uid
  1552. * @param {function ()} successCB
  1553. * @param {function (number)} failCB
  1554. */
  1555. deleteRemoteMessageByUid(msgUid, successCB, failCB) {
  1556. impl.deleteRemoteMessage(msgUid, successCB, failCB);
  1557. }
  1558. /**
  1559. * 更新远程消息消息内容,只有专业版支持。客户端仅能更新自己发送的消息,更新的消息类型不能变,更新的消息类型是服务配置允许更新的内容。Server API更新则没有限制。
  1560. * @param {Long | string} msgUid 消息uid
  1561. * @param {MessageContent} messageContent 具体的消息内容,一定要求是{@link MessageContent} 的子类,不能是普通的object
  1562. * @param {boolean} distribute 是否重新分发给其他客户端
  1563. * @param {boolean} updateLocal 是否更新本地消息内容
  1564. * @param {function ()} successCB
  1565. * @param {function (number)} failCB
  1566. */
  1567. updateRemoteMessageContent(msgUid, messageContent, distribute, updateLocal, successCB, failCB) {
  1568. impl.updateRemoteMessageContent(msgUid, messageContent, distribute, updateLocal, successCB, failCB);
  1569. }
  1570. /**
  1571. * 清除会话消息
  1572. * @param {Conversation} conversation 目标会话
  1573. * @returns {Promise<void>}
  1574. */
  1575. async clearMessages(conversation) {
  1576. impl.clearMessages(conversation);
  1577. }
  1578. /**
  1579. * 清除远程会话消息
  1580. * @param {Conversation} conversation
  1581. * @param {function ()} successCB
  1582. * @param {function (error)} failCB
  1583. * @return {Promise<void>}
  1584. */
  1585. async clearRemoteConversationMessages(conversation, successCB, failCB) {
  1586. impl.clearRemoteConversationMessages(conversation, successCB, failCB);
  1587. }
  1588. /**
  1589. * 插入消息
  1590. * @param {Conversation} conversation 目标会话
  1591. * @param {MessageContent} messageContent 具体的消息内容,一定要求是{@link MessageContent} 的子类,不能是普通的object
  1592. * @param {number} status 消息状态,可选值参考{@link MessageStatus}
  1593. * @param {boolean} notify 是否触发onReceiveMessage
  1594. * @param {Number} serverTime 服务器时间,精度到毫秒
  1595. *
  1596. * @return {Message} 插入的消息
  1597. */
  1598. insertMessage(conversation, messageContent, status, notify = false, serverTime = 0) {
  1599. return impl.insertMessage(conversation, messageContent, status, notify, serverTime);
  1600. }
  1601. /**
  1602. * 更新消息
  1603. * @param {number} messageId 消息id
  1604. * @param {MessageContent} messageContent 具体的消息内容,一定要求是{@link MessageContent} 的子类,不能是普通的object
  1605. * @returns {Promise<void>}
  1606. */
  1607. async updateMessageContent(messageId, messageContent) {
  1608. impl.updateMessageContent(messageId, messageContent);
  1609. }
  1610. /**
  1611. * 更新消息状态
  1612. * @param {number} messageId 消息id
  1613. * @param {MessageStatus} status 消息状态,可选值参考{@link MessageStatus}
  1614. */
  1615. async updateMessageStatus(messageId, status) {
  1616. impl.updateMessageStatus(messageId, status);
  1617. }
  1618. /**
  1619. * 上传媒体文件
  1620. * @param {string} fileName
  1621. * @param {string} fileOrData base64格式的dataUri
  1622. * @param {number} mediaType 媒体类型,可选值参考{@link MessageContentMediaType}
  1623. * @param {function (string)} successCB 回调通知上传成功之后的url
  1624. * @param {function (number)} failCB
  1625. * @param {function (number, number)} progressCB
  1626. * @returns {Promise<void>}
  1627. */
  1628. async uploadMedia(fileName, fileOrData, mediaType, successCB, failCB, progressCB) {
  1629. impl.uploadMedia(fileName, fileOrData, mediaType, successCB, failCB, progressCB);
  1630. }
  1631. getVersion() {
  1632. return impl.getVersion();
  1633. }
  1634. /**
  1635. * 获取经过认证的下载地址。
  1636. */
  1637. getAuthorizedMediaUrl(messageUid, mediaType, mediaPath, successCB, failCB) {
  1638. impl.getAuthorizedMediaUrl(messageUid, mediaType, mediaPath, successCB, failCB)
  1639. }
  1640. /**
  1641. * 是否支持上传大文件上传。只有专业版才支持此功能。当支持大文件上传时,调用getUploadMediaUrl获取上传url,然后在应用层上传
  1642. */
  1643. isSupportBigFilesUpload() {
  1644. return impl.isSupportBigFilesUpload();
  1645. }
  1646. /**
  1647. * 获取上传链接。一般用户大文件上传。
  1648. * @param {string} fileName
  1649. * @param {number} mediaType 媒体类型,可选值参考{@link MessageContentMediaType}
  1650. * @param {string} contentType HTTP请求的ContentType header,为空时默认为"application/octet-stream"
  1651. * @param {function (string, string)} successCB 回调通知上传成功之后的url
  1652. * @param {function (number)} failCB
  1653. */
  1654. getUploadMediaUrl(fileName, mediaType, contentType, successCB, failCB) {
  1655. impl.getUploadMediaUrl(fileName, mediaType, contentType, successCB, failCB);
  1656. }
  1657. /**
  1658. * 微信小程序切到前台时调用应用切到了前台
  1659. *
  1660. */
  1661. onForeground() {
  1662. impl.onForeground();
  1663. }
  1664. /**
  1665. *
  1666. * 是否开启了已送达报告和已读报告功能
  1667. * @return {boolean}
  1668. */
  1669. isReceiptEnabled() {
  1670. return impl.isReceiptEnabled();
  1671. }
  1672. /**
  1673. * 当前用户是否开启消息回执
  1674. * @return {boolean}
  1675. */
  1676. isUserReceiptEnabled() {
  1677. return impl.isUserReceiptEnabled();
  1678. }
  1679. /**
  1680. * 判断是否是专业版IM服务
  1681. * @return {boolean}
  1682. */
  1683. isCommercialServer() {
  1684. return impl.isCommercialServer();
  1685. }
  1686. /**
  1687. * 判断是否应用禁止草稿同步
  1688. * @return {boolean}
  1689. */
  1690. isGlobalDisableSyncDraft() {
  1691. return impl.isGlobalDisableSyncDraft();
  1692. }
  1693. /**
  1694. *
  1695. * @param disable
  1696. * @param successCB
  1697. * @param failCB
  1698. */
  1699. setDisableSyncDraft(disable, successCB, failCB) {
  1700. impl.setDisableSyncDraft(disable, successCB, failCB)
  1701. }
  1702. isDisableSyncDraft() {
  1703. return impl.isDisableSyncDraft();
  1704. }
  1705. /**
  1706. * 设置当前用户是否开启消息回执
  1707. * @param enable
  1708. * @param successCB
  1709. * @param failCB
  1710. */
  1711. setUserEnableReceipt(enable, successCB, failCB) {
  1712. impl.setUserEnableReceipt(enable, successCB, failCB);
  1713. }
  1714. /**
  1715. *
  1716. * @param conversation
  1717. * @return {Map<string, Long>}
  1718. */
  1719. getConversationRead(conversation) {
  1720. return impl.getConversationRead(conversation);
  1721. }
  1722. /**
  1723. * 获取会话中的文件记录
  1724. * @param {Conversation} conversation 会话
  1725. * @param {String} fromUser 来源用户
  1726. * @param {Long} beforeMessageUid 消息uid,表示获取此消息uid之前的文件记录
  1727. * @param {number} count 数量
  1728. * @param {function (FileRecord[])} successCB 成功回调
  1729. * @param {function (number)} failCB 失败回调
  1730. */
  1731. getConversationFileRecords(conversation, fromUser, beforeMessageUid, count, successCB, failCB) {
  1732. impl.getConversationFileRecords(conversation, fromUser, beforeMessageUid, count, successCB, failCB);
  1733. }
  1734. /**
  1735. * 获取我发送的文件记录
  1736. * @param {Long} beforeMessageUid 消息uid,表示获取此消息uid之前的文件记录
  1737. * @param {number} count 数量
  1738. * @param {function (FileRecord[])} successCB 成功回调
  1739. * @param {function (number)} failCB 失败回调
  1740. */
  1741. getMyFileRecords(beforeMessageUid, count, successCB, failCB) {
  1742. impl.getMyFileRecords(beforeMessageUid, count, successCB, failCB);
  1743. }
  1744. /**
  1745. * 删除文件记录
  1746. * @param {Long} messageUid 文件对应的消息的uid
  1747. * @param {function ()} successCB 成功回调
  1748. * @param {function (number)} failCB 失败回调
  1749. */
  1750. deleteFileRecord(messageUid, successCB, failCB) {
  1751. impl.deleteFileRecord(messageUid, successCB, failCB);
  1752. }
  1753. /**
  1754. * 搜索远程文件记录
  1755. * @param {string} keyword
  1756. * @param {Conversation} conversation 会话,如果为空则获取当前用户所有收到和发出的文件记录
  1757. * @param {string} fromUser 文件发送用户,如果为空则获取该用户发出的文件记录
  1758. * @param {Long | string} beforeMessageId 起始消息的消息id
  1759. * @param {number} count
  1760. * @param {function (FileRecord[])} successCB
  1761. * @param {function (number)} failCB
  1762. */
  1763. searchFiles(keyword, conversation, fromUser, beforeMessageId, count, successCB, failCB) {
  1764. impl.searchFiles(keyword, conversation, fromUser, beforeMessageId, count, successCB, failCB)
  1765. }
  1766. /**
  1767. * 搜索我自己的远程文件记录
  1768. * @param keyword
  1769. * @param beforeMessageUid
  1770. * @param count
  1771. * @param successCB
  1772. * @param failCB
  1773. */
  1774. searchMyFiles(keyword, beforeMessageUid, count, successCB, failCB) {
  1775. impl.searchMyFiles(keyword, beforeMessageUid, count, successCB, failCB);
  1776. }
  1777. /**
  1778. * 获取host
  1779. */
  1780. getHost() {
  1781. return impl.getHost();
  1782. }
  1783. getEncodedClientId() {
  1784. return impl.getEncodedClientId();
  1785. }
  1786. /**
  1787. *
  1788. * @param {string} data 将要编码的数据
  1789. * @returns {string} 编码结果,base64格式
  1790. */
  1791. encodeData(data) {
  1792. return impl.encodeData(data);
  1793. }
  1794. /**
  1795. *
  1796. * @param {string} encodedData 将要解码的数据,base64格式
  1797. * @returns {null | string} 解码之后的数据
  1798. */
  1799. decodeData(encodedData) {
  1800. return impl.decodeData(encodedData);
  1801. }
  1802. /**
  1803. * 发送会议相关请求
  1804. * @param sessionId
  1805. * @param roomId
  1806. * @param request
  1807. * @param data
  1808. * @param callback
  1809. */
  1810. sendConferenceRequest(sessionId, roomId, request, data, callback) {
  1811. this.sendConferenceRequestEx(sessionId, roomId, request, data, false, callback)
  1812. }
  1813. sendConferenceRequestEx(sessionId, roomId, request, data, advance, callback) {
  1814. impl.sendConferenceRequest(sessionId, roomId, request, data, advance, callback);
  1815. }
  1816. isUserOnlineStateEnabled() {
  1817. return impl.isUserOnlineStateEnabled();
  1818. }
  1819. /**
  1820. *
  1821. * @param {number} type 会话类型, 支持{@link ConversationType.Single}和{@link ConversationType.Group}
  1822. * @param {string[]} targets 会话类型为单聊时,是用户 id列表;会话类型为群组时,是群组 id 列表
  1823. * @param {number} duration 关注时间长度,单位是秒
  1824. * @param {function(UserOnlineState[])} successCB
  1825. * @param {function(number)} failCB
  1826. */
  1827. watchOnlineState(type, targets, duration, successCB, failCB) {
  1828. impl.watchOnlineState(type, targets, duration, successCB, failCB);
  1829. }
  1830. unwatchOnlineState(type, targets, successCB, failCB) {
  1831. impl.unwatchOnlineState(type, targets, successCB, failCB);
  1832. }
  1833. setMyCustomState(customState, customText, successCB, failCB) {
  1834. impl.setMyCustomState(customState, customText, successCB, failCB)
  1835. }
  1836. getAuthCode(appId, appType, host, successCB, failCB) {
  1837. impl.getAuthCode(appId, appType, host, successCB, failCB);
  1838. }
  1839. notify(title, content) {
  1840. impl.notify(title, content)
  1841. }
  1842. clearAllNotification() {
  1843. impl.clearAllNotification();
  1844. }
  1845. /**
  1846. * 设置推送 token
  1847. * @param {number} type
  1848. * @param {string} token
  1849. */
  1850. setDeviceToken(type, token) {
  1851. impl.setDeviceToken(7, token);
  1852. }
  1853. chooseFile(type, successCB, failCB) {
  1854. impl.chooseFile(type, successCB, failCB)
  1855. }
  1856. _getStore() {
  1857. return impl._getStore();
  1858. }
  1859. _getStore() {
  1860. return impl._getStore();
  1861. }
  1862. /**
  1863. * 内部使用,electron主窗口之外的,其他窗口,attach到主窗口初始化的proto上,可以调用get相关方法,但没有通知
  1864. * @param protoObj
  1865. */
  1866. attach(protoObj) {
  1867. impl.attach(protoObj);
  1868. }
  1869. /**
  1870. * utf8转base64
  1871. * @param {string} str
  1872. * @returns {string}
  1873. */
  1874. utf8_to_b64(str) {
  1875. return btoa(unescape(encodeURIComponent(str)));
  1876. }
  1877. /**
  1878. * base64转utf8
  1879. * @param {string} str
  1880. * @returns {string}
  1881. */
  1882. b64_to_utf8(str) {
  1883. return decodeURIComponent(escape(atob(str)));
  1884. }
  1885. unescape(str) {
  1886. return (str + '==='.slice((str.length + 3) % 4))
  1887. .replace(/-/g, '+')
  1888. .replace(/_/g, '/')
  1889. }
  1890. escape(str) {
  1891. return str.replace(/\+/g, '-')
  1892. .replace(/\//g, '_')
  1893. .replace(/=/g, '')
  1894. }
  1895. defaultUserPortrait(userInfo) {
  1896. return `${Config.APP_SERVER}/avatar?name=${encodeURIComponent(userInfo.displayName)}`
  1897. // return `http://localhost:8888/avatar?name=${encodeURIComponent(userInfo.displayName)}`
  1898. }
  1899. defaultGroupPortrait(groupInfo) {
  1900. let memberIds = this.getGroupMemberIds(groupInfo.target)
  1901. memberIds = memberIds.slice(0, 9);
  1902. // let members = this.getUserInfos(memberIds, groupInfo.target);
  1903. let members = impl.getUserInfos(memberIds, groupInfo.target);
  1904. let req = {
  1905. members: []
  1906. }
  1907. let pending = false;
  1908. members.forEach(m => {
  1909. if (m.portrait && !m.portrait.startsWith(`${Config.APP_SERVER}`)) {
  1910. req.members.push({
  1911. avatarUrl: m.portrait
  1912. })
  1913. } else {
  1914. req.members.push({
  1915. name: m.displayName
  1916. })
  1917. }
  1918. if (m instanceof NullUserInfo) {
  1919. pending = true;
  1920. }
  1921. })
  1922. if (members.length === 0 || pending) {
  1923. return null;
  1924. }
  1925. req = JSON.stringify(req, null, '');
  1926. return `${Config.APP_SERVER}/avatar/group?request=${encodeURIComponent(req)}`
  1927. //return `http://localhost:8888/avatar/group?request=${encodeURIComponent(req)}`
  1928. }
  1929. }
  1930. const self = new WfcManager();
  1931. export default self;