Search in sources :

Example 1 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class ChannelService method processChannelFeedForSync.

// Cleanup: private
/**
 * Internal. Do not use.
 */
public void processChannelFeedForSync(ChannelFeed channelFeed) {
    if (channelFeed != null) {
        Set<String> memberUserIds = channelFeed.getMembersName();
        Set<String> userIds = new HashSet<>();
        Channel channel = getChannel(channelFeed);
        if (channelDatabaseService.isChannelPresent(channel.getKey())) {
            channelDatabaseService.updateChannel(channel);
            channelDatabaseService.deleteChannelUserMappers(channel.getKey());
        } else {
            channelDatabaseService.addChannel(channel);
        }
        if (memberUserIds != null && memberUserIds.size() > 0) {
            for (String userId : memberUserIds) {
                ChannelUserMapper channelUserMapper = new ChannelUserMapper(channelFeed.getId(), userId);
                channelUserMapper.setParentKey(channelFeed.getParentKey());
                channelDatabaseService.addChannelUserMapper(channelUserMapper);
                if (!baseContactService.isContactExists(userId)) {
                    userIds.add(userId);
                }
            }
            if (userIds != null && userIds.size() > 0) {
                userService.processUserDetailsByUserIds(userIds);
            }
        }
        if (channelFeed.getGroupUsers() != null && channelFeed.getGroupUsers().size() > 0) {
            for (ChannelUsersFeed channelUsers : channelFeed.getGroupUsers()) {
                if (channelUsers.getRole() != null) {
                    channelDatabaseService.updateRoleInChannelUserMapper(channelFeed.getId(), channelUsers.getUserId(), channelUsers.getRole());
                }
            }
        }
        if (channelFeed.getChildKeys() != null && channelFeed.getChildKeys().size() > 0) {
            processChildGroupKeysForChannelSync(channelFeed.getChildKeys());
        }
        if (channel.isDeleted() && ApplozicClient.getInstance(context).isSkipDeletedGroups()) {
            BroadcastService.sendConversationDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString(), null, channel.getKey(), "success");
        }
    }
}
Also used : ChannelUsersFeed(com.applozic.mobicomkit.feed.ChannelUsersFeed) Channel(com.applozic.mobicommons.people.channel.Channel) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) HashSet(java.util.HashSet)

Example 2 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class ChannelService method processChannelFeed.

// Cleanup: private
/**
 * Internal method. Do not use.
 */
public void processChannelFeed(ChannelFeed channelFeed, boolean isUserDetails) {
    if (channelFeed != null) {
        Set<String> memberUserIds = null;
        if (channelFeed.getMembersName() != null) {
            memberUserIds = channelFeed.getMembersName();
        } else {
            memberUserIds = channelFeed.getContactGroupMembersId();
        }
        Channel channel = getChannel(channelFeed);
        if (channelDatabaseService.isChannelPresent(channel.getKey())) {
            channelDatabaseService.updateChannel(channel);
        } else {
            channelDatabaseService.addChannel(channel);
        }
        if (channelFeed.getConversationPxy() != null) {
            channelFeed.getConversationPxy().setGroupId(channelFeed.getId());
            ConversationService.getInstance(context).addConversation(channelFeed.getConversationPxy());
        }
        if (memberUserIds != null && memberUserIds.size() > 0) {
            for (String userId : memberUserIds) {
                ChannelUserMapper channelUserMapper = new ChannelUserMapper(channelFeed.getId(), userId);
                channelUserMapper.setParentKey(channelFeed.getParentKey());
                if (channelDatabaseService.isChannelUserPresent(channelFeed.getId(), userId)) {
                    channelDatabaseService.updateChannelUserMapper(channelUserMapper);
                } else {
                    channelDatabaseService.addChannelUserMapper(channelUserMapper);
                }
            }
        }
        if (isUserDetails) {
            userService.processUserDetail(channelFeed.getUsers());
        }
        if (channelFeed.getGroupUsers() != null && channelFeed.getGroupUsers().size() > 0) {
            for (ChannelUsersFeed channelUsers : channelFeed.getGroupUsers()) {
                if (channelUsers.getRole() != null) {
                    channelDatabaseService.updateRoleInChannelUserMapper(channelFeed.getId(), channelUsers.getUserId(), channelUsers.getRole());
                }
            }
        }
        if (channelFeed.getChildKeys() != null && channelFeed.getChildKeys().size() > 0) {
            processChildGroupKeys(channelFeed.getChildKeys());
        }
    }
}
Also used : ChannelUsersFeed(com.applozic.mobicomkit.feed.ChannelUsersFeed) Channel(com.applozic.mobicommons.people.channel.Channel) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper)

Example 3 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class ChannelService method addMemberToChannelProcessWithResponse.

/**
 * @deprecated Duplicate. Use {@link #addMemberToChannelWithResponseProcess(Integer, String)} instead.
 *
 * <p>Adds a given user to a channel.</p>
 *
 * <p>The local database is also updated.</p>
 *
 * @param channelKey the channel key (to identify the channel)
 * @param userId the id of the user to add to the channel
 * @return the {@link ApiResponse} for the request
 */
@Deprecated
public ApiResponse addMemberToChannelProcessWithResponse(Integer channelKey, String userId) {
    if (channelKey == null && TextUtils.isEmpty(userId)) {
        return null;
    }
    ApiResponse apiResponse = channelClientService.addMemberToChannel(channelKey, userId);
    if (apiResponse == null) {
        return null;
    }
    if (apiResponse.isSuccess()) {
        ChannelUserMapper channelUserMapper = new ChannelUserMapper(channelKey, userId);
        channelDatabaseService.addChannelUserMapper(channelUserMapper);
    }
    return apiResponse;
}
Also used : ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse)

Example 4 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class ChannelDatabaseService method getChannelUserByChannelKeyAndUserId.

/**
 * Get the User-To-Channel mapping object ({@link ChannelUserMapper} for the given channel
 * and user.
 *
 * @param channelKey the channel key
 * @param userId the user id
 * @return the ChannelUserMapper object, null if not found
 */
public ChannelUserMapper getChannelUserByChannelKeyAndUserId(final Integer channelKey, final String userId) {
    ChannelUserMapper channelUserMapper = null;
    Cursor cursor = null;
    try {
        String structuredNameWhere = MobiComDatabaseHelper.CHANNEL_KEY + " =? AND " + MobiComDatabaseHelper.USERID + " =?";
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        cursor = db.query(CHANNEL_USER_X, null, structuredNameWhere, new String[] { String.valueOf(channelKey), userId }, null, null, null);
        if (cursor != null) {
            if (cursor.getCount() > 0) {
                cursor.moveToFirst();
                channelUserMapper = getChannelUser(cursor);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null) {
            cursor.close();
        }
        dbHelper.close();
    }
    return channelUserMapper;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) Cursor(android.database.Cursor)

Example 5 with ChannelUserMapper

use of com.applozic.mobicommons.people.channel.ChannelUserMapper in project Applozic-Android-SDK by AppLozic.

the class ChannelDatabaseService method getGroupOfTwoReceiverId.

public String getGroupOfTwoReceiverId(Integer channelKey) {
    Cursor cursor = null;
    try {
        SQLiteDatabase db = dbHelper.getReadableDatabase();
        String structuredNameWhere = "";
        structuredNameWhere += "channelKey = ? AND userId NOT IN ('" + MobiComUserPreference.getInstance(context).getUserId().replaceAll("'", "''") + "')";
        cursor = db.query(CHANNEL_USER_X, null, structuredNameWhere, new String[] { String.valueOf(channelKey) }, null, null, null);
        List<ChannelUserMapper> channelUserMappers = getListOfUsers(cursor);
        if (channelUserMappers != null && channelUserMappers.size() > 0) {
            ChannelUserMapper channelUserMapper = channelUserMappers.get(0);
            if (channelUserMapper != null) {
                return channelUserMapper.getUserKey();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null) {
            cursor.close();
        }
        dbHelper.close();
    }
    return null;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper)

Aggregations

ChannelUserMapper (com.applozic.mobicommons.people.channel.ChannelUserMapper)22 Channel (com.applozic.mobicommons.people.channel.Channel)7 ChannelUsersFeed (com.applozic.mobicomkit.feed.ChannelUsersFeed)4 Contact (com.applozic.mobicommons.people.contact.Contact)4 Cursor (android.database.Cursor)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 ApiResponse (com.applozic.mobicomkit.feed.ApiResponse)3 ChannelFeed (com.applozic.mobicomkit.feed.ChannelFeed)3 ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 AdapterView (android.widget.AdapterView)2 ChannelDatabaseService (com.applozic.mobicomkit.channel.database.ChannelDatabaseService)2 SyncChannelFeed (com.applozic.mobicomkit.sync.SyncChannelFeed)2 Collections.disjoint (java.util.Collections.disjoint)2 Test (org.junit.Test)2 Context (android.content.Context)1 Intent (android.content.Intent)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 SpannableString (android.text.SpannableString)1