-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: video attachments not reproducing on iOS #7530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
OtavioStasiak
wants to merge
19
commits into
develop
Choose a base branch
from
fix.video-not-playing
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
653bbd5
fix: video attachments stuck loading forever on iOS
OtavioStasiak cf2adbb
chore: code improvements
OtavioStasiak 2fc4f68
chore: code improvements
OtavioStasiak 1b5bf97
test: add coverage for encodeAttachmentUrl
OtavioStasiak 39f01dd
Merge branch 'develop' into fix.video-not-playing
OtavioStasiak 87ede68
Merge branch 'develop' into fix.video-not-playing
OtavioStasiak c9abe98
refactor: encode attachment urls via the URL parser
OtavioStasiak 1f1cc90
fix: double-encoded attachment urls in inline media
OtavioStasiak 5fdc044
Merge branch 'develop' into fix.video-not-playing
OtavioStasiak 8d6a891
fix: double-encoded attachment urls in inline media
OtavioStasiak 04149da
fix: encode local file uris for non-ascii filenames
OtavioStasiak eb86b19
Merge branch 'develop' into fix.video-not-playing
OtavioStasiak e5d20d9
remove comments
OtavioStasiak 370355f
Merge branch 'develop' into fix.video-not-playing
OtavioStasiak c2671d3
fix: merge conflicts
OtavioStasiak dffddf6
chore: remove console.log from persistMessage empty-batch path
OtavioStasiak 6b5b2a2
remove unused comment
OtavioStasiak 84196a4
fix: encode attachment urls at the player sinks instead of formatAtta…
OtavioStasiak 70aa4a0
fix: test
OtavioStasiak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,13 @@ | ||
| import { useEffect, useState } from 'react'; | ||
| import { useState } from 'react'; | ||
|
|
||
| import { type IAttachment } from '../../../definitions'; | ||
| import { getMessageById } from '../../../lib/database/services/Message'; | ||
| import { getThreadMessageById } from '../../../lib/database/services/ThreadMessage'; | ||
|
|
||
| export const useFile = (file: IAttachment, messageId: string) => { | ||
| const [localFile, setLocalFile] = useState(file); | ||
| const [isMessagePersisted, setIsMessagePersisted] = useState(!!messageId); | ||
| useEffect(() => { | ||
| const checkMessage = async () => { | ||
| const threadMessage = await getThreadMessageById(messageId); | ||
| if (!threadMessage) { | ||
| const message = await getMessageById(messageId); | ||
| if (!message) { | ||
| setIsMessagePersisted(false); | ||
| } | ||
| } | ||
| }; | ||
| checkMessage(); | ||
| }, [messageId]); | ||
| export const useFile = (file: IAttachment) => { | ||
| const [overrides, setOverrides] = useState<Partial<IAttachment> | null>(null); | ||
|
|
||
| const manageForwardedFile = (f: Partial<IAttachment>) => { | ||
| if (isMessagePersisted) { | ||
| return; | ||
| } | ||
| setLocalFile(prev => ({ ...prev, ...f })); | ||
| const mergeFile = (f: Partial<IAttachment>) => { | ||
| setOverrides(prev => ({ ...prev, ...f })); | ||
| }; | ||
| return [isMessagePersisted ? file : localFile, manageForwardedFile] as const; | ||
|
|
||
| return [overrides ? { ...file, ...overrides } : file, mergeFile] as const; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/lib/methods/helpers/__tests__/formatAttachmentUrl.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { encodeAttachmentUrl } from '../formatAttachmentUrl'; | ||
|
|
||
| describe('encodeAttachmentUrl', () => { | ||
| it('encodes an unencoded path', () => { | ||
| expect(encodeAttachmentUrl('https://open.rocket.chat/file-upload/1/Screen Recording.mov')).toBe( | ||
| 'https://open.rocket.chat/file-upload/1/Screen%20Recording.mov' | ||
| ); | ||
| }); | ||
|
|
||
| it('leaves an already-encoded path untouched', () => { | ||
| expect(encodeAttachmentUrl('https://open.rocket.chat/file-upload/1/Screen%20Recording.mov')).toBe( | ||
| 'https://open.rocket.chat/file-upload/1/Screen%20Recording.mov' | ||
| ); | ||
| }); | ||
|
|
||
| it('leaves an already-escaped reserved character in the path', () => { | ||
| expect(encodeAttachmentUrl('https://open.rocket.chat/file-upload/1/a%20video%20%232.mov')).toBe( | ||
| 'https://open.rocket.chat/file-upload/1/a%20video%20%232.mov' | ||
| ); | ||
| }); | ||
|
|
||
| // Known limitation, not a regression: `#` is the fragment delimiter per the URL spec, so a raw one ends the | ||
| // path and the rest becomes the fragment — which HTTP drops, so the server sees a truncated path. The previous | ||
| // encodeURI behaved identically (it leaves `#` unescaped too). Only reachable if the server sends a raw `#`. | ||
| it('treats a raw reserved `#` in the path as a fragment', () => { | ||
| expect(encodeAttachmentUrl('https://open.rocket.chat/file-upload/1/a video #2.mov')).toBe( | ||
| 'https://open.rocket.chat/file-upload/1/a%20video%20#2.mov' | ||
| ); | ||
| }); | ||
|
|
||
| it('preserves the query string', () => { | ||
| expect(encodeAttachmentUrl('https://open.rocket.chat/file-upload/1/Screen Recording.mov?rc_token=abc&rc_uid=123')).toBe( | ||
| 'https://open.rocket.chat/file-upload/1/Screen%20Recording.mov?rc_token=abc&rc_uid=123' | ||
| ); | ||
| }); | ||
|
|
||
| // WHATWG URL passes a malformed escape through rather than throwing, so this exercises the try branch. | ||
| it('returns the raw url when it has a malformed escape', () => { | ||
| expect(encodeAttachmentUrl('https://open.rocket.chat/file-upload/1/%ZZ.mov')).toBe( | ||
| 'https://open.rocket.chat/file-upload/1/%ZZ.mov' | ||
| ); | ||
| }); | ||
|
|
||
| // A non-absolute url is what actually throws — reachable when the server/CDN prefix is empty. | ||
| it('returns the raw url when it is not absolute', () => { | ||
| expect(encodeAttachmentUrl('/file-upload/1/Screen Recording.mov')).toBe('/file-upload/1/Screen Recording.mov'); | ||
| }); | ||
|
|
||
| // Cache filenames keep unicode letters, so local uris need encoding before they reach the native players. | ||
| it('encodes unicode letters in a local file uri', () => { | ||
| expect(encodeAttachmentUrl('file:///var/app/Documents/server/msg1/vídeo.mov')).toBe( | ||
| 'file:///var/app/Documents/server/msg1/v%C3%ADdeo.mov' | ||
| ); | ||
| }); | ||
|
|
||
| it('leaves an already-encoded local file uri untouched', () => { | ||
| expect(encodeAttachmentUrl('file:///var/app/Documents/server/msg1/v%C3%ADdeo.mov')).toBe( | ||
| 'file:///var/app/Documents/server/msg1/v%C3%ADdeo.mov' | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.