save muc subject to disk and use crypto targets for offline name generation

This commit is contained in:
Daniel Gultsch 2017-12-17 16:23:19 +01:00
parent dd237a272b
commit 1753dcac76
4 changed files with 37 additions and 16 deletions

View file

@ -495,12 +495,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
public String getName() { public String getName() {
if (getMode() == MODE_MULTI) { if (getMode() == MODE_MULTI) {
if (getMucOptions().getSubject() != null) { final String subject = getMucOptions().getSubject();
return getMucOptions().getSubject(); final String bookmarkName = bookmark != null ? bookmark.getBookmarkName() : null;
} else if (bookmark != null if (subject != null && !subject.trim().isEmpty()) {
&& bookmark.getBookmarkName() != null return subject;
&& !bookmark.getBookmarkName().trim().isEmpty()) { } else if (bookmarkName != null && !bookmarkName.trim().isEmpty()) {
return bookmark.getBookmarkName().trim(); return bookmarkName;
} else { } else {
String generatedName = getMucOptions().createNameFromParticipants(); String generatedName = getMucOptions().createNameFromParticipants();
if (generatedName != null) { if (generatedName != null) {

View file

@ -3,7 +3,6 @@ package eu.siacs.conversations.entities;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -362,12 +361,11 @@ public class MucOptions {
private final Set<User> users = new HashSet<>(); private final Set<User> users = new HashSet<>();
private final List<String> features = new ArrayList<>(); private final List<String> features = new ArrayList<>();
private Data form = new Data(); private Data form = new Data();
private Conversation conversation; private final Conversation conversation;
private boolean isOnline = false; private boolean isOnline = false;
private Error error = Error.NONE; private Error error = Error.NONE;
public OnRenameListener onRenameListener = null; public OnRenameListener onRenameListener = null;
private User self; private User self;
private String subject = null;
private String password = null; private String password = null;
public MucOptions(Conversation conversation) { public MucOptions(Conversation conversation) {
@ -661,18 +659,39 @@ public class MucOptions {
return self; return self;
} }
public void setSubject(String content) { public boolean setSubject(String subject) {
this.subject = content; return this.conversation.setAttribute("subject",subject);
} }
public String getSubject() { 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 String createNameFromParticipants() { public String createNameFromParticipants() {
if (getUserCount() >= 2) { List<User> users = getUsersRelevantForNameAndAvatar();
if (users.size() >= 2) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (User user : getUsers(5)) { for (User user : users) {
if (builder.length() != 0) { if (builder.length() != 0) {
builder.append(", "); builder.append(", ");
} }

View file

@ -674,7 +674,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) { if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {
conversation.setHasMessagesLeftOnServer(conversation.countMessages() > 0); conversation.setHasMessagesLeftOnServer(conversation.countMessages() > 0);
String subject = packet.findChildContent("subject"); String subject = packet.findChildContent("subject");
conversation.getMucOptions().setSubject(subject); if (conversation.getMucOptions().setSubject(subject)) {
mXmppConnectionService.updateConversation(conversation);
}
final Bookmark bookmark = conversation.getBookmark(); final Bookmark bookmark = conversation.getBookmark();
if (bookmark != null && bookmark.getBookmarkName() == null) { if (bookmark != null && bookmark.getBookmarkName() == null) {
if (bookmark.setBookmarkName(subject)) { if (bookmark.setBookmarkName(subject)) {

View file

@ -213,7 +213,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
if (bitmap != null || cachedOnly) { if (bitmap != null || cachedOnly) {
return bitmap; return bitmap;
} }
final List<MucOptions.User> users = mucOptions.getUsers(5); final List<MucOptions.User> users = mucOptions.getUsersRelevantForNameAndAvatar();
if (users.size() == 0) { if (users.size() == 0) {
Conversation c = mucOptions.getConversation(); Conversation c = mucOptions.getConversation();
bitmap = getImpl(c.getName(),c.getJid().toBareJid().toString(),size); bitmap = getImpl(c.getName(),c.getJid().toBareJid().toString(),size);