support for unblocking messages

This commit is contained in:
Roland Osborne 2022-10-18 14:52:13 -07:00
parent 8771eba2ed
commit a86556c993
6 changed files with 84 additions and 5 deletions

View File

@ -473,6 +473,14 @@ export function useCardContext() {
const { guid } = session.current; const { guid } = session.current;
await store.actions.setCardChannelTopicBlocked(guid, cardId, channelId, topicId, true); await store.actions.setCardChannelTopicBlocked(guid, cardId, channelId, topicId, true);
}, },
clearChannelTopicBlocked: async (cardId, channelId, topicId) => {
const { guid } = session.current;
await store.actions.setCardChannelTopicBlocked(guid, cardId, channelId, topicId, false);
},
getChannelTopicBlocked: async () => {
const { guid } = session.current;
return await store.actions.getCardChannelTopicBlocked(guid);
},
getChannelTopicItems: async (cardId, channelId) => { getChannelTopicItems: async (cardId, channelId) => {
const { guid } = session.current; const { guid } = session.current;
return await store.actions.getCardChannelTopicItems(guid, cardId, channelId); return await store.actions.getCardChannelTopicItems(guid, cardId, channelId);

View File

@ -204,6 +204,14 @@ export function useChannelContext() {
const { guid } = session.current; const { guid } = session.current;
await store.actions.setChannelTopicBlocked(guid, channelId, topicId, true); await store.actions.setChannelTopicBlocked(guid, channelId, topicId, true);
}, },
clearTopicBlocked: async (channelId, topicId) => {
const { guid } = session.current;
await store.actions.setChannelTopicBlocked(guid, channelId, topicId, false);
},
getTopicBlocked: async () => {
const { guid } = session.current;
return await store.actions.getChannelTopicBlocked(guid);
},
getTopicItems: async (channelId) => { getTopicItems: async (channelId) => {
const { guid } = session.current; const { guid } = session.current;
return await store.actions.getChannelTopicItems(guid, channelId); return await store.actions.getChannelTopicItems(guid, channelId);

View File

@ -422,11 +422,25 @@ export function useConversationContext() {
await channel.actions.setTopicBlocked(channelId, topicId); await channel.actions.setTopicBlocked(channelId, topicId);
} }
const topic = topics.current.get(topicId); const topic = topics.current.get(topicId);
topic.blocked = 1; if (topic) {
force.current = true; topic.blocked = 1;
sync(); force.current = true;
sync();
}
} }
}, },
unblockTopic: async (cardId, channelId, topicId) => {
if (conversationId.current) {
if (conversationId.current.cardId == cardId && conversationId.current.channelId == channelId) {
const topic = topics.current.get(topicId);
if (topic) {
topic.blocked = 0;
force.current = true;
sync();
}
}
}
}
} }
return { state, actions } return { state, actions }

View File

@ -257,7 +257,15 @@ export function useStoreContext() {
await db.current.executeSql(`DELETE FROM channel_topic_${guid} WHERE channel_id=?`, [channelId]); await db.current.executeSql(`DELETE FROM channel_topic_${guid} WHERE channel_id=?`, [channelId]);
}, },
setChannelTopicBlocked: async (guid, channelId, topicId, blocked) => { setChannelTopicBlocked: async (guid, channelId, topicId, blocked) => {
let ret = await db.current.executeSql(`UPDATE channel_topic_${guid} set blocked=? WHERE channel_id=? and topic_id=?`, [blocked, channelId, topicId]); await db.current.executeSql(`UPDATE channel_topic_${guid} set blocked=? WHERE channel_id=? and topic_id=?`, [blocked, channelId, topicId]);
},
getChannelTopicBlocked: async (guid) => {
const values = await getAppValues(db.current, `SELECT channel_id, topic_id, detail FROM channel_topic_${guid} WHERE blocked=?`, [1]);
return values.map(topic => ({
channelId: topic.channel_id,
topicId: topic.topic_id,
detail: decodeObject(topic.detail),
}));
}, },
setCardChannelItem: async (guid, cardId, channel) => { setCardChannelItem: async (guid, cardId, channel) => {
@ -321,7 +329,7 @@ export function useStoreContext() {
detailRevision: topic.detail_revision, detailRevision: topic.detail_revision,
detail: decodeObject(topic.detail), detail: decodeObject(topic.detail),
})); }));
}, },
setCardChannelTopicItem: async (guid, cardId, channelId, topic) => { setCardChannelTopicItem: async (guid, cardId, channelId, topic) => {
const { id, revision, data } = topic; const { id, revision, data } = topic;
await db.current.executeSql(`INSERT OR REPLACE INTO card_channel_topic_${guid} (card_id, channel_id, topic_id, revision, detail_revision, detail) values (?, ?, ?, ?, ?, ?);`, [cardId, channelId, id, revision, data.detailRevision, encodeObject(data.topicDetail)]); await db.current.executeSql(`INSERT OR REPLACE INTO card_channel_topic_${guid} (card_id, channel_id, topic_id, revision, detail_revision, detail) values (?, ?, ?, ?, ?, ?);`, [cardId, channelId, id, revision, data.detailRevision, encodeObject(data.topicDetail)]);
@ -335,6 +343,15 @@ export function useStoreContext() {
setCardChannelTopicBlocked: async (guid, cardId, channelId, topicId, blocked) => { setCardChannelTopicBlocked: async (guid, cardId, channelId, topicId, blocked) => {
await db.current.executeSql(`UPDATE card_channel_topic_${guid} set blocked=? WHERE card_id=? and channel_id=? and topic_id=?`, [blocked ? 1 : 0, cardId, channelId, topicId]); await db.current.executeSql(`UPDATE card_channel_topic_${guid} set blocked=? WHERE card_id=? and channel_id=? and topic_id=?`, [blocked ? 1 : 0, cardId, channelId, topicId]);
}, },
getCardChannelTopicBlocked: async (guid) => {
const values = await getAppValues(db.current, `SELECT card_id, channel_id, topic_id, detail FROM card_channel_topic_${guid} WHERE blocked=?`, [1]);
return values.map(topic => ({
cardId: topic.card_id,
channelId: topic.channel_id,
topicId: topic.topic_id,
detail: decodeObject(topic.detail),
}));
},
} }
return { state, actions } return { state, actions }
} }

View File

@ -9,6 +9,7 @@ import ImagePicker from 'react-native-image-crop-picker'
import { SafeAreaView } from 'react-native-safe-area-context'; import { SafeAreaView } from 'react-native-safe-area-context';
import { BlockedTopics } from './blockedTopics/BlockedTopics'; import { BlockedTopics } from './blockedTopics/BlockedTopics';
import { BlockedContacts } from './blockedContacts/BlockedContacts'; import { BlockedContacts } from './blockedContacts/BlockedContacts';
import { BlockedMessages } from './blockedMessages/BlockedMessages';
export function ProfileTitle(props) { export function ProfileTitle(props) {
const { state, actions } = useProfile(); const { state, actions } = useProfile();
@ -149,6 +150,9 @@ export function Profile() {
<TouchableOpacity style={styles.link} onPress={actions.showBlockedChannels}> <TouchableOpacity style={styles.link} onPress={actions.showBlockedChannels}>
<Text style={styles.linkText}>Manage Blocked Topics</Text> <Text style={styles.linkText}>Manage Blocked Topics</Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity style={styles.link} onPress={actions.showBlockedMessages}>
<Text style={styles.linkText}>Manage Blocked Messages</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.logout} onPress={logout}> <TouchableOpacity style={styles.logout} onPress={logout}>
<Ionicons name="logout" size={14} color={Colors.white} /> <Ionicons name="logout" size={14} color={Colors.white} />
<Text style={styles.logoutText}>Logout</Text> <Text style={styles.logoutText}>Logout</Text>
@ -214,6 +218,27 @@ export function Profile() {
</View> </View>
</KeyboardAvoidingView> </KeyboardAvoidingView>
</Modal> </Modal>
<Modal
animationType="fade"
transparent={true}
visible={state.blockedMessages}
supportedOrientations={['portrait', 'landscape']}
onRequestClose={actions.hideBlockedMessages}
>
<KeyboardAvoidingView behavior="height" style={styles.editWrapper}>
<View style={styles.editContainer}>
<Text style={styles.editHeader}>Blocked Messages:</Text>
<View style={styles.editList}>
<BlockedMessages />
</View>
<View style={styles.editControls}>
<TouchableOpacity style={styles.close} onPress={actions.hideBlockedMessages}>
<Text>Close</Text>
</TouchableOpacity>
</View>
</View>
</KeyboardAvoidingView>
</Modal>
<Modal <Modal
animationType="fade" animationType="fade"
transparent={true} transparent={true}

View File

@ -30,6 +30,7 @@ export function useProfile() {
showConfirm: false, showConfirm: false,
blockedChannels: false, blockedChannels: false,
blockedCards: false, blockedCards: false,
blockedMessages: false,
tabbed: null, tabbed: null,
disconnected: false, disconnected: false,
}); });
@ -94,6 +95,12 @@ export function useProfile() {
hideBlockedCards: () => { hideBlockedCards: () => {
updateState({ blockedCards: false }); updateState({ blockedCards: false });
}, },
showBlockedMessages: () => {
updateState({ blockedMessages: true });
},
hideBlockedMessages: () => {
updateState({ blockedMessages: false });
},
showLoginEdit: () => { showLoginEdit: () => {
updateState({ showLoginEdit: true }); updateState({ showLoginEdit: true });
}, },