diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services')
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/AvatarService.java | 2 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 171 |
2 files changed, 140 insertions, 33 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/AvatarService.java b/src/main/java/eu/siacs/conversations/services/AvatarService.java index b8154d65..1125859c 100644 --- a/src/main/java/eu/siacs/conversations/services/AvatarService.java +++ b/src/main/java/eu/siacs/conversations/services/AvatarService.java @@ -274,7 +274,7 @@ public class AvatarService { } } } - String name = user.getName(); + String name = contact != null ? contact.getDisplayName() : user.getName(); String letter; int color; if (name.length() > 0) { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 89a3917c..b700da74 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -35,6 +35,7 @@ import org.openintents.openpgp.util.OpenPgpServiceConnection; import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; +import java.math.BigInteger; import java.security.SecureRandom; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -270,7 +271,6 @@ public class XmppConnectionService extends Service { } }; private LruCache<String, Bitmap> mBitmapCache; - private OnRenameListener renameListener = null; private IqGenerator mIqGenerator = new IqGenerator(this); public PgpEngine getPgpEngine() { @@ -1052,10 +1052,6 @@ public class XmppConnectionService extends Service { updateConversationUi(); } - public int getConversationCount() { - return this.databaseBackend.getConversationCount(); - } - public void createAccount(Account account) { account.initOtrEngine(this); databaseBackend.createAccount(account); @@ -1273,10 +1269,9 @@ public class XmppConnectionService extends Service { Log.d(Config.LOGTAG, "joining conversation " + conversation.getContactJid()); String nick = conversation.getMucOptions().getProposedNick(); - conversation.getMucOptions().setJoinNick(nick); + Jid joinJid = conversation.getMucOptions().createJoinJid(nick); PresencePacket packet = new PresencePacket(); - final Jid joinJid = conversation.getMucOptions().getJoinJid(); - packet.setTo(conversation.getMucOptions().getJoinJid()); + packet.setTo(joinJid); Element x = new Element("x"); x.setAttribute("xmlns", "http://jabber.org/protocol/muc"); if (conversation.getMucOptions().getPassword() != null) { @@ -1308,10 +1303,6 @@ public class XmppConnectionService extends Service { } } - public void setOnRenameListener(OnRenameListener listener) { - this.renameListener = listener; - } - public void providePasswordForMuc(Conversation conversation, String password) { if (conversation.getMode() == Conversation.MODE_MULTI) { conversation.getMucOptions().setPassword(password); @@ -1324,33 +1315,33 @@ public class XmppConnectionService extends Service { } } - public void renameInMuc(final Conversation conversation, final String nick) { + public void renameInMuc(final Conversation conversation, final String nick, final UiCallback<Conversation> callback) { final MucOptions options = conversation.getMucOptions(); - options.setJoinNick(nick); + final Jid joinJid = options.createJoinJid(nick); if (options.online()) { Account account = conversation.getAccount(); options.setOnRenameListener(new OnRenameListener() { @Override - public void onRename(boolean success) { - if (renameListener != null) { - renameListener.onRename(success); - } - if (success) { - conversation.setContactJid(conversation.getMucOptions() - .getJoinJid()); - databaseBackend.updateConversation(conversation); - Bookmark bookmark = conversation.getBookmark(); - if (bookmark != null) { - bookmark.setNick(nick); - pushBookmarks(bookmark.getAccount()); - } + public void onSuccess() { + conversation.setContactJid(joinJid); + databaseBackend.updateConversation(conversation); + Bookmark bookmark = conversation.getBookmark(); + if (bookmark != null) { + bookmark.setNick(nick); + pushBookmarks(bookmark.getAccount()); } + callback.success(conversation); + } + + @Override + public void onFailure() { + callback.error(R.string.nick_in_use,conversation); } }); - options.flagAboutToRename(); + PresencePacket packet = new PresencePacket(); - packet.setTo(options.getJoinJid()); + packet.setTo(joinJid); packet.setFrom(conversation.getAccount().getJid()); String sig = account.getPgpSignature(); @@ -1360,7 +1351,7 @@ public class XmppConnectionService extends Service { } sendPresencePacket(account, packet); } else { - conversation.setContactJid(options.getJoinJid()); + conversation.setContactJid(joinJid); databaseBackend.updateConversation(conversation); if (conversation.getAccount().getStatus() == Account.State.ONLINE) { Bookmark bookmark = conversation.getBookmark(); @@ -1379,7 +1370,7 @@ public class XmppConnectionService extends Service { account.pendingConferenceLeaves.remove(conversation); if (account.getStatus() == Account.State.ONLINE) { PresencePacket packet = new PresencePacket(); - packet.setTo(conversation.getMucOptions().getJoinJid()); + packet.setTo(conversation.getContactJid()); packet.setFrom(conversation.getAccount().getJid()); packet.setAttribute("type", "unavailable"); sendPresencePacket(conversation.getAccount(), packet); @@ -1392,6 +1383,117 @@ public class XmppConnectionService extends Service { } } + private String findConferenceServer(final Account account) { + String server; + if (account.getXmppConnection() != null) { + server = account.getXmppConnection().getMucServer(); + if (server != null) { + return server; + } + } + for(Account other : getAccounts()) { + if (other != account && other.getXmppConnection() != null) { + server = other.getXmppConnection().getMucServer(); + if (server != null) { + return server; + } + } + } + return null; + } + + public void createAdhocConference(final Account account, final List<Jid> jids, final UiCallback<Conversation> callback) { + Log.d(Config.LOGTAG,account.getJid().toBareJid().toString()+": creating adhoc conference with "+ jids.toString()); + if (account.getStatus() == Account.State.ONLINE) { + try { + String server = findConferenceServer(account); + if (server == null) { + if (callback != null) { + callback.error(R.string.no_conference_server_found,null); + } + return; + } + String name = new BigInteger(75,getRNG()).toString(32); + Jid jid = Jid.fromParts(name,server,null); + final Conversation conversation = findOrCreateConversation(account, jid, true); + joinMuc(conversation); + Bundle options = new Bundle(); + options.putString("muc#roomconfig_persistentroom", "1"); + options.putString("muc#roomconfig_membersonly", "1"); + options.putString("muc#roomconfig_publicroom", "0"); + options.putString("muc#roomconfig_whois", "anyone"); + pushConferenceConfiguration(conversation, options, new OnConferenceOptionsPushed() { + @Override + public void onPushSucceeded() { + for(Jid invite : jids) { + invite(conversation,invite); + } + if (callback != null) { + callback.success(conversation); + } + } + + @Override + public void onPushFailed() { + if (callback != null) { + callback.error(R.string.conference_creation_failed, conversation); + } + } + }); + + } catch (InvalidJidException e) { + if (callback != null) { + callback.error(R.string.conference_creation_failed, null); + } + } + } else { + if (callback != null) { + callback.error(R.string.not_connected_try_again,null); + } + } + } + + public void pushConferenceConfiguration(final Conversation conversation,final Bundle options, final OnConferenceOptionsPushed callback) { + IqPacket request = new IqPacket(IqPacket.TYPE_GET); + request.setTo(conversation.getContactJid().toBareJid()); + request.query("http://jabber.org/protocol/muc#owner"); + sendIqPacket(conversation.getAccount(),request,new OnIqPacketReceived() { + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + if (packet.getType() != IqPacket.TYPE_ERROR) { + Data data = Data.parse(packet.query().findChild("x", "jabber:x:data")); + for (Field field : data.getFields()) { + if (options.containsKey(field.getName())) { + field.setValue(options.getString(field.getName())); + } + } + data.submit(); + IqPacket set = new IqPacket(IqPacket.TYPE_SET); + set.setTo(conversation.getContactJid().toBareJid()); + set.query("http://jabber.org/protocol/muc#owner").addChild(data); + sendIqPacket(account, set, new OnIqPacketReceived() { + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + if (packet.getType() == IqPacket.TYPE_RESULT) { + if (callback != null) { + callback.onPushSucceeded(); + } + } else { + if (callback != null) { + callback.onPushFailed(); + } + } + } + }); + } else { + if (callback != null) { + callback.onPushFailed(); + } + } + } + }); + } + public void disconnect(Account account, boolean force) { if ((account.getStatus() == Account.State.ONLINE) || (account.getStatus() == Account.State.DISABLED)) { @@ -1723,7 +1825,7 @@ public class XmppConnectionService extends Service { }).start(); } - public void invite(Conversation conversation, String contact) { + public void invite(Conversation conversation, Jid contact) { MessagePacket packet = mMessageGenerator.invite(conversation, contact); sendMessagePacket(conversation.getAccount(), packet); } @@ -2020,6 +2122,11 @@ public class XmppConnectionService extends Service { public void onRosterUpdate(); } + private interface OnConferenceOptionsPushed { + public void onPushSucceeded(); + public void onPushFailed(); + } + public class XmppConnectionBinder extends Binder { public XmppConnectionService getService() { return XmppConnectionService.this; |