use of cx.ring.model.HistoryText in project ring-client-android by savoirfairelinux.
the class HistoryService method insertNewTextMessage.
public boolean insertNewTextMessage(TextMessage txt) {
HistoryText historyTxt = new HistoryText(txt);
if (!insertNewTextMessage(historyTxt)) {
return false;
}
txt.setID(historyTxt.id);
return true;
}
use of cx.ring.model.HistoryText in project ring-client-android by savoirfairelinux.
the class HistoryService method accountMessageStatusChanged.
public void accountMessageStatusChanged(String accountId, long messageId, String to, int status) {
TextMessage textMessage;
HistoryText historyText;
try {
historyText = getTextMessage(messageId);
} catch (SQLException e) {
Log.e(TAG, "accountMessageStatusChanged: a sql error occurred while getting message with id=" + messageId, e);
return;
}
if (historyText == null) {
Log.e(TAG, "accountMessageStatusChanged: not able to find message with id " + messageId + " in database");
return;
}
textMessage = new TextMessage(historyText);
if (!textMessage.getAccount().equals(accountId)) {
Log.e(TAG, "accountMessageStatusChanged: received an invalid text message");
return;
}
textMessage.setStatus(status);
updateTextMessage(new HistoryText(textMessage));
ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.ACCOUNT_MESSAGE_STATUS_CHANGED);
event.addEventInput(ServiceEvent.EventInput.MESSAGE, textMessage);
setChanged();
notifyObservers(event);
}
use of cx.ring.model.HistoryText 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);
}
});
}
use of cx.ring.model.HistoryText in project ring-client-android by savoirfairelinux.
the class SmartListPresenter method modelToViewModel.
private SmartListViewModel modelToViewModel(String ringId, CallContact callContact, @NonNull List<HistoryText> lastTexts, @NonNull List<HistoryCall> lastCalls) {
HistoryText lastText = lastTexts.size() > 0 ? lastTexts.get(0) : null;
HistoryCall lastCall = lastCalls.size() > 0 ? lastCalls.get(0) : null;
long lastInteractionLong = 0;
int lastEntryType = 0;
String lastInteraction = "";
boolean hasUnreadMessage = lastText != null && !lastText.isRead();
long lastTextTimestamp = lastText != null ? lastText.getDate() : 0;
long lastCallTimestamp = lastCall != null ? lastCall.getEndDate().getTime() : 0;
if (lastTextTimestamp > 0 && lastTextTimestamp > lastCallTimestamp) {
String msgString = lastText.getMessage();
if (msgString != null && !msgString.isEmpty() && msgString.contains("\n")) {
int lastIndexOfChar = msgString.lastIndexOf("\n");
if (lastIndexOfChar + 1 < msgString.length()) {
msgString = msgString.substring(msgString.lastIndexOf("\n") + 1);
}
}
lastInteractionLong = lastTextTimestamp;
lastEntryType = lastText.isIncoming() ? SmartListViewModel.TYPE_INCOMING_MESSAGE : SmartListViewModel.TYPE_OUTGOING_MESSAGE;
lastInteraction = msgString;
} else if (lastCallTimestamp > 0) {
lastInteractionLong = lastCallTimestamp;
lastEntryType = lastCall.isIncoming() ? SmartListViewModel.TYPE_INCOMING_CALL : SmartListViewModel.TYPE_OUTGOING_CALL;
lastInteraction = lastCall.getDurationString();
}
SmartListViewModel smartListViewModel;
mContactService.loadContactData(callContact);
smartListViewModel = new SmartListViewModel(ringId, callContact.getStatus(), callContact.getDisplayName() != null ? callContact.getDisplayName() : callContact.getUsername(), callContact.getPhoto(), lastInteractionLong, lastEntryType, lastInteraction, hasUnreadMessage);
smartListViewModel.setOnline(mPresenceService.isBuddyOnline(callContact.getIds().get(0)));
return smartListViewModel;
}
Aggregations