parse 'received' carbon-copied error messages. fixes #3803
This commit is contained in:
parent
3dcb36a417
commit
064264c20b
|
@ -13,81 +13,81 @@ import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
||||||
|
|
||||||
public class PresenceGenerator extends AbstractGenerator {
|
public class PresenceGenerator extends AbstractGenerator {
|
||||||
|
|
||||||
public PresenceGenerator(XmppConnectionService service) {
|
public PresenceGenerator(XmppConnectionService service) {
|
||||||
super(service);
|
super(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PresencePacket subscription(String type, Contact contact) {
|
private PresencePacket subscription(String type, Contact contact) {
|
||||||
PresencePacket packet = new PresencePacket();
|
PresencePacket packet = new PresencePacket();
|
||||||
packet.setAttribute("type", type);
|
packet.setAttribute("type", type);
|
||||||
packet.setTo(contact.getJid());
|
packet.setTo(contact.getJid());
|
||||||
packet.setFrom(contact.getAccount().getJid().asBareJid());
|
packet.setFrom(contact.getAccount().getJid().asBareJid());
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PresencePacket requestPresenceUpdatesFrom(Contact contact) {
|
public PresencePacket requestPresenceUpdatesFrom(Contact contact) {
|
||||||
PresencePacket packet = subscription("subscribe", contact);
|
PresencePacket packet = subscription("subscribe", contact);
|
||||||
String displayName = contact.getAccount().getDisplayName();
|
String displayName = contact.getAccount().getDisplayName();
|
||||||
if (!TextUtils.isEmpty(displayName)) {
|
if (!TextUtils.isEmpty(displayName)) {
|
||||||
packet.addChild("nick",Namespace.NICK).setContent(displayName);
|
packet.addChild("nick", Namespace.NICK).setContent(displayName);
|
||||||
}
|
}
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PresencePacket stopPresenceUpdatesFrom(Contact contact) {
|
public PresencePacket stopPresenceUpdatesFrom(Contact contact) {
|
||||||
return subscription("unsubscribe", contact);
|
return subscription("unsubscribe", contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PresencePacket stopPresenceUpdatesTo(Contact contact) {
|
public PresencePacket stopPresenceUpdatesTo(Contact contact) {
|
||||||
return subscription("unsubscribed", contact);
|
return subscription("unsubscribed", contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PresencePacket sendPresenceUpdatesTo(Contact contact) {
|
public PresencePacket sendPresenceUpdatesTo(Contact contact) {
|
||||||
return subscription("subscribed", contact);
|
return subscription("subscribed", contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PresencePacket selfPresence(Account account, Presence.Status status) {
|
public PresencePacket selfPresence(Account account, Presence.Status status) {
|
||||||
return selfPresence(account, status, true);
|
return selfPresence(account, status, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PresencePacket selfPresence(final Account account, final Presence.Status status, final boolean personal) {
|
public PresencePacket selfPresence(final Account account, final Presence.Status status, final boolean personal) {
|
||||||
final PresencePacket packet = new PresencePacket();
|
final PresencePacket packet = new PresencePacket();
|
||||||
if (personal) {
|
if (personal) {
|
||||||
final String sig = account.getPgpSignature();
|
final String sig = account.getPgpSignature();
|
||||||
final String message = account.getPresenceStatusMessage();
|
final String message = account.getPresenceStatusMessage();
|
||||||
if(status.toShowString() != null) {
|
if (status.toShowString() != null) {
|
||||||
packet.addChild("show").setContent(status.toShowString());
|
packet.addChild("show").setContent(status.toShowString());
|
||||||
}
|
}
|
||||||
if (!TextUtils.isEmpty(message)) {
|
if (!TextUtils.isEmpty(message)) {
|
||||||
packet.addChild(new Element("status").setContent(message));
|
packet.addChild(new Element("status").setContent(message));
|
||||||
}
|
}
|
||||||
if (sig != null && mXmppConnectionService.getPgpEngine() != null) {
|
if (sig != null && mXmppConnectionService.getPgpEngine() != null) {
|
||||||
packet.addChild("x", "jabber:x:signed").setContent(sig);
|
packet.addChild("x", "jabber:x:signed").setContent(sig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final String capHash = getCapHash(account);
|
final String capHash = getCapHash(account);
|
||||||
if (capHash != null) {
|
if (capHash != null) {
|
||||||
Element cap = packet.addChild("c",
|
Element cap = packet.addChild("c",
|
||||||
"http://jabber.org/protocol/caps");
|
"http://jabber.org/protocol/caps");
|
||||||
cap.setAttribute("hash", "sha-1");
|
cap.setAttribute("hash", "sha-1");
|
||||||
cap.setAttribute("node", "http://conversations.im");
|
cap.setAttribute("node", "http://conversations.im");
|
||||||
cap.setAttribute("ver", capHash);
|
cap.setAttribute("ver", capHash);
|
||||||
}
|
}
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PresencePacket leave(final MucOptions mucOptions) {
|
public PresencePacket leave(final MucOptions mucOptions) {
|
||||||
PresencePacket presencePacket = new PresencePacket();
|
PresencePacket presencePacket = new PresencePacket();
|
||||||
presencePacket.setTo(mucOptions.getSelf().getFullJid());
|
presencePacket.setTo(mucOptions.getSelf().getFullJid());
|
||||||
presencePacket.setFrom(mucOptions.getAccount().getJid());
|
presencePacket.setFrom(mucOptions.getAccount().getJid());
|
||||||
presencePacket.setAttribute("type", "unavailable");
|
presencePacket.setAttribute("type", "unavailable");
|
||||||
return presencePacket;
|
return presencePacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PresencePacket sendOfflinePresence(Account account) {
|
public PresencePacket sendOfflinePresence(Account account) {
|
||||||
PresencePacket packet = new PresencePacket();
|
PresencePacket packet = new PresencePacket();
|
||||||
packet.setFrom(account.getJid());
|
packet.setFrom(account.getJid());
|
||||||
packet.setAttribute("type","unavailable");
|
packet.setAttribute("type", "unavailable");
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,8 +308,14 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
||||||
mXmppConnectionService.updateAccountUi();
|
mXmppConnectionService.updateAccountUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleErrorMessage(Account account, MessagePacket packet) {
|
private boolean handleErrorMessage(final Account account, final MessagePacket packet) {
|
||||||
if (packet.getType() == MessagePacket.TYPE_ERROR) {
|
if (packet.getType() == MessagePacket.TYPE_ERROR) {
|
||||||
|
if (packet.fromServer(account)) {
|
||||||
|
final Pair<MessagePacket, Long> forwarded = packet.getForwardedMessagePacket("received", "urn:xmpp:carbons:2");
|
||||||
|
if (forwarded != null) {
|
||||||
|
return handleErrorMessage(account, forwarded.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
final Jid from = packet.getFrom();
|
final Jid from = packet.getFrom();
|
||||||
final String id = packet.getId();
|
final String id = packet.getId();
|
||||||
if (from != null && id != null) {
|
if (from != null && id != null) {
|
||||||
|
|
Loading…
Reference in a new issue