Skip to content

Commit

Permalink
allow disabling of binary attachments in mobile app
Browse files Browse the repository at this point in the history
  • Loading branch information
balzack committed May 3, 2024
1 parent 3b7de54 commit 0bcb289
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
6 changes: 6 additions & 0 deletions app/mobile/src/constants/Strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const Strings = [
enableImage: 'Enable Image Queue',
enableAudio: 'Enable Audio Queue',
enableVideo: 'Enable Video Queue',
enableBinary: 'Enable Binary Files',
enableCalls: 'Enable WebRTC Calls',
relayUrl: 'Relay URL',
relayUsername: 'Relay Username',
Expand Down Expand Up @@ -356,6 +357,7 @@ const Strings = [
enableImage: 'Activer les Fichiers Image',
enableAudio: 'Activer les Fichiers Audio',
enableVideo: 'Activer les Fichiers Vidéo',
enableBinary: 'Activer les Fichiers Binaires',
enableCalls: 'Activer les Appels',
relayUrl: 'URL de Relais',
relayUsername: 'Nom d\'Utilisateur du Relais',
Expand Down Expand Up @@ -554,6 +556,7 @@ const Strings = [
enableImage: 'Permitir Archivos de Imagen',
enableAudio: 'Permitir Archivos de Audio',
enableVideo: 'Permitir Archivos de Vídeo',
enableBinary: 'Permitir Archivos Binarios',
enableCalls: 'Permitier Llamadas',
relayUrl: 'URL para Llamadas',
relayUsername: 'Nombre de Usuario para Llamadas',
Expand Down Expand Up @@ -753,6 +756,7 @@ const Strings = [
enableImage: 'Bilddateien Aktivieren',
enableAudio: 'Audiodateien Aktivieren',
enableVideo: 'Videodateien aktivieren',
enableBinary: 'Binärdateien aktivieren',
enableCalls: 'Anrufe Ermöglichen',
relayUrl: 'URL für Anrufe',
relayUsername: 'Benutzername für Anrufe',
Expand Down Expand Up @@ -940,6 +944,7 @@ const Strings = [
enableImage: 'Habilitar Fila de Imagens',
enableAudio: 'Habilitar Fila de Áudio',
enableVideo: 'Habilitar Fila de Vídeo',
enableBinary: 'Habilitar Fila Binários',
enableCalls: 'Habilitar Chamadas WebRTC',
relayUrl: 'URL do Relay',
relayUsername: 'Nome de Usuário do Relay',
Expand Down Expand Up @@ -1124,6 +1129,7 @@ const Strings = [
enableImage: 'Включить очередь изображений',
enableAudio: 'Включить очередь аудио',
enableVideo: 'Включить очередь видео',
enableBinary: 'Включить двоичные файлы',
enableCalls: 'Включить звонки WebRTC',
relayUrl: 'URL релея',
relayUsername: 'Имя пользователя релея',
Expand Down
6 changes: 6 additions & 0 deletions app/mobile/src/dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ export function Dashboard(props) {
<Switch style={styles.switch} value={state.enableVideo}
onValueChange={actions.setEnableVideo} trackColor={styles.track}/>
</TouchableOpacity>
<TouchableOpacity style={styles.media} activeOpacity={1}
onPress={() => actions.setEnableBinary(!state.enableBinary)}>
<Text style={styles.modalLabel}>{ state.strings.enableBinary }</Text>
<Switch style={styles.switch} value={state.enableBinary}
onValueChange={actions.setEnableBinary} trackColor={styles.track}/>
</TouchableOpacity>

<View style={styles.label}></View>
<TouchableOpacity style={styles.ice} activeOpacity={1}
Expand Down
12 changes: 8 additions & 4 deletions app/mobile/src/dashboard/useDashboard.hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function useDashboard(config, server, token) {
enableImage: true,
enableAudio: true,
enableVideo: true,
enableBinary: true,
createToken: null,
enableIce: false,
iceUrl: null,
Expand Down Expand Up @@ -67,9 +68,9 @@ export function useDashboard(config, server, token) {
};

useEffect(() => {
const { keyType, accountStorage, domain, enableImage, enableAudio, enableVideo, transformSupported, allowUnsealed, pushSupported, enableIce, iceUrl, iceUsername, icePassword } = config;
const { keyType, accountStorage, domain, enableImage, enableAudio, enableVideo, enableBinary, transformSupported, allowUnsealed, pushSupported, enableIce, iceUrl, iceUsername, icePassword } = config;
const storage = Math.ceil(accountStorage / 1073741824);
updateState({ keyType, storage: storage.toString(), domain, enableImage, enableAudio, enableVideo, transformSupported, allowUnsealed, pushSupported, enableIce, iceUrl, iceUsername, icePassword });
updateState({ keyType, storage: storage.toString(), domain, enableImage, enableAudio, enableVideo, enableBinary, transformSupported, allowUnsealed, pushSupported, enableIce, iceUrl, iceUsername, icePassword });
}, [config]);

useEffect(() => {
Expand Down Expand Up @@ -124,6 +125,9 @@ export function useDashboard(config, server, token) {
setEnableVideo: (enableVideo) => {
updateState({ enableVideo });
},
setEnableBinary: (enableBinary) => {
updateState({ enableBinary });
},
setKeyType: (keyType) => {
updateState({ keyType });
},
Expand All @@ -140,9 +144,9 @@ export function useDashboard(config, server, token) {
updateState({ icePassword });
},
saveConfig: async () => {
const { storage, domain, keyType, enableImage, pushSupported, allowUnsealed, transformSupported, enableAudio, enableVideo, enableIce, iceUrl, iceUsername, icePassword } = state;
const { storage, domain, keyType, enableImage, pushSupported, allowUnsealed, transformSupported, enableAudio, enableVideo, enableBinary, enableIce, iceUrl, iceUsername, icePassword } = state;
const accountStorage = Number(storage) * 1073741824;
const config = { accountStorage, domain, keyType, enableImage, pushSupported, allowUnsealed, transformSupported, enableAudio, enableVideo, enableIce, iceUrl, iceUsername, icePassword };
const config = { accountStorage, domain, keyType, enableImage, pushSupported, allowUnsealed, transformSupported, enableAudio, enableVideo, enableBinary, enableIce, iceUrl, iceUsername, icePassword };
await setNodeConfig(server, token, config);
},
enableUser: async (accountId, enabled) => {
Expand Down
8 changes: 5 additions & 3 deletions app/mobile/src/session/conversation/addTopic/AddTopic.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,11 @@ export function AddTopic({ contentKey, shareIntent, setShareIntent }) {
<MatIcons name="music-note" size={24} color={Colors.text} />
</TouchableOpacity>
)}
<TouchableOpacity style={styles.addButton} onPress={addBinary}>
<MatIcons name="file-outline" size={24} color={Colors.text} />
</TouchableOpacity>
{ state.enableBinary && (
<TouchableOpacity style={styles.addButton} onPress={addBinary}>
<MatIcons name="file-outline" size={24} color={Colors.text} />
</TouchableOpacity>
)}
<View style={styles.divider} />
<TouchableOpacity style={styles.addButton} onPress={actions.showFontSize}>
<MatIcons name="format-size" size={24} color={Colors.text} />
Expand Down
17 changes: 9 additions & 8 deletions app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function useAddTopic(contentKey) {
enableImage: false,
enableAudio: false,
enableVideo: false,
enableBinary: false,
locked: true,
loaded: false,
conflict: false,
Expand All @@ -50,15 +51,18 @@ export function useAddTopic(contentKey) {
if (asset.type === 'image' && !state.enableImage) {
conflict = true;
}
if (asset.video === 'video' && !state.enableVideo) {
if (asset.type === 'video' && !state.enableVideo) {
conflict = true;
}
if (asset.audio === 'audio' && !state.enableAudio) {
if (asset.type === 'audio' && !state.enableAudio) {
conflict = true;
}
if (asset.type === 'binary' && !state.enableBinary) {
conflict = true;
}
});
updateState({ conflict });
}, [state.assets, state.locked, state.enableImage, state.enableAudio, state.enableVideo]);
}, [state.assets, state.locked, state.enableImage, state.enableAudio, state.enableVideo, state.enableBinary]);

useEffect(() => {
updateState({ assets: [] });
Expand Down Expand Up @@ -105,10 +109,10 @@ export function useAddTopic(contentKey) {
}, [upload.state, conversation.state]);

useEffect(() => {
const { enableVideo, enableAudio, enableImage } = conversation.state.channel?.detail || {};
const { enableVideo, enableAudio, enableImage, enableBinary } = conversation.state.channel?.detail || {};
const locked = conversation.state.channel?.detail?.dataType === 'superbasic' ? false : true;
const loaded = conversation.state.loaded;
updateState({ enableImage, enableAudio, enableVideo, locked, loaded });
updateState({ enableImage, enableAudio, enableVideo, enableBinary, locked, loaded });
}, [conversation.state]);

const setAsset = async (file, mime, scale) => {
Expand Down Expand Up @@ -172,9 +176,6 @@ export function useAddTopic(contentKey) {
asset.type = 'binary';
asset.extension = name.split('.').pop().toUpperCase();
asset.label = name.slice(0, -1 * (asset.extension.length + 1));

console.log(asset);

updateState({ assets: [ ...state.assets, asset ] });
},
setVideoPosition: (key, position) => {
Expand Down

0 comments on commit 0bcb289

Please sign in to comment.