rendering blocked topics

This commit is contained in:
Roland Osborne 2023-09-06 10:57:47 -07:00
parent 3052d5e1b9
commit b1557bf204
3 changed files with 72 additions and 24 deletions

View File

@ -251,7 +251,7 @@ export function useStoreContext() {
topicRevision: channel.topic_revision, topicRevision: channel.topic_revision,
topicMarker: channel.topic_marker, topicMarker: channel.topic_marker,
syncRevision: channel.sync_revision, syncRevision: channel.sync_revision,
blocked: channel.blocked, blocked: channel.blocked === 1,
detail: decodeObject(channel.detail), detail: decodeObject(channel.detail),
unsealedDetail: decodeObject(channel.unsealed_detail), unsealedDetail: decodeObject(channel.unsealed_detail),
summary: decodeObject(channel.summary), summary: decodeObject(channel.summary),
@ -265,7 +265,7 @@ export function useStoreContext() {
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, blocked: topic.blocked === 1,
detailRevision: topic.detail_revision, detailRevision: topic.detail_revision,
detail: decodeObject(topic.detail), detail: decodeObject(topic.detail),
unsealedDetail: decodeObject(topic.unsealed_detail), unsealedDetail: decodeObject(topic.unsealed_detail),
@ -284,7 +284,7 @@ export function useStoreContext() {
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, blocked: topic.blocked === 1,
detailRevision: topic.detail_revision, detailRevision: topic.detail_revision,
detail: decodeObject(topic.detail), detail: decodeObject(topic.detail),
unsealedDetail: decodeObject(topic.unsealed_detail), unsealedDetail: decodeObject(topic.unsealed_detail),
@ -337,6 +337,12 @@ export function useStoreContext() {
setCardChannelItemMarkerAndSync: async (guid, cardId, channelId, marker, revision) => { setCardChannelItemMarkerAndSync: async (guid, cardId, channelId, marker, revision) => {
await db.current.executeSql(`UPDATE card_channel_${guid} set topic_marker=?, sync_revision=? where card_id=? and channel_id=?`, [marker, revision, cardId, channelId]); await db.current.executeSql(`UPDATE card_channel_${guid} set topic_marker=?, sync_revision=? where card_id=? and channel_id=?`, [marker, revision, cardId, channelId]);
}, },
setCardChannelItemBlocked: async (guid, cardId, channelId) => {
await db.current.executeSql(`UPDATE card_channel_${guid} set blocked=? where card_id=? and channel_id=?`, [1, cardId, channelId]);
},
clearCardChannelItemBlocked: async (guid, cardId, channelId) => {
await db.current.executeSql(`UPDATE card_channel_${guid} set blocked=? where card_id=? and channel_id=?`, [0, cardId, channelId]);
},
setCardChannelItemDetail: async (guid, cardId, channelId, revision, detail) => { setCardChannelItemDetail: async (guid, cardId, channelId, revision, detail) => {
await db.current.executeSql(`UPDATE card_channel_${guid} set detail_revision=?, detail=?, unsealed_detail=null where card_id=? and channel_id=?`, [revision, encodeObject(detail), cardId, channelId]); await db.current.executeSql(`UPDATE card_channel_${guid} set detail_revision=?, detail=?, unsealed_detail=null where card_id=? and channel_id=?`, [revision, encodeObject(detail), cardId, channelId]);
}, },
@ -363,7 +369,7 @@ export function useStoreContext() {
unsealedDetail: decodeObject(channel.unsealed_detail), unsealedDetail: decodeObject(channel.unsealed_detail),
summary: decodeObject(channel.summary), summary: decodeObject(channel.summary),
unsealedSummary: decodeObject(channel.unsealed_summary), unsealedSummary: decodeObject(channel.unsealed_summary),
blocked: channel.blocked, blocked: channel.blocked === 1,
})); }));
}, },
clearCardChannelItems: async (guid, cardId) => { clearCardChannelItems: async (guid, cardId) => {
@ -375,7 +381,7 @@ export function useStoreContext() {
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, blocked: topic.blocked === 1,
detailRevision: topic.detail_revision, detailRevision: topic.detail_revision,
detail: decodeObject(topic.detail), detail: decodeObject(topic.detail),
unsealedDetail: decodeObject(topic.unsealed_detail), unsealedDetail: decodeObject(topic.unsealed_detail),
@ -394,7 +400,7 @@ export function useStoreContext() {
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, blocked: topic.blocked === 1,
detailRevision: topic.detail_revision, detailRevision: topic.detail_revision,
detail: decodeObject(topic.detail), detail: decodeObject(topic.detail),
unsealedDetail: decodeObject(topic.unsealed_detail), unsealedDetail: decodeObject(topic.unsealed_detail),

View File

@ -133,6 +133,17 @@ export function Settings() {
}; };
const BlockedTopic = ({ item }) => { const BlockedTopic = ({ item }) => {
return (
<View style={styles.item}>
<Logo src={item.logo} width={32} height={32} radius={6} />
<View style={styles.detail}>
<Text style={styles.name} numberOfLines={1} ellipsizeMode={'tail'}>{ item.subject }</Text>
</View>
<TouchableOpacity onPress={() => unblock(actions.unblockTopic, item.cardId, item.channelId)}>
<Text style={styles.restore}>{ state.strings.restore }</Text>
</TouchableOpacity>
</View>
)
}; };
const BlockedMessage = ({ item }) => { const BlockedMessage = ({ item }) => {
@ -676,9 +687,9 @@ export function Settings() {
<Text style={styles.emptyLabelText}>{ state.strings.noBlockedTopics }</Text> <Text style={styles.emptyLabelText}>{ state.strings.noBlockedTopics }</Text>
</View> </View>
)} )}
{ state.contacts.length !== 0 && ( { state.topics.length !== 0 && (
<FlatList <FlatList
data={state.contacts} data={state.topics}
renderItem={BlockedTopic} renderItem={BlockedTopic}
keyExtractor={item => item.topicId} keyExtractor={item => item.topicId}
/> />

View File

@ -8,6 +8,7 @@ import { ChannelContext } from 'context/ChannelContext';
import { AppContext } from 'context/AppContext'; import { AppContext } from 'context/AppContext';
import { generateSeal, updateSeal, unlockSeal } from 'context/sealUtil'; import { generateSeal, updateSeal, unlockSeal } from 'context/sealUtil';
import { DisplayContext } from 'context/DisplayContext'; import { DisplayContext } from 'context/DisplayContext';
import { getChannelSubjectLogo } from 'context/channelUtil';
export function useSettings() { export function useSettings() {
@ -20,6 +21,8 @@ export function useSettings() {
const debounce = useRef(null); const debounce = useRef(null);
const checking = useRef(null); const checking = useRef(null);
const channels = useRef([]);
const cardChannels = useRef([]);
const [state, setState] = useState({ const [state, setState] = useState({
strings: getLanguageStrings(), strings: getLanguageStrings(),
@ -79,18 +82,26 @@ export function useSettings() {
cardId: cardId, cardId: cardId,
name: profile?.name, name: profile?.name,
handle: `${profile?.handle} / ${profile?.node}`, handle: `${profile?.handle} / ${profile?.node}`,
blocked: item.card.blocked,
logo: profile?.imageSet ? card.actions.getCardImageUrl(cardId) : 'avatar', logo: profile?.imageSet ? card.actions.getCardImageUrl(cardId) : 'avatar',
} }
}; };
const setChannelItem = (item) => {
const profileGuid = profile.state?.identity?.guid;
const { logo, subject } = getChannelSubjectLogo(null, profileGuid, item, card.state.cards, card.actions.getCardImageUrl);
return {
cardId: null,
channelId: item.channelId,
created: item.detail.created,
logo: logo,
subject: subject,
}
};
useEffect(() => { useEffect(() => {
const cards = Array.from(card.state.cards.values()); const contacts = Array.from(card.state.cards.values());
const items = cards.map(setCardItem); const filtered = contacts.filter(contact => contact.card.blocked);
const filtered = items.filter(item => { const sorted = filtered.map(setCardItem).sort((a, b) => {
return item.blocked;
});
filtered.sort((a, b) => {
if (a.name === b.name) { if (a.name === b.name) {
return 0; return 0;
} }
@ -99,21 +110,41 @@ export function useSettings() {
} }
return 1; return 1;
}); });
updateState({ contacts: filtered }); updateState({ contacts: sorted });
cards.forEach(contact => { contacts.current = [];
const channels = Array.from(contact.channels); contacts.forEach(contact => {
channels.forEach(item => { const filtered = Array.from(contact.channels.values()).filter(topic => topic.blocked);
console.log(item.blocked); const mapped = filtered.map(setChannelItem).map(item => ({ ...item, cardId: contact.card.cardId }));
cardChannels.current = cardChannels.current.concat(mapped);
}); });
const merged = cardChannels.current.concat(channels.current);
const sortedMerge = merged.sort((a, b) => {
if (a.created === b.created) {
return 0;
}
if (a.created < b.created) {
return -1;
}
return 1;
}); });
updateState({ topics: sortedMerge });
}, [card.state]); }, [card.state]);
useEffect(() => { useEffect(() => {
const channels = Array.from(channel.state.channels); const filtered = Array.from(channel.state.channels.values()).filter(topic => topic.blocked);
channels.forEach(item => { channels.current = filtered.map(setChannelItem);
console.log(item.blocked); const merged = cardChannels.current.concat(channels.current);
const sortedMerge = merged.sort((a, b) => {
if (a.created === b.created) {
return 0;
}
if (a.created < b.created) {
return -1;
}
return 1;
}); });
updateState({ topics: sortedMerge });
}, [channel.state]); }, [channel.state]);
const unlockKey = async () => { const unlockKey = async () => {