@@ -23,7 +23,7 @@ import _ from 'lodash'
23
23
vm . tracks = { }
24
24
vm . mySkills = [ ]
25
25
vm . disableDoneButton = false
26
- vm . showCommunity = false
26
+ vm . showCommunity = true
27
27
vm . loadingCommunities = false
28
28
vm . communities = { }
29
29
vm . isPageDirty = isPageDirty
@@ -85,7 +85,8 @@ import _ from 'lodash'
85
85
programId : vm . BLOCKCHAIN_PROGRAM_ID ,
86
86
status : false ,
87
87
dirty : false ,
88
- display : true
88
+ display : true ,
89
+ groupCommunity : true ,
89
90
}
90
91
vm . communities [ 'ios' ] = {
91
92
displayName : 'iOS' ,
@@ -126,44 +127,59 @@ import _ from 'lodash'
126
127
* Checks registration status of each community and updates the state of each community.
127
128
*/
128
129
function checkCommunityStatus ( ) {
129
- var promises = [ ]
130
+ var promises = [ ] , groupPromises = [ ]
130
131
for ( var name in vm . communities ) {
131
- var community = vm . communities [ name ]
132
- promises . push ( MemberCertService . getMemberRegistration ( vm . userId , community . programId ) )
132
+ var community = vm . communities [ name ]
133
+ if ( community . groupCommunity ) {
134
+ groupPromises . push ( GroupService . getMembers ( vm . userId , community . programId ) )
135
+ } else {
136
+ promises . push ( MemberCertService . getMemberRegistration ( vm . userId , community . programId ) )
137
+ }
133
138
}
134
139
135
140
vm . loadingCommunities = true
136
141
142
+ $q . all ( groupPromises )
143
+ . then ( function ( responses ) {
144
+ let members = responses [ 0 ] || [ ]
145
+ vm . loadingCommunities = false
146
+ members . forEach ( function ( member ) {
147
+ if ( member && member . memberId === vm . userId ) {
148
+ addWatchToExistingCommunity ( member . groupId ) ;
149
+ }
150
+ } )
151
+ } )
152
+ . catch ( function ( err ) {
153
+ logger . error ( 'Could not load communities with group data' , err )
154
+ vm . loadingCommunities = false
155
+ } )
156
+
137
157
$q . all ( promises )
138
158
. then ( function ( responses ) {
139
159
vm . loadingCommunities = false
140
160
responses . forEach ( function ( program ) {
141
- if ( program ) {
142
- var community = _ . find ( vm . communities , { programId : program . eventId } )
143
- if ( community ) {
144
- // set display false to avoid showing already enabled/registered program
145
- // we expect display property to be modified after first load of the page
146
- community . status = true
147
- if ( community . unregister ) {
148
- community . unregister ( )
149
- _addWatchToCommunity ( community )
150
- }
151
- }
161
+ if ( program ) {
162
+ addWatchToExistingCommunity ( program . eventId ) ;
152
163
}
153
164
} )
154
- // if there exists at least 1 community which can be displayed, set showCommunity flag to true
155
- var community = _ . find ( vm . communities , { display : true } )
156
- if ( community ) {
157
- vm . showCommunity = true
158
- }
159
165
} )
160
166
. catch ( function ( err ) {
161
167
logger . error ( 'Could not load communities with member cert registration data' , err )
162
-
163
168
vm . loadingCommunities = false
164
169
} )
165
170
}
166
171
172
+ function addWatchToExistingCommunity ( programId ) {
173
+ var community = _ . find ( vm . communities , { programId : programId } )
174
+ if ( community ) {
175
+ community . status = true
176
+ if ( community . unregister ) {
177
+ community . unregister ( )
178
+ _addWatchToCommunity ( community )
179
+ }
180
+ }
181
+ }
182
+
167
183
/**
168
184
* Toggles the given skill for the user. If it is not added, adds it and if already added, removes it.
169
185
*/
@@ -212,8 +228,8 @@ import _ from 'lodash'
212
228
var community = vm . communities [ communityName ]
213
229
if ( community . dirty === true ) {
214
230
if ( community . status === true ) {
215
- if ( community . programId === vm . BLOCKCHAIN_PROGRAM_ID ) {
216
- promises . push ( GroupService . rm ( vm . userId , community . programId ) )
231
+ if ( community . groupCommunity ) {
232
+ promises . push ( GroupService . addMember ( vm . userId , community . programId ) )
217
233
} else {
218
234
promises . push ( MemberCertService . registerMember ( vm . userId , community . programId ) )
219
235
}
@@ -231,9 +247,7 @@ import _ from 'lodash'
231
247
} )
232
248
. catch ( function ( err ) {
233
249
logger . error ( 'Could not update update user skills or register members for community' , err )
234
-
235
250
vm . saving = false
236
-
237
251
toaster . pop ( 'error' , 'Whoops!' , 'Something went wrong. Please try again later.' )
238
252
} )
239
253
}
0 commit comments