send message is implemented
This commit is contained in:
parent
7832e7d13d
commit
90614de5d0
|
@ -40,7 +40,7 @@
|
||||||
<!-- CHAT MESSAGES -->
|
<!-- CHAT MESSAGES -->
|
||||||
<ucap-chat-messages
|
<ucap-chat-messages
|
||||||
[messages]="eventList$ | async"
|
[messages]="eventList$ | async"
|
||||||
[loginRes]="loginRes$ | async"
|
[loginRes]="loginRes"
|
||||||
></ucap-chat-messages>
|
></ucap-chat-messages>
|
||||||
<!-- CHAT MESSAGES -->
|
<!-- CHAT MESSAGES -->
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -20,7 +20,8 @@ import { map, tap } from 'rxjs/operators';
|
||||||
animations: ucapAnimations
|
animations: ucapAnimations
|
||||||
})
|
})
|
||||||
export class MessagesComponent implements OnInit, OnDestroy {
|
export class MessagesComponent implements OnInit, OnDestroy {
|
||||||
loginRes$: Observable<LoginResponse>;
|
loginRes: LoginResponse;
|
||||||
|
loginResSubscription: Subscription;
|
||||||
eventList$: Observable<Info[]>;
|
eventList$: Observable<Info[]>;
|
||||||
roomInfo: RoomInfo;
|
roomInfo: RoomInfo;
|
||||||
roomInfoSubscription: Subscription;
|
roomInfoSubscription: Subscription;
|
||||||
|
@ -34,9 +35,14 @@ export class MessagesComponent implements OnInit, OnDestroy {
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
const loginInfo = this.sessionStorageService.get<LoginInfo>(KEY_LOGIN_INFO);
|
const loginInfo = this.sessionStorageService.get<LoginInfo>(KEY_LOGIN_INFO);
|
||||||
|
|
||||||
this.loginRes$ = this.store.pipe(
|
this.loginResSubscription = this.store
|
||||||
select(AppStore.AccountSelector.AuthenticationSelector.loginRes)
|
.pipe(
|
||||||
);
|
select(AppStore.AccountSelector.AuthenticationSelector.loginRes),
|
||||||
|
tap(loginRes => {
|
||||||
|
this.loginRes = loginRes;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.subscribe();
|
||||||
|
|
||||||
this.roomInfoSubscription = this.store
|
this.roomInfoSubscription = this.store
|
||||||
.pipe(
|
.pipe(
|
||||||
|
@ -53,6 +59,9 @@ export class MessagesComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
|
if (!!this.loginResSubscription) {
|
||||||
|
this.loginResSubscription.unsubscribe();
|
||||||
|
}
|
||||||
if (!!this.roomInfoSubscription) {
|
if (!!this.roomInfoSubscription) {
|
||||||
this.roomInfoSubscription.unsubscribe();
|
this.roomInfoSubscription.unsubscribe();
|
||||||
}
|
}
|
||||||
|
@ -63,6 +72,7 @@ export class MessagesComponent implements OnInit, OnDestroy {
|
||||||
onSendMessage(message: string) {
|
onSendMessage(message: string) {
|
||||||
this.store.dispatch(
|
this.store.dispatch(
|
||||||
EventStore.send({
|
EventStore.send({
|
||||||
|
senderSeq: this.loginRes.userSeq,
|
||||||
req: {
|
req: {
|
||||||
roomSeq: this.roomInfo.roomSeq,
|
roomSeq: this.roomInfo.roomSeq,
|
||||||
eventType: EventType.Character,
|
eventType: EventType.Character,
|
||||||
|
|
|
@ -25,14 +25,22 @@ export const infoFailure = createAction(
|
||||||
props<{ error: any }>()
|
props<{ error: any }>()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const appendInfoList = createAction(
|
||||||
|
'[Messenger::Event] Append InfoList',
|
||||||
|
props<{
|
||||||
|
info: Info;
|
||||||
|
}>()
|
||||||
|
);
|
||||||
|
|
||||||
export const send = createAction(
|
export const send = createAction(
|
||||||
'[Messenger::Event] Send',
|
'[Messenger::Event] Send',
|
||||||
props<{ req: SendRequest }>()
|
props<{ senderSeq: number; req: SendRequest }>()
|
||||||
);
|
);
|
||||||
|
|
||||||
export const sendSuccess = createAction(
|
export const sendSuccess = createAction(
|
||||||
'[Messenger::Event] Send Success',
|
'[Messenger::Event] Send Success',
|
||||||
props<{
|
props<{
|
||||||
|
senderSeq: number;
|
||||||
res: SendResponse;
|
res: SendResponse;
|
||||||
}>()
|
}>()
|
||||||
);
|
);
|
||||||
|
|
|
@ -26,7 +26,8 @@ import {
|
||||||
infoFailure,
|
infoFailure,
|
||||||
send,
|
send,
|
||||||
sendSuccess,
|
sendSuccess,
|
||||||
sendFailure
|
sendFailure,
|
||||||
|
appendInfoList
|
||||||
} from './actions';
|
} from './actions';
|
||||||
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
||||||
|
|
||||||
|
@ -82,11 +83,11 @@ export class Effects {
|
||||||
send$ = createEffect(() =>
|
send$ = createEffect(() =>
|
||||||
this.actions$.pipe(
|
this.actions$.pipe(
|
||||||
ofType(send),
|
ofType(send),
|
||||||
map(action => action.req),
|
exhaustMap(action =>
|
||||||
exhaustMap(req =>
|
this.eventProtocolService.send(action.req).pipe(
|
||||||
this.eventProtocolService.send(req).pipe(
|
|
||||||
map((res: SendResponse) => {
|
map((res: SendResponse) => {
|
||||||
return sendSuccess({
|
return sendSuccess({
|
||||||
|
senderSeq: action.senderSeq,
|
||||||
res
|
res
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
@ -96,6 +97,28 @@ export class Effects {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sendSuccess$ = createEffect(
|
||||||
|
() => {
|
||||||
|
return this.actions$.pipe(
|
||||||
|
ofType(sendSuccess),
|
||||||
|
tap(action => {
|
||||||
|
const res = action.res;
|
||||||
|
const appendInfo: Info = {
|
||||||
|
seq: res.seq,
|
||||||
|
type: res.eventType,
|
||||||
|
senderSeq: action.senderSeq,
|
||||||
|
sendDate: res.sendDate,
|
||||||
|
sentMessage: res.message,
|
||||||
|
receiverCount: res.receiverCount
|
||||||
|
};
|
||||||
|
|
||||||
|
this.store.dispatch(appendInfoList({ info: appendInfo }));
|
||||||
|
})
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{ dispatch: false }
|
||||||
|
);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private actions$: Actions,
|
private actions$: Actions,
|
||||||
private store: Store<any>,
|
private store: Store<any>,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { createReducer, on } from '@ngrx/store';
|
import { createReducer, on } from '@ngrx/store';
|
||||||
import { initialState } from './state';
|
import { initialState } from './state';
|
||||||
import { infoSuccess } from './actions';
|
import { infoSuccess, appendInfoList } from './actions';
|
||||||
|
|
||||||
export const reducer = createReducer(
|
export const reducer = createReducer(
|
||||||
initialState,
|
initialState,
|
||||||
|
@ -10,5 +10,12 @@ export const reducer = createReducer(
|
||||||
infoList: action.infoList,
|
infoList: action.infoList,
|
||||||
infoStatus: action.res
|
infoStatus: action.res
|
||||||
};
|
};
|
||||||
|
}),
|
||||||
|
|
||||||
|
on(appendInfoList, (state, action) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
infoList: [...state.infoList, action.info]
|
||||||
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -29,7 +29,7 @@ export interface SendResponse extends ProtocolResponse {
|
||||||
// 이벤트타입(s)
|
// 이벤트타입(s)
|
||||||
eventType: EventType;
|
eventType: EventType;
|
||||||
// 발생일시(s)
|
// 발생일시(s)
|
||||||
sendDate: string;
|
sendDate: Date;
|
||||||
// 이벤트내용(s)
|
// 이벤트내용(s)
|
||||||
message: string;
|
message: string;
|
||||||
// 수신자수
|
// 수신자수
|
||||||
|
|
Loading…
Reference in New Issue
Block a user