@@ -4,20 +4,21 @@ import {
44 init ,
55 login as webcomLogin ,
66 createAccount ,
7- logout ,
7+ logout as logoutWebcom ,
88 push ,
99 getUserData ,
1010 screenshot
1111} from 'services' ;
1212import { Components , Component } from 'actions' ;
1313import * as actions from 'actions' ;
14+ import { getAuth } from './selectors' ;
1415
1516let appRouter ;
1617
1718export function * login ( email , password ) {
1819 try {
1920 const auth = yield call ( webcomLogin , email , password ) ;
20- yield put ( actions . logged , auth ) ;
21+ yield put ( actions . logged ( { email : auth . email , uid : auth . uid } ) ) ;
2122 return auth ;
2223 }
2324 catch ( e ) {
@@ -45,7 +46,9 @@ export function* sendMessage(message, auth, takeScreenshot) {
4546 } ;
4647 }
4748
48- yield call ( push , 'message' , data ) ;
49+ const path = `${ encodeURIComponent ( data . domain ) } }/messages` ;
50+
51+ yield call ( push , path , data ) ;
4952 yield call ( appRouter . push , '/messageSent' ) ;
5053}
5154
@@ -58,13 +61,15 @@ export function* watchInit() {
5861export function * watchSendMessage ( ) {
5962 while ( true ) {
6063 const { payload : {
61- content ,
64+ message ,
6265 takeScreenshot }
6366 } = yield take ( 'SEND_MESSAGE' ) ;
6467
68+ const auth = yield select ( getAuth ) ;
69+
6570 // get auth
6671 if ( auth ) {
67- yield call ( sendMessage , content , auth , takeScreenshot ) ;
72+ yield call ( sendMessage , message , auth , takeScreenshot ) ;
6873 }
6974 }
7075}
@@ -105,9 +110,18 @@ export function* watchCreateUser() {
105110 }
106111}
107112
113+ export function * watchLogout ( ) {
114+ while ( true ) {
115+ yield take ( 'LOGOUT' ) ;
116+ yield call ( logoutWebcom ) ;
117+ yield put ( actions . unlogged ( ) ) ;
118+ }
119+ }
120+
108121export default function * root ( ) {
109122 yield [
110123 fork ( watchInit ) ,
124+ fork ( watchLogout ) ,
111125 fork ( watchSendMessage ) ,
112126 fork ( watchLoginAndSendMessage ) ,
113127 fork ( watchCreateUser )
0 commit comments