From 3052d5e1b90a9e039e6b81b5dcf3c449f34fadec Mon Sep 17 00:00:00 2001 From: balzack Date: Wed, 6 Sep 2023 00:00:22 -0700 Subject: [PATCH] re-supporting blocked contacts --- app/mobile/src/constants/Strings.js | 4 +- app/mobile/src/context/useCardContext.hook.js | 10 +-- app/mobile/src/session/settings/Settings.jsx | 66 ++++++++++++++++--- .../src/session/settings/Settings.styled.js | 11 ++++ .../src/session/settings/useSettings.hook.js | 19 ++++++ 5 files changed, 95 insertions(+), 15 deletions(-) diff --git a/app/mobile/src/constants/Strings.js b/app/mobile/src/constants/Strings.js index b60b06b0..dc6717d3 100644 --- a/app/mobile/src/constants/Strings.js +++ b/app/mobile/src/constants/Strings.js @@ -137,7 +137,7 @@ const Strings = [ restoreMessage: 'Restaurer le Message?', close: 'Fermer', ok: 'OK', - noBlockedContacts: 'Aucun Contacts Bloqués', + noBlockedContacts: 'Aucun Contact Bloqués', noBlockedTopics: 'Aucun Sujet Bloqué', noBlockedMessages: 'Aucun Message Bloqué', restore: 'Restaurer', @@ -206,7 +206,7 @@ const Strings = [ restoreMessage: 'Restaurar Mensaje?', close: 'Cerrar', ok: 'OK', - noBlockedContacts: 'No Hay ContactosBbloqueados', + noBlockedContacts: 'No Hay Contactos Bloqueados', noBlockedTopics: 'No Hay Temas Bloqueados ', noBlockedMessages: 'No Hay Mensajes Bloqueados', restore: 'Restaurar', diff --git a/app/mobile/src/context/useCardContext.hook.js b/app/mobile/src/context/useCardContext.hook.js index d386d2dd..21faf966 100644 --- a/app/mobile/src/context/useCardContext.hook.js +++ b/app/mobile/src/context/useCardContext.hook.js @@ -63,13 +63,13 @@ export function useCardContext() { } const setCardField = (cardId, field, value) => { - const card = cards.current.get(cardId); - if (card) { - card[field] = value; - cards.current.set(cardId, { ...card }); + const item = cards.current.get(cardId); + if (item?.card) { + item.card[field] = value; + cards.current.set(cardId, { ...item }); updateState({ cards: cards.current }); } - }; + } const setCardChannelItem = (cardChannel) => { return { diff --git a/app/mobile/src/session/settings/Settings.jsx b/app/mobile/src/session/settings/Settings.jsx index dbdddce5..0c643c0b 100644 --- a/app/mobile/src/session/settings/Settings.jsx +++ b/app/mobile/src/session/settings/Settings.jsx @@ -47,7 +47,21 @@ export function Settings() { } } - const unblockContact = (cardId) => { + const unblock = async (action, id) => { + if (!busy) { + try { + setBusy(true); + await action(id); + } + catch (err) { + console.log(err); + Alert.alert( + state.strings.error, + state.strings.tryAgain, + ); + } + setBusy(false); + } }; const logout = async () => { @@ -105,16 +119,24 @@ export function Settings() { const BlockedContact = ({ item }) => { return ( - unblockContact(item.cardId)}> + { item.name } { item.handle } - { state.strings.restore } - + unblock(actions.unblockContact, item.cardId)}> + { state.strings.restore } + + ) - } + }; + + const BlockedTopic = ({ item }) => { + }; + + const BlockedMessage = ({ item }) => { + }; return ( @@ -611,7 +633,9 @@ export function Settings() { { state.contacts.length === 0 && ( - { state.strings.noBlockContacts } + + { state.strings.noBlockedContacts } + )} { state.contacts.length !== 0 && ( { state.strings.blockedTopics } - + + { state.topics.length === 0 && ( + + { state.strings.noBlockedTopics } + + )} + { state.contacts.length !== 0 && ( + item.topicId} + /> + )} + { state.strings.close } @@ -672,7 +709,20 @@ export function Settings() { { state.strings.blockedMessages } - + + { state.messages.length === 0 && ( + + { state.strings.noBlockedMessages } + + )} + { state.contacts.length !== 0 && ( + item.messageId} + /> + )} + { state.strings.close } diff --git a/app/mobile/src/session/settings/Settings.styled.js b/app/mobile/src/session/settings/Settings.styled.js index c8895963..50fe7b4d 100644 --- a/app/mobile/src/session/settings/Settings.styled.js +++ b/app/mobile/src/session/settings/Settings.styled.js @@ -350,6 +350,17 @@ export const styles = StyleSheet.create({ color: Colors.text, fontSize: 14, }, + emptyLabel: { + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + height: 128, + }, + emptyLabelText: { + fontFamily: 'roboto', + fontSize: 16, + color: Colors.inputPlaceholder, + }, handle: { color: Colors.text, fontSize: 12, diff --git a/app/mobile/src/session/settings/useSettings.hook.js b/app/mobile/src/session/settings/useSettings.hook.js index f0075220..61bf6ad2 100644 --- a/app/mobile/src/session/settings/useSettings.hook.js +++ b/app/mobile/src/session/settings/useSettings.hook.js @@ -4,6 +4,7 @@ import { getLanguageStrings } from 'constants/Strings'; import { ProfileContext } from 'context/ProfileContext'; import { AccountContext } from 'context/AccountContext'; import { CardContext } from 'context/CardContext'; +import { ChannelContext } from 'context/ChannelContext'; import { AppContext } from 'context/AppContext'; import { generateSeal, updateSeal, unlockSeal } from 'context/sealUtil'; import { DisplayContext } from 'context/DisplayContext'; @@ -14,6 +15,7 @@ export function useSettings() { const account = useContext(AccountContext); const app = useContext(AppContext); const card = useContext(CardContext); + const channel = useContext(ChannelContext); const display = useContext(DisplayContext); const debounce = useRef(null); @@ -98,8 +100,22 @@ export function useSettings() { return 1; }); updateState({ contacts: filtered }); + + cards.forEach(contact => { + const channels = Array.from(contact.channels); + channels.forEach(item => { + console.log(item.blocked); + }); + }); }, [card.state]); + useEffect(() => { + const channels = Array.from(channel.state.channels); + channels.forEach(item => { + console.log(item.blocked); + }); + }, [channel.state]); + const unlockKey = async () => { const sealKey = unlockSeal(state.seal, state.sealPassword); await account.actions.unlockAccountSeal(sealKey); @@ -268,6 +284,9 @@ export function useSettings() { removeKey: async () => { await removeKey(); }, + unblockContact: async (cardId) => { + await card.actions.clearCardFlag(cardId); + }, }; return { state, actions };