fixing race where shared intent not showing on sealed channel

This commit is contained in:
balzack 2023-05-05 22:08:19 -07:00
parent 82e15f5ec7
commit 245b05d192
2 changed files with 27 additions and 22 deletions

View File

@ -18,28 +18,30 @@ export function AddTopic({ contentKey, shareIntent, setShareIntent }) {
const { state, actions } = useAddTopic(contentKey);
useEffect(() => {
if (shareIntent) {
shareIntent.forEach(share => {
if (share.text) {
actions.setMessage(share.text);
}
if (share.weblink) {
actions.setMessage(share.weblink);
}
const mime = share.mimeType?.toLowerCase();
if (mime === '.jpg' || mime === '.png' || mime === 'image/jpeg' || mime == 'image/png' ) {
actions.addImage(share.filePath)
}
if (mime === '.mp4' || mime === 'video/mp4' || mime == 'video/mpeg') {
actions.addVideo(share.filePath)
}
if (mime === '.mp3') {
actions.addAudio(share.filePath)
}
});
setShareIntent(null);
if (shareIntent && state.loaded) {
if (!state.locked || contentKey) {
shareIntent.forEach(share => {
if (share.text) {
actions.setMessage(share.text);
}
if (share.weblink) {
actions.setMessage(share.weblink);
}
const mime = share.mimeType?.toLowerCase();
if (mime === '.jpg' || mime === '.png' || mime === 'image/jpeg' || mime == 'image/png' ) {
actions.addImage(share.filePath)
}
if (mime === '.mp4' || mime === 'video/mp4' || mime == 'video/mpeg') {
actions.addVideo(share.filePath)
}
if (mime === '.mp3') {
actions.addAudio(share.filePath)
}
});
setShareIntent(null);
}
}
}, [shareIntent]);
}, [shareIntent, state.loaded, state.locked, contentKey]);
const addImage = async () => {
try {

View File

@ -25,6 +25,7 @@ export function useAddTopic(contentKey) {
enableAudio: false,
enableVideo: false,
locked: true,
loaded: false,
conflict: false,
});
@ -100,11 +101,13 @@ export function useAddTopic(contentKey) {
useEffect(() => {
const { enableVideo, enableAudio, enableImage } = conversation.state.channel?.detail || {};
const locked = conversation.state.channel?.detail?.dataType === 'superbasic' ? false : true;
updateState({ enableImage, enableAudio, enableVideo, locked });
const loaded = conversation.state.loaded;
updateState({ enableImage, enableAudio, enableVideo, locked, loaded });
}, [conversation.state]);
const setAsset = async (file, scale) => {
const url = file.startsWith('file:') ? file : `file://${file}`;
if (contentKey) {
const scaled = scale ? await scale(url) : url;
const stat = await RNFS.stat(scaled);