~singpolyma/cheogram-android

801c6b34077acbd148790d7e3690626c0adac9c0 — Stephen Paul Weber 1 year, 7 months ago e5bdde0
Avoid pushing legacy bookmarks before they are loaded

Race condition could wipe them out
M src/main/java/eu/siacs/conversations/entities/Account.java => src/main/java/eu/siacs/conversations/entities/Account.java +4 -0
@@ 89,6 89,7 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable 
    private XmppConnection xmppConnection = null;
    private long mEndGracePeriod = 0L;
    private final Map<Jid, Bookmark> bookmarks = new HashMap<>();
    private boolean bookmarksLoaded = false;
    private Presence.Status presenceStatus = Presence.Status.ONLINE;
    private String presenceStatusMessage = null;



@@ 493,10 494,13 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable 
        }
    }

    public boolean areBookmarksLoaded() { return bookmarksLoaded; }

    public void setBookmarks(Map<Jid, Bookmark> bookmarks) {
        synchronized (this.bookmarks) {
            this.bookmarks.clear();
            this.bookmarks.putAll(bookmarks);
            this.bookmarksLoaded = true;
        }
    }


M src/main/java/eu/siacs/conversations/services/XmppConnectionService.java => src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +4 -0
@@ 1894,6 1894,8 @@ public class XmppConnectionService extends Service {
    }

    private void pushBookmarksPrivateXml(Account account) {
        if (!account.areBookmarksLoaded()) return;

        Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": pushing bookmarks via private xml");
        IqPacket iqPacket = new IqPacket(IqPacket.TYPE.SET);
        Element query = iqPacket.query("jabber:iq:private");


@@ 1905,6 1907,8 @@ public class XmppConnectionService extends Service {
    }

    private void pushBookmarksPep(Account account) {
        if (!account.areBookmarksLoaded()) return;

        Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": pushing bookmarks via pep");
        Element storage = new Element("storage", "storage:bookmarks");
        for (Bookmark bookmark : account.getBookmarks()) {