Search in sources :

Example 1 with HistoryEntry

use of cx.ring.model.HistoryEntry in project ring-client-android by savoirfairelinux.

the class HistoryService method readMessages.

public void readMessages(Conversation conversation) {
    for (HistoryEntry h : conversation.getRawHistory().values()) {
        NavigableMap<Long, TextMessage> messages = h.getTextMessages();
        for (TextMessage message : messages.descendingMap().values()) {
            if (message.isRead()) {
                break;
            }
            message.read();
            HistoryText ht = new HistoryText(message);
            updateTextMessage(ht);
        }
    }
}
Also used : HistoryText(cx.ring.model.HistoryText) HistoryEntry(cx.ring.model.HistoryEntry) TextMessage(cx.ring.model.TextMessage)

Example 2 with HistoryEntry

use of cx.ring.model.HistoryEntry in project ring-client-android by savoirfairelinux.

the class HistoryService method clearHistoryForConversation.

/**
 * Removes all the text messages and call histories from the database.
 *
 * @param conversation The conversation containing the elements to delete.
 */
public void clearHistoryForConversation(final Conversation conversation) {
    if (conversation == null) {
        Log.d(TAG, "clearHistoryForConversation: conversation is null");
        return;
    }
    mApplicationExecutor.submit(() -> {
        try {
            Map<String, HistoryEntry> history = conversation.getRawHistory();
            for (Map.Entry<String, HistoryEntry> entry : history.entrySet()) {
                // ~ Deleting messages
                ArrayList<Long> textMessagesIds = new ArrayList<>(entry.getValue().getTextMessages().size());
                for (TextMessage textMessage : entry.getValue().getTextMessages().values()) {
                    textMessagesIds.add(textMessage.getId());
                }
                DeleteBuilder<HistoryText, Long> deleteTextHistoryBuilder = getTextHistoryDao().deleteBuilder();
                deleteTextHistoryBuilder.where().in(HistoryText.COLUMN_ID_NAME, textMessagesIds);
                deleteTextHistoryBuilder.delete();
                // ~ Deleting calls
                ArrayList<String> callIds = new ArrayList<>(entry.getValue().getCalls().size());
                for (HistoryCall historyCall : entry.getValue().getCalls().values()) {
                    callIds.add(historyCall.getCallId().toString());
                }
                DeleteBuilder<HistoryCall, Integer> deleteCallsHistoryBuilder = getCallHistoryDao().deleteBuilder();
                deleteCallsHistoryBuilder.where().in(HistoryCall.COLUMN_CALL_ID_NAME, callIds);
                deleteCallsHistoryBuilder.delete();
                // ~ Deleting data transfers
                ArrayList<Long> dataTransferIds = new ArrayList<>(entry.getValue().getDataTransfers().size());
                for (DataTransfer dataTransfer : entry.getValue().getDataTransfers().values()) {
                    dataTransferIds.add(dataTransfer.getId());
                }
                DeleteBuilder<DataTransfer, Long> deleteDataTransfersHistoryBuilder = getDataHistoryDao().deleteBuilder();
                deleteDataTransfersHistoryBuilder.where().in(DataTransfer.COLUMN_ID_NAME, dataTransferIds);
                deleteDataTransfersHistoryBuilder.delete();
            }
            // notify the observers
            setChanged();
            ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.HISTORY_MODIFIED);
            notifyObservers(event);
        } catch (SQLException e) {
            Log.e(TAG, "Error while clearing history for conversation", e);
        }
    });
}
Also used : HistoryText(cx.ring.model.HistoryText) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) HistoryCall(cx.ring.model.HistoryCall) DataTransfer(cx.ring.model.DataTransfer) ServiceEvent(cx.ring.model.ServiceEvent) HistoryEntry(cx.ring.model.HistoryEntry) Map(java.util.Map) StringMap(cx.ring.daemon.StringMap) NavigableMap(java.util.NavigableMap) TextMessage(cx.ring.model.TextMessage)

Aggregations

HistoryEntry (cx.ring.model.HistoryEntry)2 HistoryText (cx.ring.model.HistoryText)2 TextMessage (cx.ring.model.TextMessage)2 StringMap (cx.ring.daemon.StringMap)1 DataTransfer (cx.ring.model.DataTransfer)1 HistoryCall (cx.ring.model.HistoryCall)1 ServiceEvent (cx.ring.model.ServiceEvent)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1