Search in sources :

Example 1 with TagParticipantVO

use of com.fanap.podchat.model.TagParticipantVO in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method prepareTagList.

private List<TagVo> prepareTagList() {
    List<CacheTagVo> tags = messageDao.getCacheTagVos();
    List<TagVo> tagVos = new ArrayList<>();
    for (CacheTagVo item : tags) {
        TagVo tag = CacheTagVoToTagVoMapper(item);
        long allUnreadCount = 0;
        List<CacheTagParticipantVO> cacheTagParticipants = messageDao.getCacheTagParticipantVosByTagId(item.getTagId());
        List<TagParticipantVO> tagParticipants = new ArrayList<>();
        for (CacheTagParticipantVO cacheTagParticipantVO : cacheTagParticipants) {
            TagParticipantVO cache = cacheTagParticipantVOToTagParticipantVOMapper(cacheTagParticipantVO);
            if (messageDao.getThreadById(cacheTagParticipantVO.getThreadId()) != null) {
                Thread thread = threadVoToThreadMapper(messageDao.getThreadById(cacheTagParticipantVO.getThreadId()), null);
                cache.setConversationVO(thread);
                // TODO it should be save in db. can save it when save tags on db
                if (thread.getUnreadCount() > 0)
                    allUnreadCount = allUnreadCount + thread.getUnreadCount();
            }
            tagParticipants.add(cache);
        }
        tag.setTagParticipants(tagParticipants);
        tag.setAllUnreadCount(allUnreadCount);
        tagVos.add(tag);
    }
    return tagVos;
}
Also used : CacheTagParticipantVO(com.fanap.podchat.cachemodel.CacheTagParticipantVO) CacheTagVo(com.fanap.podchat.cachemodel.CacheTagVo) ArrayList(java.util.ArrayList) CacheTagParticipantVO(com.fanap.podchat.cachemodel.CacheTagParticipantVO) TagParticipantVO(com.fanap.podchat.model.TagParticipantVO) TagVo(com.fanap.podchat.model.TagVo) CacheTagVo(com.fanap.podchat.cachemodel.CacheTagVo) Thread(com.fanap.podchat.mainmodel.Thread)

Example 2 with TagParticipantVO

use of com.fanap.podchat.model.TagParticipantVO in project pod-chat-android-sdk by FanapSoft.

the class TagManager method getTags.

private static List<TagVo> getTags(ChatMessage chatMessage) {
    List<TagVo> tags = App.getGson().fromJson(chatMessage.getContent(), new TypeToken<ArrayList<TagVo>>() {
    }.getType());
    for (TagVo tag : tags) {
        if (!Util.isNullOrEmpty(tag.getTagParticipants())) {
            long unreadCount = 0;
            for (TagParticipantVO tagParticipant : tag.getTagParticipants()) if (tagParticipant.getConversationVO() != null)
                unreadCount = unreadCount + tagParticipant.getConversationVO().getUnreadCount();
            tag.setAllUnreadCount(unreadCount);
        }
    }
    return tags;
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) TagParticipantVO(com.fanap.podchat.model.TagParticipantVO) TagVo(com.fanap.podchat.model.TagVo) CacheTagVo(com.fanap.podchat.cachemodel.CacheTagVo)

Example 3 with TagParticipantVO

use of com.fanap.podchat.model.TagParticipantVO in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method getTagParticipantsVos.

public Observable<List<TagParticipantVO>> getTagParticipantsVos(long tagId) {
    return Observable.create(emitter -> {
        try {
            List<CacheTagParticipantVO> tagParticipants = messageDao.getCacheTagParticipantVosByTagId(tagId);
            List<TagParticipantVO> cacheTagParticipants = new ArrayList<>();
            for (CacheTagParticipantVO item : tagParticipants) {
                TagParticipantVO cache = cacheTagParticipantVOToTagParticipantVOMapper(item);
                if (messageDao.getThreadById(item.getThreadId()) != null) {
                    Thread thread = threadVoToThreadMapper(messageDao.getThreadById(item.getThreadId()), null);
                    cache.setConversationVO(thread);
                }
                cacheTagParticipants.add(cache);
            }
            emitter.onNext(cacheTagParticipants);
            emitter.onCompleted();
        } catch (Exception e) {
            emitter.onError(e);
        }
    });
}
Also used : CacheTagParticipantVO(com.fanap.podchat.cachemodel.CacheTagParticipantVO) CacheTagParticipantVO(com.fanap.podchat.cachemodel.CacheTagParticipantVO) TagParticipantVO(com.fanap.podchat.model.TagParticipantVO) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ParseException(java.text.ParseException) Thread(com.fanap.podchat.mainmodel.Thread)

Example 4 with TagParticipantVO

use of com.fanap.podchat.model.TagParticipantVO in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method updateCacheTagParticipantVos.

public void updateCacheTagParticipantVos(List<TagParticipantVO> tagParticipantVOS, long tagId) {
    worker(() -> {
        List<CacheTagParticipantVO> tagVos = new ArrayList<>();
        for (TagParticipantVO item : tagParticipantVOS) {
            CacheTagParticipantVO cache = new CacheTagParticipantVO();
            cache.setThreadId(item.getThreadId());
            cache.setActive(item.isActive());
            cache.setTagId(tagId);
            cache.setId(item.getId());
            tagVos.add(cache);
            if (item.getConversationVO() != null)
                saveNewThread(item.getConversationVO());
        }
        messageDao.insertCacheTagParticipantVos(tagVos);
    });
}
Also used : CacheTagParticipantVO(com.fanap.podchat.cachemodel.CacheTagParticipantVO) ArrayList(java.util.ArrayList) CacheTagParticipantVO(com.fanap.podchat.cachemodel.CacheTagParticipantVO) TagParticipantVO(com.fanap.podchat.model.TagParticipantVO)

Aggregations

TagParticipantVO (com.fanap.podchat.model.TagParticipantVO)4 CacheTagParticipantVO (com.fanap.podchat.cachemodel.CacheTagParticipantVO)3 ArrayList (java.util.ArrayList)3 CacheTagVo (com.fanap.podchat.cachemodel.CacheTagVo)2 Thread (com.fanap.podchat.mainmodel.Thread)2 TagVo (com.fanap.podchat.model.TagVo)2 TypeToken (com.google.gson.reflect.TypeToken)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1