send message is implemented

This commit is contained in:
병준 박 2019-10-08 14:34:37 +09:00
parent 4e1246731e
commit 7832e7d13d
7 changed files with 116 additions and 20 deletions

View File

@ -49,7 +49,7 @@
<!-- CHAT FOOTER --> <!-- CHAT FOOTER -->
<div fxFlex="0 0 auto" fxLayout="column"> <div fxFlex="0 0 auto" fxLayout="column">
<!-- REPLY FORM --> <!-- REPLY FORM -->
<ucap-chat-form></ucap-chat-form> <ucap-chat-form (send)="onSendMessage($event)"></ucap-chat-form>
<!-- / REPLY FORM --> <!-- / REPLY FORM -->
</div> </div>
<!-- / CHAT FOOTER--> <!-- / CHAT FOOTER-->

View File

@ -1,14 +1,17 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit, OnDestroy } from '@angular/core';
import { ucapAnimations } from '@ucap-webmessenger/ui'; import { ucapAnimations } from '@ucap-webmessenger/ui';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
import { NGXLogger } from 'ngx-logger'; import { NGXLogger } from 'ngx-logger';
import { Observable } from 'rxjs'; import { Observable, Subscriber, Subscription } from 'rxjs';
import { Info } from '@ucap-webmessenger/protocol-event'; import { Info, EventType } from '@ucap-webmessenger/protocol-event';
import * as AppStore from '@app/store'; import * as AppStore from '@app/store';
import * as EventStore from '@app/store/messenger/event';
import { LoginResponse } from '@ucap-webmessenger/protocol-authentication'; import { LoginResponse } from '@ucap-webmessenger/protocol-authentication';
import { SessionStorageService } from '@ucap-webmessenger/web-storage'; import { SessionStorageService } from '@ucap-webmessenger/web-storage';
import { LoginInfo, KEY_LOGIN_INFO } from '@app/types'; import { LoginInfo, KEY_LOGIN_INFO } from '@app/types';
import { RoomInfo } from '@ucap-webmessenger/protocol-room';
import { map, tap } from 'rxjs/operators';
@Component({ @Component({
selector: 'app-layout-messenger-messages', selector: 'app-layout-messenger-messages',
@ -16,9 +19,11 @@ import { LoginInfo, KEY_LOGIN_INFO } from '@app/types';
styleUrls: ['./messages.component.scss'], styleUrls: ['./messages.component.scss'],
animations: ucapAnimations animations: ucapAnimations
}) })
export class MessagesComponent implements OnInit { export class MessagesComponent implements OnInit, OnDestroy {
loginRes$: Observable<LoginResponse>; loginRes$: Observable<LoginResponse>;
eventList$: Observable<Info[]>; eventList$: Observable<Info[]>;
roomInfo: RoomInfo;
roomInfoSubscription: Subscription;
constructor( constructor(
private store: Store<any>, private store: Store<any>,
@ -33,10 +38,37 @@ export class MessagesComponent implements OnInit {
select(AppStore.AccountSelector.AuthenticationSelector.loginRes) select(AppStore.AccountSelector.AuthenticationSelector.loginRes)
); );
this.roomInfoSubscription = this.store
.pipe(
select(AppStore.MessengerSelector.RoomSelector.roomInfo),
tap(roomInfo => {
this.roomInfo = roomInfo;
})
)
.subscribe();
this.eventList$ = this.store.pipe( this.eventList$ = this.store.pipe(
select(AppStore.MessengerSelector.EventSelector.infoList) select(AppStore.MessengerSelector.EventSelector.infoList)
); );
} }
ngOnDestroy(): void {
if (!!this.roomInfoSubscription) {
this.roomInfoSubscription.unsubscribe();
}
}
selectContact() {} selectContact() {}
onSendMessage(message: string) {
this.store.dispatch(
EventStore.send({
req: {
roomSeq: this.roomInfo.roomSeq,
eventType: EventType.Character,
sentMessage: message
}
})
);
}
} }

View File

@ -2,7 +2,9 @@ import { createAction, props } from '@ngrx/store';
import { import {
InfoRequest, InfoRequest,
Info, Info,
InfoResponse InfoResponse,
SendResponse,
SendRequest
} from '@ucap-webmessenger/protocol-event'; } from '@ucap-webmessenger/protocol-event';
export const info = createAction( export const info = createAction(
@ -22,3 +24,20 @@ export const infoFailure = createAction(
'[Messenger::Event] Info Failure', '[Messenger::Event] Info Failure',
props<{ error: any }>() props<{ error: any }>()
); );
export const send = createAction(
'[Messenger::Event] Send',
props<{ req: SendRequest }>()
);
export const sendSuccess = createAction(
'[Messenger::Event] Send Success',
props<{
res: SendResponse;
}>()
);
export const sendFailure = createAction(
'[Messenger::Event] Send Failure',
props<{ error: any }>()
);

View File

@ -7,19 +7,27 @@ import { Store } from '@ngrx/store';
import { NGXLogger } from 'ngx-logger'; import { NGXLogger } from 'ngx-logger';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { tap, switchMap, map, catchError } from 'rxjs/operators'; import { tap, switchMap, map, catchError, exhaustMap } from 'rxjs/operators';
import { import {
InfoData, InfoData,
Info, Info,
InfoResponse, InfoResponse,
EventProtocolService, EventProtocolService,
SSVC_TYPE_EVENT_INFO_DATA, SSVC_TYPE_EVENT_INFO_DATA,
SSVC_TYPE_EVENT_INFO_RES SSVC_TYPE_EVENT_INFO_RES,
SendResponse
} from '@ucap-webmessenger/protocol-event'; } from '@ucap-webmessenger/protocol-event';
import * as ChatStore from '@app/store/messenger/chat'; import * as ChatStore from '@app/store/messenger/chat';
import { info, infoSuccess, infoFailure } from './actions'; import {
info,
infoSuccess,
infoFailure,
send,
sendSuccess,
sendFailure
} from './actions';
import { SessionStorageService } from '@ucap-webmessenger/web-storage'; import { SessionStorageService } from '@ucap-webmessenger/web-storage';
@Injectable() @Injectable()
@ -71,6 +79,23 @@ export class Effects {
{ dispatch: false } { dispatch: false }
); );
send$ = createEffect(() =>
this.actions$.pipe(
ofType(send),
map(action => action.req),
exhaustMap(req =>
this.eventProtocolService.send(req).pipe(
map((res: SendResponse) => {
return sendSuccess({
res
});
}),
catchError(error => of(sendFailure({ error })))
)
)
)
);
constructor( constructor(
private actions$: Actions, private actions$: Actions,
private store: Store<any>, private store: Store<any>,

View File

@ -16,7 +16,7 @@ export interface SendRequest extends ProtocolRequest {
// 0. 대화방SEQ(s) // 0. 대화방SEQ(s)
roomSeq: string; roomSeq: string;
// 1. 이벤트타입(s) // 1. 이벤트타입(s)
type: EventType; eventType: EventType;
// 2. 이벤트내용(s) // 2. 이벤트내용(s)
sentMessage: string; sentMessage: string;
} }
@ -27,7 +27,7 @@ export interface SendResponse extends ProtocolResponse {
// 이벤트SEQ(n) // 이벤트SEQ(n)
seq: number; seq: number;
// 이벤트타입(s) // 이벤트타입(s)
type: EventType; eventType: EventType;
// 발생일시(s) // 발생일시(s)
sendDate: string; sendDate: string;
// 이벤트내용(s) // 이벤트내용(s)
@ -48,7 +48,7 @@ export interface SendNotification extends ProtocolNotification {
// 이벤트SEQ(n) // 이벤트SEQ(n)
seq: number; seq: number;
// 이벤트타입(s) // 이벤트타입(s)
type: EventType; eventType: EventType;
// 발생일시(s) // 발생일시(s)
sendDate: string; sendDate: string;
// 이벤트내용(s) // 이벤트내용(s)
@ -72,7 +72,7 @@ export const encodeSend: ProtocolEncoder<SendRequest> = (req: SendRequest) => {
bodyList.push( bodyList.push(
{ type: PacketBodyValue.String, value: req.roomSeq }, { type: PacketBodyValue.String, value: req.roomSeq },
{ type: PacketBodyValue.String, value: req.type }, { type: PacketBodyValue.String, value: req.eventType },
{ type: PacketBodyValue.String, value: req.sentMessage } { type: PacketBodyValue.String, value: req.sentMessage }
); );
@ -85,7 +85,7 @@ export const decodeSend: ProtocolDecoder<SendResponse> = (
return { return {
roomSeq: message.bodyList[0], roomSeq: message.bodyList[0],
seq: message.bodyList[1], seq: message.bodyList[1],
type: message.bodyList[2] as EventType, eventType: message.bodyList[2] as EventType,
sendDate: message.bodyList[3], sendDate: message.bodyList[3],
message: message.bodyList[4], message: message.bodyList[4],
receiverCount: message.bodyList[5] || 0, receiverCount: message.bodyList[5] || 0,
@ -101,7 +101,7 @@ export const decodeSendNotification: ProtocolDecoder<SendNotification> = (
return { return {
roomSeq: message.bodyList[0], roomSeq: message.bodyList[0],
seq: message.bodyList[1], seq: message.bodyList[1],
type: message.bodyList[2] as EventType, eventType: message.bodyList[2] as EventType,
sendDate: message.bodyList[3], sendDate: message.bodyList[3],
message: message.bodyList[4], message: message.bodyList[4],
receiverCount: message.bodyList[5] || 0, receiverCount: message.bodyList[5] || 0,

View File

@ -6,8 +6,8 @@
> >
<form <form
#replyForm="ngForm" #replyForm="ngForm"
(ngSubmit)="send($event)" (ngSubmit)="onSend($event)"
(keydown.enter)="send($event)" (keydown.enter)="onSend($event)"
fxFlex fxFlex
fxLayout="row" fxLayout="row"
fxLayoutAlign="start center" fxLayoutAlign="start center"
@ -34,6 +34,8 @@
mat-icon-button mat-icon-button
type="submit" type="submit"
aria-label="Send message" aria-label="Send message"
></button> >
Send
</button>
</form> </form>
</div> </div>

View File

@ -1,4 +1,11 @@
import { Component, OnInit } from '@angular/core'; import {
Component,
OnInit,
Output,
EventEmitter,
ViewChild
} from '@angular/core';
import { NgForm } from '@angular/forms';
@Component({ @Component({
selector: 'ucap-chat-form', selector: 'ucap-chat-form',
@ -6,9 +13,20 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./form.component.scss'] styleUrls: ['./form.component.scss']
}) })
export class FormComponent implements OnInit { export class FormComponent implements OnInit {
@Output()
send = new EventEmitter<string>();
@ViewChild('replyForm', { static: false })
replyForm: NgForm;
constructor() {} constructor() {}
ngOnInit() {} ngOnInit() {}
send() {} onSend(event: Event) {
event.preventDefault();
this.send.emit(this.replyForm.form.value.message);
this.replyForm.reset();
}
} }