podchat 12.5.0 → 12.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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.1",
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.1"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
package/src/chat.js CHANGED
@@ -3622,6 +3622,17 @@
3622
3622
  }
3623
3623
  break;
3624
3624
 
3625
+ /**
3626
+ * Type 152 Gives us a json to export for user
3627
+ */
3628
+ case chatMessageVOTypes.EXPORT_CHAT:
3629
+ if (messagesCallbacks[uniqueId]) {
3630
+ messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount, uniqueId));
3631
+ }
3632
+
3633
+ break;
3634
+
3635
+
3625
3636
  /**
3626
3637
  * Type 221 Event to tell us p2p call converted to a group call
3627
3638
  */
@@ -3648,7 +3659,6 @@
3648
3659
 
3649
3660
  break;
3650
3661
 
3651
-
3652
3662
  /**
3653
3663
  * Type 999 All unknown errors
3654
3664
  */
@@ -10321,6 +10331,193 @@
10321
10331
  });
10322
10332
  };
10323
10333
 
10334
+ function requestExportChat(stackArr, wantedCount, stepCount, offset, sendData) {
10335
+ sendData.content.offset = offset;
10336
+ sendData.content.count = stepCount;
10337
+ return new Promise(function(resolve, reject){
10338
+ return sendMessage(sendData, {
10339
+ onResult: function (result) {
10340
+
10341
+ var returnData = {
10342
+ hasError: result.hasError,
10343
+ cache: false,
10344
+ errorMessage: result.errorMessage,
10345
+ errorCode: result.errorCode
10346
+ };
10347
+
10348
+ if (!returnData.hasError) {
10349
+ for(var i in result.result) {
10350
+ stackArr.push(result.result[i]);
10351
+ }
10352
+
10353
+ consoleLogging && console.log("[SDK][exportChat] a step passed...");
10354
+ wantedCount = wantedCount > result.contentCount ? result.contentCount : wantedCount;
10355
+ setTimeout(function () {
10356
+ fireEvent('threadEvents', {
10357
+ type: 'EXPORT_CHAT',
10358
+ subType: 'IN_PROGRESS',
10359
+ threadId: sendData.subjectId,
10360
+ percent: Math.floor((stackArr.length / wantedCount) * 100)
10361
+ });
10362
+
10363
+ if(stackArr.length < wantedCount) {
10364
+ stepCount = wantedCount - stackArr.length < stepCount ? wantedCount - stackArr.length : stepCount;
10365
+ //setTimeout(function () {
10366
+ resolve(requestExportChat(stackArr, wantedCount, stepCount, stackArr.length, sendData));
10367
+ //}, 1000)
10368
+ } else {
10369
+ resolve(stackArr);
10370
+ }
10371
+ });
10372
+ } else {
10373
+ if(result.errorCode !== 21) {
10374
+ consoleLogging && console.log("[SDK][exportChat] Problem in one step... . Rerunning the request.", wantedCount, stepCount, stackArr.length, sendData, result);
10375
+ setTimeout(function () {
10376
+ resolve(requestExportChat(stackArr, wantedCount, stepCount, stackArr.length, sendData))
10377
+ }, 2000)
10378
+ } else {
10379
+ reject(result)
10380
+ }
10381
+ }
10382
+ }
10383
+ });
10384
+ })
10385
+ }
10386
+
10387
+ this.exportChat = function (params, callback) {
10388
+ var stackArr = [], wantedCount = 10000, stepCount = 500, offset = 0;
10389
+ var sendData = {
10390
+ chatMessageVOType: chatMessageVOTypes.EXPORT_CHAT,
10391
+ typeCode: generalTypeCode,//params.typeCode,
10392
+ content: {
10393
+ offset: +params.offset > 0 ? +params.offset : offset,
10394
+ count: +params.count > 0 ? +params.count : wantedCount,//config.getHistoryCount,
10395
+ },
10396
+ subjectId: params.threadId
10397
+ };
10398
+
10399
+ if (+params.fromTime > 0 && +params.fromTime < 9999999999999) {
10400
+ sendData.content.fromTime = +params.fromTime;
10401
+ }
10402
+
10403
+ if (+params.toTime > 0 && +params.toTime < 9999999999999) {
10404
+ sendData.content.toTime = +params.toTime;
10405
+ }
10406
+
10407
+ if(+params.wantedCount > 0) {
10408
+ wantedCount = params.wantedCount;
10409
+ }
10410
+
10411
+ if(+params.stepCount > 0) {
10412
+ stepCount = params.stepCount;
10413
+ }
10414
+
10415
+ if(+params.offset > 0) {
10416
+ offset = params.offset;
10417
+ }
10418
+
10419
+ // if (params.messageType && typeof params.messageType.toUpperCase() !== 'undefined' && chatMessageTypes[params.messageType.toUpperCase()] > 0) {
10420
+ // sendData.content.messageType = chatMessageTypes[params.messageType.toUpperCase()];
10421
+ // }
10422
+ sendData.content.messageType = 1;
10423
+
10424
+ if(wantedCount < stepCount)
10425
+ stepCount = wantedCount;
10426
+
10427
+ consoleLogging && console.log("[SDK][exportChat] Starting...");
10428
+ requestExportChat(stackArr, wantedCount, stepCount, offset, sendData).then(function (resultArray) {
10429
+ consoleLogging && console.log("[SDK][exportChat] Export done..., Now converting...");
10430
+
10431
+ if(!params.exportPath) {
10432
+ callback && callback({
10433
+ hasError: false,
10434
+ result: resultArray
10435
+ });
10436
+ fireEvent('threadEvents', {
10437
+ type: 'EXPORT_CHAT',
10438
+ subType: 'DONE',
10439
+ threadId: sendData.subjectId,
10440
+ result: resultArray
10441
+ });
10442
+
10443
+ return;
10444
+ }
10445
+
10446
+ var str = ''
10447
+ , universalBOM = "\uFEFF";
10448
+
10449
+ str += "\u{62A}\u{627}\u{631}\u{6CC}\u{62E} " + ','; //tarikh
10450
+ str += " \u{633}\u{627}\u{639}\u{62A} " + ','; //saat
10451
+ str += "\u{646}\u{627}\u{645} \u{641}\u{631}\u{633}\u{62A}\u{646}\u{62F}\u{647}" + ',';//name ferestande
10452
+ 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
10453
+ str += "\u{645}\u{62A}\u{646} \u{67E}\u{6CC}\u{627}\u{645}" + ',';//matne payam
10454
+ str += '\r\n';
10455
+ var line = '', radif = 1;
10456
+ for (var i = 0; i < resultArray.length; i++) {
10457
+ line = '';
10458
+
10459
+ if(resultArray[i].messageType !== 1) {
10460
+ continue;
10461
+ }
10462
+
10463
+ var sender = '';
10464
+ if(resultArray[i].participant.contactName) {
10465
+ sender = resultArray[i].participant.contactName + ',';
10466
+ } else {
10467
+ if(resultArray[i].participant.firstName) {
10468
+ sender = resultArray[i].participant.firstName + ' ';
10469
+ }
10470
+ if(resultArray[i].participant.lastName) {
10471
+ sender += resultArray[i].participant.lastName;
10472
+ }
10473
+ sender += ','
10474
+ }
10475
+
10476
+ line += new Date(resultArray[i].time).toLocaleDateString('fa-IR') + ',';
10477
+ line += new Date(resultArray[i].time).toLocaleTimeString('fa-IR') + ',';
10478
+ line += sender;
10479
+ line += resultArray[i].participant.username + ',';
10480
+ line += '"' + resultArray[i].message.replace(/,/g, "،").replace(/"/g, '”') + '",';
10481
+ // line += result[i].message.replaceAll(",", ".").replace(/(\r\n|\n|\r)/gm, " ") + ',';
10482
+ str += line + '\r\n';
10483
+ radif++;
10484
+ }
10485
+
10486
+
10487
+ FS.writeFile(params.exportPath, universalBOM + str, {encoding: 'utf8'}, function (err) {
10488
+ if (err){
10489
+ fireEvent('ERROR', {
10490
+ code: null,
10491
+ message: err
10492
+ });
10493
+ callback && callback({
10494
+ hasError: true,
10495
+ code: null,
10496
+ message: err
10497
+ });
10498
+ }
10499
+
10500
+ callback && callback({
10501
+ hasError: false,
10502
+ result: resultArray,
10503
+ exportPath: params.exportPath
10504
+ });
10505
+
10506
+ fireEvent('threadEvents', {
10507
+ type: 'EXPORT_CHAT',
10508
+ subType: 'EXPORTED_TO_DIRECTORY',
10509
+ threadId: sendData.subjectId,
10510
+ exportPath: params.exportPath,
10511
+ result: resultArray
10512
+ });
10513
+
10514
+
10515
+ });
10516
+
10517
+ callback = undefined;
10518
+ })
10519
+ }
10520
+
10324
10521
  this.getImage = getImage;
10325
10522
 
10326
10523
  this.getFile = getFile;