podchat 12.5.0 → 12.5.2

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.
Files changed (3) hide show
  1. package/changelog.md +7 -3
  2. package/package.json +2 -2
  3. package/src/chat.js +689 -14
package/changelog.md CHANGED
@@ -5,11 +5,15 @@ to see complete list of changelog please visit [ChangeLog](https://github.com/ma
5
5
 
6
6
  ## [12.5.0] - 11-7-2022
7
7
  ### Added
8
- - Added global typeCode and typeCodeOwnerId
9
- - Added SWITCH_TO_GROUP_CALL_REQUEST , RECORD_CALL_STARTED , fixed GET_CALLS_TO_JOIN
10
- - Added callId to event type: CALL_STARTED
8
+ - Global typeCode and typeCodeOwnerId
9
+ - event type: SWITCH_TO_GROUP_CALL_REQUEST , RECORD_CALL_STARTED
10
+ - callId to event type: CALL_STARTED
11
+
12
+ ### Changed
11
13
  - Removed contentCount from hasNext calculation in getThreads and getHistory
12
14
 
15
+ ### Fixed
16
+ - Bug in GET_CALLS_TO_JOIN
13
17
 
14
18
  ## [12.4.0] - 24-5-2022
15
19
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podchat",
3
- "version": "12.5.0",
3
+ "version": "12.5.2",
4
4
  "description": "Javascript SDK to use POD's Chat Service",
5
5
  "main": "./src/chat.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@
8
8
  "publish:snapshot": "npm run version:snapshot && npm publish --tag snapshot",
9
9
  "version:snapshot": "npm version prerelease --preid snapshot",
10
10
  "publish:release": "npm run version:release && npm publish",
11
- "version:release": "npm version 12.5.0"
11
+ "version:release": "npm version 12.5.2"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
package/src/chat.js CHANGED
@@ -290,6 +290,13 @@
290
290
  // POD Drive Services
291
291
  PODSPACE_UPLOAD_FILE_TO_USERGROUP: '/userGroup/uploadFile',
292
292
  PODSPACE_UPLOAD_IMAGE_TO_USERGROUP: '/userGroup/uploadImage',
293
+
294
+ PODSPACE_UPLOAD_FILE_TO_USERGROUP_NEW: '/api/usergroups/{userGroupHash}/files',
295
+ PODSPACE_UPLOAD_IMAGE_TO_USERGROUP_NEW: '/api/usergroups/{userGroupHash}/images',
296
+
297
+ PODSPACE_DOWNLOAD_FILE_NEW: '/api/files/{fileHash}',
298
+ PODSPACE_DOWNLOAD_IMAGE_NEW: '/api/images/{fileHash}',
299
+
293
300
  PODSPACE_UPLOAD_FILE: '/nzh/drive/uploadFile',
294
301
  PODSPACE_UPLOAD_FILE_FROM_URL: '/nzh/drive/uploadFileFromUrl',
295
302
  PODSPACE_UPLOAD_IMAGE: '/nzh/drive/uploadImage',
@@ -3622,6 +3629,17 @@
3622
3629
  }
3623
3630
  break;
3624
3631
 
3632
+ /**
3633
+ * Type 152 Gives us a json to export for user
3634
+ */
3635
+ case chatMessageVOTypes.EXPORT_CHAT:
3636
+ if (messagesCallbacks[uniqueId]) {
3637
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount, uniqueId));
3638
+ }
3639
+
3640
+ break;
3641
+
3642
+
3625
3643
  /**
3626
3644
  * Type 221 Event to tell us p2p call converted to a group call
3627
3645
  */
@@ -3648,7 +3666,6 @@
3648
3666
 
3649
3667
  break;
3650
3668
 
3651
-
3652
3669
  /**
3653
3670
  * Type 999 All unknown errors
3654
3671
  */
@@ -7178,6 +7195,184 @@
7178
7195
  }
7179
7196
  },
7180
7197
 
7198
+ getFileFromPodspaceNew = function (params, callback) {
7199
+ var downloadUniqueId = Utility.generateUUID(),
7200
+ getFileData = {};
7201
+ if (params) {
7202
+ if (params.hashCode && typeof params.hashCode == 'string') {
7203
+ getFileData.hash = params.hashCode;
7204
+ } else {
7205
+ callback({
7206
+ hasError: true,
7207
+ error: 'Enter a file hash to get'
7208
+ });
7209
+ return;
7210
+ }
7211
+
7212
+ if(params.checkUserGroupAccess) {
7213
+ getFileData.checkUserGroupAccess = true;
7214
+ }
7215
+ }
7216
+
7217
+ if (params.responseType === 'link') {
7218
+ var returnLink = SERVICE_ADDRESSES.PODSPACE_FILESERVER_ADDRESS + SERVICES_PATH.PODSPACE_DOWNLOAD_FILE_NEW.replace('{fileHash}', params.hashCode) + `?checkUserGroupAccess=true`;
7219
+ callback({
7220
+ hasError: false,
7221
+ type: 'link',
7222
+ result: returnLink
7223
+ });
7224
+ } else {
7225
+ httpRequest({
7226
+ url: SERVICE_ADDRESSES.PODSPACE_FILESERVER_ADDRESS + SERVICES_PATH.PODSPACE_DOWNLOAD_FILE_NEW.replace('{fileHash}', params.hashCode) + `?checkUserGroupAccess=true`,
7227
+ method: 'GET',
7228
+ responseType: 'blob',
7229
+ uniqueId: downloadUniqueId,
7230
+ headers: {
7231
+ 'Authorization': 'Bearer ' + token
7232
+ },
7233
+ enableDownloadProgressEvents: params.enableDownloadProgressEvents,
7234
+ hashCode: params.hashCode
7235
+ //data: getFileData
7236
+ }, function (result) {
7237
+ if (!result.hasError) {
7238
+ callback({
7239
+ hasError: result.hasError,
7240
+ result: result,
7241
+ type: 'blob'
7242
+ });
7243
+ } else {
7244
+ callback({
7245
+ hasError: true
7246
+ });
7247
+ }
7248
+ });
7249
+
7250
+ return {
7251
+ uniqueId: downloadUniqueId,
7252
+ cancel: function () {
7253
+ cancelFileDownload({
7254
+ uniqueId: downloadUniqueId
7255
+ }, function () {
7256
+ consoleLogging && console.log(`"${downloadUniqueId}" - File download has been canceled!`);
7257
+ });
7258
+ }
7259
+ };
7260
+ }
7261
+ },
7262
+
7263
+ getImageFromPodspaceNew = function (params, callback) {
7264
+ var downloadUniqueId = Utility.generateUUID(),
7265
+ getImageData = {
7266
+ size: params.size,
7267
+ quality: params.quality,
7268
+ crop: params.crop
7269
+ };
7270
+ if (params) {
7271
+ if (params.hashCode && typeof params.hashCode == 'string') {
7272
+ getImageData.hash = params.hashCode;
7273
+ } else {
7274
+ callback({
7275
+ hasError: true,
7276
+ error: 'Enter a file hash to get'
7277
+ });
7278
+ return;
7279
+ }
7280
+
7281
+ if (params.responseType === 'link') {
7282
+ var returnLink = SERVICE_ADDRESSES.PODSPACE_FILESERVER_ADDRESS
7283
+ + SERVICES_PATH.PODSPACE_DOWNLOAD_IMAGE_NEW.replace('{fileHash}', params.hashCode) + `?checkUserGroupAccess=true&size=${params.size}&quality=${params.quality}&crop=${params.crop}`;
7284
+ //+ SERVICES_PATH.PODSPACE_DOWNLOAD_IMAGE + `?hash=${params.hashCode}&_token_=${token}&_token_issuer_=1&size=${params.size}&quality=${params.quality}&crop=${params.crop}`;
7285
+
7286
+ callback({
7287
+ hasError: false,
7288
+ type: 'link',
7289
+ result: returnLink
7290
+ });
7291
+ } else if (params.responseType === 'base64') {
7292
+ httpRequest({
7293
+ url: SERVICE_ADDRESSES.PODSPACE_FILESERVER_ADDRESS
7294
+ + SERVICES_PATH.PODSPACE_DOWNLOAD_IMAGE_NEW.replace('{fileHash}', params.hashCode) + `?checkUserGroupAccess=true&size=${params.size}&quality=${params.quality}&crop=${params.crop}`,
7295
+ method: 'GET',
7296
+ uniqueId: downloadUniqueId,
7297
+ responseType: 'blob',
7298
+ headers: {
7299
+ 'Authorization': 'Bearer ' + token
7300
+ },
7301
+ enableDownloadProgressEvents: params.enableDownloadProgressEvents,
7302
+ hashCode: params.hashCode
7303
+ //data: getImageData
7304
+ }, function (result) {
7305
+ if (!result.hasError) {
7306
+ var fr = new FileReader();
7307
+
7308
+ fr.onloadend = function () {
7309
+ callback({
7310
+ hasError: result.hasError,
7311
+ type: 'base64',
7312
+ result: fr.result
7313
+ });
7314
+ }
7315
+
7316
+ fr.readAsDataURL(result);
7317
+ } else {
7318
+ callback({
7319
+ hasError: true
7320
+ });
7321
+ }
7322
+ });
7323
+
7324
+ return {
7325
+ uniqueId: downloadUniqueId,
7326
+ cancel: function () {
7327
+ cancelFileDownload({
7328
+ uniqueId: downloadUniqueId
7329
+ }, function () {
7330
+ consoleLogging && console.log(`"${downloadUniqueId}" - Image download has been canceled!`);
7331
+ });
7332
+ }
7333
+ };
7334
+ } else {
7335
+ httpRequest({
7336
+ url: SERVICE_ADDRESSES.PODSPACE_FILESERVER_ADDRESS
7337
+ + SERVICES_PATH.PODSPACE_DOWNLOAD_IMAGE_NEW.replace('{fileHash}', params.hashCode) + `?checkUserGroupAccess=true&size=${params.size}&quality=${params.quality}&crop=${params.crop}`,
7338
+ method: 'GET',
7339
+ responseType: 'blob',
7340
+ uniqueId: downloadUniqueId,
7341
+ headers: {
7342
+ 'Authorization': 'Bearer ' + token
7343
+ },
7344
+ enableDownloadProgressEvents: params.enableDownloadProgressEvents,
7345
+ hashCode: params.hashCode
7346
+ //data: getImageData
7347
+ }, function (result) {
7348
+ if (!result.hasError) {
7349
+ callback({
7350
+ hasError: result.hasError,
7351
+ type: 'blob',
7352
+ result: result
7353
+ });
7354
+ } else {
7355
+ callback({
7356
+ hasError: true
7357
+ });
7358
+ }
7359
+ });
7360
+
7361
+ return {
7362
+ uniqueId: downloadUniqueId,
7363
+ cancel: function () {
7364
+ cancelFileDownload({
7365
+ uniqueId: downloadUniqueId
7366
+ }, function () {
7367
+ consoleLogging && console.log(`"${downloadUniqueId}" - Image download has been canceled!`);
7368
+ });
7369
+ }
7370
+ };
7371
+ }
7372
+ }
7373
+ },
7374
+
7375
+
7181
7376
  /**
7182
7377
  * Get Image Download Link From PodSpace
7183
7378
  *
@@ -8158,6 +8353,284 @@
8158
8353
  }
8159
8354
  },
8160
8355
 
8356
+ uploadImageToPodspaceUserGroupNew = function (params, callback) {
8357
+ var fileName,
8358
+ fileType,
8359
+ fileSize,
8360
+ fileWidth = 0,
8361
+ fileHeight = 0,
8362
+ fileExtension,
8363
+ uploadUniqueId,
8364
+ uploadThreadId;
8365
+ var continueImageUpload = function (params) {
8366
+ if (imageMimeTypes.indexOf(fileType) >= 0 || imageExtentions.indexOf(fileExtension) >= 0) {
8367
+ var uploadImageData = {};
8368
+ if (params) {
8369
+ if (typeof params.image !== 'undefined') {
8370
+ uploadImageData.file = params.image;
8371
+ } else {
8372
+ callback({
8373
+ hasError: true,
8374
+ errorCode: 999,
8375
+ errorMessage: 'You need to send a image file!'
8376
+ });
8377
+ return;
8378
+ }
8379
+ if (typeof params.userGroupHash == 'string') {
8380
+ uploadImageData.userGroupHash = params.userGroupHash;
8381
+ } else {
8382
+ callback({
8383
+ hasError: true,
8384
+ errorCode: 999,
8385
+ errorMessage: 'You need to enter a userGroupHash to be able to upload on PodSpace!'
8386
+ });
8387
+ return;
8388
+ }
8389
+ if (params.randomFileName) {
8390
+ uploadImageData.fileName = Utility.generateUUID() + '.' + fileExtension;
8391
+ } else {
8392
+ uploadImageData.filename = fileName;
8393
+ }
8394
+ uploadImageData.fileSize = fileSize;
8395
+ if (parseInt(params.threadId) > 0) {
8396
+ uploadThreadId = params.threadId;
8397
+ uploadImageData.threadId = params.threadId;
8398
+ } else {
8399
+ uploadThreadId = 0;
8400
+ uploadImageData.threadId = 0;
8401
+ }
8402
+ if (typeof params.uniqueId == 'string') {
8403
+ uploadUniqueId = params.uniqueId;
8404
+ uploadImageData.uniqueId = params.uniqueId;
8405
+ } else {
8406
+ uploadUniqueId = Utility.generateUUID();
8407
+ uploadImageData.uniqueId = uploadUniqueId;
8408
+ }
8409
+ if (typeof params.originalFileName == 'string') {
8410
+ uploadImageData.originalFileName = params.originalFileName;
8411
+ } else {
8412
+ uploadImageData.originalFileName = fileName;
8413
+ }
8414
+ uploadImageData.x = parseInt(params.xC) || 0;
8415
+ uploadImageData.y = parseInt(params.yC) || 0;
8416
+ uploadImageData.height = parseInt(params.hC) || fileHeight;
8417
+ uploadImageData.weight = parseInt(params.wC) || fileWidth;
8418
+ }
8419
+ httpRequest({
8420
+ url: SERVICE_ADDRESSES.PODSPACE_FILESERVER_ADDRESS + SERVICES_PATH.PODSPACE_UPLOAD_IMAGE_TO_USERGROUP_NEW.replace('{userGroupHash}', uploadImageData.userGroupHash),
8421
+ method: 'POST',
8422
+ headers: {
8423
+ 'Authorization': 'Bearer ' + token,
8424
+ },
8425
+ data: uploadImageData,
8426
+ uniqueId: uploadUniqueId
8427
+ }, function (result) {
8428
+ if (!result.hasError) {
8429
+ try {
8430
+ var response = (typeof result.result.responseText == 'string')
8431
+ ? JSON.parse(result.result.responseText)
8432
+ : result.result.responseText;
8433
+ if (response.status < 400) {
8434
+ response.result.actualHeight = fileHeight;
8435
+ response.result.actualWidth = fileWidth;
8436
+ callback({
8437
+ hasError: response.hasError,
8438
+ result: response.result
8439
+ });
8440
+ } else {
8441
+ callback({
8442
+ hasError: true,
8443
+ errorCode: response.errorCode,
8444
+ errorMessage: response.message
8445
+ });
8446
+ }
8447
+ } catch (e) {
8448
+ consoleLogging && console.log(e)
8449
+ callback({
8450
+ hasError: true,
8451
+ errorCode: 6300,
8452
+ errorMessage: CHAT_ERRORS[6300]
8453
+ });
8454
+ }
8455
+ } else {
8456
+ callback({
8457
+ hasError: true,
8458
+ errorCode: result.errorCode,
8459
+ errorMessage: result.errorMessage
8460
+ });
8461
+ }
8462
+ });
8463
+ return {
8464
+ uniqueId: uploadUniqueId,
8465
+ threadId: uploadThreadId,
8466
+ participant: userInfo,
8467
+ content: {
8468
+ caption: params.content,
8469
+ file: {
8470
+ uniqueId: uploadUniqueId,
8471
+ fileName: fileName,
8472
+ fileSize: fileSize,
8473
+ fileObject: params.file
8474
+ }
8475
+ }
8476
+ };
8477
+ } else {
8478
+ callback({
8479
+ hasError: true,
8480
+ errorCode: 6301,
8481
+ errorMessage: CHAT_ERRORS[6301]
8482
+ });
8483
+ }
8484
+ }
8485
+
8486
+ if (isNode) {
8487
+ fileName = params.image.split('/')
8488
+ .pop();
8489
+ fileType = Mime.getType(params.image);
8490
+ fileSize = FS.statSync(params.image).size;
8491
+ fileExtension = params.image.split('.')
8492
+ .pop();
8493
+
8494
+ var dimensions = SizeOf(params.image);
8495
+ fileWidth = dimensions.width;
8496
+ fileHeight = dimensions.height;
8497
+
8498
+ continueImageUpload(params);
8499
+ } else {
8500
+ fileName = params.image.name;
8501
+ fileType = params.image.type;
8502
+ fileSize = params.image.size;
8503
+ fileExtension = params.image.name.split('.')
8504
+ .pop();
8505
+
8506
+ var reader = new FileReader();
8507
+ reader.onload = function (e) {
8508
+ var image = new Image();
8509
+ image.onload = function () {
8510
+ fileWidth = this.width;
8511
+ fileHeight = this.height;
8512
+ continueImageUpload(params);
8513
+ };
8514
+ image.src = e.target.result;
8515
+ };
8516
+ reader.readAsDataURL(params.image);
8517
+ }
8518
+
8519
+ },
8520
+
8521
+ uploadFileToPodspaceUserGroupNew = function (params, callback) {
8522
+ var fileName,
8523
+ //fileType,
8524
+ fileSize,
8525
+ //fileExtension,
8526
+ uploadUniqueId,
8527
+ uploadThreadId;
8528
+
8529
+ console.log(params)
8530
+
8531
+ if (isNode) {
8532
+ fileName = params.file.split('/')
8533
+ .pop();
8534
+ fileType = Mime.getType(params.file);
8535
+ fileSize = FS.statSync(params.file).size;
8536
+ fileExtension = params.file.split('.')
8537
+ .pop();
8538
+ } else {
8539
+ fileName = params.file.name;
8540
+ fileType = params.file.type;
8541
+ fileSize = params.file.size;
8542
+ fileExtension = params.file.name.split('.')
8543
+ .pop();
8544
+ }
8545
+ // fileName = params.file.name;
8546
+ //fileType = params.file.type;
8547
+ // fileSize = params.file.size;
8548
+ //fileExtension = params.file.name.split('.').pop();
8549
+
8550
+ var uploadFileData = {};
8551
+ if (params) {
8552
+ if (typeof params.file !== 'undefined') {
8553
+ uploadFileData.file = params.file;
8554
+ }
8555
+ if (parseInt(params.threadId) > 0) {
8556
+ uploadThreadId = params.threadId;
8557
+ uploadFileData.threadId = params.threadId;
8558
+ } else {
8559
+ uploadThreadId = 0;
8560
+ uploadFileData.threadId = 0;
8561
+ }
8562
+ if (typeof params.uniqueId == 'string') {
8563
+ uploadUniqueId = params.uniqueId;
8564
+ uploadFileData.uniqueId = params.uniqueId;
8565
+ } else {
8566
+ uploadUniqueId = Utility.generateUUID();
8567
+ uploadFileData.uniqueId = uploadUniqueId;
8568
+ }
8569
+ if (typeof params.userGroupHash == 'string') {
8570
+ uploadFileData.userGroupHash = params.userGroupHash;
8571
+ } else {
8572
+ callback({
8573
+ hasError: true,
8574
+ errorCode: 999,
8575
+ errorMessage: 'You need to enter a userGroupHash to be able to upload on PodSpace!'
8576
+ });
8577
+ return;
8578
+ }
8579
+ if (typeof params.originalFileName == 'string') {
8580
+ uploadFileData.originalFileName = params.originalFileName;
8581
+ } else {
8582
+ uploadFileData.originalFileName = fileName;
8583
+ }
8584
+ }
8585
+ httpRequest({
8586
+ url: SERVICE_ADDRESSES.PODSPACE_FILESERVER_ADDRESS + SERVICES_PATH.PODSPACE_UPLOAD_FILE_TO_USERGROUP_NEW.replace('{userGroupHash}', uploadFileData.userGroupHash),
8587
+ method: 'POST',
8588
+ headers: {
8589
+ 'Authorization': 'Bearer ' + token,
8590
+ },
8591
+ data: uploadFileData,
8592
+ uniqueId: uploadUniqueId
8593
+ }, function (result) {
8594
+ if (!result.hasError) {
8595
+ try {
8596
+ var response = (typeof result.result.responseText == 'string')
8597
+ ? JSON.parse(result.result.responseText)
8598
+ : result.result.responseText;
8599
+ callback({
8600
+ hasError: response.hasError,
8601
+ result: response.result
8602
+ });
8603
+ } catch (e) {
8604
+ callback({
8605
+ hasError: true,
8606
+ errorCode: 999,
8607
+ errorMessage: 'Problem in Parsing result'
8608
+ });
8609
+ }
8610
+ } else {
8611
+ callback({
8612
+ hasError: true,
8613
+ errorCode: result.errorCode,
8614
+ errorMessage: result.errorMessage
8615
+ });
8616
+ }
8617
+ });
8618
+ return {
8619
+ uniqueId: uploadUniqueId,
8620
+ threadId: uploadThreadId,
8621
+ participant: userInfo,
8622
+ content: {
8623
+ caption: params.content,
8624
+ file: {
8625
+ uniqueId: uploadUniqueId,
8626
+ fileName: fileName,
8627
+ fileSize: fileSize,
8628
+ fileObject: params.file
8629
+ }
8630
+ }
8631
+ };
8632
+ }
8633
+
8161
8634
  sendFileMessage = function (params, callbacks) {
8162
8635
  var metadata = {file: {}},
8163
8636
  fileUploadParams = {},
@@ -8173,6 +8646,8 @@
8173
8646
  fileUploadParams.userGroupHash = params.userGroupHash;
8174
8647
  }
8175
8648
 
8649
+ let msgType = (params.messageType && typeof params.messageType.toUpperCase() !== 'undefined' && chatMessageTypes[params.messageType.toUpperCase()] > 0) ? chatMessageTypes[params.messageType.toUpperCase()] : 1;
8650
+
8176
8651
  return chatUploadHandler({
8177
8652
  threadId: params.threadId,
8178
8653
  file: params.file,
@@ -8184,7 +8659,7 @@
8184
8659
  message: {
8185
8660
  chatMessageVOType: chatMessageVOTypes.MESSAGE,
8186
8661
  typeCode: params.typeCode,
8187
- messageType: (params.messageType && params.messageType.toUpperCase() !== undefined && chatMessageTypes[params.messageType.toUpperCase()] > 0) ? chatMessageTypes[params.messageType.toUpperCase()] : 1,
8662
+ messageType: msgType,
8188
8663
  subjectId: params.threadId,
8189
8664
  repliedTo: params.repliedTo,
8190
8665
  content: params.content,
@@ -8195,19 +8670,31 @@
8195
8670
  },
8196
8671
  callbacks: callbacks
8197
8672
  }, function () {
8198
- if (imageMimeTypes.indexOf(fileType) >= 0 || imageExtentions.indexOf(fileExtension) >= 0) {
8199
-
8200
- uploadImageToPodspaceUserGroup(fileUploadParams, function (result) {
8673
+ if ((imageMimeTypes.indexOf(fileType) >= 0 || imageExtentions.indexOf(fileExtension) >= 0)) {
8674
+ uploadImageToPodspaceUserGroupNew(fileUploadParams, function (result) {
8201
8675
  if (!result.hasError) {
8676
+ // Send onFileUpload callback result
8677
+ if (typeof callbacks === 'object' && callbacks.hasOwnProperty('onFileUpload')) {
8678
+ callbacks.onFileUpload && callbacks.onFileUpload({
8679
+ name: result.result.name,
8680
+ hashCode: result.result.hash,
8681
+ parentHash: result.result.parentHash,
8682
+ size: result.result.size,
8683
+ actualHeight: result.result.actualHeight,
8684
+ actualWidth: result.result.actualWidth,
8685
+ link: `${SERVICE_ADDRESSES.PODSPACE_FILESERVER_ADDRESS}/api/images/${result.result.hash}?checkUserGroupAccess=true`
8686
+ });
8687
+ }
8202
8688
  metadata['name'] = result.result.name;
8203
- metadata['fileHash'] = result.result.hashCode;
8689
+ metadata['fileHash'] = result.result.hash;
8204
8690
  metadata['file']['name'] = result.result.name;
8205
- metadata['file']['fileHash'] = result.result.hashCode;
8206
- metadata['file']['hashCode'] = result.result.hashCode;
8691
+ metadata['file']['fileHash'] = result.result.hash;
8692
+ metadata['file']['hashCode'] = result.result.hash;
8207
8693
  metadata['file']['parentHash'] = result.result.parentHash;
8208
8694
  metadata['file']['size'] = result.result.size;
8209
8695
  metadata['file']['actualHeight'] = result.result.actualHeight;
8210
8696
  metadata['file']['actualWidth'] = result.result.actualWidth;
8697
+
8211
8698
  metadata['file']['link'] = `https://podspace.pod.ir/nzh/drive/downloadImage?hash=${result.result.hashCode}`;
8212
8699
  transferFromUploadQToSendQ(parseInt(params.threadId), fileUniqueId, JSON.stringify(metadata), function () {
8213
8700
  chatSendQueueHandler();
@@ -8217,13 +8704,14 @@
8217
8704
  }
8218
8705
  });
8219
8706
  } else {
8220
- uploadFileToPodspace(fileUploadParams, function (result) {
8707
+ uploadFileToPodspaceUserGroupNew(fileUploadParams, function (result) {
8708
+ console.log('result.result.hashCode ::', result.result.hash)
8221
8709
  if (!result.hasError) {
8222
- metadata['fileHash'] = result.result.hashCode;
8710
+ metadata['fileHash'] = result.result.hash;
8223
8711
  metadata['name'] = result.result.name;
8224
8712
  metadata['file']['name'] = result.result.name;
8225
- metadata['file']['fileHash'] = result.result.hashCode;
8226
- metadata['file']['hashCode'] = result.result.hashCode;
8713
+ metadata['file']['fileHash'] = result.result.hash;
8714
+ metadata['file']['hashCode'] = result.result.hash;
8227
8715
  metadata['file']['parentHash'] = result.result.parentHash;
8228
8716
  metadata['file']['size'] = result.result.size;
8229
8717
 
@@ -10321,13 +10809,200 @@
10321
10809
  });
10322
10810
  };
10323
10811
 
10812
+ function requestExportChat(stackArr, wantedCount, stepCount, offset, sendData) {
10813
+ sendData.content.offset = offset;
10814
+ sendData.content.count = stepCount;
10815
+ return new Promise(function(resolve, reject){
10816
+ return sendMessage(sendData, {
10817
+ onResult: function (result) {
10818
+
10819
+ var returnData = {
10820
+ hasError: result.hasError,
10821
+ cache: false,
10822
+ errorMessage: result.errorMessage,
10823
+ errorCode: result.errorCode
10824
+ };
10825
+
10826
+ if (!returnData.hasError) {
10827
+ for(var i in result.result) {
10828
+ stackArr.push(result.result[i]);
10829
+ }
10830
+
10831
+ consoleLogging && console.log("[SDK][exportChat] a step passed...");
10832
+ wantedCount = wantedCount > result.contentCount ? result.contentCount : wantedCount;
10833
+ setTimeout(function () {
10834
+ fireEvent('threadEvents', {
10835
+ type: 'EXPORT_CHAT',
10836
+ subType: 'IN_PROGRESS',
10837
+ threadId: sendData.subjectId,
10838
+ percent: Math.floor((stackArr.length / wantedCount) * 100)
10839
+ });
10840
+
10841
+ if(stackArr.length < wantedCount) {
10842
+ stepCount = wantedCount - stackArr.length < stepCount ? wantedCount - stackArr.length : stepCount;
10843
+ //setTimeout(function () {
10844
+ resolve(requestExportChat(stackArr, wantedCount, stepCount, stackArr.length, sendData));
10845
+ //}, 1000)
10846
+ } else {
10847
+ resolve(stackArr);
10848
+ }
10849
+ });
10850
+ } else {
10851
+ if(result.errorCode !== 21) {
10852
+ consoleLogging && console.log("[SDK][exportChat] Problem in one step... . Rerunning the request.", wantedCount, stepCount, stackArr.length, sendData, result);
10853
+ setTimeout(function () {
10854
+ resolve(requestExportChat(stackArr, wantedCount, stepCount, stackArr.length, sendData))
10855
+ }, 2000)
10856
+ } else {
10857
+ reject(result)
10858
+ }
10859
+ }
10860
+ }
10861
+ });
10862
+ })
10863
+ }
10864
+
10865
+ this.exportChat = function (params, callback) {
10866
+ var stackArr = [], wantedCount = 10000, stepCount = 500, offset = 0;
10867
+ var sendData = {
10868
+ chatMessageVOType: chatMessageVOTypes.EXPORT_CHAT,
10869
+ typeCode: generalTypeCode,//params.typeCode,
10870
+ content: {
10871
+ offset: +params.offset > 0 ? +params.offset : offset,
10872
+ count: +params.count > 0 ? +params.count : wantedCount,//config.getHistoryCount,
10873
+ },
10874
+ subjectId: params.threadId
10875
+ };
10876
+
10877
+ if (+params.fromTime > 0 && +params.fromTime < 9999999999999) {
10878
+ sendData.content.fromTime = +params.fromTime;
10879
+ }
10880
+
10881
+ if (+params.toTime > 0 && +params.toTime < 9999999999999) {
10882
+ sendData.content.toTime = +params.toTime;
10883
+ }
10884
+
10885
+ if(+params.wantedCount > 0) {
10886
+ wantedCount = params.wantedCount;
10887
+ }
10888
+
10889
+ if(+params.stepCount > 0) {
10890
+ stepCount = params.stepCount;
10891
+ }
10892
+
10893
+ if(+params.offset > 0) {
10894
+ offset = params.offset;
10895
+ }
10896
+
10897
+ // if (params.messageType && typeof params.messageType.toUpperCase() !== 'undefined' && chatMessageTypes[params.messageType.toUpperCase()] > 0) {
10898
+ // sendData.content.messageType = chatMessageTypes[params.messageType.toUpperCase()];
10899
+ // }
10900
+ sendData.content.messageType = 1;
10901
+
10902
+ if(wantedCount < stepCount)
10903
+ stepCount = wantedCount;
10904
+
10905
+ consoleLogging && console.log("[SDK][exportChat] Starting...");
10906
+ requestExportChat(stackArr, wantedCount, stepCount, offset, sendData).then(function (resultArray) {
10907
+ consoleLogging && console.log("[SDK][exportChat] Export done..., Now converting...");
10908
+
10909
+ if(!params.exportPath) {
10910
+ callback && callback({
10911
+ hasError: false,
10912
+ result: resultArray
10913
+ });
10914
+ fireEvent('threadEvents', {
10915
+ type: 'EXPORT_CHAT',
10916
+ subType: 'DONE',
10917
+ threadId: sendData.subjectId,
10918
+ result: resultArray
10919
+ });
10920
+
10921
+ return;
10922
+ }
10923
+
10924
+ var str = ''
10925
+ , universalBOM = "\uFEFF";
10926
+
10927
+ str += "\u{62A}\u{627}\u{631}\u{6CC}\u{62E} " + ','; //tarikh
10928
+ str += " \u{633}\u{627}\u{639}\u{62A} " + ','; //saat
10929
+ str += "\u{646}\u{627}\u{645} \u{641}\u{631}\u{633}\u{62A}\u{646}\u{62F}\u{647}" + ',';//name ferestande
10930
+ str += "\u{646}\u{627}\u{645} \u{6A9}\u{627}\u{631}\u{628}\u{631}\u{6CC} \u{641}\u{631}\u{633}\u{62A}\u{646}\u{62F}\u{647}" + ','; //name karbariye ferestande
10931
+ str += "\u{645}\u{62A}\u{646} \u{67E}\u{6CC}\u{627}\u{645}" + ',';//matne payam
10932
+ str += '\r\n';
10933
+ var line = '', radif = 1;
10934
+ for (var i = 0; i < resultArray.length; i++) {
10935
+ line = '';
10936
+
10937
+ if(resultArray[i].messageType !== 1) {
10938
+ continue;
10939
+ }
10940
+
10941
+ var sender = '';
10942
+ if(resultArray[i].participant.contactName) {
10943
+ sender = resultArray[i].participant.contactName + ',';
10944
+ } else {
10945
+ if(resultArray[i].participant.firstName) {
10946
+ sender = resultArray[i].participant.firstName + ' ';
10947
+ }
10948
+ if(resultArray[i].participant.lastName) {
10949
+ sender += resultArray[i].participant.lastName;
10950
+ }
10951
+ sender += ','
10952
+ }
10953
+
10954
+ line += new Date(resultArray[i].time).toLocaleDateString('fa-IR') + ',';
10955
+ line += new Date(resultArray[i].time).toLocaleTimeString('fa-IR') + ',';
10956
+ line += sender;
10957
+ line += resultArray[i].participant.username + ',';
10958
+ line += '"' + resultArray[i].message.replace(/,/g, "،").replace(/"/g, '”') + '",';
10959
+ // line += result[i].message.replaceAll(",", ".").replace(/(\r\n|\n|\r)/gm, " ") + ',';
10960
+ str += line + '\r\n';
10961
+ radif++;
10962
+ }
10963
+
10964
+
10965
+ FS.writeFile(params.exportPath, universalBOM + str, {encoding: 'utf8'}, function (err) {
10966
+ if (err){
10967
+ fireEvent('ERROR', {
10968
+ code: null,
10969
+ message: err
10970
+ });
10971
+ callback && callback({
10972
+ hasError: true,
10973
+ code: null,
10974
+ message: err
10975
+ });
10976
+ }
10977
+
10978
+ callback && callback({
10979
+ hasError: false,
10980
+ result: resultArray,
10981
+ exportPath: params.exportPath
10982
+ });
10983
+
10984
+ fireEvent('threadEvents', {
10985
+ type: 'EXPORT_CHAT',
10986
+ subType: 'EXPORTED_TO_DIRECTORY',
10987
+ threadId: sendData.subjectId,
10988
+ exportPath: params.exportPath,
10989
+ result: resultArray
10990
+ });
10991
+
10992
+
10993
+ });
10994
+
10995
+ callback = undefined;
10996
+ })
10997
+ }
10998
+
10324
10999
  this.getImage = getImage;
10325
11000
 
10326
11001
  this.getFile = getFile;
10327
11002
 
10328
- this.getFileFromPodspace = getFileFromPodspace;
11003
+ this.getFileFromPodspace = getFileFromPodspaceNew;//getFileFromPodspace;
10329
11004
 
10330
- this.getImageFromPodspace = getImageFromPodspace;
11005
+ this.getImageFromPodspace = getImageFromPodspaceNew;
10331
11006
 
10332
11007
  this.uploadFile = uploadFile;
10333
11008