aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-12-27 21:01:13 +0100
committerChristian Schneppe <christian@pix-art.de>2017-12-27 21:01:13 +0100
commit7542322a40a9c22e6fbcdbc7f69bb3deecf9e197 (patch)
treea35ba89a27c1dbcbc191df1c34ef812874f9b11b /src/main/java/de/pixart
parent044bc0e95d81cb12c6ba47c72db930616205e7eb (diff)
save muc subject to disk and use crypto targets for offline name generation
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java13
-rw-r--r--src/main/java/de/pixart/messenger/entities/MucOptions.java34
-rw-r--r--src/main/java/de/pixart/messenger/parser/MessageParser.java4
-rw-r--r--src/main/java/de/pixart/messenger/services/AvatarService.java2
4 files changed, 39 insertions, 14 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java
index 3df78fde0..1bfb50034 100644
--- a/src/main/java/de/pixart/messenger/entities/Conversation.java
+++ b/src/main/java/de/pixart/messenger/entities/Conversation.java
@@ -509,12 +509,13 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
public String getName() {
if (getMode() == MODE_MULTI) {
- if (getMucOptions().getSubject() != null) {
- return getMucOptions().getSubject();
- } else if (bookmark != null
- && bookmark.getBookmarkName() != null
- && !bookmark.getBookmarkName().trim().isEmpty()) {
- return bookmark.getBookmarkName().trim();
+ final String subject = getMucOptions().getSubject();
+ final String bookmarkName = bookmark != null ? bookmark.getBookmarkName() : null;
+
+ if (subject != null && !subject.trim().isEmpty()) {
+ return subject;
+ } else if (bookmarkName != null && !bookmarkName.trim().isEmpty()) {
+ return bookmarkName;
} else {
String generatedName = getMucOptions().createNameFromParticipants();
if (generatedName != null) {
diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java
index f1c3aa9e8..c6e0b6dc2 100644
--- a/src/main/java/de/pixart/messenger/entities/MucOptions.java
+++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java
@@ -361,12 +361,11 @@ public class MucOptions {
private final Set<User> users = new HashSet<>();
private final List<String> features = new ArrayList<>();
private Data form = new Data();
- private Conversation conversation;
+ private final Conversation conversation;
private boolean isOnline = false;
private Error error = Error.NONE;
public OnRenameListener onRenameListener = null;
private User self;
- private String subject = null;
private String password = null;
public MucOptions(Conversation conversation) {
@@ -660,15 +659,37 @@ public class MucOptions {
return self;
}
- public void setSubject(String content) {
- this.subject = content;
+ public boolean setSubject(String subject) {
+ return this.conversation.setAttribute("subject", subject);
}
public String getSubject() {
- return this.subject;
+ return this.conversation.getAttribute("subject");
}
+ public List<User> getFallbackUsersFromCryptoTargets() {
+ List<User> users = new ArrayList<>();
+ for (Jid jid : conversation.getAcceptedCryptoTargets()) {
+ User user = new User(this, null);
+ user.setRealJid(jid);
+ users.add(user);
+ }
+ return users;
+ }
+
+ public List<User> getUsersRelevantForNameAndAvatar() {
+ final List<User> users;
+ if (isOnline) {
+ users = getUsers(5);
+ } else {
+ users = getFallbackUsersFromCryptoTargets();
+ }
+ return users;
+ }
+
+
public int NumberOfUsers() {
+ List<User> users = getUsersRelevantForNameAndAvatar();
if (users.size() >= 1) {
return users.size();
} else {
@@ -679,9 +700,10 @@ public class MucOptions {
public String createNameFromParticipants() {
+ List<User> users = getUsersRelevantForNameAndAvatar();
if (users.size() >= 1) {
StringBuilder builder = new StringBuilder();
- for (User user : getUsers(5)) {
+ for (User user : users) {
if (builder.length() != 0) {
builder.append(", ");
}
diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java
index dead57709..f20e3132e 100644
--- a/src/main/java/de/pixart/messenger/parser/MessageParser.java
+++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java
@@ -661,7 +661,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {
conversation.setHasMessagesLeftOnServer(conversation.countMessages() > 0);
String subject = packet.findChildContent("subject");
- conversation.getMucOptions().setSubject(subject);
+ if (conversation.getMucOptions().setSubject(subject)) {
+ mXmppConnectionService.updateConversation(conversation);
+ }
final Bookmark bookmark = conversation.getBookmark();
if (bookmark != null && bookmark.getBookmarkName() == null) {
if (bookmark.setBookmarkName(subject)) {
diff --git a/src/main/java/de/pixart/messenger/services/AvatarService.java b/src/main/java/de/pixart/messenger/services/AvatarService.java
index 76e80679e..a0fc5ed53 100644
--- a/src/main/java/de/pixart/messenger/services/AvatarService.java
+++ b/src/main/java/de/pixart/messenger/services/AvatarService.java
@@ -217,7 +217,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
if (bitmap != null || cachedOnly) {
return bitmap;
}
- final List<MucOptions.User> users = mucOptions.getUsers(5);
+ final List<MucOptions.User> users = mucOptions.getUsersRelevantForNameAndAvatar();
if (users.size() == 0) {
Conversation c = mucOptions.getConversation();
bitmap = getImpl(c.getName(), c.getJid().toBareJid().toString(), size);