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;
}
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();
}
}
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));
}
Aggregations