Search in sources :

Example 66 with Channel

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;
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) AlResponse(com.applozic.mobicomkit.feed.AlResponse) ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) SyncChannelFeed(com.applozic.mobicomkit.sync.SyncChannelFeed) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse)

Example 67 with Channel

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;
}
Also used : ContentValues(android.content.ContentValues) Channel(com.applozic.mobicommons.people.channel.Channel) HashMap(java.util.HashMap) Map(java.util.Map)

Example 68 with Channel

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;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Channel(com.applozic.mobicommons.people.channel.Channel) Cursor(android.database.Cursor)

Example 69 with 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;
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) NonNull(androidx.annotation.NonNull)

Example 70 with 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();
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) Data(androidx.work.Data) Contact(com.applozic.mobicommons.people.contact.Contact) NonNull(androidx.annotation.NonNull)

Aggregations

Channel (com.applozic.mobicommons.people.channel.Channel)70 Contact (com.applozic.mobicommons.people.contact.Contact)26 Intent (android.content.Intent)12 ChannelFeed (com.applozic.mobicomkit.feed.ChannelFeed)10 ArrayList (java.util.ArrayList)10 Message (com.applozic.mobicomkit.api.conversation.Message)8 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)7 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)7 SyncChannelFeed (com.applozic.mobicomkit.sync.SyncChannelFeed)7 ChannelUserMapper (com.applozic.mobicommons.people.channel.ChannelUserMapper)7 NonNull (androidx.annotation.NonNull)6 FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)6 Context (android.content.Context)4 Cursor (android.database.Cursor)4 Bitmap (android.graphics.Bitmap)4 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)4 ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)4 ChannelUsersFeed (com.applozic.mobicomkit.feed.ChannelUsersFeed)4 Conversation (com.applozic.mobicommons.people.channel.Conversation)4 JSONException (org.json.JSONException)4