@@ -27,57 +27,6 @@ const findAccount = (state: AccountsState, identity: Identity): number => {
27
27
) ;
28
28
} ;
29
29
30
- const loginSuccess = ( state , action ) => {
31
- const { realm, email, apiKey } = action ;
32
- const accountIndex = findAccount ( state , { realm, email } ) ;
33
- if ( accountIndex === - 1 ) {
34
- return [
35
- {
36
- realm,
37
- email,
38
- apiKey,
39
- userId : null ,
40
- ackedPushToken : null ,
41
- zulipVersion : null ,
42
- zulipFeatureLevel : null ,
43
- lastDismissedServerPushSetupNotice : null ,
44
- } ,
45
- ...state ,
46
- ] ;
47
- }
48
- return [
49
- { ...state [ accountIndex ] , apiKey, ackedPushToken : null } ,
50
- ...state . slice ( 0 , accountIndex ) ,
51
- ...state . slice ( accountIndex + 1 ) ,
52
- ] ;
53
- } ;
54
-
55
- const ackPushToken = ( state , action ) => {
56
- const { pushToken : ackedPushToken , identity } = action ;
57
- const accountIndex = findAccount ( state , identity ) ;
58
- if ( accountIndex === - 1 ) {
59
- return state ;
60
- }
61
- return [
62
- ...state . slice ( 0 , accountIndex ) ,
63
- { ...state [ accountIndex ] , ackedPushToken } ,
64
- ...state . slice ( accountIndex + 1 ) ,
65
- ] ;
66
- } ;
67
-
68
- const unackPushToken = ( state , action ) => {
69
- const { identity } = action ;
70
- const accountIndex = findAccount ( state , identity ) ;
71
- if ( accountIndex === - 1 ) {
72
- return state ;
73
- }
74
- return [
75
- ...state . slice ( 0 , accountIndex ) ,
76
- { ...state [ accountIndex ] , ackedPushToken : null } ,
77
- ...state . slice ( accountIndex + 1 ) ,
78
- ] ;
79
- } ;
80
-
81
30
// eslint-disable-next-line default-param-last
82
31
export default ( state : AccountsState = initialState , action : Action ) : AccountsState => {
83
32
switch ( action . type ) {
@@ -107,14 +56,56 @@ export default (state: AccountsState = initialState, action: Action): AccountsSt
107
56
: [ account , ...state . filter ( a => a !== account ) ] ; // put account first
108
57
}
109
58
110
- case LOGIN_SUCCESS :
111
- return loginSuccess ( state , action ) ;
59
+ case LOGIN_SUCCESS : {
60
+ const { realm, email, apiKey } = action ;
61
+ const accountIndex = findAccount ( state , { realm, email } ) ;
62
+ if ( accountIndex === - 1 ) {
63
+ return [
64
+ {
65
+ realm,
66
+ email,
67
+ apiKey,
68
+ userId : null ,
69
+ ackedPushToken : null ,
70
+ zulipVersion : null ,
71
+ zulipFeatureLevel : null ,
72
+ lastDismissedServerPushSetupNotice : null ,
73
+ } ,
74
+ ...state ,
75
+ ] ;
76
+ }
77
+ return [
78
+ { ...state [ accountIndex ] , apiKey, ackedPushToken : null } ,
79
+ ...state . slice ( 0 , accountIndex ) ,
80
+ ...state . slice ( accountIndex + 1 ) ,
81
+ ] ;
82
+ }
112
83
113
- case ACK_PUSH_TOKEN :
114
- return ackPushToken ( state , action ) ;
84
+ case ACK_PUSH_TOKEN : {
85
+ const { pushToken : ackedPushToken , identity } = action ;
86
+ const accountIndex = findAccount ( state , identity ) ;
87
+ if ( accountIndex === - 1 ) {
88
+ return state ;
89
+ }
90
+ return [
91
+ ...state . slice ( 0 , accountIndex ) ,
92
+ { ...state [ accountIndex ] , ackedPushToken } ,
93
+ ...state . slice ( accountIndex + 1 ) ,
94
+ ] ;
95
+ }
115
96
116
- case UNACK_PUSH_TOKEN :
117
- return unackPushToken ( state , action ) ;
97
+ case UNACK_PUSH_TOKEN : {
98
+ const { identity } = action ;
99
+ const accountIndex = findAccount ( state , identity ) ;
100
+ if ( accountIndex === - 1 ) {
101
+ return state ;
102
+ }
103
+ return [
104
+ ...state . slice ( 0 , accountIndex ) ,
105
+ { ...state [ accountIndex ] , ackedPushToken : null } ,
106
+ ...state . slice ( accountIndex + 1 ) ,
107
+ ] ;
108
+ }
118
109
119
110
case LOGOUT : {
120
111
return [ { ...state [ 0 ] , apiKey : '' , ackedPushToken : null } , ...state . slice ( 1 ) ] ;
0 commit comments