bugfix : duplication message unread count retrieve

This commit is contained in:
leejinho 2020-02-04 09:52:43 +09:00
parent 8629d1f321
commit f98acedbb2
3 changed files with 11 additions and 56 deletions

View File

@ -34,8 +34,8 @@
<ng-template mat-tab-label> <ng-template mat-tab-label>
<div <div
class="icon-item" class="icon-item"
[matBadgeHidden]="badgeChatUnReadCount <= 0" [matBadgeHidden]="(badgeChatUnReadCount$ | async) <= 0"
[matBadge]="badgeChatUnReadCount" [matBadge]="badgeChatUnReadCount$ | async"
matBadgeDescription="{{ matBadgeDescription="{{
'chat.badgeDescriptionForUnread' | translate 'chat.badgeDescriptionForUnread' | translate
}}" }}"

View File

@ -1,20 +1,14 @@
import { import { Component, OnInit, OnDestroy } from '@angular/core';
Component,
OnInit,
OnDestroy,
} from '@angular/core';
import { NGXLogger } from 'ngx-logger'; import { NGXLogger } from 'ngx-logger';
import { ucapAnimations } from '@ucap-webmessenger/ui'; import { ucapAnimations } from '@ucap-webmessenger/ui';
import { Subscription, Observable, } from 'rxjs'; import { Observable } from 'rxjs';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
import * as AppStore from '@app/store'; import * as AppStore from '@app/store';
import * as MessageStore from '@app/store/messenger/message'; import * as MessageStore from '@app/store/messenger/message';
import * as SettingsStore from '@app/store/messenger/settings'; import * as SettingsStore from '@app/store/messenger/settings';
import { MatTabChangeEvent } from '@angular/material'; import { MatTabChangeEvent } from '@angular/material';
import { import { MainMenu } from '@app/types';
MainMenu
} from '@app/types';
@Component({ @Component({
selector: 'app-layout-messenger-left-nav', selector: 'app-layout-messenger-left-nav',
@ -23,8 +17,7 @@ import {
animations: ucapAnimations animations: ucapAnimations
}) })
export class LeftNaviComponent implements OnInit, OnDestroy { export class LeftNaviComponent implements OnInit, OnDestroy {
badgeChatUnReadCount: number; badgeChatUnReadCount$: Observable<number>;
badgeChatUnReadCountSubscription: Subscription;
badgeMessageUnReadCount$: Observable<number>; badgeMessageUnReadCount$: Observable<number>;
badgeMessageInterval: any; badgeMessageInterval: any;
@ -33,13 +26,10 @@ export class LeftNaviComponent implements OnInit, OnDestroy {
constructor(private store: Store<any>, private logger: NGXLogger) {} constructor(private store: Store<any>, private logger: NGXLogger) {}
ngOnInit() { ngOnInit() {
this.badgeChatUnReadCountSubscription = this.store /** About Chat Badge */
.pipe( this.badgeChatUnReadCount$ = this.store.pipe(
select(AppStore.MessengerSelector.SyncSelector.selectChatUnreadCount) select(AppStore.MessengerSelector.SyncSelector.selectChatUnreadCount)
) );
.subscribe(count => {
this.badgeChatUnReadCount = count;
});
/** About Message Badge */ /** About Message Badge */
this.badgeMessageUnReadCount$ = this.store.pipe( this.badgeMessageUnReadCount$ = this.store.pipe(
@ -54,10 +44,6 @@ export class LeftNaviComponent implements OnInit, OnDestroy {
} }
ngOnDestroy(): void { ngOnDestroy(): void {
if (!!this.badgeChatUnReadCountSubscription) {
this.badgeChatUnReadCountSubscription.unsubscribe();
}
if (!!this.badgeMessageInterval) { if (!!this.badgeMessageInterval) {
clearInterval(this.badgeMessageInterval); clearInterval(this.badgeMessageInterval);
} }

View File

@ -17,7 +17,7 @@ import {
CreateChatDialogData, CreateChatDialogData,
CreateChatDialogResult CreateChatDialogResult
} from '@app/layouts/messenger/dialogs/chat/create-chat.dialog.component'; } from '@app/layouts/messenger/dialogs/chat/create-chat.dialog.component';
import { Subscription, Observable, merge } from 'rxjs'; import { Subscription, merge } from 'rxjs';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
import * as AppStore from '@app/store'; import * as AppStore from '@app/store';
@ -76,11 +76,6 @@ export class LeftSideComponent implements OnInit, OnDestroy {
onLangChangeSubscription: Subscription; onLangChangeSubscription: Subscription;
badgeChatUnReadCount: number;
badgeChatUnReadCountSubscription: Subscription;
badgeMessageUnReadCount$: Observable<number>;
badgeMessageInterval: any;
/** 조직도에서 부서원 선택 */ /** 조직도에서 부서원 선택 */
selectedUserList: (UserInfo | UserInfoSS | UserInfoF | UserInfoDN)[] = []; selectedUserList: (UserInfo | UserInfoSS | UserInfoF | UserInfoDN)[] = [];
@ -113,14 +108,6 @@ export class LeftSideComponent implements OnInit, OnDestroy {
} }
ngOnInit() { ngOnInit() {
this.badgeChatUnReadCountSubscription = this.store
.pipe(
select(AppStore.MessengerSelector.SyncSelector.selectChatUnreadCount)
)
.subscribe(count => {
this.badgeChatUnReadCount = count;
});
this.loginResSubscription = this.store this.loginResSubscription = this.store
.pipe( .pipe(
select(AppStore.AccountSelector.AuthenticationSelector.loginRes), select(AppStore.AccountSelector.AuthenticationSelector.loginRes),
@ -130,17 +117,6 @@ export class LeftSideComponent implements OnInit, OnDestroy {
) )
.subscribe(); .subscribe();
/** About Message Badge */
this.badgeMessageUnReadCount$ = this.store.pipe(
select(AppStore.MessengerSelector.MessageSelector.unReadMessageCount)
);
this.getMessageUnreadCount();
this.badgeMessageInterval = setInterval(
() => this.getMessageUnreadCount(),
5 * 60 * 1000
);
this.setFabInitial(MainMenu.Group); this.setFabInitial(MainMenu.Group);
this.currentTabLable = MainMenu.Group; this.currentTabLable = MainMenu.Group;
@ -164,19 +140,12 @@ export class LeftSideComponent implements OnInit, OnDestroy {
} }
ngOnDestroy(): void { ngOnDestroy(): void {
if (!!this.badgeChatUnReadCountSubscription) {
this.badgeChatUnReadCountSubscription.unsubscribe();
}
if (!!this.loginResSubscription) { if (!!this.loginResSubscription) {
this.loginResSubscription.unsubscribe(); this.loginResSubscription.unsubscribe();
} }
if (!!this.onLangChangeSubscription) { if (!!this.onLangChangeSubscription) {
this.onLangChangeSubscription.unsubscribe(); this.onLangChangeSubscription.unsubscribe();
} }
if (!!this.badgeMessageInterval) {
clearInterval(this.badgeMessageInterval);
}
} }
async onClickNewChat(type: string = 'NORMAL') { async onClickNewChat(type: string = 'NORMAL') {