-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reenable header, add disable e2ee on header if needed, disable most o…
…f actions on RoomActionsView
- Loading branch information
1 parent
354e156
commit 9c796e0
Showing
9 changed files
with
196 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Alert } from 'react-native'; | ||
|
||
import { Services } from '../../services'; | ||
import database from '../../database'; | ||
import { getSubscriptionByRoomId } from '../../database/services/Subscription'; | ||
import log from '../../methods/helpers/log'; | ||
import I18n from '../../../i18n'; | ||
|
||
export const toggleRoomE2EE = async (rid: string): Promise<void> => { | ||
const room = await getSubscriptionByRoomId(rid); | ||
if (!room) { | ||
return; | ||
} | ||
|
||
const isEncrypted = room.encrypted; | ||
const title = I18n.t(isEncrypted ? 'Disable_encryption_title' : 'Enable_encryption_title'); | ||
const message = I18n.t(isEncrypted ? 'Disable_encryption_description' : 'Enable_encryption_description'); | ||
const confirmationText = I18n.t(isEncrypted ? 'Disable' : 'Enable'); | ||
|
||
Alert.alert( | ||
title, | ||
message, | ||
[ | ||
{ | ||
text: I18n.t('Cancel'), | ||
style: 'cancel' | ||
}, | ||
{ | ||
text: confirmationText, | ||
style: isEncrypted ? 'destructive' : 'default', | ||
onPress: async () => { | ||
try { | ||
const db = database.active; | ||
|
||
// Toggle encrypted value | ||
const encrypted = !room.encrypted; | ||
|
||
// Instantly feedback to the user | ||
await db.write(async () => { | ||
await room.update(r => { | ||
r.encrypted = encrypted; | ||
}); | ||
}); | ||
|
||
try { | ||
// Send new room setting value to server | ||
const { result } = await Services.saveRoomSettings(rid, { encrypted }); | ||
// If it was saved successfully | ||
if (result) { | ||
return; | ||
} | ||
} catch { | ||
// do nothing | ||
} | ||
|
||
// If something goes wrong we go back to the previous value | ||
await db.write(async () => { | ||
await room.update(r => { | ||
r.encrypted = room.encrypted; | ||
}); | ||
}); | ||
} catch (e) { | ||
log(e); | ||
} | ||
} | ||
} | ||
], | ||
{ cancelable: true } | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.