aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/MucOptions.java48
-rw-r--r--src/main/java/eu/siacs/conversations/generator/IqGenerator.java11
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java29
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java76
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationActivity.java1
-rw-r--r--src/main/java/eu/siacs/conversations/utils/UIHelper.java12
6 files changed, 147 insertions, 30 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java
index ce2c5b04..6a12f407 100644
--- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java
+++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java
@@ -17,40 +17,64 @@ import android.annotation.SuppressLint;
public class MucOptions {
public enum Affiliation {
- OWNER(R.string.owner),
- ADMIN(R.string.admin),
- MEMBER(R.string.member),
- OUTCAST(R.string.outcast),
- NONE(R.string.no_affiliation);
-
- private Affiliation(int resId) {
+ OWNER("owner", 4, R.string.owner),
+ ADMIN("admin", 3, R.string.admin),
+ MEMBER("member", 2, R.string.member),
+ OUTCAST("outcast", 0, R.string.outcast),
+ NONE("none", 1, R.string.no_affiliation);
+
+ private Affiliation(String string, int rank, int resId) {
+ this.string = string;
this.resId = resId;
+ this.rank = rank;
}
+ private String string;
private int resId;
+ private int rank;
public int getResId() {
return resId;
}
+
+ @Override
+ public String toString() {
+ return this.string;
+ }
+
+ public boolean outranks(Affiliation affiliation) {
+ return rank > affiliation.rank;
+ }
+
+ public boolean ranks(Affiliation affiliation) {
+ return rank >= affiliation.rank;
+ }
}
;
public enum Role {
- MODERATOR(R.string.moderator),
- VISITOR(R.string.visitor),
- PARTICIPANT(R.string.participant),
- NONE(R.string.no_role);
+ MODERATOR("moderator", R.string.moderator),
+ VISITOR("visitor", R.string.visitor),
+ PARTICIPANT("participant", R.string.participant),
+ NONE("none", R.string.no_role);
- private Role(int resId) {
+ private Role(String string, int resId) {
+ this.string = string;
this.resId = resId;
}
+ private String string;
private int resId;
public int getResId() {
return resId;
}
+
+ @Override
+ public String toString() {
+ return this.string;
+ }
}
public static final int ERROR_NO_ERROR = 0;
diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
index 58933692..988b9744 100644
--- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java
@@ -5,6 +5,7 @@ import java.util.Collections;
import java.util.List;
import eu.siacs.conversations.entities.Account;
+import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.services.MessageArchiveService;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.Xmlns;
@@ -148,4 +149,14 @@ public class IqGenerator extends AbstractGenerator {
query.addChild("password").setContent(newPassword);
return packet;
}
+
+ public IqPacket changeAffiliation(Conversation conference, Jid jid, String affiliation) {
+ IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
+ packet.setTo(conference.getJid().toBareJid());
+ packet.setFrom(conference.getAccount().getJid());
+ Element item = packet.query("http://jabber.org/protocol/muc#admin").addChild("item");
+ item.setAttribute("jid", jid.toString());
+ item.setAttribute("affiliation", affiliation);
+ return packet;
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index cf3f72dc..4ab2d42b 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -389,7 +389,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
final String action = intent == null ? null : intent.getAction();
if (action != null) {
if (action.equals(ACTION_MERGE_PHONE_CONTACTS)) {
- PhoneHelper.loadPhoneContacts(getApplicationContext(), new ArrayList<Bundle>(), this);
+ PhoneHelper.loadPhoneContacts(getApplicationContext(), new CopyOnWriteArrayList<Bundle>(), this);
return START_STICKY;
} else if (action.equals(Intent.ACTION_SHUTDOWN)) {
logoutAndSave();
@@ -500,7 +500,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
this.databaseBackend.readRoster(account.getRoster());
}
initConversations();
- PhoneHelper.loadPhoneContacts(getApplicationContext(),new ArrayList<Bundle>(), this);
+ PhoneHelper.loadPhoneContacts(getApplicationContext(),new CopyOnWriteArrayList<Bundle>(), this);
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver);
this.fileObserver.startWatching();
@@ -1005,6 +1005,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
} else {
conversation.setMode(Conversation.MODE_SINGLE);
}
+ conversation.setNextEncryption(-1);
conversation.addAll(0, databaseBackend.getMessages(conversation, Config.PAGE_SIZE));
this.databaseBackend.updateConversation(conversation);
} else {
@@ -1040,6 +1041,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void archiveConversation(Conversation conversation) {
+ conversation.setStatus(Conversation.STATUS_ARCHIVED);
+ conversation.setNextEncryption(-1);
synchronized (this.conversations) {
if (conversation.getMode() == Conversation.MODE_MULTI) {
if (conversation.getAccount().getStatus() == Account.State.ONLINE) {
@@ -1513,6 +1516,28 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
});
}
+ public void changeAffiliationInConference(final Conversation conference, Jid user, MucOptions.Affiliation affiliation, final OnAffiliationChanged callback) {
+ final Jid jid = user.toBareJid();
+ IqPacket request = this.mIqGenerator.changeAffiliation(conference, jid, affiliation.toString());
+ Log.d(Config.LOGTAG,request.toString());
+ sendIqPacket(conference.getAccount(),request,new OnIqPacketReceived() {
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ Log.d(Config.LOGTAG,packet.toString());
+ if (packet.getType() == IqPacket.TYPE.RESULT) {
+ callback.onAffiliationChangedSuccessful(jid);
+ } else {
+ callback.onAffiliationChangeFailed(jid,R.string.could_not_change_affiliation);
+ }
+ }
+ });
+ }
+
+ public interface OnAffiliationChanged {
+ public void onAffiliationChangedSuccessful(Jid jid);
+ public void onAffiliationChangeFailed(Jid jid, int resId);
+ }
+
public void disconnect(Account account, boolean force) {
if ((account.getStatus() == Account.State.ONLINE)
|| (account.getStatus() == Account.State.DISABLED)) {
diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
index 5a30d761..41190ef2 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
@@ -33,11 +33,13 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.MucOptions.User;
+import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
+import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
-public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate {
+public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged {
public static final String ACTION_VIEW_MUC = "view_muc";
private Conversation mConversation;
private OnClickListener inviteListener = new OnClickListener() {
@@ -222,21 +224,44 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
if (tag instanceof User) {
getMenuInflater().inflate(R.menu.muc_details_context,menu);
final User user = (User) tag;
+ final User self = mConversation.getMucOptions().getSelf();
this.mSelectedUser = user;
String name;
- final Contact contact = user.getContact();
- if (contact != null) {
- name = contact.getDisplayName();
- } else if (user.getJid() != null) {
- name = user.getJid().toBareJid().toString();
- } else {
- name = user.getName();
- }
- menu.setHeaderTitle(name);
- MenuItem startConversation = menu.findItem(R.id.start_conversation);
- if (user.getJid() == null) {
- startConversation.setVisible(false);
+ if (user.getJid() != null) {
+ final Contact contact = user.getContact();
+ if (contact != null) {
+ name = contact.getDisplayName();
+ } else if (user.getJid() != null) {
+ name = user.getJid().toBareJid().toString();
+ } else {
+ name = user.getName();
+ }
+ menu.setHeaderTitle(name);
+ MenuItem startConversation = menu.findItem(R.id.start_conversation);
+ MenuItem giveMembership = menu.findItem(R.id.give_membership);
+ MenuItem removeMembership = menu.findItem(R.id.remove_membership);
+ MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges);
+ MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges);
+ MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room);
+ startConversation.setVisible(true);
+ if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) &&
+ self.getAffiliation().outranks(user.getAffiliation())) {
+ if (mAdvancedMode) {
+ if (user.getAffiliation() == MucOptions.Affiliation.NONE) {
+ giveMembership.setVisible(true);
+ } else {
+ removeMembership.setVisible(true);
+ }
+ }
+ if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) {
+ giveAdminPrivileges.setVisible(true);
+ } else {
+ removeAdminPrivileges.setVisible(true);
+ }
+ removeFromRoom.setVisible(true);
+ }
}
+
}
super.onCreateContextMenu(menu,v,menuInfo);
}
@@ -247,6 +272,21 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
case R.id.start_conversation:
startConversation(mSelectedUser);
return true;
+ case R.id.give_admin_privileges:
+ xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.ADMIN,this);
+ return true;
+ case R.id.give_membership:
+ xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.MEMBER,this);
+ return true;
+ case R.id.remove_membership:
+ xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.NONE,this);
+ return true;
+ case R.id.remove_admin_privileges:
+ xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.MEMBER,this);
+ return true;
+ case R.id.remove_from_room:
+ xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.OUTCAST,this);
+ return true;
default:
return super.onContextItemSelected(item);
}
@@ -399,4 +439,14 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
}
}
}
+
+ @Override
+ public void onAffiliationChangedSuccessful(Jid jid) {
+
+ }
+
+ @Override
+ public void onAffiliationChangeFailed(Jid jid, int resId) {
+
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
index e71f4cbb..795dabf2 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
@@ -492,7 +492,6 @@ public class ConversationActivity extends XmppActivity
}
public void endConversation(Conversation conversation) {
- conversation.setStatus(Conversation.STATUS_ARCHIVED);
showConversationsOverview();
xmppConnectionService.archiveConversation(conversation);
if (conversationList.size() > 0) {
diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java
index 2f1383b8..74f0d345 100644
--- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java
@@ -51,10 +51,18 @@ public class UIHelper {
}
private static boolean today(Date date) {
+ return sameDay(date,new Date(System.currentTimeMillis()));
+ }
+
+ public static boolean sameDay(long timestamp1, long timestamp2) {
+ return sameDay(new Date(timestamp1),new Date(timestamp2));
+ }
+
+ private static boolean sameDay(Date a, Date b) {
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
- cal1.setTime(date);
- cal2.setTimeInMillis(System.currentTimeMillis());
+ cal1.setTime(a);
+ cal2.setTime(b);
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
&& cal1.get(Calendar.DAY_OF_YEAR) == cal2
.get(Calendar.DAY_OF_YEAR);