@@ -132,31 +132,46 @@ globalFrontendRefRegistry.register({
132
132
} ,
133
133
134
134
query ( db , userId , value ) {
135
- const result = [ ] ;
135
+ const resultSet = { } ;
136
136
let requestedPermissions = [ ] ;
137
137
if ( value ) {
138
138
requestedPermissions = Capnp . parse ( Identity . PowerboxTag , value ) . permissions || [ ] ;
139
139
}
140
140
141
+ const resultForIdentity = function ( identity ) {
142
+ return {
143
+ _id : "frontendref-identity-" + identity . _id ,
144
+ frontendRef : { identity : identity . _id } ,
145
+ cardTemplate : "identityPowerboxCard" ,
146
+ configureTemplate : "identityPowerboxConfiguration" ,
147
+ profile : identity . profile ,
148
+ requestedPermissions,
149
+ searchTerms : [
150
+ identity . profile . name ,
151
+ identity . profile . handle ,
152
+ identity . profile . intrinsicName ,
153
+ ] ,
154
+ } ;
155
+ } ;
156
+
141
157
db . collections . contacts . find ( { ownerId : userId } ) . forEach ( contact => {
142
158
const identity = db . getIdentity ( contact . identityId ) ;
143
159
if ( identity ) {
144
- result . push ( {
145
- _id : "frontendref-identity-" + contact . identityId ,
146
- frontendRef : { identity : contact . identityId } ,
147
- cardTemplate : "identityPowerboxCard" ,
148
- configureTemplate : "identityPowerboxConfiguration" ,
149
- profile : identity . profile ,
150
- requestedPermissions,
151
- searchTerms : [
152
- identity . profile . name ,
153
- identity . profile . handle ,
154
- identity . profile . intrinsicName ,
155
- ] ,
156
- } ) ;
160
+ resultSet [ contact . identityId ] = resultForIdentity ( identity ) ;
157
161
}
158
162
} ) ;
159
163
160
- return result ;
164
+ if ( db . getOrganizationShareContacts ( ) &&
165
+ db . isUserInOrganization ( db . collections . users . findOne ( { _id : userId } ) ) ) {
166
+
167
+ // TODO(perf): Add some way to efficiently fetch all members in an organization.
168
+ db . collections . users . find ( { profile : { $exists : 1 } } ) . forEach ( ( user ) => {
169
+ if ( db . isIdentityInOrganization ( user ) ) {
170
+ resultSet [ user . _id ] = resultForIdentity ( db . getIdentity ( user . _id ) ) ;
171
+ }
172
+ } ) ;
173
+ }
174
+
175
+ return _ . values ( resultSet ) ;
161
176
} ,
162
177
} ) ;
0 commit comments