put jingle messages in MAM and parse call log during catchup
This commit is contained in:
parent
9a41d11aed
commit
5b98107e9a
|
@ -733,6 +733,18 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Message findRtpSession(final String sessionId, final int s) {
|
||||||
|
synchronized (this.messages) {
|
||||||
|
for (int i = this.messages.size() - 1; i >= 0; --i) {
|
||||||
|
final Message message = this.messages.get(i);
|
||||||
|
if ((message.getStatus() == s) && (message.getType() == Message.TYPE_RTP_SESSION) && sessionId.equals(message.getRemoteMsgId())) {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean possibleDuplicate(final String serverMsgId, final String remoteMsgId) {
|
public boolean possibleDuplicate(final String serverMsgId, final String remoteMsgId) {
|
||||||
if (serverMsgId == null || remoteMsgId == null) {
|
if (serverMsgId == null || remoteMsgId == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -243,6 +243,7 @@ public class MessageGenerator extends AbstractGenerator {
|
||||||
propose.setAttribute("id", proposal.sessionId);
|
propose.setAttribute("id", proposal.sessionId);
|
||||||
propose.addChild("description", Namespace.JINGLE_APPS_RTP);
|
propose.addChild("description", Namespace.JINGLE_APPS_RTP);
|
||||||
packet.addChild("request", "urn:xmpp:receipts");
|
packet.addChild("request", "urn:xmpp:receipts");
|
||||||
|
packet.addChild("store", "urn:xmpp:hints");
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,6 +254,7 @@ public class MessageGenerator extends AbstractGenerator {
|
||||||
final Element propose = packet.addChild("retract", Namespace.JINGLE_MESSAGE);
|
final Element propose = packet.addChild("retract", Namespace.JINGLE_MESSAGE);
|
||||||
propose.setAttribute("id", proposal.sessionId);
|
propose.setAttribute("id", proposal.sessionId);
|
||||||
propose.addChild("description", Namespace.JINGLE_APPS_RTP);
|
propose.addChild("description", Namespace.JINGLE_APPS_RTP);
|
||||||
|
packet.addChild("store", "urn:xmpp:hints");
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,6 +265,7 @@ public class MessageGenerator extends AbstractGenerator {
|
||||||
final Element propose = packet.addChild("reject", Namespace.JINGLE_MESSAGE);
|
final Element propose = packet.addChild("reject", Namespace.JINGLE_MESSAGE);
|
||||||
propose.setAttribute("id", sessionId);
|
propose.setAttribute("id", sessionId);
|
||||||
propose.addChild("description", Namespace.JINGLE_APPS_RTP);
|
propose.addChild("description", Namespace.JINGLE_APPS_RTP);
|
||||||
|
packet.addChild("store", "urn:xmpp:hints");
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import eu.siacs.conversations.entities.Message;
|
||||||
import eu.siacs.conversations.entities.MucOptions;
|
import eu.siacs.conversations.entities.MucOptions;
|
||||||
import eu.siacs.conversations.entities.ReadByMarker;
|
import eu.siacs.conversations.entities.ReadByMarker;
|
||||||
import eu.siacs.conversations.entities.ReceiptRequest;
|
import eu.siacs.conversations.entities.ReceiptRequest;
|
||||||
|
import eu.siacs.conversations.entities.RtpSessionStatus;
|
||||||
import eu.siacs.conversations.http.HttpConnectionManager;
|
import eu.siacs.conversations.http.HttpConnectionManager;
|
||||||
import eu.siacs.conversations.http.P1S3UrlStreamHandler;
|
import eu.siacs.conversations.http.P1S3UrlStreamHandler;
|
||||||
import eu.siacs.conversations.services.MessageArchiveService;
|
import eu.siacs.conversations.services.MessageArchiveService;
|
||||||
|
@ -73,6 +74,11 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
||||||
return safeToExtract ? extractStanzaId(packet, by) : null;
|
return safeToExtract ? extractStanzaId(packet, by) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String extractStanzaId(Account account, Element packet) {
|
||||||
|
final boolean safeToExtract = account.getXmppConnection().getFeatures().stanzaIds();
|
||||||
|
return safeToExtract ? extractStanzaId(packet, account.getJid().asBareJid()) : null;
|
||||||
|
}
|
||||||
|
|
||||||
private static String extractStanzaId(Element packet, Jid by) {
|
private static String extractStanzaId(Element packet, Jid by) {
|
||||||
for (Element child : packet.getChildren()) {
|
for (Element child : packet.getChildren()) {
|
||||||
if (child.getName().equals("stanza-id")
|
if (child.getName().equals("stanza-id")
|
||||||
|
@ -829,17 +835,56 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
||||||
if (!isTypeGroupChat) {
|
if (!isTypeGroupChat) {
|
||||||
for (Element child : packet.getChildren()) {
|
for (Element child : packet.getChildren()) {
|
||||||
if (Namespace.JINGLE_MESSAGE.equals(child.getNamespace()) && JINGLE_MESSAGE_ELEMENT_NAMES.contains(child.getName())) {
|
if (Namespace.JINGLE_MESSAGE.equals(child.getNamespace()) && JINGLE_MESSAGE_ELEMENT_NAMES.contains(child.getName())) {
|
||||||
//TODO in this case we probably only want to send receipts for live messages
|
final String action = child.getName();
|
||||||
//as soon as it comes from MAM it is probably too late anyway
|
if (query == null) {
|
||||||
if (!account.getJid().asBareJid().equals(from.asBareJid())) {
|
if (!account.getJid().asBareJid().equals(from.asBareJid())) {
|
||||||
processMessageReceipts(account, packet, query);
|
processMessageReceipts(account, packet, query);
|
||||||
}
|
}
|
||||||
//TODO only live propose messages should get processed that way; however we may want to deliver 'accept' and 'reject' to stop ringing
|
if (serverMsgId == null) {
|
||||||
|
serverMsgId = extractStanzaId(account, packet);
|
||||||
|
}
|
||||||
mXmppConnectionService.getJingleConnectionManager().deliverMessage(account, packet.getTo(), packet.getFrom(), child, serverMsgId, timestamp);
|
mXmppConnectionService.getJingleConnectionManager().deliverMessage(account, packet.getTo(), packet.getFrom(), child, serverMsgId, timestamp);
|
||||||
|
} else if (query.isCatchup()) {
|
||||||
|
final String sessionId = child.getAttribute("id");
|
||||||
|
if (sessionId == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ("propose".equals(action)) {
|
||||||
|
final Element description = child.findChild("description");
|
||||||
|
final String namespace = description == null ? null : description.getNamespace();
|
||||||
|
if (Namespace.JINGLE_APPS_RTP.equals(namespace)) {
|
||||||
|
final Conversation c = mXmppConnectionService.findOrCreateConversation(account, counterpart.asBareJid(), false, false);
|
||||||
|
final Message message = new Message(
|
||||||
|
c,
|
||||||
|
status,
|
||||||
|
Message.TYPE_RTP_SESSION,
|
||||||
|
sessionId
|
||||||
|
);
|
||||||
|
message.setServerMsgId(serverMsgId);
|
||||||
|
message.setTime(timestamp);
|
||||||
|
message.setBody(new RtpSessionStatus(false, 0).toString());
|
||||||
|
c.add(message);
|
||||||
|
mXmppConnectionService.databaseBackend.createMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if ("proceed".equals(action)) {
|
||||||
|
//status needs to be flipped to find the original propose
|
||||||
|
final Conversation c = mXmppConnectionService.findOrCreateConversation(account, counterpart.asBareJid(), false, false);
|
||||||
|
final int s = packet.fromAccount(account) ? Message.STATUS_RECEIVED : Message.STATUS_SEND;
|
||||||
|
final Message message = c.findRtpSession(sessionId, s);
|
||||||
|
if (message != null) {
|
||||||
|
message.setBody(new RtpSessionStatus(true, 0).toString());
|
||||||
|
if (serverMsgId != null) {
|
||||||
|
message.setServerMsgId(serverMsgId);
|
||||||
|
}
|
||||||
|
message.setTime(timestamp);
|
||||||
|
mXmppConnectionService.updateMessage(message, true);
|
||||||
|
} else {
|
||||||
|
Log.d(Config.LOGTAG, "unable to find original rtp session message for received propose");
|
||||||
|
}
|
||||||
|
|
||||||
//TODO for queries we might want to process 'propose' and 'proceed'
|
}
|
||||||
//TODO propose will trigger a 'missed call' entry; 'proceed' might update that to a non missed call
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -494,7 +494,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
|
||||||
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 (serverMsgId="+serverMsgId+")");
|
||||||
if (serverMsgId != null) {
|
if (serverMsgId != null) {
|
||||||
this.message.setServerMsgId(serverMsgId);
|
this.message.setServerMsgId(serverMsgId);
|
||||||
}
|
}
|
||||||
|
@ -776,7 +776,7 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
|
||||||
messagePacket.setType(MessagePacket.TYPE_CHAT); //we want to carbon copy those
|
messagePacket.setType(MessagePacket.TYPE_CHAT); //we want to carbon copy those
|
||||||
messagePacket.setTo(to);
|
messagePacket.setTo(to);
|
||||||
messagePacket.addChild(action, Namespace.JINGLE_MESSAGE).setAttribute("id", id.sessionId);
|
messagePacket.addChild(action, Namespace.JINGLE_MESSAGE).setAttribute("id", id.sessionId);
|
||||||
Log.d(Config.LOGTAG, messagePacket.toString());
|
messagePacket.addChild("store", "urn:xmpp:hints");
|
||||||
xmppConnectionService.sendMessagePacket(id.account, messagePacket);
|
xmppConnectionService.sendMessagePacket(id.account, messagePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue