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