Search in sources :

Example 1 with SyncUserBlockListFeed

use of com.applozic.mobicomkit.sync.SyncUserBlockListFeed in project Applozic-Android-SDK by AppLozic.

the class MockedConstants method syncUserBlockListFeed.

public static SyncUserBlockListFeed syncUserBlockListFeed() {
    SyncUserBlockListFeed syncUserBlockListFeed = new SyncUserBlockListFeed();
    List<SyncUserBlockFeed> blockedBySyncUserBlockFeed = new ArrayList<>();
    SyncUserBlockFeed syncUserBlockFeed1 = new SyncUserBlockFeed();
    syncUserBlockFeed1.setBlockedBy(blockedByUserId1);
    syncUserBlockFeed1.setBlockedTo(blockedToUserId1);
    syncUserBlockFeed1.setUserBlocked(true);
    SyncUserBlockFeed syncUserBlockFeed2 = new SyncUserBlockFeed();
    syncUserBlockFeed2.setBlockedBy(blockedByUserId2);
    syncUserBlockFeed2.setBlockedTo(blockedToUserId2);
    syncUserBlockFeed2.setUserBlocked(false);
    blockedBySyncUserBlockFeed.add(syncUserBlockFeed1);
    blockedBySyncUserBlockFeed.add(syncUserBlockFeed2);
    List<SyncUserBlockFeed> blockedToSyncUserBlockFeed = new ArrayList<>();
    blockedToSyncUserBlockFeed.add(syncUserBlockFeed1);
    blockedToSyncUserBlockFeed.add(syncUserBlockFeed2);
    syncUserBlockListFeed.setBlockedByUserList(blockedBySyncUserBlockFeed);
    syncUserBlockListFeed.setBlockedToUserList(blockedToSyncUserBlockFeed);
    return syncUserBlockListFeed;
}
Also used : SyncUserBlockListFeed(com.applozic.mobicomkit.sync.SyncUserBlockListFeed) ArrayList(java.util.ArrayList) SyncUserBlockFeed(com.applozic.mobicomkit.sync.SyncUserBlockFeed)

Example 2 with SyncUserBlockListFeed

use of com.applozic.mobicomkit.sync.SyncUserBlockListFeed 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 3 with SyncUserBlockListFeed

use of com.applozic.mobicomkit.sync.SyncUserBlockListFeed 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

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