block send if share sheet adds unsupported asset type

This commit is contained in:
balzack 2023-04-23 21:24:15 -07:00
parent 9539a1f038
commit a9cb556392
2 changed files with 27 additions and 4 deletions

View File

@ -53,7 +53,7 @@ export function AddTopic({ contentKey, shareIntent, setShareIntent }) {
const sendMessage = async () => {
try {
if (state.message || state.assets.length > 0) {
if (!state.conflict && (state.message || state.assets.length > 0)) {
await actions.addTopic();
}
}
@ -183,13 +183,16 @@ export function AddTopic({ contentKey, shareIntent, setShareIntent }) {
{ state.busy && (
<ActivityIndicator color={Colors.primary} />
)}
{ state.locked && !contentKey && (
{ state.conflict && (
<MatIcons name="send-outline" size={20} color={Colors.alert} />
)}
{ !state.conflict && state.locked && !contentKey && (
<MatIcons name="lock" size={20} color={Colors.lightgrey} />
)}
{ !state.busy && (!state.locked || contentKey) && (state.message || state.assets.length > 0) && (
{ !state.conflict && !state.busy && (!state.locked || contentKey) && (state.message || state.assets.length > 0) && (
<MatIcons name="send-outline" size={20} color={Colors.text} />
)}
{ !state.busy && (!state.locked || contentKey) && !(state.message || state.assets.length > 0) && (
{ !state.conflict && !state.busy && (!state.locked || contentKey) && !(state.message || state.assets.length > 0) && (
<MatIcons name="send-outline" size={20} color={Colors.lightgrey} />
)}
</TouchableOpacity>

View File

@ -23,6 +23,7 @@ export function useAddTopic(contentKey) {
enableAudio: false,
enableVideo: false,
locked: true,
conflict: false,
});
const assetId = useRef(0);
@ -34,6 +35,25 @@ export function useAddTopic(contentKey) {
setState((s) => ({ ...s, ...value }));
}
useEffect(() => {
let conflict = false;
if (state.locked) {
conflict = true;
}
state.assets.forEach(asset => {
if (asset.type === 'image' && !state.enableImage) {
conflict = true;
}
if (asset.video === 'video' && !state.enableVideo) {
conflict = true;
}
if (asset.audio === 'audio' && !state.enableAudio) {
conflict = true;
}
});
updateState({ conflict });
}, [state.assets, state.locked, state.enableImage, state.enableAudio, state.enableVideo]);
useEffect(() => {
const cardId = conversation.state.card?.card?.cardId;
const channelId = conversation.state.channel?.channelId;