more conditions under which to print call log

This commit is contained in:
Daniel Gultsch 2020-04-12 18:07:31 +02:00
parent 3439f40411
commit 4be2309202
5 changed files with 84 additions and 20 deletions

View file

@ -832,7 +832,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (!account.getJid().asBareJid().equals(from.asBareJid())) { if (!account.getJid().asBareJid().equals(from.asBareJid())) {
processMessageReceipts(account, packet, query); processMessageReceipts(account, packet, query);
} }
mXmppConnectionService.getJingleConnectionManager().deliverMessage(account, packet.getTo(), packet.getFrom(), child); mXmppConnectionService.getJingleConnectionManager().deliverMessage(account, packet.getTo(), packet.getFrom(), child, serverMsgId, timestamp);
break; break;
} }
} }

View file

@ -31,6 +31,7 @@ import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.Presence; import eu.siacs.conversations.entities.Presence;
import eu.siacs.conversations.entities.RtpSessionStatus;
import eu.siacs.conversations.entities.Transferable; import eu.siacs.conversations.entities.Transferable;
import eu.siacs.conversations.services.ExportBackupService; import eu.siacs.conversations.services.ExportBackupService;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
@ -300,7 +301,13 @@ public class UIHelper {
} else if (message.isFileOrImage()) { } else if (message.isFileOrImage()) {
return new Pair<>(getFileDescriptionString(context, message), true); return new Pair<>(getFileDescriptionString(context, message), true);
} else if (message.getType() == Message.TYPE_RTP_SESSION) { } else if (message.getType() == Message.TYPE_RTP_SESSION) {
return new Pair<>(context.getString(message.getStatus() == Message.STATUS_RECEIVED ? R.string.incoming_call : R.string.outgoing_call), true); RtpSessionStatus rtpSessionStatus = RtpSessionStatus.of(message.getBody());
final boolean received = message.getStatus() == Message.STATUS_RECEIVED;
if (!rtpSessionStatus.successful && received) {
return new Pair<>(context.getString(R.string.missed_call),true);
} else {
return new Pair<>(context.getString(received ? R.string.incoming_call : R.string.outgoing_call), true);
}
} else { } else {
final String body = MessageUtils.filterLtrRtl(message.getBody()); final String body = MessageUtils.filterLtrRtl(message.getBody());
if (body.startsWith(Message.ME_COMMAND)) { if (body.startsWith(Message.ME_COMMAND)) {

View file

@ -14,6 +14,8 @@ import java.util.concurrent.ConcurrentHashMap;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Conversational;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.Transferable; import eu.siacs.conversations.entities.Transferable;
import eu.siacs.conversations.services.AbstractConnectionManager; import eu.siacs.conversations.services.AbstractConnectionManager;
@ -108,7 +110,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
account.getXmppConnection().sendIqPacket(response, null); account.getXmppConnection().sendIqPacket(response, null);
} }
public void deliverMessage(final Account account, final Jid to, final Jid from, final Element message) { public void deliverMessage(final Account account, final Jid to, final Jid from, final Element message, String serverMsgId, long timestamp) {
Preconditions.checkArgument(Namespace.JINGLE_MESSAGE.equals(message.getNamespace())); Preconditions.checkArgument(Namespace.JINGLE_MESSAGE.equals(message.getNamespace()));
final String sessionId = message.getAttribute("id"); final String sessionId = message.getAttribute("id");
if (sessionId == null) { if (sessionId == null) {
@ -120,7 +122,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
final JingleRtpConnection rtpConnection = (JingleRtpConnection) connection; final JingleRtpConnection rtpConnection = (JingleRtpConnection) connection;
final AbstractJingleConnection.Id id = connection.getId(); final AbstractJingleConnection.Id id = connection.getId();
if (id.account == account && id.sessionId.equals(sessionId)) { if (id.account == account && id.sessionId.equals(sessionId)) {
rtpConnection.deliveryMessage(from, message); rtpConnection.deliveryMessage(from, message, serverMsgId, timestamp);
return; return;
} }
} }
@ -141,7 +143,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
final AbstractJingleConnection existingJingleConnection = connections.get(id); final AbstractJingleConnection existingJingleConnection = connections.get(id);
if (existingJingleConnection != null) { if (existingJingleConnection != null) {
if (existingJingleConnection instanceof JingleRtpConnection) { if (existingJingleConnection instanceof JingleRtpConnection) {
((JingleRtpConnection) existingJingleConnection).deliveryMessage(from, message); ((JingleRtpConnection) existingJingleConnection).deliveryMessage(from, message, serverMsgId, timestamp);
} else { } else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": " + existingJingleConnection.getClass().getName() + " does not support jingle messages"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": " + existingJingleConnection.getClass().getName() + " does not support jingle messages");
} }
@ -162,7 +164,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} else { } else {
final JingleRtpConnection rtpConnection = new JingleRtpConnection(this, id, from); final JingleRtpConnection rtpConnection = new JingleRtpConnection(this, id, from);
this.connections.put(id, rtpConnection); this.connections.put(id, rtpConnection);
rtpConnection.deliveryMessage(from, message); rtpConnection.deliveryMessage(from, message, serverMsgId, timestamp);
} }
} else { } else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": unable to react to proposed " + namespace + " session"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": unable to react to proposed " + namespace + " session");
@ -175,7 +177,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
final JingleRtpConnection rtpConnection = new JingleRtpConnection(this, id, account.getJid()); final JingleRtpConnection rtpConnection = new JingleRtpConnection(this, id, account.getJid());
this.connections.put(id, rtpConnection); this.connections.put(id, rtpConnection);
rtpConnection.transitionOrThrow(AbstractJingleConnection.State.PROPOSED); rtpConnection.transitionOrThrow(AbstractJingleConnection.State.PROPOSED);
rtpConnection.deliveryMessage(from, message); rtpConnection.deliveryMessage(from, message, serverMsgId, timestamp);
} else { } else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": no rtp session proposal found for " + from + " to deliver proceed"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": no rtp session proposal found for " + from + " to deliver proceed");
} }
@ -184,6 +186,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
final RtpSessionProposal proposal = new RtpSessionProposal(account, from.asBareJid(), sessionId); final RtpSessionProposal proposal = new RtpSessionProposal(account, from.asBareJid(), sessionId);
synchronized (rtpSessionProposals) { synchronized (rtpSessionProposals) {
if (rtpSessionProposals.remove(proposal) != null) { if (rtpSessionProposals.remove(proposal) != null) {
writeLogMissedOutgoing(account, proposal.with, proposal.sessionId, serverMsgId, timestamp);
mXmppConnectionService.notifyJingleRtpConnectionUpdate(account, proposal.with, proposal.sessionId, RtpEndUserState.DECLINED_OR_BUSY); mXmppConnectionService.notifyJingleRtpConnectionUpdate(account, proposal.with, proposal.sessionId, RtpEndUserState.DECLINED_OR_BUSY);
} else { } else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": no rtp session proposal found for " + from + " to deliver reject"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": no rtp session proposal found for " + from + " to deliver reject");
@ -195,6 +198,35 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} }
private void writeLogMissedOutgoing(final Account account, Jid with, final String sessionId, String serverMsgId, long timestamp) {
final Conversation conversation = mXmppConnectionService.findOrCreateConversation(
account,
with.asBareJid(),
false,
false
);
final Message message = new Message(
conversation,
Message.STATUS_SEND,
Message.TYPE_RTP_SESSION,
sessionId
);
message.setServerMsgId(serverMsgId);
message.setTime(timestamp);
writeMessage(message);
}
private void writeMessage(final Message message) {
final Conversational conversational = message.getConversation();
if (conversational instanceof Conversation) {
((Conversation) conversational).add(message);
mXmppConnectionService.databaseBackend.createMessage(message);
mXmppConnectionService.updateConversationUi();
} else {
throw new IllegalStateException("Somehow the conversation in a message was a stub");
}
}
public void startJingleFileTransfer(final Message message) { public void startJingleFileTransfer(final Message message) {
Preconditions.checkArgument(message.isFileOrImage(), "Message is not of type file or image"); Preconditions.checkArgument(message.isFileOrImage(), "Message is not of type file or image");
final Transferable old = message.getTransferable(); final Transferable old = message.getTransferable();
@ -271,7 +303,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
if (matchingProposal != null) { if (matchingProposal != null) {
this.rtpSessionProposals.remove(matchingProposal); this.rtpSessionProposals.remove(matchingProposal);
final MessagePacket messagePacket = mXmppConnectionService.getMessageGenerator().sessionRetract(matchingProposal); final MessagePacket messagePacket = mXmppConnectionService.getMessageGenerator().sessionRetract(matchingProposal);
Log.d(Config.LOGTAG, messagePacket.toString()); writeLogMissedOutgoing(account, matchingProposal.with, matchingProposal.sessionId, null, System.currentTimeMillis());
mXmppConnectionService.sendMessagePacket(account, messagePacket); mXmppConnectionService.sendMessagePacket(account, messagePacket);
} }

View file

@ -371,23 +371,23 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
send(sessionAccept); send(sessionAccept);
} }
void deliveryMessage(final Jid from, final Element message) { void deliveryMessage(final Jid from, final Element message, final String serverMessageId, final long timestamp) {
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": delivered message to JingleRtpConnection " + message); Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": delivered message to JingleRtpConnection " + message);
switch (message.getName()) { switch (message.getName()) {
case "propose": case "propose":
receivePropose(from, message); receivePropose(from, serverMessageId, timestamp);
break; break;
case "proceed": case "proceed":
receiveProceed(from, message); receiveProceed(from, serverMessageId, timestamp);
break; break;
case "retract": case "retract":
receiveRetract(from, message); receiveRetract(from, serverMessageId, timestamp);
break; break;
case "reject": case "reject":
receiveReject(from, message); receiveReject(from, serverMessageId, timestamp);
break; break;
case "accept": case "accept":
receiveAccept(from, message); receiveAccept(from, serverMessageId, timestamp);
break; break;
default: default:
break; break;
@ -403,10 +403,16 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
} }
} }
private void receiveAccept(Jid from, Element message) { private void receiveAccept(final Jid from, final String serverMsgId, final long timestamp) {
final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid()); final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid());
if (originatedFromMyself) { if (originatedFromMyself) {
if (transition(State.ACCEPTED)) { if (transition(State.ACCEPTED)) {
if (serverMsgId != null) {
this.message.setServerMsgId(serverMsgId);
}
this.message.setTime(timestamp);
this.message.setCarbon(true); //indicate that call was accepted on other device
this.writeLogMessageSuccess(0);
this.xmppConnectionService.getNotificationService().cancelIncomingCallNotification(); this.xmppConnectionService.getNotificationService().cancelIncomingCallNotification();
this.jingleConnectionManager.finishConnection(this); this.jingleConnectionManager.finishConnection(this);
} else { } else {
@ -417,13 +423,19 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
} }
} }
private void receiveReject(Jid from, Element message) { private void receiveReject(Jid from, String serverMsgId, long timestamp) {
final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid()); final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid());
//reject from another one of my clients //reject from another one of my clients
if (originatedFromMyself) { if (originatedFromMyself) {
if (transition(State.REJECTED)) { if (transition(State.REJECTED)) {
this.xmppConnectionService.getNotificationService().cancelIncomingCallNotification(); this.xmppConnectionService.getNotificationService().cancelIncomingCallNotification();
this.jingleConnectionManager.finishConnection(this); this.jingleConnectionManager.finishConnection(this);
if (serverMsgId != null) {
this.message.setServerMsgId(serverMsgId);
}
this.message.setTime(timestamp);
this.message.setCarbon(true); //indicate that call was rejected on other device
writeLogMessageMissed();
} else { } else {
Log.d(Config.LOGTAG, "not able to transition into REJECTED because already in " + this.state); Log.d(Config.LOGTAG, "not able to transition into REJECTED because already in " + this.state);
} }
@ -432,12 +444,15 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
} }
} }
private void receivePropose(final Jid from, final Element propose) { private void receivePropose(final Jid from, final String serverMsgId, final long timestamp) {
final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid()); final boolean originatedFromMyself = from.asBareJid().equals(id.account.getJid().asBareJid());
//TODO we can use initiator logic here
if (originatedFromMyself) { if (originatedFromMyself) {
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": saw proposal from mysql. ignoring"); Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": saw proposal from mysql. ignoring");
} else if (transition(State.PROPOSED)) { } else if (transition(State.PROPOSED)) {
if (serverMsgId != null) {
this.message.setServerMsgId(serverMsgId);
}
this.message.setTime(timestamp);
startRinging(); startRinging();
} else { } else {
Log.d(Config.LOGTAG, id.account.getJid() + ": ignoring session proposal because already in " + state); Log.d(Config.LOGTAG, id.account.getJid() + ": ignoring session proposal because already in " + state);
@ -449,10 +464,14 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
xmppConnectionService.getNotificationService().showIncomingCallNotification(id); xmppConnectionService.getNotificationService().showIncomingCallNotification(id);
} }
private void receiveProceed(final Jid from, final Element proceed) { private void receiveProceed(final Jid from, final String serverMsgId, final long timestamp) {
if (from.equals(id.with)) { if (from.equals(id.with)) {
if (isInitiator()) { if (isInitiator()) {
if (transition(State.PROCEED)) { if (transition(State.PROCEED)) {
if (serverMsgId != null) {
this.message.setServerMsgId(serverMsgId);
}
this.message.setTime(timestamp);
this.sendSessionInitiate(State.SESSION_INITIALIZED_PRE_APPROVED); this.sendSessionInitiate(State.SESSION_INITIALIZED_PRE_APPROVED);
} else { } else {
Log.d(Config.LOGTAG, String.format("%s: ignoring proceed because already in %s", id.account.getJid().asBareJid(), this.state)); Log.d(Config.LOGTAG, String.format("%s: ignoring proceed because already in %s", id.account.getJid().asBareJid(), this.state));
@ -471,11 +490,15 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
} }
} }
private void receiveRetract(final Jid from, final Element retract) { private void receiveRetract(final Jid from, final String serverMsgId, final long timestamp) {
if (from.equals(id.with)) { if (from.equals(id.with)) {
if (transition(State.RETRACTED)) { if (transition(State.RETRACTED)) {
xmppConnectionService.getNotificationService().cancelIncomingCallNotification(); xmppConnectionService.getNotificationService().cancelIncomingCallNotification();
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": session with " + id.with + " has been retracted"); Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": session with " + id.with + " has been retracted");
if (serverMsgId != null) {
this.message.setServerMsgId(serverMsgId);
}
this.message.setTime(timestamp);
writeLogMessageMissed(); writeLogMessageMissed();
jingleConnectionManager.finishConnection(this); jingleConnectionManager.finishConnection(this);
} else { } else {
@ -729,6 +752,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
private void rejectCallFromProposed() { private void rejectCallFromProposed() {
transitionOrThrow(State.REJECTED); transitionOrThrow(State.REJECTED);
writeLogMessageMissed();
xmppConnectionService.getNotificationService().cancelIncomingCallNotification(); xmppConnectionService.getNotificationService().cancelIncomingCallNotification();
this.sendJingleMessage("reject"); this.sendJingleMessage("reject");
jingleConnectionManager.finishConnection(this); jingleConnectionManager.finishConnection(this);

View file

@ -907,6 +907,7 @@
<string name="incoming_call_duration">Incoming call · %s</string> <string name="incoming_call_duration">Incoming call · %s</string>
<string name="outgoing_call">Outgoing call</string> <string name="outgoing_call">Outgoing call</string>
<string name="outgoing_call_duration">Outgoing call · %s</string> <string name="outgoing_call_duration">Outgoing call · %s</string>
<string name="missed_call">Missed call</string>
<plurals name="view_users"> <plurals name="view_users">
<item quantity="one">View %1$d Participant</item> <item quantity="one">View %1$d Participant</item>
<item quantity="other">View %1$d Participants</item> <item quantity="other">View %1$d Participants</item>