暫無描述

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. var __assign = (this && this.__assign) || function () {
  16. __assign = Object.assign || function(t) {
  17. for (var s, i = 1, n = arguments.length; i < n; i++) {
  18. s = arguments[i];
  19. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  20. t[p] = s[p];
  21. }
  22. return t;
  23. };
  24. return __assign.apply(this, arguments);
  25. };
  26. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  27. return new (P || (P = Promise))(function (resolve, reject) {
  28. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  29. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  30. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  31. step((generator = generator.apply(thisArg, _arguments || [])).next());
  32. });
  33. };
  34. var __generator = (this && this.__generator) || function (thisArg, body) {
  35. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  36. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  37. function verb(n) { return function (v) { return step([n, v]); }; }
  38. function step(op) {
  39. if (f) throw new TypeError("Generator is already executing.");
  40. while (_) try {
  41. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  42. if (y = 0, t) op = [op[0] & 2, t.value];
  43. switch (op[0]) {
  44. case 0: case 1: t = op; break;
  45. case 4: _.label++; return { value: op[1], done: false };
  46. case 5: _.label++; y = op[1]; op = [0]; continue;
  47. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  48. default:
  49. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  50. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  51. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  52. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  53. if (t[2]) _.ops.pop();
  54. _.trys.pop(); continue;
  55. }
  56. op = body.call(thisArg, _);
  57. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  58. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  59. }
  60. };
  61. Object.defineProperty(exports, "__esModule", { value: true });
  62. var WebSocketClient_1 = require("./../WebSocketClient");
  63. var CmdMsg_1 = require("../protocol/CmdMsg");
  64. var WsApi = (function (_super) {
  65. __extends(WsApi, _super);
  66. function WsApi() {
  67. return _super !== null && _super.apply(this, arguments) || this;
  68. }
  69. WsApi.prototype.sendMsg = function (msg) {
  70. return __awaiter(this, void 0, void 0, function () {
  71. return __generator(this, function (_a) {
  72. return [2, this.sendMessage(msg)];
  73. });
  74. });
  75. };
  76. WsApi.prototype.sendGetCmdMsg = function (action, extra) {
  77. if (extra === void 0) { extra = {}; }
  78. return __awaiter(this, void 0, void 0, function () {
  79. var msg;
  80. return __generator(this, function (_a) {
  81. msg = CmdMsg_1.CmdMsg.createMsg(__assign({ from: this.from, action: action }, extra));
  82. return [2, this.sendMsg(msg)];
  83. });
  84. });
  85. };
  86. WsApi.prototype.sendPostCmdMsg = function (action, userIds, extra) {
  87. if (extra === void 0) { extra = {}; }
  88. return __awaiter(this, void 0, void 0, function () {
  89. var msg;
  90. return __generator(this, function (_a) {
  91. msg = CmdMsg_1.CmdMsg.createMsg(__assign({ from: this.from, to: (userIds || []).join(','), action: action }, extra));
  92. return [2, this.sendMsg(msg)];
  93. });
  94. });
  95. };
  96. WsApi.prototype.getRoster = function () {
  97. return this.sendGetCmdMsg('getRoster');
  98. };
  99. WsApi.prototype.addFriends = function (userIds) {
  100. return this.sendPostCmdMsg('addFriends', userIds);
  101. };
  102. WsApi.prototype.agreeFriends = function (userIds) {
  103. return this.sendPostCmdMsg('agreeFriends', userIds);
  104. };
  105. WsApi.prototype.rejectFriends = function (userIds) {
  106. return this.sendPostCmdMsg('rejectFriends', userIds);
  107. };
  108. WsApi.prototype.removeFriends = function (userIds) {
  109. return this.sendPostCmdMsg('removeFriends', userIds);
  110. };
  111. WsApi.prototype.getBlacklist = function () {
  112. return this.sendGetCmdMsg('getBlacklist');
  113. };
  114. WsApi.prototype.addToBlackList = function (userIds) {
  115. return this.sendPostCmdMsg('addToBlackList', userIds);
  116. };
  117. WsApi.prototype.removeBlackList = function (userIds) {
  118. return this.sendPostCmdMsg('removeBlackList', userIds);
  119. };
  120. WsApi.prototype.deleteConversation = function (contactId, deleteMessage) {
  121. if (deleteMessage === void 0) { deleteMessage = false; }
  122. return this.request('/v1/delete/conversation', {
  123. contact: contactId,
  124. delete_message: deleteMessage
  125. });
  126. };
  127. WsApi.prototype.markMessageRead = function (contactId, chatType) {
  128. return this.request('/v1/mark/messages/read', {
  129. contact: contactId,
  130. msg_type: chatType,
  131. });
  132. };
  133. WsApi.prototype.listGroups = function () {
  134. return this.sendGetCmdMsg('listGroups');
  135. };
  136. WsApi.prototype.queryGroupInfo = function (roomId) {
  137. return this.sendGetCmdMsg('queryGroupInfo', { to: roomId });
  138. };
  139. WsApi.prototype.queryRoomMember = function (roomId) {
  140. return this.sendGetCmdMsg('queryRoomMember', { to: roomId });
  141. };
  142. WsApi.prototype.getGroupBlackList = function (roomId) {
  143. return this.sendGetCmdMsg('getGroupBlackList', { to: roomId });
  144. };
  145. WsApi.prototype.createGroup = function (groupOption) {
  146. return this.sendPostCmdMsg('createGroup', null, { ext: groupOption });
  147. };
  148. WsApi.prototype.changeGroupInfo = function (groupOption) {
  149. return this.sendPostCmdMsg('changeGroupInfo', null, { ext: groupOption });
  150. };
  151. WsApi.prototype.addGroupMembers = function (roomId, userIds) {
  152. return this.sendPostCmdMsg('addGroupMembers', [roomId], {
  153. ext: {
  154. members: userIds
  155. }
  156. });
  157. };
  158. WsApi.prototype.addToGroupBlackList = function (roomId, userIds) {
  159. return this.sendPostCmdMsg('addToGroupBlackList', [roomId], {
  160. ext: {
  161. members: userIds
  162. }
  163. });
  164. };
  165. WsApi.prototype.destroyGroup = function (roomId) {
  166. return this.sendPostCmdMsg('destroyGroup', [roomId]);
  167. };
  168. WsApi.prototype.leaveGroup = function (roomId) {
  169. return this.sendPostCmdMsg('leaveGroup', [roomId]);
  170. };
  171. WsApi.prototype.createRoom = function (groupOption) {
  172. return this.sendPostCmdMsg('createGroup', null, { ext: groupOption });
  173. };
  174. WsApi.prototype.listRooms = function () {
  175. return this.sendGetCmdMsg('listRooms');
  176. };
  177. WsApi.prototype.joinRoom = function (roomId) {
  178. return this.sendPostCmdMsg('joinRoom', [roomId]);
  179. };
  180. WsApi.prototype.quitRoom = function (roomId) {
  181. return this.sendPostCmdMsg('quitRoom', [roomId]);
  182. };
  183. return WsApi;
  184. }(WebSocketClient_1.WebSocketClient));
  185. exports.WsApi = WsApi;