File tree 2 files changed +54
-6
lines changed
2 files changed +54
-6
lines changed Original file line number Diff line number Diff line change @@ -150,7 +150,23 @@ function ContactSidebarController(
150
150
var categories = contactAddressbookDisplayService . categorizeDisplayShells ( self . displayShells ) ;
151
151
152
152
self . userAddressbooks = categories . userAddressbooks ;
153
- self . sharedAddressbooks = categories . sharedAddressbooks ;
153
+ self . sharedAddressbooks = _getUniqueSharedAddressbooks ( categories . sharedAddressbooks ) ;
154
154
self . virtualAddressbooks = categories . virtualAddressbooks ;
155
155
}
156
+
157
+ function _getUniqueSharedAddressbooks ( addressbooks ) {
158
+ if ( ! addressbooks ) return ;
159
+
160
+ const uniqueAddressbookList = addressbooks . reduce ( ( acc , current ) => {
161
+ const href = current . shell . source . href ;
162
+
163
+ if ( ! acc [ href ] ) {
164
+ acc [ href ] = current ;
165
+ }
166
+
167
+ return acc ;
168
+ } , { } ) ;
169
+
170
+ return Object . values ( uniqueAddressbookList ) ;
171
+ }
156
172
}
Original file line number Diff line number Diff line change @@ -46,13 +46,11 @@ describe('The ContactSidebarController controller', function() {
46
46
userAPI = _userAPI_ ;
47
47
userUtils = _userUtils_ ;
48
48
CONTACT_ADDRESSBOOK_EVENTS = _CONTACT_ADDRESSBOOK_EVENTS_ ;
49
-
50
- contactAddressbookDisplayService . categorizeDisplayShells = function ( ) {
51
- return {
49
+ contactAddressbookDisplayService . categorizeDisplayShells = sinon . stub ( )
50
+ . returns ( {
52
51
userAddressbooks : [ ] ,
53
52
externalAddressbooks : [ ]
54
- } ;
55
- } ;
53
+ } ) ;
56
54
} ) ;
57
55
} ) ;
58
56
@@ -260,6 +258,40 @@ describe('The ContactSidebarController controller', function() {
260
258
] ) ;
261
259
} ) ;
262
260
261
+ it ( 'should avoid listing duplicate entries when an adressbook is shared an delegated to the same user' , ( ) => {
262
+ contactAddressbookService . listAddressbooks = sinon . stub ( ) . returns ( $q . when ( [ ] ) ) ;
263
+ contactAddressbookDisplayService . categorizeDisplayShells . returns ( {
264
+ userAddressbooks : [
265
+ {
266
+ name : 'bookA' ,
267
+ shell : {
268
+ source : { bookId : 'user0' , href : '0' }
269
+ }
270
+ }
271
+ ] ,
272
+ sharedAddressbooks : [
273
+ {
274
+ name : 'bookB' ,
275
+ shell : {
276
+ source : { bookId : 'user1' , href : '1' }
277
+ }
278
+ } ,
279
+ {
280
+ name : 'bookC' ,
281
+ shell : {
282
+ source : { bookId : 'user1' , href : '1' }
283
+ }
284
+ }
285
+ ]
286
+ } ) ;
287
+
288
+ const controller = initController ( ) ;
289
+
290
+ $rootScope . $digest ( ) ;
291
+
292
+ expect ( controller . sharedAddressbooks . length ) . to . equal ( 1 ) ;
293
+ } ) ;
294
+
263
295
describe ( 'On updated address book event' , function ( ) {
264
296
it ( 'should update an address book when updated address book event is fired' , function ( ) {
265
297
var addressbooks = [
You can’t perform that action at this time.
0 commit comments