Search in sources :

Example 1 with SyncUserBlockFeed

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

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

Aggregations

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