copy bookmarks before passing them to other parts of the app for read

closes #4381
This commit is contained in:
Daniel Gultsch 2022-09-14 12:49:15 +02:00
parent d0efe6eae2
commit c1abca35da
4 changed files with 13 additions and 10 deletions

View file

@ -57,7 +57,7 @@ public final class Config {
public static final long CONTACT_SYNC_RETRY_INTERVAL = 1000L * 60 * 5;
public static final boolean SASL_2_ENABLED = false;
public static final boolean SASL_2_ENABLED = true;
//Notification settings
public static final boolean HIDE_MESSAGE_TEXT_IN_NOTIFICATION = false;

View file

@ -6,6 +6,7 @@ import android.os.SystemClock;
import android.util.Log;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import org.json.JSONException;
import org.json.JSONObject;
@ -488,17 +489,19 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
}
public Collection<Bookmark> getBookmarks() {
return this.bookmarks.values();
synchronized (this.bookmarks) {
return ImmutableList.copyOf(this.bookmarks.values());
}
}
public void setBookmarks(Map<Jid, Bookmark> bookmarks) {
public void setBookmarks(final Map<Jid, Bookmark> bookmarks) {
synchronized (this.bookmarks) {
this.bookmarks.clear();
this.bookmarks.putAll(bookmarks);
}
}
public void putBookmark(Bookmark bookmark) {
public void putBookmark(final Bookmark bookmark) {
synchronized (this.bookmarks) {
this.bookmarks.put(bookmark.getJid(), bookmark);
}

View file

@ -1862,7 +1862,7 @@ public class XmppConnectionService extends Service {
IqPacket iqPacket = new IqPacket(IqPacket.TYPE.SET);
Element query = iqPacket.query("jabber:iq:private");
Element storage = query.addChild("storage", "storage:bookmarks");
for (Bookmark bookmark : account.getBookmarks()) {
for (final Bookmark bookmark : account.getBookmarks()) {
storage.addChild(bookmark);
}
sendIqPacket(account, iqPacket, mDefaultIqHandler);
@ -1870,8 +1870,8 @@ public class XmppConnectionService extends Service {
private void pushBookmarksPep(Account account) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": pushing bookmarks via pep");
Element storage = new Element("storage", "storage:bookmarks");
for (Bookmark bookmark : account.getBookmarks()) {
final Element storage = new Element("storage", "storage:bookmarks");
for (final Bookmark bookmark : account.getBookmarks()) {
storage.addChild(bookmark);
}
pushNodeAndEnforcePublishOptions(account, Namespace.BOOKMARKS, storage, "current", PublishOptions.persistentWhitelistAccess());
@ -4418,7 +4418,7 @@ public class XmppConnectionService extends Service {
for (final Account account : accounts) {
if (account.getXmppConnection() != null) {
mucServers.addAll(account.getXmppConnection().getMucServers());
for (Bookmark bookmark : account.getBookmarks()) {
for (final Bookmark bookmark : account.getBookmarks()) {
final Jid jid = bookmark.getJid();
final String s = jid == null ? null : jid.getDomain().toEscapedString();
if (s != null) {

View file

@ -980,9 +980,9 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
protected void filterConferences(String needle) {
this.conferences.clear();
for (Account account : xmppConnectionService.getAccounts()) {
for (final Account account : xmppConnectionService.getAccounts()) {
if (account.getStatus() != Account.State.DISABLED) {
for (Bookmark bookmark : account.getBookmarks()) {
for (final Bookmark bookmark : account.getBookmarks()) {
if (bookmark.match(this, needle)) {
this.conferences.add(bookmark);
}