2014-10-22 16:38:44 +00:00
|
|
|
package eu.siacs.conversations.parser;
|
|
|
|
|
2016-02-01 11:11:40 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
2015-02-21 21:19:10 +00:00
|
|
|
import java.util.ArrayList;
|
2015-12-03 17:18:34 +00:00
|
|
|
import java.util.List;
|
2015-02-21 21:19:10 +00:00
|
|
|
|
2016-02-01 11:11:40 +00:00
|
|
|
|
|
|
|
import eu.siacs.conversations.Config;
|
2014-10-22 16:38:44 +00:00
|
|
|
import eu.siacs.conversations.crypto.PgpEngine;
|
2017-06-28 07:49:24 +00:00
|
|
|
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
2014-10-22 16:38:44 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
|
|
|
import eu.siacs.conversations.entities.Contact;
|
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
2015-11-05 02:56:45 +00:00
|
|
|
import eu.siacs.conversations.entities.Message;
|
2014-11-20 21:44:31 +00:00
|
|
|
import eu.siacs.conversations.entities.MucOptions;
|
2016-01-17 21:28:38 +00:00
|
|
|
import eu.siacs.conversations.entities.Presence;
|
2016-05-26 10:39:31 +00:00
|
|
|
import eu.siacs.conversations.generator.IqGenerator;
|
2014-10-22 16:38:44 +00:00
|
|
|
import eu.siacs.conversations.generator.PresenceGenerator;
|
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
2018-07-11 19:33:27 +00:00
|
|
|
import eu.siacs.conversations.utils.XmppUri;
|
2014-10-22 16:38:44 +00:00
|
|
|
import eu.siacs.conversations.xml.Element;
|
2017-03-20 16:58:58 +00:00
|
|
|
import eu.siacs.conversations.xml.Namespace;
|
2018-04-28 14:26:40 +00:00
|
|
|
import eu.siacs.conversations.xmpp.InvalidJid;
|
2014-10-22 16:38:44 +00:00
|
|
|
import eu.siacs.conversations.xmpp.OnPresencePacketReceived;
|
2015-05-05 04:17:34 +00:00
|
|
|
import eu.siacs.conversations.xmpp.pep.Avatar;
|
2014-10-22 16:38:44 +00:00
|
|
|
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
2020-05-15 15:06:16 +00:00
|
|
|
import eu.siacs.conversations.xmpp.Jid;
|
2014-10-22 16:38:44 +00:00
|
|
|
|
|
|
|
public class PresenceParser extends AbstractParser implements
|
|
|
|
OnPresencePacketReceived {
|
|
|
|
|
|
|
|
public PresenceParser(XmppConnectionService service) {
|
|
|
|
super(service);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void parseConferencePresence(PresencePacket packet, Account account) {
|
2018-03-05 17:30:40 +00:00
|
|
|
final Conversation conversation = packet.getFrom() == null ? null : mXmppConnectionService.find(account, packet.getFrom().asBareJid());
|
2014-11-21 19:02:13 +00:00
|
|
|
if (conversation != null) {
|
|
|
|
final MucOptions mucOptions = conversation.getMucOptions();
|
|
|
|
boolean before = mucOptions.online();
|
2015-12-03 17:18:34 +00:00
|
|
|
int count = mucOptions.getUserCount();
|
|
|
|
final List<MucOptions.User> tileUserBefore = mucOptions.getUsers(5);
|
2016-11-13 18:25:58 +00:00
|
|
|
processConferencePresence(packet, conversation);
|
2015-12-03 17:18:34 +00:00
|
|
|
final List<MucOptions.User> tileUserAfter = mucOptions.getUsers(5);
|
2015-02-21 21:19:10 +00:00
|
|
|
if (!tileUserAfter.equals(tileUserBefore)) {
|
2015-12-04 20:36:48 +00:00
|
|
|
mXmppConnectionService.getAvatarService().clear(mucOptions);
|
2015-02-21 21:19:10 +00:00
|
|
|
}
|
2015-12-03 17:18:34 +00:00
|
|
|
if (before != mucOptions.online() || (mucOptions.online() && count != mucOptions.getUserCount())) {
|
2014-11-21 19:02:13 +00:00
|
|
|
mXmppConnectionService.updateConversationUi();
|
2014-11-23 14:19:44 +00:00
|
|
|
} else if (mucOptions.online()) {
|
|
|
|
mXmppConnectionService.updateMucRosterUi();
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-13 18:25:58 +00:00
|
|
|
private void processConferencePresence(PresencePacket packet, Conversation conversation) {
|
|
|
|
MucOptions mucOptions = conversation.getMucOptions();
|
2017-04-15 13:14:08 +00:00
|
|
|
final Jid jid = conversation.getAccount().getJid();
|
2015-12-03 17:18:34 +00:00
|
|
|
final Jid from = packet.getFrom();
|
|
|
|
if (!from.isBareJid()) {
|
|
|
|
final String type = packet.getAttribute("type");
|
2019-09-22 08:00:09 +00:00
|
|
|
final Element x = packet.findChild("x", Namespace.MUC_USER);
|
2015-12-03 17:18:34 +00:00
|
|
|
Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));
|
|
|
|
final List<String> codes = getStatusCodes(x);
|
|
|
|
if (type == null) {
|
|
|
|
if (x != null) {
|
|
|
|
Element item = x.findChild("item");
|
|
|
|
if (item != null && !from.isBareJid()) {
|
2016-02-22 19:19:58 +00:00
|
|
|
mucOptions.setError(MucOptions.Error.NONE);
|
2016-11-13 18:25:58 +00:00
|
|
|
MucOptions.User user = parseItem(conversation, item, from);
|
2018-04-28 14:26:40 +00:00
|
|
|
if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE) || (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && jid.equals(InvalidJid.getNullForInvalid(item.getAttributeAsJid("jid"))))) {
|
2017-12-18 12:19:11 +00:00
|
|
|
if (mucOptions.setOnline()) {
|
|
|
|
mXmppConnectionService.getAvatarService().clear(mucOptions);
|
|
|
|
}
|
2018-07-08 18:52:55 +00:00
|
|
|
if (mucOptions.setSelf(user)) {
|
|
|
|
Log.d(Config.LOGTAG,"role or affiliation changed");
|
|
|
|
mXmppConnectionService.databaseBackend.updateConversation(conversation);
|
|
|
|
}
|
2018-02-10 15:24:55 +00:00
|
|
|
|
|
|
|
mXmppConnectionService.persistSelfNick(user);
|
2017-12-11 14:55:10 +00:00
|
|
|
invokeRenameListener(mucOptions, true);
|
2015-12-03 17:18:34 +00:00
|
|
|
}
|
2017-06-28 07:49:24 +00:00
|
|
|
boolean isNew = mucOptions.updateUser(user);
|
|
|
|
final AxolotlService axolotlService = conversation.getAccount().getAxolotlService();
|
2018-02-24 09:03:22 +00:00
|
|
|
Contact contact = user.getContact();
|
|
|
|
if (isNew
|
|
|
|
&& user.getRealJid() != null
|
|
|
|
&& mucOptions.isPrivateAndNonAnonymous()
|
|
|
|
&& (contact == null || !contact.mutualPresenceSubscription())
|
|
|
|
&& axolotlService.hasEmptyDeviceList(user.getRealJid())) {
|
2017-06-28 07:49:24 +00:00
|
|
|
axolotlService.fetchDeviceIds(user.getRealJid());
|
|
|
|
}
|
2016-05-27 08:35:00 +00:00
|
|
|
if (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && mucOptions.autoPushConfiguration()) {
|
2018-03-05 17:30:40 +00:00
|
|
|
Log.d(Config.LOGTAG,mucOptions.getAccount().getJid().asBareJid()
|
2016-05-26 10:39:31 +00:00
|
|
|
+": room '"
|
2018-03-05 17:30:40 +00:00
|
|
|
+mucOptions.getConversation().getJid().asBareJid()
|
2016-05-26 10:39:31 +00:00
|
|
|
+"' created. pushing default configuration");
|
|
|
|
mXmppConnectionService.pushConferenceConfiguration(mucOptions.getConversation(),
|
2019-02-06 17:29:07 +00:00
|
|
|
IqGenerator.defaultChannelConfiguration(),
|
2016-05-26 10:39:31 +00:00
|
|
|
null);
|
|
|
|
}
|
2015-12-03 17:18:34 +00:00
|
|
|
if (mXmppConnectionService.getPgpEngine() != null) {
|
|
|
|
Element signed = packet.findChild("x", "jabber:x:signed");
|
|
|
|
if (signed != null) {
|
|
|
|
Element status = packet.findChild("status");
|
|
|
|
String msg = status == null ? "" : status.getContent();
|
|
|
|
long keyId = mXmppConnectionService.getPgpEngine().fetchKeyId(mucOptions.getAccount(), msg, signed.getContent());
|
|
|
|
if (keyId != 0) {
|
|
|
|
user.setPgpKeyId(keyId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (avatar != null) {
|
|
|
|
avatar.owner = from;
|
|
|
|
if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
|
2015-12-04 20:36:48 +00:00
|
|
|
if (user.setAvatar(avatar)) {
|
|
|
|
mXmppConnectionService.getAvatarService().clear(user);
|
|
|
|
}
|
2018-09-21 10:27:58 +00:00
|
|
|
if (user.getRealJid() != null) {
|
|
|
|
Contact c = conversation.getAccount().getRoster().getContact(user.getRealJid());
|
|
|
|
if (c.setAvatar(avatar)) {
|
|
|
|
mXmppConnectionService.syncRoster(conversation.getAccount());
|
|
|
|
mXmppConnectionService.getAvatarService().clear(c);
|
|
|
|
mXmppConnectionService.updateRosterUi();
|
|
|
|
}
|
|
|
|
}
|
2016-08-27 11:35:52 +00:00
|
|
|
} else if (mXmppConnectionService.isDataSaverDisabled()) {
|
2015-12-03 17:18:34 +00:00
|
|
|
mXmppConnectionService.fetchAvatar(mucOptions.getAccount(), avatar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (type.equals("unavailable")) {
|
2018-07-11 19:33:27 +00:00
|
|
|
final boolean fullJidMatches = from.equals(mucOptions.getSelf().getFullJid());
|
|
|
|
if (x.hasChild("destroy") && fullJidMatches) {
|
|
|
|
Element destroy = x.findChild("destroy");
|
|
|
|
final Jid alternate = destroy == null ? null : InvalidJid.getNullForInvalid(destroy.getAttributeAsJid("jid"));
|
|
|
|
mucOptions.setError(MucOptions.Error.DESTROYED);
|
|
|
|
if (alternate != null) {
|
|
|
|
Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": muc destroyed. alternate location " + alternate);
|
|
|
|
}
|
|
|
|
} else if (codes.contains(MucOptions.STATUS_CODE_SHUTDOWN) && fullJidMatches) {
|
2017-11-30 12:21:03 +00:00
|
|
|
mucOptions.setError(MucOptions.Error.SHUTDOWN);
|
|
|
|
} else if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE)) {
|
2017-03-05 16:42:17 +00:00
|
|
|
if (codes.contains(MucOptions.STATUS_CODE_KICKED)) {
|
2016-02-22 19:19:58 +00:00
|
|
|
mucOptions.setError(MucOptions.Error.KICKED);
|
2015-12-03 17:18:34 +00:00
|
|
|
} else if (codes.contains(MucOptions.STATUS_CODE_BANNED)) {
|
2016-02-22 19:19:58 +00:00
|
|
|
mucOptions.setError(MucOptions.Error.BANNED);
|
2015-12-03 17:18:34 +00:00
|
|
|
} else if (codes.contains(MucOptions.STATUS_CODE_LOST_MEMBERSHIP)) {
|
2016-02-22 19:19:58 +00:00
|
|
|
mucOptions.setError(MucOptions.Error.MEMBERS_ONLY);
|
|
|
|
} else if (codes.contains(MucOptions.STATUS_CODE_AFFILIATION_CHANGE)) {
|
|
|
|
mucOptions.setError(MucOptions.Error.MEMBERS_ONLY);
|
|
|
|
} else if (codes.contains(MucOptions.STATUS_CODE_SHUTDOWN)) {
|
|
|
|
mucOptions.setError(MucOptions.Error.SHUTDOWN);
|
2017-03-05 16:42:17 +00:00
|
|
|
} else if (!codes.contains(MucOptions.STATUS_CODE_CHANGED_NICK)) {
|
2016-02-22 19:19:58 +00:00
|
|
|
mucOptions.setError(MucOptions.Error.UNKNOWN);
|
2016-02-01 11:11:40 +00:00
|
|
|
Log.d(Config.LOGTAG, "unknown error in conference: " + packet);
|
2015-12-03 17:18:34 +00:00
|
|
|
}
|
|
|
|
} else if (!from.isBareJid()){
|
2016-11-13 18:25:58 +00:00
|
|
|
Element item = x.findChild("item");
|
|
|
|
if (item != null) {
|
|
|
|
mucOptions.updateUser(parseItem(conversation, item, from));
|
|
|
|
}
|
2016-05-16 12:10:40 +00:00
|
|
|
MucOptions.User user = mucOptions.deleteUser(from);
|
2015-12-09 09:30:26 +00:00
|
|
|
if (user != null) {
|
|
|
|
mXmppConnectionService.getAvatarService().clear(user);
|
|
|
|
}
|
2015-12-03 17:18:34 +00:00
|
|
|
}
|
|
|
|
} else if (type.equals("error")) {
|
2017-12-11 14:55:10 +00:00
|
|
|
final Element error = packet.findChild("error");
|
|
|
|
if (error == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (error.hasChild("conflict")) {
|
2015-12-03 17:18:34 +00:00
|
|
|
if (mucOptions.online()) {
|
2017-12-11 14:55:10 +00:00
|
|
|
invokeRenameListener(mucOptions, false);
|
2015-12-03 17:18:34 +00:00
|
|
|
} else {
|
2016-02-22 19:19:58 +00:00
|
|
|
mucOptions.setError(MucOptions.Error.NICK_IN_USE);
|
2015-12-03 17:18:34 +00:00
|
|
|
}
|
2017-12-11 14:55:10 +00:00
|
|
|
} else if (error.hasChild("not-authorized")) {
|
2016-02-22 19:19:58 +00:00
|
|
|
mucOptions.setError(MucOptions.Error.PASSWORD_REQUIRED);
|
2017-12-11 14:55:10 +00:00
|
|
|
} else if (error.hasChild("forbidden")) {
|
2016-02-22 19:19:58 +00:00
|
|
|
mucOptions.setError(MucOptions.Error.BANNED);
|
2017-12-11 14:55:10 +00:00
|
|
|
} else if (error.hasChild("registration-required")) {
|
2016-05-16 13:50:57 +00:00
|
|
|
mucOptions.setError(MucOptions.Error.MEMBERS_ONLY);
|
2018-07-07 08:28:31 +00:00
|
|
|
} else if (error.hasChild("resource-constraint")) {
|
|
|
|
mucOptions.setError(MucOptions.Error.RESOURCE_CONSTRAINT);
|
2018-10-08 08:31:11 +00:00
|
|
|
} else if (error.hasChild("remote-server-timeout")) {
|
|
|
|
mucOptions.setError(MucOptions.Error.REMOTE_SERVER_TIMEOUT);
|
2018-07-11 19:33:27 +00:00
|
|
|
} else if (error.hasChild("gone")) {
|
|
|
|
final String gone = error.findChildContent("gone");
|
|
|
|
final Jid alternate;
|
|
|
|
if (gone != null) {
|
|
|
|
final XmppUri xmppUri = new XmppUri(gone);
|
2020-01-10 11:51:04 +00:00
|
|
|
if (xmppUri.isValidJid()) {
|
2018-07-11 19:33:27 +00:00
|
|
|
alternate = xmppUri.getJid();
|
|
|
|
} else {
|
|
|
|
alternate = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
alternate = null;
|
|
|
|
}
|
|
|
|
mucOptions.setError(MucOptions.Error.DESTROYED);
|
|
|
|
if (alternate != null) {
|
|
|
|
Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": muc destroyed. alternate location " + alternate);
|
|
|
|
}
|
2017-12-11 14:55:10 +00:00
|
|
|
} else {
|
|
|
|
final String text = error.findChildContent("text");
|
|
|
|
if (text != null && text.contains("attribute 'to'")) {
|
|
|
|
if (mucOptions.online()) {
|
|
|
|
invokeRenameListener(mucOptions, false);
|
|
|
|
} else {
|
|
|
|
mucOptions.setError(MucOptions.Error.INVALID_NICK);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mucOptions.setError(MucOptions.Error.UNKNOWN);
|
|
|
|
Log.d(Config.LOGTAG, "unknown error in conference: " + packet);
|
|
|
|
}
|
2015-12-03 17:18:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 14:55:10 +00:00
|
|
|
private static void invokeRenameListener(final MucOptions options, boolean success) {
|
|
|
|
if (options.onRenameListener != null) {
|
|
|
|
if (success) {
|
|
|
|
options.onRenameListener.onSuccess();
|
|
|
|
} else {
|
|
|
|
options.onRenameListener.onFailure();
|
|
|
|
}
|
|
|
|
options.onRenameListener = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-03 17:18:34 +00:00
|
|
|
private static List<String> getStatusCodes(Element x) {
|
|
|
|
List<String> codes = new ArrayList<>();
|
|
|
|
if (x != null) {
|
|
|
|
for (Element child : x.getChildren()) {
|
|
|
|
if (child.getName().equals("status")) {
|
|
|
|
String code = child.getAttribute("code");
|
|
|
|
if (code != null) {
|
|
|
|
codes.add(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return codes;
|
|
|
|
}
|
|
|
|
|
2018-09-08 10:45:05 +00:00
|
|
|
private void parseContactPresence(final PresencePacket packet, final Account account) {
|
2015-11-05 02:56:45 +00:00
|
|
|
final PresenceGenerator mPresenceGenerator = mXmppConnectionService.getPresenceGenerator();
|
2015-05-27 09:44:44 +00:00
|
|
|
final Jid from = packet.getFrom();
|
2016-05-13 09:20:27 +00:00
|
|
|
if (from == null || from.equals(account.getJid())) {
|
2014-10-22 16:38:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-05-27 09:44:44 +00:00
|
|
|
final String type = packet.getAttribute("type");
|
|
|
|
final Contact contact = account.getRoster().getContact(from);
|
2014-12-20 16:23:03 +00:00
|
|
|
if (type == null) {
|
2018-03-05 17:30:40 +00:00
|
|
|
final String resource = from.isBareJid() ? "" : from.getResource();
|
2015-05-27 09:44:44 +00:00
|
|
|
Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));
|
2016-09-09 09:04:05 +00:00
|
|
|
if (avatar != null && (!contact.isSelf() || account.getAvatar() == null)) {
|
2018-03-05 17:30:40 +00:00
|
|
|
avatar.owner = from.asBareJid();
|
2015-05-27 09:44:44 +00:00
|
|
|
if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
|
2018-03-05 17:30:40 +00:00
|
|
|
if (avatar.owner.equals(account.getJid().asBareJid())) {
|
2016-09-09 09:04:05 +00:00
|
|
|
account.setAvatar(avatar.getFilename());
|
|
|
|
mXmppConnectionService.databaseBackend.updateAccount(account);
|
|
|
|
mXmppConnectionService.getAvatarService().clear(account);
|
|
|
|
mXmppConnectionService.updateConversationUi();
|
|
|
|
mXmppConnectionService.updateAccountUi();
|
|
|
|
} else if (contact.setAvatar(avatar)) {
|
2018-06-30 11:35:17 +00:00
|
|
|
mXmppConnectionService.syncRoster(account);
|
2015-05-27 09:44:44 +00:00
|
|
|
mXmppConnectionService.getAvatarService().clear(contact);
|
|
|
|
mXmppConnectionService.updateConversationUi();
|
|
|
|
mXmppConnectionService.updateRosterUi();
|
|
|
|
}
|
2016-08-27 11:35:52 +00:00
|
|
|
} else if (mXmppConnectionService.isDataSaverDisabled()){
|
2015-05-27 09:44:44 +00:00
|
|
|
mXmppConnectionService.fetchAvatar(account, avatar);
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
2018-09-08 10:45:05 +00:00
|
|
|
|
|
|
|
if (mXmppConnectionService.isMuc(account, from)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-20 16:23:03 +00:00
|
|
|
int sizeBefore = contact.getPresences().size();
|
2016-01-17 21:46:32 +00:00
|
|
|
|
2016-02-19 10:09:28 +00:00
|
|
|
final String show = packet.findChildContent("show");
|
2016-02-03 09:40:02 +00:00
|
|
|
final Element caps = packet.findChild("c", "http://jabber.org/protocol/caps");
|
2016-04-22 19:25:06 +00:00
|
|
|
final String message = packet.findChildContent("status");
|
|
|
|
final Presence presence = Presence.parse(show, caps, message);
|
2016-02-03 09:40:02 +00:00
|
|
|
contact.updatePresence(resource, presence);
|
2016-05-13 09:20:27 +00:00
|
|
|
if (presence.hasCaps()) {
|
2016-02-03 09:40:02 +00:00
|
|
|
mXmppConnectionService.fetchCaps(account, from, presence);
|
2016-01-17 22:11:00 +00:00
|
|
|
}
|
2016-01-17 21:46:32 +00:00
|
|
|
|
2017-03-20 16:58:58 +00:00
|
|
|
final Element idle = packet.findChild("idle", Namespace.IDLE);
|
2016-06-04 14:16:14 +00:00
|
|
|
if (idle != null) {
|
|
|
|
try {
|
2017-05-30 06:39:04 +00:00
|
|
|
final String since = idle.getAttribute("since");
|
2016-06-04 14:16:14 +00:00
|
|
|
contact.setLastseen(AbstractParser.parseTimestamp(since));
|
2017-05-30 06:39:04 +00:00
|
|
|
contact.flagInactive();
|
2017-11-16 11:47:49 +00:00
|
|
|
} catch (Throwable throwable) {
|
2017-05-30 06:39:04 +00:00
|
|
|
if (contact.setLastseen(AbstractParser.parseTimestamp(packet))) {
|
|
|
|
contact.flagActive();
|
|
|
|
}
|
2016-06-04 14:16:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-20 16:58:58 +00:00
|
|
|
if (contact.setLastseen(AbstractParser.parseTimestamp(packet))) {
|
|
|
|
contact.flagActive();
|
|
|
|
}
|
2016-06-04 14:16:14 +00:00
|
|
|
}
|
|
|
|
|
2014-12-20 16:23:03 +00:00
|
|
|
PgpEngine pgp = mXmppConnectionService.getPgpEngine();
|
2015-05-27 09:44:44 +00:00
|
|
|
Element x = packet.findChild("x", "jabber:x:signed");
|
|
|
|
if (pgp != null && x != null) {
|
|
|
|
Element status = packet.findChild("status");
|
|
|
|
String msg = status != null ? status.getContent() : "";
|
2018-09-08 10:46:15 +00:00
|
|
|
if (contact.setPgpKeyId(pgp.fetchKeyId(account, msg, x.getContent()))) {
|
|
|
|
mXmppConnectionService.syncRoster(account);
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
2014-12-20 16:23:03 +00:00
|
|
|
boolean online = sizeBefore < contact.getPresences().size();
|
2015-01-03 12:01:38 +00:00
|
|
|
mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, online);
|
2014-12-20 16:23:03 +00:00
|
|
|
} else if (type.equals("unavailable")) {
|
2017-06-01 14:45:00 +00:00
|
|
|
if (contact.setLastseen(AbstractParser.parseTimestamp(packet,0L,true))) {
|
2017-03-20 16:58:58 +00:00
|
|
|
contact.flagInactive();
|
|
|
|
}
|
2014-12-20 16:23:03 +00:00
|
|
|
if (from.isBareJid()) {
|
|
|
|
contact.clearPresences();
|
|
|
|
} else {
|
2018-03-05 17:30:40 +00:00
|
|
|
contact.removePresence(from.getResource());
|
2014-12-20 16:23:03 +00:00
|
|
|
}
|
2018-05-26 13:57:33 +00:00
|
|
|
if (contact.getShownStatus() == Presence.Status.OFFLINE) {
|
|
|
|
contact.flagInactive();
|
|
|
|
}
|
2015-05-27 09:44:44 +00:00
|
|
|
mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, false);
|
2014-12-20 16:23:03 +00:00
|
|
|
} else if (type.equals("subscribe")) {
|
2018-11-26 11:56:30 +00:00
|
|
|
if (contact.setPresenceName(packet.findChildContent("nick", Namespace.NICK))) {
|
|
|
|
mXmppConnectionService.getAvatarService().clear(contact);
|
|
|
|
}
|
2014-12-20 16:23:03 +00:00
|
|
|
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
|
|
|
mXmppConnectionService.sendPresencePacket(account,
|
|
|
|
mPresenceGenerator.sendPresenceUpdatesTo(contact));
|
|
|
|
} else {
|
|
|
|
contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);
|
2015-12-09 11:18:06 +00:00
|
|
|
final Conversation conversation = mXmppConnectionService.findOrCreateConversation(
|
2018-03-05 17:30:40 +00:00
|
|
|
account, contact.getJid().asBareJid(), false, false);
|
2015-11-05 02:56:45 +00:00
|
|
|
final String statusMessage = packet.findChildContent("status");
|
2015-12-09 11:18:06 +00:00
|
|
|
if (statusMessage != null
|
|
|
|
&& !statusMessage.isEmpty()
|
|
|
|
&& conversation.countMessages() == 0) {
|
2015-11-05 02:56:45 +00:00
|
|
|
conversation.add(new Message(
|
|
|
|
conversation,
|
|
|
|
statusMessage,
|
|
|
|
Message.ENCRYPTION_NONE,
|
|
|
|
Message.STATUS_RECEIVED
|
|
|
|
));
|
|
|
|
}
|
2014-10-22 16:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mXmppConnectionService.updateRosterUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPresencePacketReceived(Account account, PresencePacket packet) {
|
2019-09-22 08:00:09 +00:00
|
|
|
if (packet.hasChild("x", Namespace.MUC_USER)) {
|
2014-10-22 16:38:44 +00:00
|
|
|
this.parseConferencePresence(packet, account);
|
|
|
|
} else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) {
|
|
|
|
this.parseConferencePresence(packet, account);
|
2018-08-28 13:04:55 +00:00
|
|
|
} else if ("error".equals(packet.getAttribute("type")) && mXmppConnectionService.isMuc(account, packet.getFrom())) {
|
|
|
|
this.parseConferencePresence(packet, account);
|
2014-10-22 16:38:44 +00:00
|
|
|
} else {
|
|
|
|
this.parseContactPresence(packet, account);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|