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);
}
}
}
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);
}
});
}
Aggregations