aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-13 23:11:28 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-13 23:11:28 +0200
commit1b6bf807de1b442687ec5f9982e551bb16923f04 (patch)
tree69f18a6c9e78c8e622c316c1016f27639a9dee9e /src
parentbcbc0006a171c06e896e6430d239e7a57357b016 (diff)
persist some muc configurations
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java12
-rw-r--r--src/main/java/de/pixart/messenger/entities/MucOptions.java29
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java8
3 files changed, 33 insertions, 16 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java
index a010a3799..fa5e5ef60 100644
--- a/src/main/java/de/pixart/messenger/entities/Conversation.java
+++ b/src/main/java/de/pixart/messenger/entities/Conversation.java
@@ -62,6 +62,10 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
private static final String ATTRIBUTE_NEXT_MESSAGE_TIMESTAMP = "next_message_timestamp";
private static final String ATTRIBUTE_CRYPTO_TARGETS = "crypto_targets";
private static final String ATTRIBUTE_NEXT_ENCRYPTION = "next_encryption";
+ public static final String ATTRIBUTE_ALLOW_PM = "allow_pm";
+ public static final String ATTRIBUTE_MEMBERS_ONLY = "members_only";
+ public static final String ATTRIBUTE_MODERATED = "moderated";
+ public static final String ATTRIBUTE_NON_ANONYMOUS = "non_anonymous";
protected final ArrayList<Message> messages = new ArrayList<>();
public AtomicBoolean messagesLoaded = new AtomicBoolean(true);
protected Account account = null;
@@ -895,6 +899,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
return mode == MODE_SINGLE || getBooleanAttribute(ATTRIBUTE_ALWAYS_NOTIFY, Config.ALWAYS_NOTIFY_BY_DEFAULT || isPrivateAndNonAnonymous());
}
+ public boolean setAttribute(String key, boolean value) {
+ boolean prev = getBooleanAttribute(key, false);
+ setAttribute(key, Boolean.toString(value));
+ return prev != value;
+ }
+
private boolean setAttribute(String key, long value) {
return setAttribute(key, Long.toString(value));
}
@@ -981,7 +991,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
}
}
- private boolean getBooleanAttribute(String key, boolean defaultValue) {
+ public boolean getBooleanAttribute(String key, boolean defaultValue) {
String value = this.getAttribute(key);
if (value == null) {
return defaultValue;
diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java
index 25d059c93..255eecc79 100644
--- a/src/main/java/de/pixart/messenger/entities/MucOptions.java
+++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java
@@ -373,12 +373,24 @@ public class MucOptions {
this.self = new User(this, createJoinJid(getProposedNick()));
}
- public void updateFeatures(ArrayList<String> features) {
+ public boolean updateConfiguration(List<String> features, Data data) {
+ updateFeatures(features);
+ updateFormData(data == null ? new Data() : data);
+ Field allowPmField = this.form.getFieldByName("muc#roomconfig_allowpm");
+ boolean changed = false;
+ changed |= conversation.setAttribute(Conversation.ATTRIBUTE_ALLOW_PM, allowPmField == null || "1".equals(allowPmField.getValue()));
+ changed |= conversation.setAttribute(Conversation.ATTRIBUTE_MEMBERS_ONLY, this.hasFeature("muc_membersonly"));
+ changed |= conversation.setAttribute(Conversation.ATTRIBUTE_MODERATED, this.hasFeature("muc_moderated"));
+ changed |= conversation.setAttribute(Conversation.ATTRIBUTE_NON_ANONYMOUS, this.hasFeature("muc_nonanonymous"));
+ return changed;
+ }
+
+ private void updateFeatures(List<String> features) {
this.features.clear();
this.features.addAll(features);
}
- public void updateFormData(Data form) {
+ private void updateFormData(Data form) {
this.form = form;
}
@@ -397,8 +409,7 @@ public class MucOptions {
}
public boolean allowPm() {
- Field field = this.form.getFieldByName("muc#roomconfig_allowpm");
- return field == null || "1".equals(field.getValue());
+ return conversation.getBooleanAttribute(Conversation.ATTRIBUTE_ALLOW_PM, false);
}
public boolean participating() {
@@ -408,7 +419,7 @@ public class MucOptions {
}
public boolean membersOnly() {
- return hasFeature("muc_membersonly");
+ return conversation.getBooleanAttribute(Conversation.ATTRIBUTE_MEMBERS_ONLY, false);
}
public boolean mamSupport() {
@@ -420,19 +431,15 @@ public class MucOptions {
}
public boolean nonanonymous() {
- return hasFeature("muc_nonanonymous");
+ return conversation.getBooleanAttribute(Conversation.ATTRIBUTE_NON_ANONYMOUS, false);
}
public boolean isPrivateAndNonAnonymous() {
return membersOnly() && nonanonymous();
}
- public boolean persistent() {
- return hasFeature("muc_persistent");
- }
-
public boolean moderated() {
- return hasFeature("muc_moderated");
+ return conversation.getBooleanAttribute(Conversation.ATTRIBUTE_MODERATED, false);
}
public User deleteUser(Jid jid) {
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 60ecbe7c0..dfd05bbe3 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -2747,14 +2747,14 @@ public class XmppConnectionService extends Service {
}
}
Element form = query.findChild("x", Namespace.DATA);
- if (form != null) {
- conversation.getMucOptions().updateFormData(Data.parse(form));
+ Data data = form == null ? null : Data.parse(form);
+ if (conversation.getMucOptions().updateConfiguration(features, data)) {
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": muc configuration changed for " + conversation.getJid().asBareJid());
+ updateConversation(conversation);
}
- conversation.getMucOptions().updateFeatures(features);
if (callback != null) {
callback.onConferenceConfigurationFetched(conversation);
}
- Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetched muc configuration for " + conversation.getJid().asBareJid() + " - " + features.toString());
updateConversationUi();
} else if (packet.getType() == IqPacket.TYPE.ERROR) {
if (callback != null) {