Search in sources :

Example 1 with SyncBlockUserApiResponse

use of com.applozic.mobicomkit.feed.SyncBlockUserApiResponse in project Applozic-Android-SDK by AppLozic.

the class UserService method processSyncUserBlock.

/**
 * Internal. Do not use.
 *
 * This method handle block user syncing. Calling this method is done internally by the SDK.
 */
public synchronized void processSyncUserBlock() {
    try {
        SyncBlockUserApiResponse apiResponse = userClientService.getSyncUserBlockList(userPreference.getUserBlockSyncTime());
        if (apiResponse != null && SyncBlockUserApiResponse.SUCCESS.equals(apiResponse.getStatus())) {
            SyncUserBlockListFeed syncUserBlockListFeed = apiResponse.getResponse();
            if (syncUserBlockListFeed != null) {
                List<SyncUserBlockFeed> blockedToUserList = syncUserBlockListFeed.getBlockedToUserList();
                List<SyncUserBlockFeed> blockedByUserList = syncUserBlockListFeed.getBlockedByUserList();
                if (blockedToUserList != null && blockedToUserList.size() > 0) {
                    for (SyncUserBlockFeed syncUserBlockedFeed : blockedToUserList) {
                        Contact contact = new Contact();
                        if (syncUserBlockedFeed.getUserBlocked() != null && !TextUtils.isEmpty(syncUserBlockedFeed.getBlockedTo())) {
                            if (baseContactService.isContactExists(syncUserBlockedFeed.getBlockedTo())) {
                                baseContactService.updateUserBlocked(syncUserBlockedFeed.getBlockedTo(), syncUserBlockedFeed.getUserBlocked());
                            } else {
                                contact.setBlocked(syncUserBlockedFeed.getUserBlocked());
                                contact.setUserId(syncUserBlockedFeed.getBlockedTo());
                                baseContactService.upsert(contact);
                                baseContactService.updateUserBlocked(syncUserBlockedFeed.getBlockedTo(), syncUserBlockedFeed.getUserBlocked());
                            }
                        }
                    }
                }
                if (blockedByUserList != null && blockedByUserList.size() > 0) {
                    for (SyncUserBlockFeed syncUserBlockByFeed : blockedByUserList) {
                        Contact contact = new Contact();
                        if (syncUserBlockByFeed.getUserBlocked() != null && !TextUtils.isEmpty(syncUserBlockByFeed.getBlockedBy())) {
                            if (baseContactService.isContactExists(syncUserBlockByFeed.getBlockedBy())) {
                                baseContactService.updateUserBlockedBy(syncUserBlockByFeed.getBlockedBy(), syncUserBlockByFeed.getUserBlocked());
                            } else {
                                contact.setBlockedBy(syncUserBlockByFeed.getUserBlocked());
                                contact.setUserId(syncUserBlockByFeed.getBlockedBy());
                                baseContactService.upsert(contact);
                                baseContactService.updateUserBlockedBy(syncUserBlockByFeed.getBlockedBy(), syncUserBlockByFeed.getUserBlocked());
                            }
                        }
                    }
                }
            }
            userPreference.setUserBlockSyncTime(apiResponse.getGeneratedAt());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SyncUserBlockListFeed(com.applozic.mobicomkit.sync.SyncUserBlockListFeed) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) SyncUserBlockFeed(com.applozic.mobicomkit.sync.SyncUserBlockFeed) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 2 with SyncBlockUserApiResponse

use of com.applozic.mobicomkit.feed.SyncBlockUserApiResponse in project Applozic-Android-SDK by AppLozic.

the class UserServiceTest method processSyncUserBlock.

@Test
public void processSyncUserBlock() {
    SyncBlockUserApiResponse expectedSyncBlockUserApiResponse = new SyncBlockUserApiResponse();
    SyncUserBlockListFeed expectedSyncUserBlockListFeed = syncUserBlockListFeed();
    expectedSyncBlockUserApiResponse.setStatus("success");
    expectedSyncBlockUserApiResponse.setResponse(expectedSyncUserBlockListFeed);
    Mockito.when(userClientService.getSyncUserBlockList(ArgumentMatchers.anyString())).thenReturn(expectedSyncBlockUserApiResponse);
    // to go inside if for blocked to list
    Mockito.when(appContactService.isContactExists(expectedSyncUserBlockListFeed.getBlockedToUserList().get(0).getBlockedTo())).thenReturn(true);
    // to go inside if for blocked by list
    Mockito.when(appContactService.isContactExists(expectedSyncUserBlockListFeed.getBlockedToUserList().get(0).getBlockedBy())).thenReturn(true);
    userService.processSyncUserBlock();
    // 2 for blocked to
    Mockito.verify(appContactService, Mockito.times(2)).updateUserBlocked(ArgumentMatchers.anyString(), ArgumentMatchers.anyBoolean());
    // 2 for blocked by
    Mockito.verify(appContactService, Mockito.times(2)).updateUserBlockedBy(ArgumentMatchers.anyString(), ArgumentMatchers.anyBoolean());
    // for each SyncUserBlockFeed
    Mockito.verify(appContactService, Mockito.times(1)).isContactExists(expectedSyncUserBlockListFeed.getBlockedToUserList().get(0).getBlockedTo());
    Mockito.verify(appContactService, Mockito.times(1)).isContactExists(expectedSyncUserBlockListFeed.getBlockedToUserList().get(1).getBlockedTo());
    Mockito.verify(appContactService, Mockito.times(1)).isContactExists(expectedSyncUserBlockListFeed.getBlockedByUserList().get(0).getBlockedBy());
    Mockito.verify(appContactService, Mockito.times(1)).isContactExists(expectedSyncUserBlockListFeed.getBlockedByUserList().get(1).getBlockedBy());
    // 2 else {} paths, one for each list (blocked by and blocked to)
    Mockito.verify(appContactService, Mockito.times(2)).upsert(ArgumentMatchers.any(Contact.class));
}
Also used : SyncUserBlockListFeed(com.applozic.mobicomkit.sync.SyncUserBlockListFeed) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) Contact(com.applozic.mobicommons.people.contact.Contact) Test(org.junit.Test)

Aggregations

SyncBlockUserApiResponse (com.applozic.mobicomkit.feed.SyncBlockUserApiResponse)2 SyncUserBlockListFeed (com.applozic.mobicomkit.sync.SyncUserBlockListFeed)2 Contact (com.applozic.mobicommons.people.contact.Contact)2 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)1 SyncUserBlockFeed (com.applozic.mobicomkit.sync.SyncUserBlockFeed)1 Test (org.junit.Test)1