diff --git a/app/mobile/src/context/useCardContext.hook.js b/app/mobile/src/context/useCardContext.hook.js index 116b8c86..01e6cf7f 100644 --- a/app/mobile/src/context/useCardContext.hook.js +++ b/app/mobile/src/context/useCardContext.hook.js @@ -469,6 +469,10 @@ export function useCardContext() { setCardChannelBlocked(cardId, channelId, false); updateState({ cards: cards.current }); }, + setChannelTopicBlocked: async (cardId, channelId, topicId) => { + const { guid } = session.current; + await store.actions.setCardChannelTopicBlocked(guid, cardId, channelId, topicId, true); + }, getChannelTopicItems: async (cardId, channelId) => { const { guid } = session.current; return await store.actions.getCardChannelTopicItems(guid, cardId, channelId); diff --git a/app/mobile/src/context/useChannelContext.hook.js b/app/mobile/src/context/useChannelContext.hook.js index 80478915..cc23d844 100644 --- a/app/mobile/src/context/useChannelContext.hook.js +++ b/app/mobile/src/context/useChannelContext.hook.js @@ -200,6 +200,10 @@ export function useChannelContext() { setChannelBlocked(channelId, 0); updateState({ channels: channels.current }); }, + setTopicBlocked: async (channelId, topicId) => { + const { guid } = session.current; + await store.actions.setChannelTopicBlocked(guid, channelId, topicId, true); + }, getTopicItems: async (channelId) => { const { guid } = session.current; return await store.actions.getChannelTopicItems(guid, channelId); diff --git a/app/mobile/src/context/useConversationContext.hook.js b/app/mobile/src/context/useConversationContext.hook.js index 2c3daf80..f93a5c44 100644 --- a/app/mobile/src/context/useConversationContext.hook.js +++ b/app/mobile/src/context/useConversationContext.hook.js @@ -13,7 +13,7 @@ export function useConversationContext() { revision: null, contacts: [], topics: new Map(), - createed: null, + created: null, host: null, }); const store = useContext(StoreContext); @@ -412,6 +412,21 @@ export function useConversationContext() { } } }, + blockTopic: async (topicId) => { + if (conversationId.current) { + const { cardId, channelId } = conversationId.current; + if (cardId) { + await card.actions.setChannelTopicBlocked(cardId, channelId, topicId); + } + else { + await channel.actions.setTopicBlocked(channelId, topicId); + } + const topic = topics.current.get(topicId); + topic.blocked = 1; + force.current = true; + sync(); + } + }, } return { state, actions } diff --git a/app/mobile/src/context/useStoreContext.hook.js b/app/mobile/src/context/useStoreContext.hook.js index 2b9b7aa3..58b05e02 100644 --- a/app/mobile/src/context/useStoreContext.hook.js +++ b/app/mobile/src/context/useStoreContext.hook.js @@ -1,7 +1,7 @@ import { useEffect, useState, useRef, useContext } from 'react'; import SQLite from "react-native-sqlite-storage"; -const DATABAG_DB = 'databag_v041.db'; +const DATABAG_DB = 'databag_v042.db'; export function useStoreContext() { const [state, setState] = useState({}); @@ -13,10 +13,10 @@ export function useStoreContext() { const initSession = async (guid) => { await db.current.executeSql(`CREATE TABLE IF NOT EXISTS channel_${guid} (channel_id text, revision integer, detail_revision integer, topic_revision integer, blocked integer, sync_revision integer, detail text, summary text, offsync integer, read_revision integer, unique(channel_id))`); - await db.current.executeSql(`CREATE TABLE IF NOT EXISTS channel_topic_${guid} (channel_id text, topic_id text, revision integer, detail_revision integer, detail text, unique(channel_id, topic_id))`); + await db.current.executeSql(`CREATE TABLE IF NOT EXISTS channel_topic_${guid} (channel_id text, topic_id text, revision integer, detail_revision integer, blocked integer, detail text, unique(channel_id, topic_id))`); await db.current.executeSql(`CREATE TABLE IF NOT EXISTS card_${guid} (card_id text, revision integer, detail_revision integer, profile_revision integer, detail text, profile text, notified_view integer, notified_article integer, notified_profile integer, notified_channel integer, offsync integer, blocked integer, unique(card_id))`); await db.current.executeSql(`CREATE TABLE IF NOT EXISTS card_channel_${guid} (card_id text, channel_id text, revision integer, detail_revision integer, topic_revision integer, sync_revision integer, detail text, summary text, offsync integer, blocked integer, read_revision integer, unique(card_id, channel_id))`); - await db.current.executeSql(`CREATE TABLE IF NOT EXISTS card_channel_topic_${guid} (card_id text, channel_id text, topic_id text, revision integer, detail_revision integer, detail text, unique(card_id, channel_id, topic_id))`); + await db.current.executeSql(`CREATE TABLE IF NOT EXISTS card_channel_topic_${guid} (card_id text, channel_id text, topic_id text, revision integer, detail_revision integer, blocked integer, detail text, unique(card_id, channel_id, topic_id))`); } const actions = { @@ -237,10 +237,11 @@ export function useStoreContext() { getChannelTopicItems: async (guid, channelId) => { - const values = await getAppValues(db.current, `SELECT topic_id, revision, detail_revision, detail FROM channel_topic_${guid} WHERE channel_id=?`, [channelId]); + const values = await getAppValues(db.current, `SELECT topic_id, revision, blocked, detail_revision, detail FROM channel_topic_${guid} WHERE channel_id=?`, [channelId]); return values.map(topic => ({ topicId: topic.topic_id, revision: topic.revision, + blocked: topic.blocked, detailRevision: topic.detail_revision, detail: decodeObject(topic.detail), })); @@ -255,6 +256,9 @@ export function useStoreContext() { clearChannelTopicItems: async (guid, channelId) => { await db.current.executeSql(`DELETE FROM channel_topic_${guid} WHERE channel_id=?`, [channelId]); }, + 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]); + }, setCardChannelItem: async (guid, cardId, channel) => { const { id, revision, data } = channel; @@ -309,10 +313,11 @@ export function useStoreContext() { }, getCardChannelTopicItems: async (guid, cardId, channelId) => { - const values = await getAppValues(db.current, `SELECT topic_id, revision, detail_revision, detail FROM card_channel_topic_${guid} WHERE card_id=? AND channel_id=?`, [cardId, channelId]); + const values = await getAppValues(db.current, `SELECT topic_id, revision, blocked, detail_revision, detail FROM card_channel_topic_${guid} WHERE card_id=? AND channel_id=?`, [cardId, channelId]); return values.map(topic => ({ topicId: topic.topic_id, revision: topic.revision, + blocked: topic.blocked, detailRevision: topic.detail_revision, detail: decodeObject(topic.detail), })); @@ -327,7 +332,9 @@ export function useStoreContext() { clearCardChannelTopicItems: async (guid, cardId, channelId) => { await db.current.executeSql(`DELETE FROM card_channel_topic_${guid} WHERE card_id=? and channel_id=?`, [cardId, channelId]); }, - + 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]); + }, } return { state, actions } } diff --git a/app/mobile/src/session/conversation/Conversation.jsx b/app/mobile/src/session/conversation/Conversation.jsx index cc8c55cb..d3fc17f0 100644 --- a/app/mobile/src/session/conversation/Conversation.jsx +++ b/app/mobile/src/session/conversation/Conversation.jsx @@ -60,7 +60,7 @@ export function ConversationBody() { inverted={true} renderItem={({item}) => actions.setFocus(item.topicId)} hosting={state.host == null} - remove={actions.removeTopic} update={actions.updateTopic} />} + remove={actions.removeTopic} update={actions.updateTopic} block={actions.blockTopic} />} keyExtractor={item => item.topicId} /> diff --git a/app/mobile/src/session/conversation/Conversation.styled.js b/app/mobile/src/session/conversation/Conversation.styled.js index 401176ff..ce404114 100644 --- a/app/mobile/src/session/conversation/Conversation.styled.js +++ b/app/mobile/src/session/conversation/Conversation.styled.js @@ -96,7 +96,7 @@ export const styles = StyleSheet.create({ width: '100%', }, latch: { - backgroundColor: Colors.formBackground, + backgroundColor: Colors.white, borderRadius: 12, borderWidth: 1, padding: 4, diff --git a/app/mobile/src/session/conversation/topicItem/TopicItem.jsx b/app/mobile/src/session/conversation/topicItem/TopicItem.jsx index 08fcc71f..57d98b29 100644 --- a/app/mobile/src/session/conversation/topicItem/TopicItem.jsx +++ b/app/mobile/src/session/conversation/topicItem/TopicItem.jsx @@ -16,7 +16,7 @@ import Carousel from 'react-native-snap-carousel'; import GestureRecognizer from 'react-native-swipe-gestures'; import avatar from 'images/avatar.png'; -export function TopicItem({ item, focused, focus, hosting, remove, update }) { +export function TopicItem({ item, focused, focus, hosting, remove, update, block }) { const { state, actions } = useTopicItem(item, hosting); @@ -60,7 +60,7 @@ export function TopicItem({ item, focused, focus, hosting, remove, update }) { } } - const block = () => { + const hideMessage = () => { Alert.alert( "Blocking Message", "Confirm?", @@ -71,7 +71,7 @@ export function TopicItem({ item, focused, focus, hosting, remove, update }) { { text: "Block", onPress: async () => { try { - await actions.block(); + await block(item.topicId); } catch (err) { console.log(err); @@ -213,7 +213,7 @@ export function TopicItem({ item, focused, focus, hosting, remove, update }) { )} - + { state.deletable && ( diff --git a/app/mobile/src/session/conversation/useConversation.hook.js b/app/mobile/src/session/conversation/useConversation.hook.js index 2b4dc1da..30112ae3 100644 --- a/app/mobile/src/session/conversation/useConversation.hook.js +++ b/app/mobile/src/session/conversation/useConversation.hook.js @@ -33,7 +33,8 @@ export function useConversation() { } return -1; }); - updateState({ topics, subject, logo, host, topics: sorted }); + const filtered = sorted.filter(item => !(item.blocked === 1)); + updateState({ topics, subject, logo, host, topics: filtered }); }, [conversation]); const actions = { @@ -58,6 +59,9 @@ export function useConversation() { updateTopic: async (topicId, data) => { await conversation.actions.setTopicSubject(topicId, data); }, + blockTopic: async (topicId) => { + await conversation.actions.blockTopic(topicId); + } }; return { state, actions };