aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-11-23 13:51:53 +0100
committerChristian Schneppe <christian@pix-art.de>2018-11-23 13:55:13 +0100
commit06ada3372ea812adb3ea1233bc6e224f7ba3de8b (patch)
tree4b6f9c09aa5804f85da4b1dd6c95534b77407d45 /src/main/java/de/pixart
parentb2969350c6b9ff64c9ae14fb7edcdcc5e69d7ae2 (diff)
added interface to edit nick
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/entities/MucOptions.java8
-rw-r--r--src/main/java/de/pixart/messenger/generator/AbstractGenerator.java2
-rw-r--r--src/main/java/de/pixart/messenger/generator/IqGenerator.java11
-rw-r--r--src/main/java/de/pixart/messenger/parser/MessageParser.java59
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java31
-rw-r--r--src/main/java/de/pixart/messenger/ui/XmppActivity.java1
-rw-r--r--src/main/java/de/pixart/messenger/utils/Namespace.java1
7 files changed, 77 insertions, 36 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java
index 84dcb263b..8291188ae 100644
--- a/src/main/java/de/pixart/messenger/entities/MucOptions.java
+++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java
@@ -3,6 +3,7 @@ package de.pixart.messenger.entities;
import android.annotation.SuppressLint;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Collections;
@@ -382,7 +383,12 @@ public class MucOptions {
} else if (!conversation.getJid().isBareJid()) {
return conversation.getJid().getResource();
} else {
- return JidHelper.localPartOrFallback(account.getJid());
+ final String displayName = account.getDisplayName();
+ if (TextUtils.isEmpty(displayName)) {
+ return JidHelper.localPartOrFallback(account.getJid());
+ } else {
+ return displayName;
+ }
}
}
diff --git a/src/main/java/de/pixart/messenger/generator/AbstractGenerator.java b/src/main/java/de/pixart/messenger/generator/AbstractGenerator.java
index ac57c74d1..710a4fb8e 100644
--- a/src/main/java/de/pixart/messenger/generator/AbstractGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/AbstractGenerator.java
@@ -35,7 +35,7 @@ public abstract class AbstractGenerator {
"http://jabber.org/protocol/caps",
"http://jabber.org/protocol/disco#info",
"urn:xmpp:avatar:metadata+notify",
- "http://jabber.org/protocol/nick+notify",
+ Namespace.NICK + "+notify",
Namespace.BOOKMARKS + "+notify",
"urn:xmpp:ping",
"jabber:iq:version",
diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
index 86f58af69..cb56d66a8 100644
--- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
@@ -126,8 +126,15 @@ public class IqGenerator extends AbstractGenerator {
public IqPacket publishNick(String nick) {
final Element item = new Element("item");
- item.addChild("nick", "http://jabber.org/protocol/nick").setContent(nick);
- return publish("http://jabber.org/protocol/nick", item);
+ item.addChild("nick", Namespace.NICK).setContent(nick);
+ return publish(Namespace.NICK, item);
+ }
+
+ public IqPacket deleteNode(String node) {
+ IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
+ final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB_OWNER);
+ pubsub.addChild("delete").setAttribute("node", node);
+ return packet;
}
public IqPacket publishAvatar(Avatar avatar) {
diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java
index dca999069..ed12d6473 100644
--- a/src/main/java/de/pixart/messenger/parser/MessageParser.java
+++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java
@@ -286,16 +286,11 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
mXmppConnectionService.fetchAvatar(account, avatar);
}
}
- } else if ("http://jabber.org/protocol/nick".equals(node)) {
+ } else if (Namespace.NICK.equals(node)) {
final Element i = items.findChild("item");
final String nick = i == null ? null : i.findChildContent("nick", Namespace.NICK);
if (nick != null) {
- Contact contact = account.getRoster().getContact(from);
- if (contact.setPresenceName(nick)) {
- mXmppConnectionService.getAvatarService().clear(contact);
- }
- mXmppConnectionService.updateConversationUi();
- mXmppConnectionService.updateAccountUi();
+ setNick(account, from, nick);
}
} else if (AxolotlService.PEP_DEVICE_LIST.equals(node)) {
Element item = items.findChild("item");
@@ -313,6 +308,31 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
}
}
+ private void parseDeleteEvent(final Element event, final Jid from, final Account account) {
+ final Element delete = event.findChild("delete");
+ if (delete == null) {
+ return;
+ }
+ String node = delete.getAttribute("node");
+ if (Namespace.NICK.equals(node)) {
+ Log.d(Config.LOGTAG, "parsing nick delete event from " + from);
+ setNick(account, from, null);
+ }
+ }
+
+ private void setNick(Account account, Jid user, String nick) {
+ if (user.asBareJid().equals(account.getJid().asBareJid())) {
+ account.setDisplayName(nick);
+ } else {
+ Contact contact = account.getRoster().getContact(user);
+ if (contact.setPresenceName(nick)) {
+ mXmppConnectionService.getAvatarService().clear(contact);
+ }
+ }
+ mXmppConnectionService.updateConversationUi();
+ mXmppConnectionService.updateAccountUi();
+ }
+
private boolean handleErrorMessage(Account account, MessagePacket packet) {
if (packet.getType() == MessagePacket.TYPE_ERROR) {
Jid from = packet.getFrom();
@@ -784,7 +804,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
}
} else if ("item".equals(child.getName())) {
MucOptions.User user = AbstractParser.parseItem(conversation, child);
- Log.d(Config.LOGTAG, account.getJid() + ": changing affiliation for " + user.getRealJid() + " to " + user.getAffiliation() + " in " + conversation.getJid().asBareJid());
+ Log.d(Config.LOGTAG, account.getJid() + ": changing affiliation for "
+ + user.getRealJid() + " to " + user.getAffiliation() + " in "
+ + conversation.getJid().asBareJid());
if (!user.realJidMatchesAccount()) {
boolean isNew = conversation.getMucOptions().updateUser(user);
mXmppConnectionService.getAvatarService().clear(conversation);
@@ -850,17 +872,6 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (message.addReadByMarker(readByMarker)) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": added read by (" + readByMarker.getRealJid() + ") to message '" + message.getBody() + "'");
mXmppConnectionService.updateMessage(message, false);
- final Message displayedMessage = mXmppConnectionService.markMessage(account, from.asBareJid(), id, Message.STATUS_SEND_DISPLAYED);
- Message m = displayedMessage == null ? null : displayedMessage.prev();
- while (m != null
- && m.getStatus() == Message.STATUS_SEND_RECEIVED
- && m.getTimeSent() < displayedMessage.getTimeSent()) {
- mXmppConnectionService.markMessage(m, Message.STATUS_SEND_DISPLAYED);
- m = m.prev();
- }
- if (displayedMessage != null && selfAddressed) {
- dismissNotification(account, counterpart, query);
- }
}
}
}
@@ -881,9 +892,13 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
}
}
- Element event = original.findChild("event", "http://jabber.org/protocol/pubsub#event");
+ final Element event = original.findChild("event", "http://jabber.org/protocol/pubsub#event");
if (event != null && InvalidJid.hasValidFrom(original)) {
- parseEvent(event, original.getFrom(), account);
+ if (event.hasChild("items")) {
+ parseEvent(event, original.getFrom(), account);
+ } else if (event.hasChild("delete")) {
+ parseDeleteEvent(event, original.getFrom(), account);
+ }
}
final String nick = packet.findChildContent("nick", Namespace.NICK);
@@ -958,4 +973,4 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
return false;
}
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index d889cdee8..b8986bf77 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -300,11 +300,19 @@ public class XmppConnectionService extends Service {
}
}
}
- boolean needsUpdating = account.setOption(Account.OPTION_LOGGED_IN_SUCCESSFULLY, true);
- needsUpdating |= account.setOption(Account.OPTION_HTTP_UPLOAD_AVAILABLE, account.getXmppConnection().getFeatures().httpUpload(0));
- if (needsUpdating) {
+ boolean loggedInSuccessfully = account.setOption(Account.OPTION_LOGGED_IN_SUCCESSFULLY, true);
+ boolean gainedFeature = account.setOption(Account.OPTION_HTTP_UPLOAD_AVAILABLE, account.getXmppConnection().getFeatures().httpUpload(0));
+ if (loggedInSuccessfully || gainedFeature) {
databaseBackend.updateAccount(account);
}
+
+ if (loggedInSuccessfully) {
+ if (!TextUtils.isEmpty(account.getDisplayName())) {
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": display name wasn't empty on first log in. publishing");
+ publishDisplayName(account);
+ }
+ }
+
account.getRoster().clearPresences();
mJingleConnectionManager.cancelInTransmission();
mQuickConversationsService.considerSyncBackground(false);
@@ -4204,14 +4212,17 @@ public class XmppConnectionService extends Service {
public void publishDisplayName(Account account) {
String displayName = account.getDisplayName();
- if (displayName != null && !displayName.isEmpty()) {
- IqPacket publish = mIqGenerator.publishNick(displayName);
- sendIqPacket(account, publish, (account1, packet) -> {
- if (packet.getType() == IqPacket.TYPE.ERROR) {
- Log.d(Config.LOGTAG, account1.getJid().asBareJid() + ": could not publish nick");
- }
- });
+ final IqPacket request;
+ if (TextUtils.isEmpty(displayName)) {
+ request = mIqGenerator.deleteNode(Namespace.NICK);
+ } else {
+ request = mIqGenerator.publishNick(displayName);
}
+ sendIqPacket(account, request, (account1, packet) -> {
+ if (packet.getType() == IqPacket.TYPE.ERROR) {
+ Log.d(Config.LOGTAG, account1.getJid().asBareJid() + ": unable to modify nick name " + packet.toString());
+ }
+ });
}
public ServiceDiscoveryResult getCachedServiceDiscoveryResult(Pair<String, String> key) {
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
index 1ec68d0f7..ee606395a 100644
--- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
@@ -744,6 +744,7 @@ public abstract class XmppActivity extends ActionBarActivity {
SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
dialog.dismiss();
}));
+ dialog.setCanceledOnTouchOutside(false);
dialog.setOnDismissListener(dialog1 -> {
SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
});
diff --git a/src/main/java/de/pixart/messenger/utils/Namespace.java b/src/main/java/de/pixart/messenger/utils/Namespace.java
index 71906cd4a..6f460a2f5 100644
--- a/src/main/java/de/pixart/messenger/utils/Namespace.java
+++ b/src/main/java/de/pixart/messenger/utils/Namespace.java
@@ -16,6 +16,7 @@ public final class Namespace {
public static final String PUBSUB = "http://jabber.org/protocol/pubsub";
public static final String PUBSUB_PUBLISH_OPTIONS = PUBSUB + "#publish-options";
public static final String PUBSUB_ERROR = PUBSUB + "#errors";
+ public static final String PUBSUB_OWNER = PUBSUB + "#owner";
public static final String NICK = "http://jabber.org/protocol/nick";
public static final String FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL = "http://jabber.org/protocol/offline";
public static final String BIND = "urn:ietf:params:xml:ns:xmpp-bind";