Skip to content

Commit

Permalink
Merge pull request #204 from sendbird/fix/open-file-backward
Browse files Browse the repository at this point in the history
fix: remove default onOpenFileURL handler
  • Loading branch information
bang9 authored Oct 17, 2024
2 parents 933c75b + 2ad2275 commit 542dbca
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
useSendbirdChat,
useUserProfile,
} from '../../hooks/useContext';
import SBUUtils from '../../libs/SBUUtils';
import ChatFlatList from '../ChatFlatList';
import { ReactionAddons } from '../ReactionAddons';

Expand Down Expand Up @@ -271,8 +272,11 @@ const useCreateMessagePressActions = <T extends SendbirdGroupChannel | SendbirdO
const fileType = getFileType(message.type || getFileExtension(message.name));
if (['image', 'video', 'audio'].includes(fileType)) {
onPressMediaMessage?.(message, () => onDeleteMessage(message), getAvailableUriFromFileMessage(message));
handlers.onOpenFileURL?.(message.url);
} else {
const openFile = handlers.onOpenFileURL ?? SBUUtils.openURL;
openFile(message.url);
}
handlers.onOpenFileURL(message.url);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
useSendbirdChat,
useUserProfile,
} from '../../hooks/useContext';
import SBUUtils from '../../libs/SBUUtils';
import { ReactionAddons } from '../ReactionAddons';
import ThreadChatFlatList from '../ThreadChatFlatList';

Expand Down Expand Up @@ -249,8 +250,11 @@ const useCreateMessagePressActions = <T extends SendbirdGroupChannel | SendbirdO
const fileType = getFileType(message.type || getFileExtension(message.name));
if (['image', 'video', 'audio'].includes(fileType)) {
onPressMediaMessage?.(message, () => onDeleteMessage(message), getAvailableUriFromFileMessage(message));
handlers.onOpenFileURL?.(message.url);
} else {
const openFile = handlers.onOpenFileURL ?? SBUUtils.openURL;
openFile(message.url);
}
handlers.onOpenFileURL(message.url);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ const SendbirdUIKitContainer = (props: SendbirdUIKitContainerProps) => {

const sbuHandlers: SBUHandlers = {
onOpenURL: SBUUtils.openURL,
onOpenFileURL: SBUUtils.openURL,
...handlers,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface SBUHandlers {
* Note that this function is also called redundantly
* when `onPressMediaMessage` handler is triggered by clicking on media messages containing images, videos, or audio.
*/
onOpenFileURL: (url: string) => void;
onOpenFileURL?: (url: string) => void;
}

type Props = React.PropsWithChildren<SBUHandlers>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import ThreadParentMessageRenderer, {
ThreadParentMessageRendererProps,
} from '../../../components/ThreadParentMessageRenderer';
import { useLocalization, usePlatformService, useSBUHandlers, useSendbirdChat } from '../../../hooks/useContext';
import SBUUtils from '../../../libs/SBUUtils';
import { GroupChannelThreadContexts } from '../module/moduleContext';
import type { GroupChannelThreadProps } from '../types';
import { ReactionAddons } from './../../../components/ReactionAddons';
Expand Down Expand Up @@ -224,9 +225,12 @@ const useCreateMessagePressActions = ({
if (message.isFileMessage()) {
const fileType = getFileType(message.type || getFileExtension(message.name));
if (['image', 'video', 'audio'].includes(fileType)) {
onPressMediaMessage?.(message, () => onDeleteMessage?.(message), getAvailableUriFromFileMessage(message));
onPressMediaMessage?.(message, () => onDeleteMessage(message), getAvailableUriFromFileMessage(message));
handlers.onOpenFileURL?.(message.url);
} else {
const openFile = handlers.onOpenFileURL ?? SBUUtils.openURL;
openFile(message.url);
}
handlers.onOpenFileURL(message.url);
}
};

Expand All @@ -239,7 +243,7 @@ const useCreateMessagePressActions = ({
text: STRINGS.LABELS.CHANNEL_MESSAGE_DELETE_CONFIRM_OK,
style: 'destructive',
onPress: () => {
onDeleteMessage?.(message).catch(onDeleteFailure);
onDeleteMessage(message).catch(onDeleteFailure);
},
},
],
Expand Down

0 comments on commit 542dbca

Please sign in to comment.