jointakahe / takahe

An ActivityPub/Fediverse server
BSD 3-Clause "New" or "Revised" License
1.1k stars 83 forks source link

Order of media attachments not preserved when creating a status #673

Open ghost opened 7 months ago

ghost commented 7 months ago

When attaching multiple media attachments to a post on a Takahe instance, the order of attachment is sometimes not preserved.

While I have not tested this myself, it appears that Mastodon preserves the order of media attachments (as per https://github.com/mastodon/mastodon/issues/5857).

I initially was not sure if this was a client issue, and so made the script below for confirmation. The order of media_attachments returned when creating a status is sometimes different to the order in the creation request.

Python script ```python import requests from collections import OrderedDict SERVER = "" TOKEN = "" filename_lookup = OrderedDict() headers = { 'Authorization': f'Bearer {TOKEN}', } filenames = ["twin_peaks.png", "guinea_pig.png", "map.png", "menu.png"] for filename in filenames: f = { 'file': open(filename, 'rb'), } tmp = requests.post(f'{SERVER}/api/v1/media', headers=headers, files=f) m_id = tmp.json()["id"] filename_lookup[m_id] = filename files = [("media_ids[]", (None, m_id)) for m_id in filename_lookup] files.append(("status", (None, "text"))) response = requests.post(f'{SERVER}/api/v1/statuses', headers=headers, files=files) attached_ids = [a["id"] for a in response.json()["media_attachments"]] attached_files = [filename_lookup[x] for x in attached_ids] assert filenames == attached_files ```

images.tar.gz

andrewgodwin commented 7 months ago

There is no ordering in Takahē for attachments other than the natural ordering in the PostgreSQL database, so this is not surprising. Fixing it would require adding an explicit ordering column.