@@ -13,11 +13,11 @@ const camelizeKeysAndDispatch = (dispatch, actionCreator) => data => dispatch(ac
13
13
const getRecipientName = data => data . invite . recipient . name ;
14
14
const getCreatorName = data => data . invite . creator . name ;
15
15
const getOpponentName = ( data , userId ) => {
16
- if ( userId === data . invite . creator_id ) {
16
+ if ( userId === data . invite . creatorId ) {
17
17
return getRecipientName ( data ) ;
18
18
}
19
19
20
- if ( userId === data . invite . recipient_id ) {
20
+ if ( userId === data . invite . recipientId ) {
21
21
return getCreatorName ( data ) ;
22
22
}
23
23
@@ -28,22 +28,26 @@ export const initInvites = currentUserId => dispatch => {
28
28
const onJoinSuccess = ( ) => {
29
29
channel . addListener ( channelTopics . invitesInitTopic , data => {
30
30
if ( data . invites . length > 0 ) {
31
- const message = getSystemMessage ( { text : `You have (${ data . invites . length } ) invites to battle. Check ` } ) ;
31
+ const message = getSystemMessage ( {
32
+ text : `You have (${ data . invites . length } ) invites to battle. Check ` ,
33
+ } ) ;
32
34
setTimeout ( ( ) => dispatch ( actions . newChatMessage ( message ) ) , 100 ) ;
33
35
}
34
36
dispatch ( actions . setInvites ( data ) ) ;
35
37
} ) ;
36
38
37
39
channel . addListener ( channelTopics . invitesCreatedTopic , data => {
38
- if ( data . invite . creator_id !== currentUserId ) {
39
- const message = getSystemMessage ( { text : `You received battle invite (from ${ getCreatorName ( data ) } )` } ) ;
40
+ if ( data . invite . creatorId !== currentUserId ) {
41
+ const message = getSystemMessage ( {
42
+ text : `You received battle invite (from ${ getCreatorName ( data ) } )` ,
43
+ } ) ;
40
44
dispatch ( actions . newChatMessage ( message ) ) ;
41
45
}
42
46
43
47
dispatch ( actions . addInvite ( data ) ) ;
44
48
} ) ;
45
49
channel . addListener ( channelTopics . invitesCanceledTopic , data => {
46
- if ( data . invite . executor_id !== currentUserId ) {
50
+ if ( data . invite . executorId !== currentUserId ) {
47
51
const message = getSystemMessage ( {
48
52
text : `Invite has been canceled (Opponent ${ getOpponentName ( data , currentUserId ) } )` ,
49
53
status : 'failure' ,
@@ -54,14 +58,16 @@ export const initInvites = currentUserId => dispatch => {
54
58
dispatch ( actions . updateInvite ( data ) ) ;
55
59
} ) ;
56
60
channel . addListener ( channelTopics . invitesAcceptedTopic , data => {
57
- if ( data . invite . executor_id !== currentUserId ) {
61
+ if ( data . invite . executorId !== currentUserId ) {
58
62
const message = getSystemMessage ( {
59
63
text : `Invite has been accepted (Opponent ${ getOpponentName ( data , currentUserId ) } )` ,
60
64
status : 'success' ,
61
65
} ) ;
62
66
dispatch ( actions . newChatMessage ( message ) ) ;
63
67
}
64
- setTimeout ( ( ) => { window . location . href = `/games/${ data . invite . game_id } ` ; } , 250 ) ;
68
+ setTimeout ( ( ) => {
69
+ window . location . href = `/games/${ data . invite . gameId } ` ;
70
+ } , 250 ) ;
65
71
66
72
dispatch ( actions . updateInvite ( data ) ) ;
67
73
} ) ;
@@ -85,57 +91,63 @@ export const initInvites = currentUserId => dispatch => {
85
91
} ) ;
86
92
} ;
87
93
88
- channel
89
- . join ( )
90
- . receive ( 'ok' , onJoinSuccess ) ;
94
+ channel . join ( ) . receive ( 'ok' , onJoinSuccess ) ;
91
95
} ;
92
96
93
97
export const createInvite = params => dispatch => channel
94
- . push ( channelMethods . invitesCreate , params )
95
- . receive ( 'ok' , data => {
96
- const message = getSystemMessage ( { text : `You invite ${ params . recipient_name } to battle. Wait for his reply` } ) ;
97
- dispatch ( actions . newChatMessage ( message ) ) ;
98
+ . push ( channelMethods . invitesCreate , params )
99
+ . receive ( 'ok' , data => {
100
+ const message = getSystemMessage ( {
101
+ text : `You invite ${ data ?. invite ?. recipient ?. name } to battle. Wait for his reply` ,
102
+ } ) ;
103
+ dispatch ( actions . newChatMessage ( message ) ) ;
98
104
99
- dispatch ( actions . addInvite ( data ) ) ;
100
- } )
101
- . receive ( 'error' , ( { reason } ) => {
102
- throw new Error ( reason ) ;
103
- } ) ;
105
+ dispatch ( actions . addInvite ( data ) ) ;
106
+ } )
107
+ . receive ( 'error' , ( { reason } ) => {
108
+ throw new Error ( reason ) ;
109
+ } ) ;
104
110
105
111
export const acceptInvite = id => dispatch => channel
106
- . push ( channelMethods . invitesAccept , { id } )
107
- . receive ( 'ok' , data => {
108
- setTimeout ( ( ) => { window . location . href = `/games/${ data . invite . game_id } ` ; } , 250 ) ;
112
+ . push ( channelMethods . invitesAccept , { id } )
113
+ . receive ( 'ok' , data => {
114
+ setTimeout ( ( ) => {
115
+ window . location . href = `/games/${ data . invite . gameId } ` ;
116
+ } , 250 ) ;
109
117
110
- dispatch ( actions . updateInvite ( data ) ) ;
111
- } )
112
- . receive ( 'error' , ( { reason } ) => {
113
- dispatch ( actions . updateInvite ( { id, state : 'invalid' } ) ) ;
114
- throw new Error ( reason ) ;
115
- } ) ;
118
+ dispatch ( actions . updateInvite ( data ) ) ;
119
+ } )
120
+ . receive ( 'error' , ( { reason } ) => {
121
+ dispatch ( actions . updateInvite ( { id, state : 'invalid' } ) ) ;
122
+ throw new Error ( reason ) ;
123
+ } ) ;
116
124
117
125
export const declineInvite = ( id , opponentName ) => dispatch => channel
118
- . push ( channelMethods . invitesCancel , { id } )
119
- . receive ( 'ok' , data => {
120
- const message = getSystemMessage ( { text : `You decline battle invite [Opponent ${ opponentName } ]` } ) ;
121
- dispatch ( actions . newChatMessage ( message ) ) ;
122
-
123
- camelizeKeysAndDispatch ( dispatch , actions . updateInvite ) ( data ) ;
124
- } )
125
- . receive ( 'error' , ( { reason } ) => {
126
- dispatch ( actions . updateInvite ( { id, state : 'invalid' } ) ) ;
127
- throw new Error ( reason ) ;
128
- } ) ;
126
+ . push ( channelMethods . invitesCancel , { id } )
127
+ . receive ( 'ok' , data => {
128
+ const message = getSystemMessage ( {
129
+ text : `You decline battle invite [Opponent ${ opponentName } ]` ,
130
+ } ) ;
131
+ dispatch ( actions . newChatMessage ( message ) ) ;
132
+
133
+ camelizeKeysAndDispatch ( dispatch , actions . updateInvite ) ( data ) ;
134
+ } )
135
+ . receive ( 'error' , ( { reason } ) => {
136
+ dispatch ( actions . updateInvite ( { id, state : 'invalid' } ) ) ;
137
+ throw new Error ( reason ) ;
138
+ } ) ;
129
139
130
140
export const cancelInvite = ( id , opponentName ) => dispatch => channel
131
- . push ( channelMethods . invitesCancel , { id } )
132
- . receive ( 'ok' , data => {
133
- const message = getSystemMessage ( { text : `You cancel battle invite [Opponent ${ opponentName } ]` } ) ;
134
- dispatch ( actions . newChatMessage ( message ) ) ;
135
-
136
- camelizeKeysAndDispatch ( dispatch , actions . updateInvite ) ( data ) ;
137
- } )
138
- . receive ( 'error' , ( { reason } ) => {
139
- dispatch ( actions . updateInvite ( { id, state : 'invalid' } ) ) ;
140
- throw new Error ( reason ) ;
141
- } ) ;
141
+ . push ( channelMethods . invitesCancel , { id } )
142
+ . receive ( 'ok' , data => {
143
+ const message = getSystemMessage ( {
144
+ text : `You cancel battle invite [Opponent ${ opponentName } ]` ,
145
+ } ) ;
146
+ dispatch ( actions . newChatMessage ( message ) ) ;
147
+
148
+ camelizeKeysAndDispatch ( dispatch , actions . updateInvite ) ( data ) ;
149
+ } )
150
+ . receive ( 'error' , ( { reason } ) => {
151
+ dispatch ( actions . updateInvite ( { id, state : 'invalid' } ) ) ;
152
+ throw new Error ( reason ) ;
153
+ } ) ;
0 commit comments