Commit e6c32aca authored by Mark Harding's avatar Mark Harding
Browse files

Merge branch 'hotfix/sentry-injection' into 'master'

[Sprint/ModestMonkey] (fix): Diagnostics ID flood (#1857)

See merge request !534
parents 100602ee 61c1fc76
Loading
Loading
Loading
Loading
+6 −1
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@ import { BlockListService } from './common/services/block-list.service';
import { FeaturesService } from './services/features.service';
import { FeaturesService } from './services/features.service';
import { ThemeService } from './common/services/theme.service';
import { ThemeService } from './common/services/theme.service';
import { BannedService } from './modules/report/banned/banned.service';
import { BannedService } from './modules/report/banned/banned.service';
import { DiagnosticsService } from './services/diagnostics.service';


@Component({
@Component({
  moduleId: module.id,
  moduleId: module.id,
@@ -50,12 +51,16 @@ export class Minds {
    public blockListService: BlockListService,
    public blockListService: BlockListService,
    public featuresService: FeaturesService,
    public featuresService: FeaturesService,
    public themeService: ThemeService,
    public themeService: ThemeService,
    private bannedService: BannedService
    private bannedService: BannedService,
    private diagnostics: DiagnosticsService
  ) {
  ) {
    this.name = 'Minds';
    this.name = 'Minds';
  }
  }


  async ngOnInit() {
  async ngOnInit() {
    this.diagnostics.setUser(this.minds.user);
    this.diagnostics.listen(); // Listen for user changes

    this.notificationService.getNotifications();
    this.notificationService.getNotifications();


    this.session.isLoggedIn(async is => {
    this.session.isLoggedIn(async is => {
+28 −0
Original line number Original line Diff line number Diff line
import { Injectable } from '@angular/core';
import * as Sentry from '@sentry/browser';
import { Session } from './session';

@Injectable()
export class DiagnosticsService {
  constructor(protected session: Session) {}

  listen() {
    this.session.getLoggedInUser(currentUser => {
      this.setUser(currentUser);
    });
  }

  setUser(currentUser) {
    let userId = null;

    if (currentUser) {
      userId = currentUser.guid || null;
    }

    Sentry.setUser({
      id: userId,
    });

    console.info('Diagnostics ID:', userId);
  }
}
+2 −0
Original line number Original line Diff line number Diff line
@@ -42,6 +42,7 @@ import { InMemoryStorageService } from './in-memory-storage.service';
import { FeedsService } from '../common/services/feeds.service';
import { FeedsService } from '../common/services/feeds.service';
import { ThemeService } from '../common/services/theme.service';
import { ThemeService } from '../common/services/theme.service';
import { GlobalScrollService } from './ux/global-scroll.service';
import { GlobalScrollService } from './ux/global-scroll.service';
import { DiagnosticsService } from './diagnostics.service';


export const MINDS_PROVIDERS: any[] = [
export const MINDS_PROVIDERS: any[] = [
  {
  {
@@ -222,4 +223,5 @@ export const MINDS_PROVIDERS: any[] = [
    useFactory: ThemeService._,
    useFactory: ThemeService._,
    deps: [RendererFactory2, Client, Session, Storage],
    deps: [RendererFactory2, Client, Session, Storage],
  },
  },
  DiagnosticsService,
];
];
+0 −4
Original line number Original line Diff line number Diff line
@@ -2,7 +2,6 @@
 * Sessions
 * Sessions
 */
 */
import { EventEmitter } from '@angular/core';
import { EventEmitter } from '@angular/core';
import * as Sentry from '@sentry/browser';


export class Session {
export class Session {
  loggedinEmitter: EventEmitter<any> = new EventEmitter();
  loggedinEmitter: EventEmitter<any> = new EventEmitter();
@@ -51,9 +50,6 @@ export class Session {


    if (window.Minds.user) {
    if (window.Minds.user) {
      // Attach user_guid to debug logs
      // Attach user_guid to debug logs
      Sentry.setUser({
        id: window.Minds.user.guid,
      });
      return window.Minds.user;
      return window.Minds.user;
    }
    }