more workaroud for ejabberd bugs

This commit is contained in:
Daniel Gultsch 2014-03-04 04:09:15 +01:00
parent 8e4be5256e
commit 6f86638341
7 changed files with 74 additions and 51 deletions

View file

@ -54,25 +54,25 @@ public final class R {
} }
public static final class id { public static final class id {
public static final int account_confirm_password_desc=0x7f0a001c; public static final int account_confirm_password_desc=0x7f0a001c;
public static final int account_delete=0x7f0a0042; public static final int account_delete=0x7f0a0041;
public static final int account_disable=0x7f0a0043; public static final int account_disable=0x7f0a0042;
public static final int account_enable=0x7f0a0044; public static final int account_enable=0x7f0a0043;
public static final int account_jid=0x7f0a0000; public static final int account_jid=0x7f0a0000;
public static final int account_list=0x7f0a002b; public static final int account_list=0x7f0a002b;
public static final int account_password=0x7f0a0019; public static final int account_password=0x7f0a0019;
public static final int account_password_confirm2=0x7f0a001d; public static final int account_password_confirm2=0x7f0a001d;
public static final int account_status=0x7f0a0002; public static final int account_status=0x7f0a0002;
public static final int account_usetls=0x7f0a001a; public static final int account_usetls=0x7f0a001a;
public static final int action_accounts=0x7f0a003c; public static final int action_accounts=0x7f0a003b;
public static final int action_add=0x7f0a0037; public static final int action_add=0x7f0a0036;
public static final int action_add_account=0x7f0a0041; public static final int action_add_account=0x7f0a0040;
public static final int action_archive=0x7f0a003b; public static final int action_archive=0x7f0a003a;
public static final int action_contact_details=0x7f0a0039; public static final int action_contact_details=0x7f0a0038;
public static final int action_muc_details=0x7f0a003a; public static final int action_muc_details=0x7f0a0039;
public static final int action_refresh_contacts=0x7f0a0046; public static final int action_refresh_contacts=0x7f0a0045;
public static final int action_security=0x7f0a0038; public static final int action_security=0x7f0a0037;
public static final int action_settings=0x7f0a003d; public static final int action_settings=0x7f0a003c;
public static final int announce_pgp=0x7f0a0045; public static final int announce_pgp=0x7f0a0044;
public static final int contactList=0x7f0a0006; public static final int contactList=0x7f0a0006;
public static final int contact_display_name=0x7f0a0008; public static final int contact_display_name=0x7f0a0008;
public static final int contact_jid=0x7f0a0009; public static final int contact_jid=0x7f0a0009;
@ -90,24 +90,23 @@ public final class R {
public static final int details_receive_presence=0x7f0a0014; public static final int details_receive_presence=0x7f0a0014;
public static final int details_send_presence=0x7f0a0013; public static final int details_send_presence=0x7f0a0013;
public static final int edit_account_register_new=0x7f0a001b; public static final int edit_account_register_new=0x7f0a001b;
public static final int encryption_choice_none=0x7f0a003e; public static final int encryption_choice_none=0x7f0a003d;
public static final int encryption_choice_otr=0x7f0a003f; public static final int encryption_choice_otr=0x7f0a003e;
public static final int encryption_choice_pgp=0x7f0a0040; public static final int encryption_choice_pgp=0x7f0a003f;
public static final int imageView1=0x7f0a0030;
public static final int info_box=0x7f0a0022; public static final int info_box=0x7f0a0022;
public static final int list=0x7f0a0029; public static final int list=0x7f0a0029;
public static final int message_body=0x7f0a002d; public static final int message_body=0x7f0a002d;
public static final int message_photo=0x7f0a002c; public static final int message_photo=0x7f0a002c;
public static final int message_time=0x7f0a002e; public static final int message_time=0x7f0a002e;
public static final int messages_view=0x7f0a0021; public static final int messages_view=0x7f0a0021;
public static final int muc_edit_nick=0x7f0a0031; public static final int muc_edit_nick=0x7f0a0030;
public static final int muc_error=0x7f0a0023; public static final int muc_error=0x7f0a0023;
public static final int muc_error_msg=0x7f0a0024; public static final int muc_error_msg=0x7f0a0024;
public static final int muc_jabberid=0x7f0a0032; public static final int muc_jabberid=0x7f0a0031;
public static final int muc_members=0x7f0a0036; public static final int muc_members=0x7f0a0035;
public static final int muc_more_details=0x7f0a0033; public static final int muc_more_details=0x7f0a0032;
public static final int muc_participants_header=0x7f0a0035; public static final int muc_participants_header=0x7f0a0034;
public static final int muc_role=0x7f0a0034; public static final int muc_role=0x7f0a0033;
public static final int muc_your_nick=0x7f0a002f; public static final int muc_your_nick=0x7f0a002f;
public static final int new_conversation_search=0x7f0a0004; public static final int new_conversation_search=0x7f0a0004;
public static final int new_fingerprint=0x7f0a0025; public static final int new_fingerprint=0x7f0a0025;

View file

@ -28,7 +28,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/imageView1" android:layout_toLeftOf="@+id/muc_edit_nick"
android:background="#eee" android:background="#eee"
android:ems="10" android:ems="10"
android:hint="Search or enter Jabber ID" android:hint="Search or enter Jabber ID"

View file

@ -99,7 +99,6 @@ public class MucOptions {
} }
public void processPacket(PresencePacket packet) { public void processPacket(PresencePacket packet) {
Log.d("xmppService","process Packet for muc options: "+packet.toString());
String name = packet.getAttribute("from").split("/")[1]; String name = packet.getAttribute("from").split("/")[1];
String type = packet.getAttribute("type"); String type = packet.getAttribute("type");
if (type==null) { if (type==null) {
@ -109,8 +108,6 @@ public class MucOptions {
user.setAffiliation(item.getAttribute("affiliation")); user.setAffiliation(item.getAttribute("affiliation"));
user.setRole(item.getAttribute("role")); user.setRole(item.getAttribute("role"));
user.setName(name); user.setName(name);
Log.d("xmppService","nick: "+getNick());
Log.d("xmppService","name: "+name);
if (name.equals(getNick())) { if (name.equals(getNick())) {
this.isOnline = true; this.isOnline = true;
this.error = 0; this.error = 0;
@ -119,10 +116,8 @@ public class MucOptions {
addUser(user); addUser(user);
} }
} else if (type.equals("unavailable")) { } else if (type.equals("unavailable")) {
Log.d("xmppService","name: "+name);
if (name.equals(getNick())) { if (name.equals(getNick())) {
Element item = packet.findChild("x").findChild("item"); Element item = packet.findChild("x").findChild("item");
Log.d("xmppService","nick equals name");
String nick = item.getAttribute("nick"); String nick = item.getAttribute("nick");
if (nick!=null) { if (nick!=null) {
if (renameListener!=null) { if (renameListener!=null) {

View file

@ -192,12 +192,13 @@ public class XmppConnectionService extends Service {
@Override @Override
public void onPresencePacketReceived(Account account, public void onPresencePacketReceived(Account account,
PresencePacket packet) { PresencePacket packet) {
Log.d(LOGTAG, packet.toString());
if (packet.hasChild("x")&&(packet.findChild("x").getAttribute("xmlns").startsWith("http://jabber.org/protocol/muc"))) { if (packet.hasChild("x")&&(packet.findChild("x").getAttribute("xmlns").startsWith("http://jabber.org/protocol/muc"))) {
Conversation muc = findMuc(packet.getAttribute("from").split("/")[0]); Conversation muc = findMuc(packet.getAttribute("from").split("/")[0]);
int error = muc.getMucOptions().getError();
if (muc!=null) { if (muc!=null) {
muc.getMucOptions().processPacket(packet); muc.getMucOptions().processPacket(packet);
if (convChangedListener!=null) { if ((muc.getMucOptions().getError()!=error)&&(convChangedListener!=null)) {
Log.d(LOGTAG,"muc error status changed");
convChangedListener.onConversationListChanged(); convChangedListener.onConversationListChanged();
} }
} }
@ -846,30 +847,31 @@ public class XmppConnectionService extends Service {
.sendPresencePacket(packet); .sendPresencePacket(packet);
} }
public void renameInMuc(final Conversation conversation, final String nick, final XmppActivity activity) { private OnRenameListener renameListener = null;
public void setOnRenameListener(OnRenameListener listener) {
this.renameListener = listener;
}
public void renameInMuc(final Conversation conversation, final String nick) {
final MucOptions options = conversation.getMucOptions(); final MucOptions options = conversation.getMucOptions();
if (options.online()) { if (options.online()) {
options.setOnRenameListener(new OnRenameListener() { options.setOnRenameListener(new OnRenameListener() {
@Override @Override
public void onRename(final boolean success) { public void onRename(boolean success) {
activity.runOnUiThread(new Runnable() { if (renameListener!=null) {
renameListener.onRename(success);
@Override }
public void run() {
if (success) { if (success) {
databaseBackend.updateConversation(conversation); databaseBackend.updateConversation(conversation);
Toast.makeText(activity, "Your nickname has been changed", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(activity, "Nickname already in use",Toast.LENGTH_SHORT).show();
} }
} }
}); });
}
});
PresencePacket packet = new PresencePacket(); PresencePacket packet = new PresencePacket();
packet.setAttribute("to", conversation.getContactJid().split("/")[0]+"/"+nick); packet.setAttribute("to", conversation.getContactJid().split("/")[0]+"/"+nick);
conversation.getAccount().getXmppConnection().sendPresencePacket(packet, new OnPresencePacketReceived() { packet.setAttribute("from", conversation.getAccount().getFullJid());
packet = conversation.getAccount().getXmppConnection().sendPresencePacket(packet, new OnPresencePacketReceived() {
@Override @Override
public void onPresencePacketReceived(Account account, PresencePacket packet) { public void onPresencePacketReceived(Account account, PresencePacket packet) {
@ -877,10 +879,16 @@ public class XmppConnectionService extends Service {
String type = packet.getAttribute("type"); String type = packet.getAttribute("type");
changed = (!"error".equals(type)); changed = (!"error".equals(type));
if (!changed) { if (!changed) {
options.getOnRenameListener().onRename(changed); options.getOnRenameListener().onRename(false);
} } else {
if (type==null) {
options.getOnRenameListener().onRename(true);
options.setNick(packet.getAttribute("from").split("/")[1]);
} else {
options.processPacket(packet); options.processPacket(packet);
} }
}
}
}); });
} else { } else {
String jid = conversation.getContactJid().split("/")[0]+"/"+nick; String jid = conversation.getContactJid().split("/")[0]+"/"+nick;

View file

@ -18,6 +18,7 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.PhoneHelper; import eu.siacs.conversations.utils.PhoneHelper;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
@ -49,6 +50,7 @@ import android.widget.ListView;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
public class ConversationFragment extends Fragment { public class ConversationFragment extends Fragment {
@ -351,6 +353,25 @@ public class ConversationFragment extends Fragment {
Message.ENCRYPTION_PGP); Message.ENCRYPTION_PGP);
sendPgpMessage(message); sendPgpMessage(message);
} }
if (conversation.getMode() == Conversation.MODE_MULTI) {
activity.xmppConnectionService.setOnRenameListener(new OnRenameListener() {
@Override
public void onRename(final boolean success) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (success) {
Toast.makeText(getActivity(), "Your nickname has been changed",Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "Nichname is already in use",Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
} }
public void updateMessages() { public void updateMessages() {

View file

@ -20,7 +20,6 @@ import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
public class MucOptionsActivity extends XmppActivity { public class MucOptionsActivity extends XmppActivity {
@ -44,7 +43,7 @@ public class MucOptionsActivity extends XmppActivity {
String nick = mYourNick.getText().toString(); String nick = mYourNick.getText().toString();
if (!options.getNick().equals(nick)) { if (!options.getNick().equals(nick)) {
Log.d("gultsch","call to change muc"); Log.d("gultsch","call to change muc");
xmppConnectionService.renameInMuc(conversation, nick, activity); xmppConnectionService.renameInMuc(conversation, nick);
finish(); finish();
} }
} }

View file

@ -442,13 +442,14 @@ public class XmppConnection implements Runnable {
this.sendPresencePacket(packet, null); this.sendPresencePacket(packet, null);
} }
public void sendPresencePacket(PresencePacket packet, OnPresencePacketReceived callback) { public PresencePacket sendPresencePacket(PresencePacket packet, OnPresencePacketReceived callback) {
String id = nextRandomId(); String id = nextRandomId();
packet.setAttribute("id", id); packet.setAttribute("id", id);
tagWriter.writeElement(packet); tagWriter.writeElement(packet);
if (callback != null) { if (callback != null) {
packetCallbacks.put(id, callback); packetCallbacks.put(id, callback);
} }
return packet;
} }
public void setOnMessagePacketReceivedListener( public void setOnMessagePacketReceivedListener(