Merge pull request #713 from betheg/muc

MUC: do not add yourself to the muc user list.
This commit is contained in:
Daniel Gultsch 2014-11-24 11:53:28 +01:00
commit 7a75a8bc5a
5 changed files with 65 additions and 1 deletions

View file

@ -190,6 +190,8 @@ public class MucOptions {
this.onJoinListener.onSuccess(); this.onJoinListener.onSuccess();
this.onJoinListener = null; this.onJoinListener = null;
} }
} else if (packet.getFrom().equals(this.conversation.getContactJid())) {
self = user;
} else { } else {
addUser(user); addUser(user);
} }

View file

@ -31,6 +31,8 @@ public class PresenceParser extends AbstractParser implements
mXmppConnectionService.getAvatarService().clear(conversation); mXmppConnectionService.getAvatarService().clear(conversation);
if (before != mucOptions.online() || (mucOptions.online() && count != mucOptions.getUsers().size())) { if (before != mucOptions.online() || (mucOptions.online() && count != mucOptions.getUsers().size())) {
mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateConversationUi();
} else if (mucOptions.online()) {
mXmppConnectionService.updateMucRosterUi();
} }
} }
} }

View file

@ -212,6 +212,8 @@ public class XmppConnectionService extends Service {
private Integer accountChangedListenerCount = 0; private Integer accountChangedListenerCount = 0;
private OnRosterUpdate mOnRosterUpdate = null; private OnRosterUpdate mOnRosterUpdate = null;
private Integer rosterChangedListenerCount = 0; private Integer rosterChangedListenerCount = 0;
private OnMucRosterUpdate mOnMucRosterUpdate = null;
private Integer mucRosterChangedListenerCount = 0;
private SecureRandom mRandom; private SecureRandom mRandom;
private FileObserver fileObserver = new FileObserver( private FileObserver fileObserver = new FileObserver(
FileBackend.getConversationsImageDirectory()) { FileBackend.getConversationsImageDirectory()) {
@ -1116,6 +1118,13 @@ public class XmppConnectionService extends Service {
removedListener = true; removedListener = true;
} }
} }
synchronized (this.mucRosterChangedListenerCount) {
if (this.mOnMucRosterUpdate != null) {
this.mOnMucRosterUpdate = null;
this.mucRosterChangedListenerCount = 0;
removedListener = true;
}
}
if (removedListener) { if (removedListener) {
final String msg = "removed stale listeners"; final String msg = "removed stale listeners";
Log.d(Config.LOGTAG, msg); Log.d(Config.LOGTAG, msg);
@ -1217,6 +1226,29 @@ public class XmppConnectionService extends Service {
} }
} }
public void setOnMucRosterUpdateListener(OnMucRosterUpdate listener) {
synchronized (this.mucRosterChangedListenerCount) {
if (checkListeners()) {
switchToForeground();
}
this.mOnMucRosterUpdate = listener;
this.mucRosterChangedListenerCount++;
}
}
public void removeOnMucRosterUpdateListener() {
synchronized (this.mucRosterChangedListenerCount) {
this.mucRosterChangedListenerCount--;
if (this.mucRosterChangedListenerCount <= 0) {
this.mucRosterChangedListenerCount = 0;
this.mOnMucRosterUpdate = null;
if (checkListeners()) {
switchToBackground();
}
}
}
}
private boolean checkListeners() { private boolean checkListeners() {
return (this.mOnAccountUpdate == null return (this.mOnAccountUpdate == null
&& this.mOnConversationUpdate == null && this.mOnRosterUpdate == null); && this.mOnConversationUpdate == null && this.mOnRosterUpdate == null);
@ -1928,6 +1960,12 @@ public class XmppConnectionService extends Service {
} }
} }
public void updateMucRosterUi() {
if (mOnMucRosterUpdate != null) {
mOnMucRosterUpdate.onMucRosterUpdate();
}
}
public Account findAccountByJid(final Jid accountJid) { public Account findAccountByJid(final Jid accountJid) {
for (Account account : this.accounts) { for (Account account : this.accounts) {
if (account.getJid().toBareJid().equals(accountJid.toBareJid())) { if (account.getJid().toBareJid().equals(accountJid.toBareJid())) {
@ -2125,6 +2163,10 @@ public class XmppConnectionService extends Service {
public void onRosterUpdate(); public void onRosterUpdate();
} }
public interface OnMucRosterUpdate {
public void onMucRosterUpdate();
}
private interface OnConferenceOptionsPushed { private interface OnConferenceOptionsPushed {
public void onPushSucceeded(); public void onPushSucceeded();
public void onPushFailed(); public void onPushFailed();

View file

@ -32,10 +32,11 @@ import eu.siacs.conversations.entities.Bookmark;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.MucOptions.User; import eu.siacs.conversations.entities.MucOptions.User;
import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket; import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate { public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate {
public static final String ACTION_VIEW_MUC = "view_muc"; public static final String ACTION_VIEW_MUC = "view_muc";
private Conversation mConversation; private Conversation mConversation;
private OnClickListener inviteListener = new OnClickListener() { private OnClickListener inviteListener = new OnClickListener() {
@ -98,6 +99,17 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
}); });
} }
@Override
public void onMucRosterUpdate() {
runOnUiThread(new Runnable() {
@Override
public void run() {
populateView();
}
});
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);

View file

@ -241,6 +241,9 @@ public abstract class XmppActivity extends Activity {
if (this instanceof XmppConnectionService.OnRosterUpdate) { if (this instanceof XmppConnectionService.OnRosterUpdate) {
this.xmppConnectionService.setOnRosterUpdateListener((XmppConnectionService.OnRosterUpdate) this); this.xmppConnectionService.setOnRosterUpdateListener((XmppConnectionService.OnRosterUpdate) this);
} }
if (this instanceof XmppConnectionService.OnMucRosterUpdate) {
this.xmppConnectionService.setOnMucRosterUpdateListener((XmppConnectionService.OnMucRosterUpdate) this);
}
} }
protected void unregisterListeners() { protected void unregisterListeners() {
@ -253,6 +256,9 @@ public abstract class XmppActivity extends Activity {
if (this instanceof XmppConnectionService.OnRosterUpdate) { if (this instanceof XmppConnectionService.OnRosterUpdate) {
this.xmppConnectionService.removeOnRosterUpdateListener(); this.xmppConnectionService.removeOnRosterUpdateListener();
} }
if (this instanceof XmppConnectionService.OnMucRosterUpdate) {
this.xmppConnectionService.removeOnMucRosterUpdateListener();
}
} }
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {