Search in sources :

Example 6 with HistoryText

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;
}
Also used : HistoryText(cx.ring.model.HistoryText)

Example 7 with HistoryText

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);
}
Also used : HistoryText(cx.ring.model.HistoryText) SQLException(java.sql.SQLException) ServiceEvent(cx.ring.model.ServiceEvent) TextMessage(cx.ring.model.TextMessage)

Example 8 with HistoryText

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

Example 9 with HistoryText

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;
}
Also used : HistoryText(cx.ring.model.HistoryText) HistoryCall(cx.ring.model.HistoryCall)

Aggregations

HistoryText (cx.ring.model.HistoryText)9 TextMessage (cx.ring.model.TextMessage)5 HistoryCall (cx.ring.model.HistoryCall)4 ServiceEvent (cx.ring.model.ServiceEvent)4 Conversation (cx.ring.model.Conversation)3 DataTransfer (cx.ring.model.DataTransfer)3 SQLException (java.sql.SQLException)3 HistoryEntry (cx.ring.model.HistoryEntry)2 Uri (cx.ring.model.Uri)2 ArrayList (java.util.ArrayList)2 StringMap (cx.ring.daemon.StringMap)1 Account (cx.ring.model.Account)1 CallContact (cx.ring.model.CallContact)1 Conference (cx.ring.model.Conference)1 DataTransferEventCode (cx.ring.model.DataTransferEventCode)1 SecureSipCall (cx.ring.model.SecureSipCall)1 SipCall (cx.ring.model.SipCall)1 AccountService (cx.ring.services.AccountService)1 CallService (cx.ring.services.CallService)1 ContactService (cx.ring.services.ContactService)1