Search in sources :

Example 1 with SyncMessageFeed

use of com.applozic.mobicomkit.sync.SyncMessageFeed in project Applozic-Android-SDK by AppLozic.

the class MobiComMessageService method syncMessages.

public synchronized void syncMessages() {
    final MobiComUserPreference userpref = MobiComUserPreference.getInstance(context);
    Utils.printLog(context, TAG, "Starting syncMessages for lastSyncTime: " + userpref.getLastSyncTime());
    SyncMessageFeed syncMessageFeed = messageClientService.getMessageFeed(userpref.getLastSyncTime(), false);
    if (syncMessageFeed == null) {
        return;
    }
    if (syncMessageFeed != null && syncMessageFeed.getMessages() != null) {
        Utils.printLog(context, TAG, "Got sync response " + syncMessageFeed.getMessages().size() + " messages.");
        processUserDetailFromMessages(syncMessageFeed.getMessages());
    }
    // more valid, do it again and make the sync request again
    if (syncMessageFeed != null && syncMessageFeed.isRegIdInvalid() && Utils.hasFroyo()) {
        Utils.printLog(context, TAG, "Going to call GCM device registration");
    // Todo: Replace it with mobicomkit gcm registration
    // C2DMessaging.register(context);
    }
    if (syncMessageFeed != null && syncMessageFeed.getMessages() != null) {
        List<Message> messageList = syncMessageFeed.getMessages();
        for (final Message message : messageList) {
            if (Message.ContentType.CHANNEL_CUSTOM_MESSAGE.getValue().equals(message.getContentType())) {
                ChannelService.getInstance(context).syncChannels();
                // Todo: fix this, what if there are mulitple messages.
                ChannelService.isUpdateTitle = true;
            }
            processMessage(message, message.getTo());
            MobiComUserPreference.getInstance(context).setLastInboxSyncTime(message.getCreatedAtTime());
        }
        updateDeliveredStatus(syncMessageFeed.getDeliveredMessageKeys());
        userpref.setLastSyncTime(String.valueOf(syncMessageFeed.getLastSyncTime()));
    }
}
Also used : PersonalizedMessage(com.applozic.mobicommons.personalization.PersonalizedMessage) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) SyncMessageFeed(com.applozic.mobicomkit.sync.SyncMessageFeed)

Example 2 with SyncMessageFeed

use of com.applozic.mobicomkit.sync.SyncMessageFeed in project Applozic-Android-SDK by AppLozic.

the class MobiComMessageService method syncMessageForMetadataUpdate.

public synchronized void syncMessageForMetadataUpdate() {
    final MobiComUserPreference userpref = MobiComUserPreference.getInstance(context);
    SyncMessageFeed syncMessageFeed = messageClientService.getMessageFeed(userpref.getLastSyncTimeForMetadataUpdate(), true);
    Utils.printLog(context, TAG, "\nStarting syncMessages for metadata update for lastSyncTime: " + userpref.getLastSyncTimeForMetadataUpdate());
    if (syncMessageFeed != null && syncMessageFeed.getMessages() != null) {
        userpref.setLastSyncTimeForMetadataUpdate(String.valueOf(syncMessageFeed.getLastSyncTime()));
        List<Message> messageList = syncMessageFeed.getMessages();
        for (final Message message : messageList) {
            if (message != null) {
                new MessageDatabaseService(context).updateMessageMetadata(message.getKeyString(), message.getMetadata());
                BroadcastService.updateMessageMetadata(context, message.getKeyString(), BroadcastService.INTENT_ACTIONS.MESSAGE_METADATA_UPDATE.toString());
            }
        }
    }
}
Also used : PersonalizedMessage(com.applozic.mobicommons.personalization.PersonalizedMessage) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) SyncMessageFeed(com.applozic.mobicomkit.sync.SyncMessageFeed) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)

Aggregations

MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)2 SyncMessageFeed (com.applozic.mobicomkit.sync.SyncMessageFeed)2 PersonalizedMessage (com.applozic.mobicommons.personalization.PersonalizedMessage)2 MessageDatabaseService (com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)1