added interface to edit nick
This commit is contained in:
parent
b2969350c6
commit
06ada3372e
7 changed files with 77 additions and 36 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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";
|
||||
|
|
Reference in a new issue