change affiliation for in memory users that are currently not joined in a conference

This commit is contained in:
Daniel Gultsch 2016-05-16 15:50:57 +02:00
parent 8d0693ed6a
commit fc5304c6fe
4 changed files with 18 additions and 7 deletions

View File

@ -28,10 +28,12 @@ public class MucOptions {
public void changeAffiliation(Jid jid, Affiliation affiliation) {
User user = findUserByRealJid(jid);
if (user != null) {
if (user != null && user.getRole() == Role.NONE) {
users.remove(user);
user.affiliation = affiliation;
users.add(user);
if (affiliation.ranks(Affiliation.MEMBER)) {
user.affiliation = affiliation;
users.add(user);
}
}
}

View File

@ -140,9 +140,11 @@ public class PresenceParser extends AbstractParser implements
} else if (error != null && error.hasChild("forbidden")) {
mucOptions.setError(MucOptions.Error.BANNED);
} else if (error != null && error.hasChild("registration-required")) {
mucOptions.setError(MucOptions.Error.BANNED);
mucOptions.setError(MucOptions.Error.MEMBERS_ONLY);
}
}
} else {
Log.d(Config.LOGTAG,mucOptions.getAccount().getJid().toBareJid()+": "+packet);
}
}

View File

@ -2198,6 +2198,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.getType() == IqPacket.TYPE.RESULT) {
conference.getMucOptions().changeAffiliation(jid, affiliation);
getAvatarService().clear(conference);
callback.onAffiliationChangedSuccessful(jid);
} else {
callback.onAffiliationChangeFailed(jid, R.string.could_not_change_affiliation);

View File

@ -438,7 +438,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
return true;
case R.id.ban_from_conference:
xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getRealJid(), MucOptions.Affiliation.OUTCAST,this);
xmppConnectionService.changeRoleInConference(mConversation,mSelectedUser.getName(), MucOptions.Role.NONE,this);
if (mSelectedUser.getRole() != MucOptions.Role.NONE) {
xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, this);
}
return true;
case R.id.send_private_message:
privateMsgInMuc(mConversation,mSelectedUser.getName());
@ -451,7 +453,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
private void removeFromRoom(final User user) {
if (mConversation.getMucOptions().membersOnly()) {
xmppConnectionService.changeAffiliationInConference(mConversation,user.getRealJid(), MucOptions.Affiliation.NONE,this);
xmppConnectionService.changeRoleInConference(mConversation,mSelectedUser.getName(), MucOptions.Role.NONE,ConferenceDetailsActivity.this);
if (user.getRole() != MucOptions.Role.NONE) {
xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, ConferenceDetailsActivity.this);
}
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.ban_from_conference);
@ -461,7 +465,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
@Override
public void onClick(DialogInterface dialog, int which) {
xmppConnectionService.changeAffiliationInConference(mConversation,user.getRealJid(), MucOptions.Affiliation.OUTCAST,ConferenceDetailsActivity.this);
xmppConnectionService.changeRoleInConference(mConversation,mSelectedUser.getName(), MucOptions.Role.NONE,ConferenceDetailsActivity.this);
if (user.getRole() != MucOptions.Role.NONE) {
xmppConnectionService.changeRoleInConference(mConversation, mSelectedUser.getName(), MucOptions.Role.NONE, ConferenceDetailsActivity.this);
}
}
});
builder.create().show();