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