Search in sources :

Example 1 with HistoryCall

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

the class ConversationFacade method update.

@Override
public void update(Observable observable, ServiceEvent event) {
    if (event == null) {
        return;
    }
    ServiceEvent mEvent;
    if (observable instanceof HistoryService) {
        switch(event.getEventType()) {
            case INCOMING_MESSAGE:
                {
                    TextMessage txt = event.getEventInput(ServiceEvent.EventInput.MESSAGE, TextMessage.class);
                    if (txt == null) {
                        Log.d(TAG, "Received a null text message");
                        return;
                    }
                    parseNewMessage(txt);
                    updateTextNotifications();
                    setChanged();
                    mEvent = new ServiceEvent(ServiceEvent.EventType.INCOMING_MESSAGE);
                    notifyObservers(mEvent);
                    break;
                }
            case ACCOUNT_MESSAGE_STATUS_CHANGED:
                {
                    TextMessage newMsg = event.getEventInput(ServiceEvent.EventInput.MESSAGE, TextMessage.class);
                    Conversation conv = getConversationByContact(mContactService.findContactByNumber(newMsg.getNumber()));
                    if (conv != null) {
                        conv.updateTextMessage(newMsg);
                    }
                    setChanged();
                    mEvent = new ServiceEvent(ServiceEvent.EventType.INCOMING_MESSAGE);
                    notifyObservers(mEvent);
                    break;
                }
            case HISTORY_LOADED:
                Account account = mAccountService.getCurrentAccount();
                if (account != null) {
                    boolean acceptAllMessages = account.getDetailBoolean(ConfigKey.DHT_PUBLIC_IN);
                    mConversationMap.clear();
                    addContacts(acceptAllMessages);
                    List<HistoryCall> historyCalls = (List<HistoryCall>) event.getEventInput(ServiceEvent.EventInput.HISTORY_CALLS, ArrayList.class);
                    parseHistoryCalls(historyCalls, acceptAllMessages);
                    List<HistoryText> historyTexts = (List<HistoryText>) event.getEventInput(ServiceEvent.EventInput.HISTORY_TEXTS, ArrayList.class);
                    parseHistoryTexts(historyTexts, acceptAllMessages);
                    List<DataTransfer> historyTransfers = (List<DataTransfer>) event.getEventInput(ServiceEvent.EventInput.HISTORY_TRANSFERS, ArrayList.class);
                    parseHistoryTransfers(historyTransfers, acceptAllMessages);
                    aggregateHistory();
                    searchForRingIdInBlockchain();
                }
                setChanged();
                mEvent = new ServiceEvent(ServiceEvent.EventType.CONVERSATIONS_CHANGED);
                notifyObservers(mEvent);
                break;
            case HISTORY_MODIFIED:
                refreshConversations();
                break;
        }
    } else if (observable instanceof CallService) {
        Conversation conversation = null;
        Conference conference = null;
        SipCall call;
        switch(event.getEventType()) {
            case CALL_STATE_CHANGED:
                call = event.getEventInput(ServiceEvent.EventInput.CALL, SipCall.class);
                if (call == null) {
                    Log.w(TAG, "CALL_STATE_CHANGED : call is null");
                    return;
                }
                int newState = call.getCallState();
                mHardwareService.updateAudioState(newState == SipCall.State.RINGING && call.isIncoming(), call.isOnGoing() && !call.isAudioOnly());
                for (Conversation conv : mConversationMap.values()) {
                    conference = conv.getConference(call.getCallId());
                    if (conference != null) {
                        conversation = conv;
                        Log.w(TAG, "CALL_STATE_CHANGED : found conversation " + call.getCallId());
                        break;
                    }
                }
                if (conversation == null) {
                    conversation = startConversation(call.getContact());
                    conference = new Conference(call);
                    conversation.addConference(conference);
                }
                Log.w(TAG, "CALL_STATE_CHANGED : updating call state to " + newState);
                if ((call.isRinging() || newState == SipCall.State.CURRENT) && call.getTimestampStart() == 0) {
                    call.setTimestampStart(System.currentTimeMillis());
                }
                if ((newState == SipCall.State.CURRENT && call.isIncoming()) || newState == SipCall.State.RINGING && call.isOutGoing()) {
                    mAccountService.sendProfile(call.getCallId(), call.getAccount());
                } else if (newState == SipCall.State.HUNGUP || newState == SipCall.State.BUSY || newState == SipCall.State.FAILURE || newState == SipCall.State.OVER) {
                    mNotificationService.cancelCallNotification(call.getCallId().hashCode());
                    mHardwareService.closeAudioState();
                    if (newState == SipCall.State.HUNGUP) {
                        call.setTimestampEnd(System.currentTimeMillis());
                    }
                    if (call.getTimestampStart() == 0) {
                        call.setTimestampStart(System.currentTimeMillis());
                    }
                    if (call.getTimestampEnd() == 0) {
                        call.setTimestampEnd(System.currentTimeMillis());
                    }
                    mHistoryService.insertNewEntry(conference);
                    conference.removeParticipant(call);
                    conversation.addHistoryCall(new HistoryCall(call));
                    mCallService.removeCallForId(call.getCallId());
                }
                if (conference.getParticipants().isEmpty()) {
                    conversation.removeConference(conference);
                }
                setChanged();
                mEvent = new ServiceEvent(ServiceEvent.EventType.CALL_STATE_CHANGED);
                notifyObservers(mEvent);
                break;
            case INCOMING_CALL:
                call = event.getEventInput(ServiceEvent.EventInput.CALL, SipCall.class);
                conversation = startConversation(call.getContact());
                conference = new Conference(call);
                conversation.addConference(conference);
                mNotificationService.showCallNotification(conference);
                mHardwareService.setPreviewSettings();
                Conference currenConf = getCurrentCallingConf();
                mHardwareService.updateAudioState(currenConf.getState() == SipCall.State.RINGING && currenConf.isIncoming(), false);
                setChanged();
                ServiceEvent serviceEvent = new ServiceEvent(ServiceEvent.EventType.INCOMING_CALL);
                notifyObservers(serviceEvent);
                break;
        }
    } else if (observable instanceof ContactService) {
        switch(event.getEventType()) {
            case CONTACTS_CHANGED:
                refreshConversations();
                break;
        }
    } else if (observable instanceof AccountService) {
        switch(event.getEventType()) {
            case REGISTERED_NAME_FOUND:
                {
                    int state = event.getEventInput(ServiceEvent.EventInput.STATE, Integer.class);
                    if (state != 0) {
                        break;
                    }
                    String accountId = event.getEventInput(ServiceEvent.EventInput.ACCOUNT_ID, String.class);
                    String name = event.getEventInput(ServiceEvent.EventInput.NAME, String.class);
                    Uri address = new Uri(event.getEventInput(ServiceEvent.EventInput.ADDRESS, String.class));
                    if (mContactService.setRingContactName(accountId, address, name)) {
                        setChanged();
                        notifyObservers(new ServiceEvent(ServiceEvent.EventType.USERNAME_CHANGED));
                    }
                    break;
                }
            case DATA_TRANSFER:
                {
                    DataTransferEventCode transferEventCode = event.getEventInput(ServiceEvent.EventInput.TRANSFER_EVENT_CODE, DataTransferEventCode.class);
                    DataTransfer transfer = event.getEventInput(ServiceEvent.EventInput.TRANSFER_INFO, DataTransfer.class);
                    handleDataTransferEvent(transfer, transferEventCode);
                    break;
                }
        }
    }
}
Also used : Account(cx.ring.model.Account) SipCall(cx.ring.model.SipCall) SecureSipCall(cx.ring.model.SecureSipCall) HistoryText(cx.ring.model.HistoryText) ArrayList(java.util.ArrayList) HistoryService(cx.ring.services.HistoryService) Conversation(cx.ring.model.Conversation) Conference(cx.ring.model.Conference) Uri(cx.ring.model.Uri) HistoryCall(cx.ring.model.HistoryCall) ContactService(cx.ring.services.ContactService) DataTransfer(cx.ring.model.DataTransfer) ServiceEvent(cx.ring.model.ServiceEvent) ArrayList(java.util.ArrayList) List(java.util.List) AccountService(cx.ring.services.AccountService) TextMessage(cx.ring.model.TextMessage) DataTransferEventCode(cx.ring.model.DataTransferEventCode) CallService(cx.ring.services.CallService)

Example 2 with HistoryCall

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

the class HistoryService method getCallAndTextAsyncForAccount.

public void getCallAndTextAsyncForAccount(final String accountId) {
    mApplicationExecutor.submit(() -> {
        try {
            List<HistoryCall> historyCalls = getAllForAccount(accountId);
            List<HistoryText> historyTexts = getAllTextMessagesForAccount(accountId);
            List<DataTransfer> historyTransfers = getHistoryDataTransfers(accountId);
            ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.HISTORY_LOADED);
            event.addEventInput(ServiceEvent.EventInput.HISTORY_CALLS, historyCalls);
            event.addEventInput(ServiceEvent.EventInput.HISTORY_TEXTS, historyTexts);
            event.addEventInput(ServiceEvent.EventInput.HISTORY_TRANSFERS, historyTransfers);
            setChanged();
            notifyObservers(event);
        } catch (SQLException e) {
            Log.e(TAG, "Can't load calls and texts", e);
        }
    });
}
Also used : HistoryText(cx.ring.model.HistoryText) DataTransfer(cx.ring.model.DataTransfer) SQLException(java.sql.SQLException) ServiceEvent(cx.ring.model.ServiceEvent) HistoryCall(cx.ring.model.HistoryCall)

Example 3 with HistoryCall

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

the class HistoryService method insertNewEntry.

public boolean insertNewEntry(Conference toInsert) {
    for (SipCall call : toInsert.getParticipants()) {
        call.setTimestampEnd(System.currentTimeMillis());
        HistoryCall persistent = new HistoryCall(call);
        try {
            Log.d(TAG, "HistoryDao().create() " + persistent.getNumber() + " " + persistent.getStartDate().toString() + " " + persistent.getEndDate());
            getCallHistoryDao().create(persistent);
        } catch (SQLException e) {
            Log.e(TAG, "Error while inserting text conference entry", e);
            return false;
        }
    }
    return true;
}
Also used : SipCall(cx.ring.model.SipCall) SQLException(java.sql.SQLException) HistoryCall(cx.ring.model.HistoryCall)

Example 4 with HistoryCall

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

the class ConversationAdapter method configureForCallInfoTextMessage.

/**
 * Configures the viewholder to display a call info text message, ie. not a classic text message
 *
 * @param convViewHolder The conversation viewHolder
 * @param convElement    The conversation element to display
 */
private void configureForCallInfoTextMessage(final ConversationViewHolder convViewHolder, final IConversationElement convElement) {
    if (convViewHolder == null || convElement == null) {
        return;
    }
    int pictureResID;
    String historyTxt;
    convViewHolder.mPhoto.setScaleY(1);
    Context context = convViewHolder.itemView.getContext();
    HistoryCall hc = (HistoryCall) convElement;
    if (hc.isMissed()) {
        if (hc.isIncoming()) {
            pictureResID = R.drawable.ic_call_missed_incoming_black;
        } else {
            pictureResID = R.drawable.ic_call_missed_outgoing_black;
            // Flip the photo upside down to show a "missed outgoing call"
            convViewHolder.mPhoto.setScaleY(-1);
        }
        historyTxt = hc.isIncoming() ? context.getString(R.string.notif_missed_incoming_call) : context.getString(R.string.notif_missed_outgoing_call);
    } else {
        pictureResID = (hc.isIncoming()) ? R.drawable.ic_incoming_black : R.drawable.ic_outgoing_black;
        historyTxt = hc.isIncoming() ? context.getString(R.string.notif_incoming_call) : context.getString(R.string.notif_outgoing_call);
    }
    convViewHolder.mCid = hc.getContactID();
    convViewHolder.mPhoto.setImageResource(pictureResID);
    convViewHolder.mHistTxt.setText(historyTxt);
    convViewHolder.mHistDetailTxt.setText(DateFormat.getDateTimeInstance().format(hc.getStartDate()));
}
Also used : Context(android.content.Context) HistoryCall(cx.ring.model.HistoryCall)

Example 5 with HistoryCall

use of cx.ring.model.HistoryCall 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)

Aggregations

HistoryCall (cx.ring.model.HistoryCall)7 HistoryText (cx.ring.model.HistoryText)4 DataTransfer (cx.ring.model.DataTransfer)3 ServiceEvent (cx.ring.model.ServiceEvent)3 SQLException (java.sql.SQLException)3 Conversation (cx.ring.model.Conversation)2 SipCall (cx.ring.model.SipCall)2 TextMessage (cx.ring.model.TextMessage)2 Uri (cx.ring.model.Uri)2 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 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 HistoryEntry (cx.ring.model.HistoryEntry)1 SecureSipCall (cx.ring.model.SecureSipCall)1 AccountService (cx.ring.services.AccountService)1 CallService (cx.ring.services.CallService)1