@banta/sdk 4.0.12 → 4.0.13

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.
@@ -12,6 +12,7 @@ import { __awaiter, __decorate, __metadata } from 'tslib';
12
12
  import { MatDialog, MatDialogModule } from '@angular/material/dialog';
13
13
  import { CommentsOrder, CDNProvider, SocketRPC, RpcEvent, DurableSocket } from '@banta/common';
14
14
  import { ActivatedRoute } from '@angular/router';
15
+ import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
15
16
  import { MatMenuModule } from '@angular/material/menu';
16
17
  import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
17
18
  import { TextFieldModule } from '@angular/cdk/text-field';
@@ -7765,7 +7766,6 @@ class CommentComponent {
7765
7766
  }
7766
7767
  avatarForUser(user) {
7767
7768
  let url = this.genericAvatarUrl;
7768
- console.log(`GENERIC: ${this.genericAvatarUrl}`);
7769
7769
  if (user && user.avatarUrl) {
7770
7770
  url = user.avatarUrl;
7771
7771
  }
@@ -8052,10 +8052,11 @@ CommentViewComponent.propDecorators = {
8052
8052
  * Comments component
8053
8053
  */
8054
8054
  class BantaCommentsComponent {
8055
- constructor(backend, elementRef, activatedRoute) {
8055
+ constructor(backend, elementRef, activatedRoute, matSnackBar) {
8056
8056
  this.backend = backend;
8057
8057
  this.elementRef = elementRef;
8058
8058
  this.activatedRoute = activatedRoute;
8059
+ this.matSnackBar = matSnackBar;
8059
8060
  // Loading Screen
8060
8061
  this._loadingMessage = '';
8061
8062
  this.loadingMessageVisible = false;
@@ -8084,6 +8085,12 @@ class BantaCommentsComponent {
8084
8085
  this._shared = new Subject();
8085
8086
  this._usernameSelected = new Subject();
8086
8087
  this._avatarSelected = new Subject();
8088
+ /**
8089
+ * Track whether we created this source. If we did not (ie it was passed in from the caller),
8090
+ * then we are not responsible for calling close(). If we do own it though, we will call close()
8091
+ * when we are done with it.
8092
+ */
8093
+ this._sourceIsOwned = false;
8087
8094
  this._subs = new Subscription();
8088
8095
  this._sortOrder = CommentsOrder.NEWEST;
8089
8096
  this.selectedMessageVisible = false;
@@ -8174,20 +8181,10 @@ class BantaCommentsComponent {
8174
8181
  }
8175
8182
  setSourceFromTopicID(topicID) {
8176
8183
  return __awaiter(this, void 0, void 0, function* () {
8177
- if (this._source) {
8178
- this._source.close();
8179
- this._source = null;
8180
- }
8181
8184
  setTimeout(() => __awaiter(this, void 0, void 0, function* () {
8182
8185
  console.log(`[banta-comments] Subscribing to topic source '${topicID}'`);
8183
- this._source = yield this.backend.getSourceForTopic(topicID, { sortOrder: this.sortOrder });
8184
- if (this.sharedCommentID) {
8185
- this.navigateToSharedComment(this.sharedCommentID);
8186
- this.sharedCommentID = null;
8187
- }
8188
- this._source.messageReceived.subscribe(m => this.addParticipant(m));
8189
- this._source.messageSent.subscribe(m => this.addParticipant(m));
8190
- this._source.messages.forEach(m => this.addParticipant(m));
8186
+ this.source = yield this.backend.getSourceForTopic(topicID, { sortOrder: this.sortOrder });
8187
+ this._sourceIsOwned = true;
8191
8188
  }));
8192
8189
  });
8193
8190
  }
@@ -8245,10 +8242,34 @@ class BantaCommentsComponent {
8245
8242
  }
8246
8243
  get source() { return this._source; }
8247
8244
  set source(value) {
8245
+ var _a;
8246
+ if (this._source && this._sourceIsOwned) {
8247
+ this._source.close();
8248
+ (_a = this._sourceSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
8249
+ this._source = null;
8250
+ this.participants = [];
8251
+ }
8248
8252
  this._source = value;
8249
- if (value && this.sharedCommentID) {
8250
- this.navigateToSharedComment(this.sharedCommentID);
8251
- this.sharedCommentID = null;
8253
+ this._sourceIsOwned = false; // Assume we don't own this source.
8254
+ this._sourceSubscription = new Subscription();
8255
+ if (value) {
8256
+ if (this.sharedCommentID) {
8257
+ this.navigateToSharedComment(this.sharedCommentID);
8258
+ this.sharedCommentID = null;
8259
+ }
8260
+ this._source.messages.forEach(m => this.addParticipant(m));
8261
+ this._sourceSubscription.add(this._source.messageReceived.subscribe(m => this.addParticipant(m)));
8262
+ this._sourceSubscription.add(this._source.messageSent.subscribe(m => this.addParticipant(m)));
8263
+ this._sourceSubscription.add(this._source.messageUpdated.subscribe(msg => {
8264
+ var _a;
8265
+ console.log(`comments received message: `, msg);
8266
+ if (msg.id === ((_a = this.selectedMessage) === null || _a === void 0 ? void 0 : _a.id) && msg.hidden) {
8267
+ this.unselectMessage();
8268
+ this.matSnackBar.open("The thread you were viewing was removed.", undefined, {
8269
+ duration: 2500
8270
+ });
8271
+ }
8272
+ }));
8252
8273
  }
8253
8274
  }
8254
8275
  get topicID() { return this._topicID; }
@@ -8500,7 +8521,8 @@ BantaCommentsComponent.decorators = [
8500
8521
  BantaCommentsComponent.ctorParameters = () => [
8501
8522
  { type: ChatBackendBase },
8502
8523
  { type: ElementRef },
8503
- { type: ActivatedRoute }
8524
+ { type: ActivatedRoute },
8525
+ { type: MatSnackBar }
8504
8526
  ];
8505
8527
  BantaCommentsComponent.propDecorators = {
8506
8528
  loadingMessages: [{ type: Input }],
@@ -8999,6 +9021,7 @@ class ChatSource extends SocketRPC {
8999
9021
  this.state = 'connecting';
9000
9022
  this.messageMap = new Map();
9001
9023
  this._messageReceived = new Subject();
9024
+ this._messageUpdated = new Subject();
9002
9025
  this._messageSent = new Subject();
9003
9026
  this.messages = [];
9004
9027
  this.ready = new Promise(resolve => this.markReady = resolve);
@@ -9069,6 +9092,7 @@ class ChatSource extends SocketRPC {
9069
9092
  onChatMessage(message) {
9070
9093
  if (this.messageMap.has(message.id)) {
9071
9094
  Object.assign(this.messageMap.get(message.id), message);
9095
+ this._messageUpdated.next(message);
9072
9096
  }
9073
9097
  else if (!message.hidden) {
9074
9098
  // Only process non-hidden messages through here.
@@ -9079,6 +9103,7 @@ class ChatSource extends SocketRPC {
9079
9103
  }
9080
9104
  }
9081
9105
  get messageReceived() { return this._messageReceived.asObservable(); }
9106
+ get messageUpdated() { return this._messageUpdated.asObservable(); }
9082
9107
  get messageSent() { return this._messageSent.asObservable(); }
9083
9108
  send(message) {
9084
9109
  return __awaiter(this, void 0, void 0, function* () {
@@ -9237,7 +9262,8 @@ BantaSdkModule.decorators = [
9237
9262
  MatDialogModule,
9238
9263
  MatFormFieldModule,
9239
9264
  MatInputModule,
9240
- MatProgressSpinnerModule
9265
+ MatProgressSpinnerModule,
9266
+ MatSnackBarModule
9241
9267
  ],
9242
9268
  declarations: [
9243
9269
  BantaComponent,