기능추가 :: 대화 > unread Count Badge 처리.

This commit is contained in:
leejh 2019-10-17 15:06:38 +09:00
parent 6f5a4bfc99
commit 99d7440c25
4 changed files with 41 additions and 11 deletions

View File

@ -14,13 +14,8 @@
</mat-tab> </mat-tab>
<mat-tab> <mat-tab>
<ng-template mat-tab-label> <ng-template mat-tab-label>
<mat-icon <mat-icon [matBadgeHidden]="((badgeChatUnReadCount$ | async) <= 0)" [matBadge]="badgeChatUnReadCount$ | async"
matBadge="22" matBadgeDescription="확인하지 않은 메시지가 있습니다." matBadgeColor="accent" matBadgePosition="above after">chat</mat-icon>
matBadgeDescription="확인하지 않은 메시지가 있습니다."
matBadgeColor="accent"
matBadgePosition="above after"
>chat</mat-icon
>
</ng-template> </ng-template>
<app-layout-chat-left-sidenav-chat></app-layout-chat-left-sidenav-chat> <app-layout-chat-left-sidenav-chat></app-layout-chat-left-sidenav-chat>
</mat-tab> </mat-tab>

View File

@ -6,6 +6,10 @@ 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 { Observable } from 'rxjs';
import { Store, select } from '@ngrx/store';
import * as AppStore from '@app/store';
@Component({ @Component({
selector: 'app-layout-messenger-left-side', selector: 'app-layout-messenger-left-side',
@ -14,12 +18,19 @@ import {
animations: ucapAnimations animations: ucapAnimations
}) })
export class LeftSideComponent implements OnInit { export class LeftSideComponent implements OnInit {
badgeChatUnReadCount$: Observable<number>;
constructor( constructor(
private store: Store<any>,
private dialogService: DialogService, private dialogService: DialogService,
private logger: NGXLogger private logger: NGXLogger
) {} ) {}
ngOnInit() {} ngOnInit() {
this.badgeChatUnReadCount$ = this.store.pipe(
select(AppStore.MessengerSelector.SyncSelector.selectChatUnreadCount)
);
}
async onClickNewChat() { async onClickNewChat() {
const result = await this.dialogService.open< const result = await this.dialogService.open<

View File

@ -68,6 +68,9 @@ export const reducer = createReducer(
} }
} }
let unReadCount = 0;
action.roomList.map(item => (unReadCount += item.noReadCnt));
return { return {
...state, ...state,
room: adapterRoom.upsertMany(action.roomList, { room: adapterRoom.upsertMany(action.roomList, {
@ -79,7 +82,8 @@ export const reducer = createReducer(
}), }),
roomUserShort: adapterRoomUserShort.upsertMany(roomUserShortList, { roomUserShort: adapterRoomUserShort.upsertMany(roomUserShortList, {
...state.roomUserShort ...state.roomUserShort
}) }),
chatUnreadCount: unReadCount
}; };
}), }),
@ -152,12 +156,26 @@ export const reducer = createReducer(
noReadCnt: action.noReadCnt noReadCnt: action.noReadCnt
}; };
let unReadCount = 0;
if (action.noReadCnt === 0) {
// tslint:disable-next-line: forin
for (const key in state.room.entities) {
if (key !== action.roomSeq) {
const value = state.room.entities[key];
unReadCount += value.noReadCnt;
}
}
} else {
unReadCount = state.chatUnreadCount + 1;
}
return { return {
...state, ...state,
room: adapterRoom.updateOne( room: adapterRoom.updateOne(
{ id: action.roomSeq, changes: roomInfo }, { id: action.roomSeq, changes: roomInfo },
{ ...state.room } { ...state.room }
) ),
chatUnreadCount: unReadCount
}; };
}), }),

View File

@ -34,6 +34,7 @@ export interface State {
room: RoomState; room: RoomState;
roomUser: RoomUserState; roomUser: RoomUserState;
roomUserShort: RoomUserShortState; roomUserShort: RoomUserShortState;
chatUnreadCount: number;
} }
export const adapterBuddy2 = createEntityAdapter<UserInfo>({ export const adapterBuddy2 = createEntityAdapter<UserInfo>({
@ -93,7 +94,8 @@ export const initialState: State = {
group2: group2InitialState, group2: group2InitialState,
room: roomInitialState, room: roomInitialState,
roomUser: roomUserInitialState, roomUser: roomUserInitialState,
roomUserShort: roomUserShortInitialState roomUserShort: roomUserShortInitialState,
chatUnreadCount: 0
}; };
const { const {
@ -189,6 +191,10 @@ export function selectors<S>(selector: Selector<any, State>) {
selectAllRoomUserShort: createSelector( selectAllRoomUserShort: createSelector(
selectRoomUserShort, selectRoomUserShort,
ngeSelectAllRoomUserShort ngeSelectAllRoomUserShort
),
selectChatUnreadCount: createSelector(
selector,
(state: State) => state.chatUnreadCount
) )
}; };
} }