Search in sources :

Example 1 with TextMessage

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

the class ConversationAdapter method configureForTextMessage.

/**
 * Configures the viewholder to display a classic text message, ie. not a call info text message
 *
 * @param convViewHolder The conversation viewHolder
 * @param convElement    The conversation element to display
 * @param position       The position of the viewHolder
 */
private void configureForTextMessage(final ConversationViewHolder convViewHolder, final IConversationElement convElement, int position) {
    if (convViewHolder == null || convElement == null) {
        return;
    }
    TextMessage textMessage = (TextMessage) convElement;
    CallContact contact = textMessage.getContact();
    if (contact == null) {
        Log.e(TAG, "Invalid contact, not able to display message correctly");
        return;
    }
    convViewHolder.mCid = textMessage.getContact().getId();
    String message = textMessage.getMessage().trim();
    if (StringUtils.isOnlyEmoji(message)) {
        convViewHolder.mMsgTxt.getBackground().setAlpha(0);
        convViewHolder.mMsgTxt.setTextSize(24.f);
        convViewHolder.mMsgTxt.setPadding(hPadding, vPaddingEmoticon, hPadding, vPaddingEmoticon);
    } else {
        convViewHolder.mMsgTxt.getBackground().setAlpha(255);
        convViewHolder.mMsgTxt.setTextSize(16.f);
        convViewHolder.mMsgTxt.setPadding(hPadding, vPadding, hPadding, vPadding);
    }
    convViewHolder.mMsgTxt.setText(message);
    if (convViewHolder.mPhoto != null) {
        convViewHolder.mPhoto.setImageBitmap(null);
    }
    boolean shouldSeparateByDetails = this.shouldSeparateByDetails(textMessage, position);
    boolean isConfigSameAsPreviousMsg = this.isMessageConfigSameAsPrevious(textMessage, position);
    if (textMessage.isIncoming() && !isConfigSameAsPreviousMsg) {
        Drawable contactPicture = AvatarFactory.getAvatar(convViewHolder.itemView.getContext(), mPhoto, contact.getUsername(), textMessage.getNumberUri().getHost());
        Glide.with(convViewHolder.itemView.getContext()).load(contactPicture).apply(AvatarFactory.getGlideOptions(true, true)).into(convViewHolder.mPhoto);
    }
    if (textMessage.getStatus() == TextMessage.Status.SENDING) {
        convViewHolder.mMsgDetailTxt.setVisibility(View.VISIBLE);
        convViewHolder.mMsgDetailTxt.setText(R.string.message_sending);
    } else if (shouldSeparateByDetails) {
        convViewHolder.mMsgDetailTxt.setVisibility(View.VISIBLE);
        String timeSeparationString = computeTimeSeparationStringFromMsgTimeStamp(convViewHolder.itemView.getContext(), textMessage.getDate());
        convViewHolder.mMsgDetailTxt.setText(timeSeparationString);
    } else {
        convViewHolder.mMsgDetailTxt.setVisibility(View.GONE);
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) TextMessage(cx.ring.model.TextMessage) CallContact(cx.ring.model.CallContact)

Example 2 with TextMessage

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

the class ConversationPresenter method sendTextMessage.

public void sendTextMessage(String message) {
    if (message != null && !message.equals("")) {
        getView().clearMsgEdit();
        if (mConversation == null)
            mConversation = mConversationFacade.startConversation(mCurrentContact);
        Conference conference = mConversation.getCurrentCall();
        TextMessage txtMessage;
        if (conference == null || !conference.isOnGoing()) {
            long id = mCallService.sendAccountTextMessage(mAccountId, mContactRingId.getRawUriString(), message);
            txtMessage = new TextMessage(false, message, mContactRingId, null, mAccountId);
            txtMessage.setID(id);
        } else {
            mCallService.sendTextMessage(conference.getId(), message);
            SipCall call = conference.getParticipants().get(0);
            txtMessage = new TextMessage(false, message, call.getNumberUri(), conference.getId(), call.getAccount());
        }
        txtMessage.read();
        mHistoryService.insertNewTextMessage(txtMessage);
        mConversation.addTextMessage(txtMessage);
        checkTrustRequestStatus();
        Log.d(TAG, "sendTextMessage: AggregateHistorySize=" + mConversation.getAggregateHistory().size());
        getView().refreshView(mConversation);
    }
}
Also used : SipCall(cx.ring.model.SipCall) Conference(cx.ring.model.Conference) TextMessage(cx.ring.model.TextMessage)

Example 3 with TextMessage

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

the class ConversationFacade method updateTextNotifications.

public void updateTextNotifications() {
    Log.d(TAG, "updateTextNotifications()");
    for (Conversation conversation : mConversationMap.values()) {
        TreeMap<Long, TextMessage> texts = conversation.getUnreadTextMessages();
        if (texts.isEmpty() || conversation.isVisible()) {
            mNotificationService.cancelTextNotification(conversation.getContact());
            continue;
        }
        if (texts.lastEntry().getValue().isNotified()) {
            continue;
        }
        CallContact contact = conversation.getContact();
        mNotificationService.showTextNotification(contact, conversation, texts);
    }
}
Also used : Conversation(cx.ring.model.Conversation) TextMessage(cx.ring.model.TextMessage) CallContact(cx.ring.model.CallContact)

Example 4 with TextMessage

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

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

the class ConversationFacade method sendTextMessage.

public void sendTextMessage(String account, Uri to, String txt) {
    long id = mCallService.sendAccountTextMessage(account, to.getRawUriString(), txt);
    Log.i(TAG, "sendAccountTextMessage " + txt + " got id " + id);
    TextMessage message = new TextMessage(false, txt, to, null, account);
    message.setID(id);
    message.read();
    mHistoryService.insertNewTextMessage(message);
}
Also used : 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