mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
support blocking topics
This commit is contained in:
parent
6db15568f8
commit
8771eba2ed
@ -469,6 +469,10 @@ export function useCardContext() {
|
|||||||
setCardChannelBlocked(cardId, channelId, false);
|
setCardChannelBlocked(cardId, channelId, false);
|
||||||
updateState({ cards: cards.current });
|
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) => {
|
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);
|
||||||
|
@ -200,6 +200,10 @@ export function useChannelContext() {
|
|||||||
setChannelBlocked(channelId, 0);
|
setChannelBlocked(channelId, 0);
|
||||||
updateState({ channels: channels.current });
|
updateState({ channels: channels.current });
|
||||||
},
|
},
|
||||||
|
setTopicBlocked: async (channelId, topicId) => {
|
||||||
|
const { guid } = session.current;
|
||||||
|
await store.actions.setChannelTopicBlocked(guid, channelId, topicId, true);
|
||||||
|
},
|
||||||
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);
|
||||||
|
@ -13,7 +13,7 @@ export function useConversationContext() {
|
|||||||
revision: null,
|
revision: null,
|
||||||
contacts: [],
|
contacts: [],
|
||||||
topics: new Map(),
|
topics: new Map(),
|
||||||
createed: null,
|
created: null,
|
||||||
host: null,
|
host: null,
|
||||||
});
|
});
|
||||||
const store = useContext(StoreContext);
|
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 }
|
return { state, actions }
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useEffect, useState, useRef, useContext } from 'react';
|
import { useEffect, useState, useRef, useContext } from 'react';
|
||||||
import SQLite from "react-native-sqlite-storage";
|
import SQLite from "react-native-sqlite-storage";
|
||||||
|
|
||||||
const DATABAG_DB = 'databag_v041.db';
|
const DATABAG_DB = 'databag_v042.db';
|
||||||
|
|
||||||
export function useStoreContext() {
|
export function useStoreContext() {
|
||||||
const [state, setState] = useState({});
|
const [state, setState] = useState({});
|
||||||
@ -13,10 +13,10 @@ export function useStoreContext() {
|
|||||||
|
|
||||||
const initSession = async (guid) => {
|
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_${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_${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_${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 = {
|
const actions = {
|
||||||
@ -237,10 +237,11 @@ export function useStoreContext() {
|
|||||||
|
|
||||||
|
|
||||||
getChannelTopicItems: async (guid, channelId) => {
|
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 => ({
|
return values.map(topic => ({
|
||||||
topicId: topic.topic_id,
|
topicId: topic.topic_id,
|
||||||
revision: topic.revision,
|
revision: topic.revision,
|
||||||
|
blocked: topic.blocked,
|
||||||
detailRevision: topic.detail_revision,
|
detailRevision: topic.detail_revision,
|
||||||
detail: decodeObject(topic.detail),
|
detail: decodeObject(topic.detail),
|
||||||
}));
|
}));
|
||||||
@ -255,6 +256,9 @@ export function useStoreContext() {
|
|||||||
clearChannelTopicItems: async (guid, channelId) => {
|
clearChannelTopicItems: async (guid, channelId) => {
|
||||||
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) => {
|
||||||
|
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) => {
|
setCardChannelItem: async (guid, cardId, channel) => {
|
||||||
const { id, revision, data } = channel;
|
const { id, revision, data } = channel;
|
||||||
@ -309,10 +313,11 @@ export function useStoreContext() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getCardChannelTopicItems: async (guid, cardId, channelId) => {
|
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 => ({
|
return values.map(topic => ({
|
||||||
topicId: topic.topic_id,
|
topicId: topic.topic_id,
|
||||||
revision: topic.revision,
|
revision: topic.revision,
|
||||||
|
blocked: topic.blocked,
|
||||||
detailRevision: topic.detail_revision,
|
detailRevision: topic.detail_revision,
|
||||||
detail: decodeObject(topic.detail),
|
detail: decodeObject(topic.detail),
|
||||||
}));
|
}));
|
||||||
@ -327,7 +332,9 @@ export function useStoreContext() {
|
|||||||
clearCardChannelTopicItems: async (guid, cardId, channelId) => {
|
clearCardChannelTopicItems: async (guid, cardId, channelId) => {
|
||||||
await db.current.executeSql(`DELETE FROM card_channel_topic_${guid} WHERE card_id=? and channel_id=?`, [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 }
|
return { state, actions }
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ export function ConversationBody() {
|
|||||||
inverted={true}
|
inverted={true}
|
||||||
renderItem={({item}) => <TopicItem item={item} focused={item.topicId === state.focus}
|
renderItem={({item}) => <TopicItem item={item} focused={item.topicId === state.focus}
|
||||||
focus={() => actions.setFocus(item.topicId)} hosting={state.host == null}
|
focus={() => 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}
|
keyExtractor={item => item.topicId}
|
||||||
/>
|
/>
|
||||||
<View>
|
<View>
|
||||||
|
@ -96,7 +96,7 @@ export const styles = StyleSheet.create({
|
|||||||
width: '100%',
|
width: '100%',
|
||||||
},
|
},
|
||||||
latch: {
|
latch: {
|
||||||
backgroundColor: Colors.formBackground,
|
backgroundColor: Colors.white,
|
||||||
borderRadius: 12,
|
borderRadius: 12,
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
padding: 4,
|
padding: 4,
|
||||||
|
@ -16,7 +16,7 @@ import Carousel from 'react-native-snap-carousel';
|
|||||||
import GestureRecognizer from 'react-native-swipe-gestures';
|
import GestureRecognizer from 'react-native-swipe-gestures';
|
||||||
import avatar from 'images/avatar.png';
|
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);
|
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(
|
Alert.alert(
|
||||||
"Blocking Message",
|
"Blocking Message",
|
||||||
"Confirm?",
|
"Confirm?",
|
||||||
@ -71,7 +71,7 @@ export function TopicItem({ item, focused, focus, hosting, remove, update }) {
|
|||||||
{ text: "Block",
|
{ text: "Block",
|
||||||
onPress: async () => {
|
onPress: async () => {
|
||||||
try {
|
try {
|
||||||
await actions.block();
|
await block(item.topicId);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@ -213,7 +213,7 @@ export function TopicItem({ item, focused, focus, hosting, remove, update }) {
|
|||||||
<AntIcons name="edit" size={24} color={Colors.white} />
|
<AntIcons name="edit" size={24} color={Colors.white} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)}
|
)}
|
||||||
<TouchableOpacity style={styles.icon} onPress={block}>
|
<TouchableOpacity style={styles.icon} onPress={hideMessage}>
|
||||||
<MatIcons name="block-helper" size={18} color={Colors.white} />
|
<MatIcons name="block-helper" size={18} color={Colors.white} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
{ state.deletable && (
|
{ state.deletable && (
|
||||||
|
@ -33,7 +33,8 @@ export function useConversation() {
|
|||||||
}
|
}
|
||||||
return -1;
|
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]);
|
}, [conversation]);
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
@ -58,6 +59,9 @@ export function useConversation() {
|
|||||||
updateTopic: async (topicId, data) => {
|
updateTopic: async (topicId, data) => {
|
||||||
await conversation.actions.setTopicSubject(topicId, data);
|
await conversation.actions.setTopicSubject(topicId, data);
|
||||||
},
|
},
|
||||||
|
blockTopic: async (topicId) => {
|
||||||
|
await conversation.actions.blockTopic(topicId);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return { state, actions };
|
return { state, actions };
|
||||||
|
Loading…
Reference in New Issue
Block a user