Search in sources :

Example 1 with TagVo

use of com.fanap.podchat.model.TagVo 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 TagVo

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

the class TagManager method prepareTagResponse.

public static ChatResponse<TagResult> prepareTagResponse(ChatMessage chatMessage) {
    TagVo tag = App.getGson().fromJson(chatMessage.getContent(), TagVo.class);
    TagResult tagResult = new TagResult(tag);
    ChatResponse<TagResult> finalResponse = new ChatResponse<>();
    finalResponse.setResult(tagResult);
    finalResponse.setUniqueId(chatMessage.getUniqueId());
    finalResponse.setSubjectId(chatMessage.getSubjectId());
    return finalResponse;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) TagResult(com.fanap.podchat.chat.tag.result_model.TagResult) TagVo(com.fanap.podchat.model.TagVo) CacheTagVo(com.fanap.podchat.cachemodel.CacheTagVo)

Example 3 with TagVo

use of com.fanap.podchat.model.TagVo 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 4 with TagVo

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

the class TagCacheTest method testIfTagsAreSame.

// @Test
// public void testIfTagParticipantsAreSame() {
// populateServerTags();
// 
// populateCacheTags();
// assert serverTags.size() > 0;
// assert cacheTags.size() > 0;
// assert serverTags.size() == cacheTags.size();
// 
// }
@Test
public void testIfTagsAreSame() {
    populateServerTags();
    populateCacheTags();
    assert serverTags.size() > 0;
    assert cacheTags.size() > 0;
    assert serverTags.size() == cacheTags.size();
    for (TagVo serverTag : serverTags) {
        if (serverTag == null)
            continue;
        System.out.println(">>>>>>>>>>> Server Tag " + serverTag.getTagId());
        TagVo tagInCache = cacheTags.stream().filter(cacheTag -> cacheTag.getTagId() == serverTag.getTagId()).findFirst().get();
        System.out.println(">>>>>>>>>>> Cache Tag " + tagInCache.getTagName());
        Assert.assertEquals(serverTag.getTagId(), tagInCache.getTagId());
        Assert.assertEquals(serverTag.getTagName(), tagInCache.getTagName());
        // Assert.assertEquals(serverTag.getOwner(), tagInCache.getOwner());
        Assert.assertEquals(serverTag.getAllUnreadCount(), tagInCache.getAllUnreadCount());
        Assert.assertEquals(serverTag.isActive(), tagInCache.isActive());
        System.out.println(">>>>>>>>>>>TagParticipants in cache" + tagInCache.getTagParticipants().size());
        System.out.println(">>>>>>>>>>>TagParticipants in server" + serverTag.getTagParticipants().size());
        System.out.println(">>>>>>>>>>>Tags are same");
    }
}
Also used : TagVo(com.fanap.podchat.model.TagVo) Test(org.junit.Test)

Aggregations

TagVo (com.fanap.podchat.model.TagVo)4 CacheTagVo (com.fanap.podchat.cachemodel.CacheTagVo)3 TagParticipantVO (com.fanap.podchat.model.TagParticipantVO)2 CacheTagParticipantVO (com.fanap.podchat.cachemodel.CacheTagParticipantVO)1 TagResult (com.fanap.podchat.chat.tag.result_model.TagResult)1 Thread (com.fanap.podchat.mainmodel.Thread)1 ChatResponse (com.fanap.podchat.model.ChatResponse)1 TypeToken (com.google.gson.reflect.TypeToken)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1