incyclist-services 1.5.49 → 1.5.50

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.
@@ -264,37 +264,45 @@ let ActiveRidesService = (() => {
264
264
  }
265
265
  getDisplayProps() {
266
266
  const items = this.get();
267
- if (!items.length)
268
- return [];
269
- const displayProps = [];
270
- items.forEach(item => {
271
- var _a, _b;
272
- const displayItem = {
273
- isUser: item.sessionId === this.session,
274
- name: this.getName(item),
275
- diffDistance: this.getDistanceDiff(item),
276
- distance: item.currentRideDistance,
277
- avatar: this.getAvatar(item),
278
- lap: this.getLap(item, true),
279
- power: item.currentPower,
280
- mpower: this.getRelativePower(item),
281
- speed: item.currentSpeed,
282
- lat: (_a = item.currentPosition) === null || _a === void 0 ? void 0 : _a.lat,
283
- lng: (_b = item.currentPosition) === null || _b === void 0 ? void 0 : _b.lng,
284
- };
285
- displayProps.push(displayItem);
286
- });
287
- if (displayProps.length > this.maxLength) {
288
- const absDiff = (r) => Math.abs(r.diffDistance);
267
+ try {
268
+ if (!items.length)
269
+ return [];
270
+ const displayProps = [];
271
+ items.forEach(item => {
272
+ var _a, _b, _c, _d;
273
+ if (!(item === null || item === void 0 ? void 0 : item.id) && !((_b = (_a = item === null || item === void 0 ? void 0 : item.user) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.length) && (item === null || item === void 0 ? void 0 : item.sessionId) !== this.session)
274
+ return;
275
+ const displayItem = {
276
+ isUser: item.sessionId === this.session,
277
+ name: this.getName(item),
278
+ diffDistance: this.getDistanceDiff(item),
279
+ distance: item.currentRideDistance,
280
+ avatar: this.getAvatar(item),
281
+ lap: this.getLap(item, true),
282
+ power: item.currentPower,
283
+ mpower: this.getRelativePower(item),
284
+ speed: item.currentSpeed,
285
+ lat: (_c = item.currentPosition) === null || _c === void 0 ? void 0 : _c.lat,
286
+ lng: (_d = item.currentPosition) === null || _d === void 0 ? void 0 : _d.lng,
287
+ };
288
+ displayProps.push(displayItem);
289
+ });
290
+ if (displayProps.length > this.maxLength) {
291
+ const absDiff = (r) => Math.abs(r.diffDistance);
292
+ displayProps.sort((a, b) => {
293
+ return absDiff(b) > absDiff(a) ? -1 : 1;
294
+ });
295
+ return displayProps.filter((_r, idx) => idx < this.maxLength);
296
+ }
289
297
  displayProps.sort((a, b) => {
290
- return absDiff(b) > absDiff(a) ? -1 : 1;
298
+ return b.diffDistance > a.diffDistance ? -1 : 1;
291
299
  });
292
- return displayProps.filter((_r, idx) => idx < this.maxLength);
300
+ return displayProps;
301
+ }
302
+ catch (err) {
303
+ this.logError(err, 'getDisplayProps', { items });
304
+ return [];
293
305
  }
294
- displayProps.sort((a, b) => {
295
- return b.diffDistance > a.diffDistance ? -1 : 1;
296
- });
297
- return displayProps;
298
306
  }
299
307
  validName(str) {
300
308
  if (!(str === null || str === void 0 ? void 0 : str.length))
@@ -309,6 +317,8 @@ let ActiveRidesService = (() => {
309
317
  return this.validName((_f = item.user) === null || _f === void 0 ? void 0 : _f.name) ? (_g = item.user) === null || _g === void 0 ? void 0 : _g.name : this.randomName((_h = item.user) === null || _h === void 0 ? void 0 : _h.id);
310
318
  }
311
319
  randomName(id) {
320
+ if (!id)
321
+ return 'Anonymous';
312
322
  const names = ['Alex', 'Bart', 'Cosmas', 'Dirk', 'Ernesto', 'Frank', 'Guido', 'Hans', 'Irene', 'John', 'Kai', 'Lorenzo', 'Martin', 'Naijb', 'Oswaldo', 'Pete', 'Quentin', 'Rachel', 'Sophia', 'Trevor', 'Ute', 'Vivian', 'Wil', 'Xaver', 'Younes', 'Zoe'];
313
323
  const fnKey = id.charAt(0).toLowerCase();
314
324
  const idx = !isNaN(parseInt(fnKey)) ? parseInt(fnKey) : fnKey.charCodeAt(0) - 96;
@@ -514,21 +524,25 @@ let ActiveRidesService = (() => {
514
524
  this.getMessageQueue().sendMessage(topic, payload);
515
525
  }
516
526
  onActivityStartEvent(session, payload) {
517
- var _a, _b, _c, _d, _e, _f;
527
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
518
528
  const prevActive = (_a = this.others) === null || _a === void 0 ? void 0 : _a.length;
519
529
  try {
520
530
  const others = (_b = this.others) !== null && _b !== void 0 ? _b : [];
521
- if (others.find(ar => ar.sessionId === session))
531
+ if (others.some(ar => ar.sessionId === session))
532
+ return;
533
+ if (((_c = payload.user) === null || _c === void 0 ? void 0 : _c.id) && ((_d = payload.user) === null || _d === void 0 ? void 0 : _d.id) === ((_e = this.current.user) === null || _e === void 0 ? void 0 : _e.id))
534
+ return;
535
+ if (((_f = payload.user) === null || _f === void 0 ? void 0 : _f.id) && others.some(ar => { var _a, _b; return ((_a = ar.user) === null || _a === void 0 ? void 0 : _a.id) === ((_b = payload.user) === null || _b === void 0 ? void 0 : _b.id); }))
522
536
  return;
523
537
  const entry = Object.assign(Object.assign({ id: Date.now().toString(), tsLastUpdate: Date.now() }, payload), { sessionId: session });
524
538
  this.addActiveRide(entry);
525
539
  if (prevActive === 0) {
526
540
  this.isStarted = true;
527
- this.logEvent({ message: 'group ride started', active: this.others.length + 1, activityId: (_c = this.activity) === null || _c === void 0 ? void 0 : _c.id, route: (_d = this.activity.route) === null || _d === void 0 ? void 0 : _d.title, routeHash: this.getRouteHash() });
541
+ this.logEvent({ message: 'group ride started', active: this.others.length + 1, activityId: (_g = this.activity) === null || _g === void 0 ? void 0 : _g.id, route: (_h = this.activity.route) === null || _h === void 0 ? void 0 : _h.title, routeHash: this.getRouteHash() });
528
542
  }
529
543
  else {
530
544
  this.isStarted = true;
531
- this.logEvent({ message: 'group ride user joined', active: this.others.length + 1, activityId: (_e = this.activity) === null || _e === void 0 ? void 0 : _e.id, route: (_f = this.activity.route) === null || _f === void 0 ? void 0 : _f.title, routeHash: this.getRouteHash() });
545
+ this.logEvent({ message: 'group ride user joined', active: this.others.length + 1, activityId: (_j = this.activity) === null || _j === void 0 ? void 0 : _j.id, route: (_k = this.activity.route) === null || _k === void 0 ? void 0 : _k.title, routeHash: this.getRouteHash(), user: (_l = payload === null || payload === void 0 ? void 0 : payload.user) === null || _l === void 0 ? void 0 : _l.id });
532
546
  }
533
547
  if (!payload.user) {
534
548
  this.getRemoteActivityDetails(session);
@@ -644,31 +658,36 @@ let ActiveRidesService = (() => {
644
658
  }
645
659
  }
646
660
  updateCoaches() {
647
- if (!this.current)
648
- return;
649
- const coachesService = this.getCoachesService();
650
- const coaches = coachesService.getCoaches();
651
- if (!(coaches === null || coaches === void 0 ? void 0 : coaches.length)) {
652
- this.coaches = undefined;
653
- return;
654
- }
655
- this.coaches = coaches.map(c => {
656
- var _a;
657
- const props = c.getDisplayProperties();
658
- const rideEntry = {
659
- id: `coach:${props.name}`,
660
- user: {
661
- name: props.name,
661
+ try {
662
+ if (!this.current)
663
+ return;
664
+ const coachesService = this.getCoachesService();
665
+ const coaches = coachesService.getCoaches();
666
+ if (!(coaches === null || coaches === void 0 ? void 0 : coaches.length)) {
667
+ this.coaches = undefined;
668
+ return;
669
+ }
670
+ this.coaches = coaches.map(c => {
671
+ var _a;
672
+ const props = c.getDisplayProperties();
673
+ const rideEntry = {
662
674
  id: `coach:${props.name}`,
663
- },
664
- ride: (_a = this.current) === null || _a === void 0 ? void 0 : _a.ride,
665
- tsLastUpdate: Date.now(),
666
- currentRideDistance: c.getProgess(),
667
- currentPosition: c.getPosition(),
668
- isCoach: true
669
- };
670
- return rideEntry;
671
- });
675
+ user: {
676
+ name: props.name,
677
+ id: `coach:${props.name}`,
678
+ },
679
+ ride: (_a = this.current) === null || _a === void 0 ? void 0 : _a.ride,
680
+ tsLastUpdate: Date.now(),
681
+ currentRideDistance: c.getProgess(),
682
+ currentPosition: c.getPosition(),
683
+ isCoach: true
684
+ };
685
+ return rideEntry;
686
+ });
687
+ }
688
+ catch (err) {
689
+ this.logError(err, 'updateCoaches');
690
+ }
672
691
  }
673
692
  cleanup() {
674
693
  delete this.current;
@@ -334,7 +334,10 @@ let ActivityRideService = (() => {
334
334
  }
335
335
  }
336
336
  canShowDonate() {
337
- if (this.isDonateShown)
337
+ var _a, _b, _c, _d;
338
+ if (!((_b = (_a = this.activity) === null || _a === void 0 ? void 0 : _a.user) === null || _b === void 0 ? void 0 : _b.uuid))
339
+ return false;
340
+ if (this.isDonateShown || !((_d = (_c = this.activity) === null || _c === void 0 ? void 0 : _c.user) === null || _d === void 0 ? void 0 : _d.uuid))
338
341
  return true;
339
342
  let trialGroup;
340
343
  if (this.activity.user.uuid.startsWith('1') || this.activity.user.uuid.startsWith('a')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.5.49",
3
+ "version": "1.5.50",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },