use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelService method createGroupOfTwoWithResponse.
/**
* Internal. Group-of-two channels are implemented in the UI. You will not need them.
*
* <p>Create a {@link Channel.GroupType#GROUPOFTWO} channel.</p>
*
* <p>A group-of-two type channel is implemented in the UI to look like a 1-to-1 chat.
* It is meant to have two members only.</p>
*
* @param channelInfo the channel info that will be used to create the channel
* @return the {@link AlResponse} from the server
*/
public AlResponse createGroupOfTwoWithResponse(ChannelInfo channelInfo) {
if (channelInfo == null) {
return null;
}
AlResponse alResponse = new AlResponse();
if (!TextUtils.isEmpty(channelInfo.getClientGroupId())) {
Channel channel = channelDatabaseService.getChannelByClientGroupId(channelInfo.getClientGroupId());
if (channel != null) {
alResponse.setStatus(AlResponse.SUCCESS);
alResponse.setResponse(channel);
} else {
ChannelFeedApiResponse channelFeedApiResponse = channelClientService.createChannelWithResponse(channelInfo);
if (channelFeedApiResponse == null) {
alResponse.setStatus(AlResponse.ERROR);
} else {
if (channelFeedApiResponse.isSuccess()) {
ChannelFeed channelFeed = channelFeedApiResponse.getResponse();
if (channelFeed != null) {
ChannelFeed[] channelFeeds = new ChannelFeed[1];
channelFeeds[0] = channelFeed;
processChannelFeedList(channelFeeds, true);
alResponse.setStatus(AlResponse.SUCCESS);
alResponse.setResponse(getChannel(channelFeed));
}
} else {
ChannelFeed channelFeed = channelClientService.getChannelInfo(channelInfo.getClientGroupId());
if (channelFeed != null) {
ChannelFeed[] channelFeeds = new ChannelFeed[1];
channelFeeds[0] = channelFeed;
processChannelFeedList(channelFeeds, false);
alResponse.setStatus(AlResponse.SUCCESS);
alResponse.setResponse(getChannel(channelFeed));
}
}
}
}
}
return alResponse;
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelDatabaseService method updateChannel.
// Cleanup: default
public int updateChannel(GroupInfoUpdate groupInfoUpdate) {
if (groupInfoUpdate.getImageUrl() == null && groupInfoUpdate.getNewName() == null) {
return 0;
}
int rowUpdated = 0;
try {
ContentValues values = new ContentValues();
if (groupInfoUpdate != null) {
if (!TextUtils.isEmpty(groupInfoUpdate.getClientGroupId())) {
Channel channel = getChannelByClientGroupId(groupInfoUpdate.getClientGroupId());
groupInfoUpdate.setGroupId(channel.getKey());
}
if (groupInfoUpdate.getNewName() != null) {
values.put("channelName", groupInfoUpdate.getNewName());
}
if (groupInfoUpdate.getImageUrl() != null) {
values.put("channelImageURL", groupInfoUpdate.getImageUrl());
values.putNull("channelImageLocalURI");
}
if (groupInfoUpdate.getMetadata() != null) {
Map<String, String> metadataToUpdate = getMetadataToUpdateToDatabaseFromGroupInfoUpdate(groupInfoUpdate);
if (metadataToUpdate != null) {
values.put(MobiComDatabaseHelper.CHANNEL_META_DATA, GsonUtils.getJsonFromObject(metadataToUpdate, Map.class));
if (metadataToUpdate.containsKey(Channel.AL_CATEGORY)) {
values.put(MobiComDatabaseHelper.AL_CATEGORY, metadataToUpdate.get(Channel.AL_CATEGORY));
}
}
}
}
rowUpdated = dbHelper.getWritableDatabase().update("channel", values, "channelKey=" + groupInfoUpdate.getGroupId(), null);
} catch (Exception e) {
e.printStackTrace();
}
return rowUpdated;
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelDatabaseService method getChannelByChannelKey.
/**
* Will get a channel object from the database, corresponding to the passed channel key.
*
* @param channelKey the channel key/group id. used to identify a channel
* @return the channel object, null if no such channel exists in database
*/
public Channel getChannelByChannelKey(final Integer channelKey) {
Channel channel = null;
try {
String structuredNameWhere = MobiComDatabaseHelper.CHANNEL_KEY + " =?";
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor cursor = db.query(CHANNEL, null, structuredNameWhere, new String[] { String.valueOf(channelKey) }, null, null, null);
try {
if (cursor != null) {
if (cursor.getCount() > 0) {
cursor.moveToFirst();
channel = getChannel(cursor);
}
}
} finally {
if (cursor != null) {
cursor.close();
}
dbHelper.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return channel;
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelService method getChannel.
/**
* Internal method. Use {@link ChannelDatabaseService#getChannelByChannelKey(Integer)}.
*
* <p>Gets the Channel object for the given channel key from local sources.</p>
*
* @param channelKey the channel key
* @return the channel object (one with just the channel key if no channel is found)
*/
@NonNull
public Channel getChannel(@NonNull Integer channelKey) {
Channel channel;
channel = MessageSearchCache.getChannelByKey(channelKey);
if (channel == null) {
channel = channelDatabaseService.getChannelByChannelKey(channelKey);
}
if (channel == null) {
channel = new Channel(channelKey);
}
return channel;
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class UserWorker method doWork.
@NonNull
@Override
public Result doWork() {
Utils.printLog(getApplicationContext(), TAG, "Started user worker...");
Data data = getInputData();
int unreadCount = data.getInt(UNREAD_COUNT, 0);
String contactJson = data.getString(CONTACT);
Contact contact = null;
if (!TextUtils.isEmpty(contactJson)) {
contact = (Contact) GsonUtils.getObjectFromJson(contactJson, Contact.class);
}
String channelJson = data.getString(CHANNEL);
Channel channel = null;
if (!TextUtils.isEmpty(channelJson)) {
channel = (Channel) GsonUtils.getObjectFromJson(channelJson, Channel.class);
}
String messageKey = data.getString(PAIRED_MESSAGE_KEY_STRING);
if (contact != null) {
Utils.printLog(getApplicationContext(), TAG, "Updating read status local for contact...");
messageDatabaseService.updateReadStatusForContact(contact.getContactIds());
} else if (channel != null) {
Utils.printLog(getApplicationContext(), TAG, "Updating read status local for channel...");
messageDatabaseService.updateReadStatusForChannel(String.valueOf(channel.getKey()));
}
if (unreadCount != 0 || !TextUtils.isEmpty(messageKey) && !isMessageStatusPublished(getApplicationContext(), messageKey, Message.Status.READ.getValue())) {
Utils.printLog(getApplicationContext(), TAG, "Updating read status in server...");
messageClientService.updateReadStatus(contact, channel);
} else {
String userId = data.getString(USER_ID);
if (!TextUtils.isEmpty(userId)) {
Utils.printLog(getApplicationContext(), TAG, "Syncing user details...");
SyncCallService.getInstance(getApplicationContext()).processUserStatus(userId);
} else if (data.getBoolean(USER_LAST_SEEN_AT_STATUS, false)) {
Utils.printLog(getApplicationContext(), TAG, "Processing last seen at status for all users...");
mobiComConversationService.processLastSeenAtStatus();
}
}
Utils.printLog(getApplicationContext(), TAG, "Adding logged in user deleted data to shared pref if required...");
checkAndSaveLoggedUserDeletedDataToSharedPref();
return Result.success();
}
Aggregations