calpaterson / quarchive

Traditional "Web 2.0" social bookmarking, with small improvements
https://quarchive.com/
GNU Affero General Public License v3.0
99 stars 6 forks source link

Make the extension's merge use the EXACT same logic for determining which is more recent #57

Open calpaterson opened 3 years ago

calpaterson commented 3 years ago

The server uses this to determine which of two bookmarks being merged is more recent:

        more_recent: "Bookmark" = sorted(
            (self, other),
            # 1. Take the most recently updated.
            # 2. If they're equally recent, take the longer title
            # 3. If that's not enough add the longest description
            # 4. If that's not enough compare the titles
            # 5. If that's not enough compare the description
            # 6. Then compare everything else
            key=lambda b: (
                b.updated,
                len(b.title),
                len(b.description),
                b.title,
                b.description,
                b.unread,
                not b.deleted,
            ),
            reverse=True,
        )[0]

The extension uses just this:

        let moreRecent;
        // --snip--
        if (this.updated > other.updated) {
            moreRecent = this;
        } else if (other.updated > this.updated) {
            moreRecent = other;
        } else {
            const thisLengths = this.title.length + this.description.length;
            const otherLengths = other.title.length + other.description.length;
            if (otherLengths > thisLengths) {
                moreRecent = other;
            } else {
                moreRecent = this;
            }
        }

These need to be brought into line with each other