It took me a while to dig through this, but I think I find the cause. I think it has to do with this code:
def fetch_uploads(params:, guardian:)
return [] if !SiteSetting.chat_allow_uploads
guardian.user.uploads.where(id: params.upload_ids) # Specifically, here
end
When a new chat message is created, this is called to fetch the uploads to attach to the message. Possibly to ensure ownership, the method goes through the Guardian’s user to fetch the uploads so as to only allow uploads belonging to that user.
The problem is that uploads are deduplicated, as seen here:
# do we already have that upload?
@upload = Upload.find_by(sha1: sha1)
# ...
# return the previous upload if any
if @upload
add_metadata!
UserUpload.find_or_create_by!(user_id: user_id, upload_id: @upload.id) if user_id
return @upload
end
I think that a possible fix would be to go through the UserUpload
s instead of just considering the uploads belonging to the user. UserUpload
links uploads to multiple users, which seems to be what we need. I’m not yet 100% sure how to do it properly; it’s getting late, so I’ll tuck in, but if no one else fixes it, I’ll try to come back later and work on a PR.