Fix bad content types when sending unencrypted media event with additional content data #7519
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of change
Content
Fix incorrect type of event content entries when sending unencrypted events related to media files
Motivation and context
After uploading a media file (eg. voice message), the local event related to the media is updated with some metadata (eg. size). The event entity was retrieved from the database and mapped to the Event model without casting the json numbers to their original type.
Here is the issue, after retrieving some additional data, the entity was updated with the new metadata plus the additional data, with the wrong number types, causing an error when sending the event to the server.
This PR forces the cast of the json number before updating the event in the database.
Note: the issue is only visible on voice broadcast because additional data are added to the voice message events triggering a specific code to retrieve the additional data after uploading the voice message file.
Screenshots / GIFs
Before:
Event(type=m.room.message, eventId=$xxx, content={msgtype=m.audio, body=Voice Broadcast Part (2).mp4, info={mimetype=video/mp4, size=11275.0, duration=3413.0}, url=xxx, m.relates_to={rel_type=m.reference, event_id=$xxx}, org.matrix.msc1767.audio={duration=3413.0}, org.matrix.msc3245.voice={}, io.element.voice_broadcast_chunk={sequence=2.0}}, prevContent=null, originServerTs=1667415437377, senderId=@xxx:matrix.org, stateKey=null, roomId=!xxx:matrix.org, unsignedData=UnsignedData(age=null, redactedEvent=null, transactionId=$xxx, prevContent=null, relations=null, replacesState=null), redacts=null)
After:
Event(type=m.room.message, eventId=$xxx, content={msgtype=m.audio, body=Voice Broadcast Part (2).mp4, info={mimetype=video/mp4, size=11275, duration=3413}, url=xxx, m.relates_to={rel_type=m.reference, event_id=$xxx}, org.matrix.msc1767.audio={duration=3413}, org.matrix.msc3245.voice={}, io.element.voice_broadcast_chunk={sequence=2}}, prevContent=null, originServerTs=1667415437377, senderId=@xxx:matrix.org, stateKey=null, roomId=!xxx:matrix.org, unsignedData=UnsignedData(age=null, redactedEvent=null, transactionId=$xxx, prevContent=null, relations=null, replacesState=null), redacts=null)
Tests
Tested devices
Checklist