Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 3efbc38

Browse files
committed
Optimized legacy and group community subscription code. Adding new new service for group-subscription members
1 parent 922900c commit 3efbc38

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

app/services/group.service.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import angular from 'angular'
1111
var service = ApiService.restangularV3
1212

1313
// Retrieves the registration status of the member for the given program
14-
service.getMemberRegistration = function(userId, programId) {
15-
return service.one('groups').get({'memberId': userId,'membershipType':'user'})
14+
service.getMembers = function(userId, programId) {
15+
return service.one('groups',programId).one('members').get()
1616
}
1717

1818
// Registers the given member for the given program.
19-
service.rm = function(userId, programId) {
20-
return service.one('groups', programId).one('members').post({
19+
service.addMember = function(userId, programId) {
20+
return service.one('groups', programId).one('members').customPOST({
2121
memberId : userId +'', membershipType : 'user'
2222
})
2323
}

app/skill-picker/skill-picker.controller.js

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import _ from 'lodash'
2323
vm.tracks = {}
2424
vm.mySkills = []
2525
vm.disableDoneButton = false
26-
vm.showCommunity = false
26+
vm.showCommunity = true
2727
vm.loadingCommunities = false
2828
vm.communities = {}
2929
vm.isPageDirty = isPageDirty
@@ -85,7 +85,8 @@ import _ from 'lodash'
8585
programId: vm.BLOCKCHAIN_PROGRAM_ID,
8686
status: false,
8787
dirty: false,
88-
display: true
88+
display: true,
89+
groupCommunity: true,
8990
}
9091
vm.communities['ios'] = {
9192
displayName: 'iOS',
@@ -126,44 +127,59 @@ import _ from 'lodash'
126127
* Checks registration status of each community and updates the state of each community.
127128
*/
128129
function checkCommunityStatus() {
129-
var promises = []
130+
var promises = [], groupPromises = []
130131
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+
}
133138
}
134139

135140
vm.loadingCommunities = true
136141

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+
137157
$q.all(promises)
138158
.then(function(responses) {
139159
vm.loadingCommunities = false
140160
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);
152163
}
153164
})
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-
}
159165
})
160166
.catch(function(err) {
161167
logger.error('Could not load communities with member cert registration data', err)
162-
163168
vm.loadingCommunities = false
164169
})
165170
}
166171

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+
167183
/**
168184
* Toggles the given skill for the user. If it is not added, adds it and if already added, removes it.
169185
*/
@@ -212,8 +228,8 @@ import _ from 'lodash'
212228
var community = vm.communities[communityName]
213229
if (community.dirty === true) {
214230
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))
217233
}else{
218234
promises.push(MemberCertService.registerMember(vm.userId, community.programId))
219235
}
@@ -231,9 +247,7 @@ import _ from 'lodash'
231247
})
232248
.catch(function(err) {
233249
logger.error('Could not update update user skills or register members for community', err)
234-
235250
vm.saving = false
236-
237251
toaster.pop('error', 'Whoops!', 'Something went wrong. Please try again later.')
238252
})
239253
}

0 commit comments

Comments
 (0)