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