Search in sources :

Example 36 with ServiceEvent

use of cx.ring.model.ServiceEvent 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 37 with ServiceEvent

use of cx.ring.model.ServiceEvent 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 38 with ServiceEvent

use of cx.ring.model.ServiceEvent 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 39 with ServiceEvent

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

the class CallService method onRtcpReportReceived.

void onRtcpReportReceived(String callId, IntegerMap stats) {
    Log.i(TAG, "on RTCP report received: " + callId);
    setChanged();
    ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.CONFERENCE_CHANGED);
    event.addEventInput(ServiceEvent.EventInput.CALL_ID, callId);
    event.addEventInput(ServiceEvent.EventInput.STATS, stats);
    notifyObservers(event);
}
Also used : ServiceEvent(cx.ring.model.ServiceEvent)

Example 40 with ServiceEvent

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

the class CallService method callStateChanged.

void callStateChanged(String callId, String newState, int detailCode) {
    Log.d(TAG, "call state changed: " + callId + ", " + newState + ", " + detailCode);
    try {
        SipCall call = parseCallState(callId, newState);
        if (call != null) {
            setChanged();
            ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.CALL_STATE_CHANGED);
            event.addEventInput(ServiceEvent.EventInput.CALL, call);
            notifyObservers(event);
            if (call.getCallState() == SipCall.State.OVER) {
                currentCalls.remove(call.getCallId());
            }
        }
    } catch (Exception e) {
        Log.w(TAG, "Exception during state change: ", e);
    }
}
Also used : SipCall(cx.ring.model.SipCall) ServiceEvent(cx.ring.model.ServiceEvent)

Aggregations

ServiceEvent (cx.ring.model.ServiceEvent)43 Account (cx.ring.model.Account)13 DataTransfer (cx.ring.model.DataTransfer)4 HistoryText (cx.ring.model.HistoryText)4 TextMessage (cx.ring.model.TextMessage)4 SQLException (java.sql.SQLException)4 SurfaceHolder (android.view.SurfaceHolder)3 CallContact (cx.ring.model.CallContact)3 Conversation (cx.ring.model.Conversation)3 HistoryCall (cx.ring.model.HistoryCall)3 SipCall (cx.ring.model.SipCall)3 Uri (cx.ring.model.Uri)3 IOException (java.io.IOException)3 Camera (android.hardware.Camera)2 StringMap (cx.ring.daemon.StringMap)2 DataTransferEventCode (cx.ring.model.DataTransferEventCode)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Point (android.graphics.Point)1 DataTransferInfo (cx.ring.daemon.DataTransferInfo)1