Search in sources :

Example 1 with ResultDeleteMessage

use of com.fanap.podchat.mainmodel.ResultDeleteMessage in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method findDeletedMessages.

private void findDeletedMessages(List<MessageVO> messagesFromCache, List<MessageVO> newMessagesFromServer, String uniqueId, long threadId) {
    for (MessageVO msg : messagesFromCache) {
        if (!newMessagesFromServer.contains(msg)) {
            ChatResponse<ResultDeleteMessage> chatResponse = MessageManager.prepareDeleteMessageResponseForFind(msg, uniqueId, threadId);
            String jsonDeleteMsg = gson.toJson(chatResponse);
            listenerManager.callOnDeleteMessage(jsonDeleteMsg, chatResponse);
            showLog("RECEIVE_DELETE_MESSAGE", jsonDeleteMsg);
            if (cache) {
                dataSource.deleteMessage(msg, threadId);
                messageDatabaseHelper.deleteMessage(msg.getId(), threadId);
                showLog("Delete message from database with this messageId" + " " + msg.getId(), "");
            }
        }
    }
}
Also used : GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO) ResultDeleteMessage(com.fanap.podchat.mainmodel.ResultDeleteMessage)

Example 2 with ResultDeleteMessage

use of com.fanap.podchat.mainmodel.ResultDeleteMessage in project pod-chat-android-sdk by FanapSoft.

the class MessageManager method prepareDeleteMessageResponseForFind.

public static ChatResponse<ResultDeleteMessage> prepareDeleteMessageResponseForFind(MessageVO msg, String uniqueId, long threadId) {
    ChatResponse<ResultDeleteMessage> chatResponse = new ChatResponse<>();
    chatResponse.setUniqueId(uniqueId);
    ResultDeleteMessage resultDeleteMessage = new ResultDeleteMessage();
    DeleteMessageContent deleteMessage = new DeleteMessageContent();
    deleteMessage.setId(msg.getId());
    resultDeleteMessage.setDeletedMessage(deleteMessage);
    chatResponse.setResult(resultDeleteMessage);
    chatResponse.setSubjectId(threadId);
    return chatResponse;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ResultDeleteMessage(com.fanap.podchat.mainmodel.ResultDeleteMessage) DeleteMessageContent(com.fanap.podchat.model.DeleteMessageContent)

Example 3 with ResultDeleteMessage

use of com.fanap.podchat.mainmodel.ResultDeleteMessage in project pod-chat-android-sdk by FanapSoft.

the class MessageManager method prepareDeleteMessageResponse.

public static ChatResponse<ResultDeleteMessage> prepareDeleteMessageResponse(ChatMessage chatMessage, long messageId) {
    ChatResponse<ResultDeleteMessage> chatResponse = new ChatResponse<>();
    chatResponse.setUniqueId(chatMessage.getUniqueId());
    ResultDeleteMessage resultDeleteMessage = new ResultDeleteMessage();
    DeleteMessageContent deleteMessage = new DeleteMessageContent();
    deleteMessage.setId(messageId);
    resultDeleteMessage.setDeletedMessage(deleteMessage);
    chatResponse.setResult(resultDeleteMessage);
    chatResponse.setSubjectId(chatMessage.getSubjectId());
    return chatResponse;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ResultDeleteMessage(com.fanap.podchat.mainmodel.ResultDeleteMessage) DeleteMessageContent(com.fanap.podchat.model.DeleteMessageContent)

Example 4 with ResultDeleteMessage

use of com.fanap.podchat.mainmodel.ResultDeleteMessage in project pod-chat-android-sdk by FanapSoft.

the class ThreadCacheTest method sendMessageAndDelete.

public void sendMessageAndDelete() {
    populateThreadsFromServer();
    Collections.shuffle(threadsInServer);
    Thread thread = threadsInServer.get(0);
    Assert.assertNotNull(thread);
    ArrayList<Long> msgIds = new ArrayList<>();
    // send new message
    chatListeners = new ChatListener() {

        @Override
        public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
            resumeProcess();
            msgIds.add(response.getResult().getMessageVO().getId());
            System.out.println("new message sent -> msg : " + content);
            chat.removeListener(chatListeners);
        }

        @Override
        public void onError(String content, ErrorOutPut error) {
            resumeProcess();
            System.out.println("Error: " + content);
            Assert.assertEquals(0, 1);
            chat.removeListener(chatListeners);
        }
    };
    chat.addListener(chatListeners);
    RequestMessage request = new RequestMessage.Builder("Message for test delete :" + thread.getId(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
    chat.sendTextMessage(request, null);
    pauseProcess();
    // delete last message
    chatListeners = new ChatListener() {

        @Override
        public void onDeleteMessage(String content, ChatResponse<ResultDeleteMessage> response) {
            resumeProcess();
            System.out.println("Deleted: " + content);
            chat.removeListener(chatListeners);
        }

        @Override
        public void onError(String content, ErrorOutPut error) {
            resumeProcess();
            System.out.println("Error: " + content);
            Assert.assertEquals(0, 1);
            chat.removeListener(chatListeners);
        }
    };
    chat.addListener(chatListeners);
    RequestDeleteMessage requestDeleteMessage = new RequestDeleteMessage.Builder().messageIds(msgIds).deleteForAll(true).build();
    presenter.deleteMessage(requestDeleteMessage, null);
    pauseProcess();
}
Also used : RequestDeleteMessage(com.fanap.podchat.requestobject.RequestDeleteMessage) ArrayList(java.util.ArrayList) Thread(com.fanap.podchat.mainmodel.Thread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ChatListener(com.fanap.podchat.chat.ChatListener) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) ResultDeleteMessage(com.fanap.podchat.mainmodel.ResultDeleteMessage)

Aggregations

ResultDeleteMessage (com.fanap.podchat.mainmodel.ResultDeleteMessage)4 ChatResponse (com.fanap.podchat.model.ChatResponse)2 DeleteMessageContent (com.fanap.podchat.model.DeleteMessageContent)2 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)1 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)1 ChatListener (com.fanap.podchat.chat.ChatListener)1 MessageVO (com.fanap.podchat.mainmodel.MessageVO)1 Thread (com.fanap.podchat.mainmodel.Thread)1 ErrorOutPut (com.fanap.podchat.model.ErrorOutPut)1 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)1 ResultThread (com.fanap.podchat.model.ResultThread)1 RequestDeleteMessage (com.fanap.podchat.requestobject.RequestDeleteMessage)1 RequestMessage (com.fanap.podchat.requestobject.RequestMessage)1 RequestThread (com.fanap.podchat.requestobject.RequestThread)1 ArrayList (java.util.ArrayList)1