Skip to content

Commit

Permalink
fix: ignore attachments that are too big
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexogamer committed Oct 28, 2023
1 parent c3ff76a commit e4db6eb
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/MessageBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {observer} from 'mobx-react-lite';
import DocumentPicker, {
DocumentPickerResponse,
} from 'react-native-document-picker';
import FA5Icon from 'react-native-vector-icons/FontAwesome5';
import MaterialIcon from 'react-native-vector-icons/MaterialIcons';
import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons';

Expand All @@ -18,7 +17,7 @@ import {styles, currentTheme} from './Theme';
import {Text, Username} from './components/common/atoms';
import {USER_IDS} from './lib/consts';
import {ReplyingMessage} from './lib/types';
import {getReadableFileSize} from './lib/utils';
import {getReadableFileSize, showToast} from './lib/utils';

let typing = false;

Expand Down Expand Up @@ -190,25 +189,33 @@ export const MessageBox = observer((props: MessageBoxProps) => {
let res = await DocumentPicker.pickSingle({
type: [DocumentPicker.types.allFiles],
});
let isDuplicate = false;
for (const a of attachments) {
if (a.uri === res.uri) {
let tooBig = false;
if (res.size && res.size > 20000000) {
showToast('Attachments must be less than 20MB!');
tooBig = true;
}
if (!tooBig) {
let isDuplicate = false;
for (const a of attachments) {
if (a.uri === res.uri) {
console.log(
`[MESSAGEBOX] Not pushing duplicate attachment ${res.name} (${res.uri})`,
);
isDuplicate = true;
}
}

if (res.uri && !isDuplicate) {
console.log(
`[MESSAGEBOX] Not pushing duplicate attachment ${res.name} (${res.uri})`,
`[MESSAGEBOX] Pushing attachment ${res.name} (${res.uri})`,
);
isDuplicate = true;
setAttachments(existingAttachments => [
...existingAttachments,
res,
]);
console.log(attachments);
}
}
if (res.uri && !isDuplicate) {
console.log(
`[MESSAGEBOX] Pushing attachment ${res.name} (${res.uri})`,
);
setAttachments(existingAttachments => [
...existingAttachments,
res,
]);
console.log(attachments);
}
} catch (error) {
console.log(`[MESSAGEBOX] Error: ${error}`);
}
Expand Down

0 comments on commit e4db6eb

Please sign in to comment.