Search in sources :

Example 11 with TextMessage

use of cx.ring.model.TextMessage 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 12 with TextMessage

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

the class HistoryService method incomingMessage.

public void incomingMessage(String accountId, String callId, String from, StringMap messages) {
    String msg = null;
    final String textPlainMime = "text/plain";
    if (null != messages && messages.has_key(textPlainMime)) {
        msg = messages.getRaw(textPlainMime).toJavaString();
    }
    if (msg == null) {
        return;
    }
    if (!from.contains(CallContact.PREFIX_RING)) {
        from = CallContact.PREFIX_RING + from;
    }
    TextMessage txt = new TextMessage(true, msg, new Uri(from), callId, accountId);
    Log.w(TAG, "New text messsage " + txt.getAccount() + " " + txt.getCallId() + " " + txt.getMessage());
    insertNewTextMessage(txt);
    ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.INCOMING_MESSAGE);
    event.addEventInput(ServiceEvent.EventInput.MESSAGE, txt);
    setChanged();
    notifyObservers(event);
}
Also used : ServiceEvent(cx.ring.model.ServiceEvent) Uri(cx.ring.model.Uri) TextMessage(cx.ring.model.TextMessage)

Example 13 with TextMessage

use of cx.ring.model.TextMessage 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 14 with TextMessage

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

the class SmartListPresenter method update.

@Override
public void update(Observable observable, ServiceEvent event) {
    if (event == null) {
        return;
    }
    switch(event.getEventType()) {
        case REGISTERED_NAME_FOUND:
            String name = event.getEventInput(ServiceEvent.EventInput.NAME, String.class);
            if (mLastBlockchainQuery != null && (mLastBlockchainQuery.equals("") || !mLastBlockchainQuery.equals(name))) {
                return;
            }
            String address = event.getEventInput(ServiceEvent.EventInput.ADDRESS, String.class);
            int state = event.getEventInput(ServiceEvent.EventInput.STATE, Integer.class);
            parseEventState(name, address, state);
            break;
        case REGISTRATION_STATE_CHANGED:
            refreshConnectivity();
            break;
        case CONTACTS_CHANGED:
            loadConversations();
            break;
    }
    if (observable instanceof HistoryService) {
        switch(event.getEventType()) {
            case INCOMING_MESSAGE:
                TextMessage txt = event.getEventInput(ServiceEvent.EventInput.MESSAGE, TextMessage.class);
                if (txt.getAccount().equals(mAccountService.getCurrentAccount().getAccountID())) {
                    loadConversations();
                    getView().scrollToTop();
                }
                return;
            case HISTORY_MODIFIED:
                loadConversations();
                getView().scrollToTop();
                return;
        }
    }
    if (observable instanceof CallService) {
        switch(event.getEventType()) {
            case INCOMING_CALL:
                SipCall call = event.getEventInput(ServiceEvent.EventInput.CALL, SipCall.class);
                updateIncomingCall(call.getNumber());
                return;
        }
    }
    if (observable instanceof PresenceService) {
        switch(event.getEventType()) {
            case NEW_BUDDY_NOTIFICATION:
                updatePresence();
                return;
            default:
        }
    }
}
Also used : SipCall(cx.ring.model.SipCall) HistoryService(cx.ring.services.HistoryService) PresenceService(cx.ring.services.PresenceService) TextMessage(cx.ring.model.TextMessage) CallService(cx.ring.services.CallService)

Example 15 with TextMessage

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

the class ConversationFacade method sendTextMessage.

public void sendTextMessage(Conference conf, String txt) {
    mCallService.sendTextMessage(conf.getId(), txt);
    SipCall call = conf.getParticipants().get(0);
    TextMessage message = new TextMessage(false, txt, call.getNumberUri(), conf.getId(), call.getAccount());
    message.read();
    mHistoryService.insertNewTextMessage(message);
}
Also used : SipCall(cx.ring.model.SipCall) SecureSipCall(cx.ring.model.SecureSipCall) TextMessage(cx.ring.model.TextMessage)

Aggregations

TextMessage (cx.ring.model.TextMessage)15 HistoryText (cx.ring.model.HistoryText)5 ServiceEvent (cx.ring.model.ServiceEvent)4 SipCall (cx.ring.model.SipCall)4 CallContact (cx.ring.model.CallContact)3 Conversation (cx.ring.model.Conversation)3 Uri (cx.ring.model.Uri)3 ArrayList (java.util.ArrayList)3 Conference (cx.ring.model.Conference)2 DataTransfer (cx.ring.model.DataTransfer)2 HistoryCall (cx.ring.model.HistoryCall)2 HistoryEntry (cx.ring.model.HistoryEntry)2 SecureSipCall (cx.ring.model.SecureSipCall)2 CallService (cx.ring.services.CallService)2 HistoryService (cx.ring.services.HistoryService)2 SQLException (java.sql.SQLException)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 NotificationCompat (android.support.v4.app.NotificationCompat)1