adding blocked message support to refactored settings

This commit is contained in:
balzack 2023-09-06 16:53:10 -07:00
parent 0d04c26b2a
commit 66c9710764
5 changed files with 76 additions and 11 deletions

View File

@ -473,9 +473,13 @@ export function useCardContext() {
await store.actions.setCardChannelTopicBlocked(guid, cardId, channelId, topicId, true); await store.actions.setCardChannelTopicBlocked(guid, cardId, channelId, topicId, true);
}, },
clearTopicFlag: async (cardId, channelId, topicId) => { clearTopicFlag: async (cardId, channelId, topicId) => {
const { guid } = access.current; const { guid } = access.current || {};
await store.actions.setCardChannelTopicBlocked(guid, cardId, channelId, topicId, false); await store.actions.setCardChannelTopicBlocked(guid, cardId, channelId, topicId, false);
}, },
getFlaggedTopics: async () => {
const { guid } = access.current || {};
return await store.actions.getCardChannelTopicBlocked(guid);
},
addChannelAlert: async (cardId, channelId) => { addChannelAlert: async (cardId, channelId) => {
const { detail, profile } = (cards.current.get(cardId) || {}).card; const { detail, profile } = (cards.current.get(cardId) || {}).card;
const node = profile?.node ? profile.node : access.current.server; const node = profile?.node ? profile.node : access.current.server;

View File

@ -251,6 +251,10 @@ export function useChannelContext() {
const { guid } = access.current || {}; const { guid } = access.current || {};
await store.actions.setChannelTopicBlocked(guid, channelId, topicId, 0); await store.actions.setChannelTopicBlocked(guid, channelId, topicId, 0);
}, },
getFlaggedTopics: async () => {
const { guid } = access.current || {};
return await store.actions.getChannelTopicBlocked(guid);
},
addChannelAlert: async (channelId) => { addChannelAlert: async (channelId) => {
const { server, guid } = access.current || {}; const { server, guid } = access.current || {};
return await addFlag(server, guid, channelId); return await addFlag(server, guid, channelId);

View File

@ -193,11 +193,9 @@ export function TopicItem({ item, focused, focus, hosting, remove, update, block
<AntIcons name="edit" size={24} color={Colors.white} /> <AntIcons name="edit" size={24} color={Colors.white} />
</TouchableOpacity> </TouchableOpacity>
)} )}
{ !state.editable && ( <TouchableOpacity style={styles.icon} onPress={hideMessage}>
<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.editable && ( { !state.editable && (
<TouchableOpacity style={styles.icon} onPress={reportMessage}> <TouchableOpacity style={styles.icon} onPress={reportMessage}>
<MatIcons name="flag-outline" size={22} color={Colors.white} /> <MatIcons name="flag-outline" size={22} color={Colors.white} />

View File

@ -147,6 +147,17 @@ export function Settings() {
}; };
const BlockedMessage = ({ item }) => { const BlockedMessage = ({ 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.handle }</Text>
</View>
<TouchableOpacity onPress={() => unblock(actions.unblockMessage, { cardId: item.cardId, channelId: item.channelId, topicId: item.topicId })}>
<Text style={styles.restore}>{ state.strings.restore }</Text>
</TouchableOpacity>
</View>
)
}; };
return ( return (
@ -726,11 +737,11 @@ export function Settings() {
<Text style={styles.emptyLabelText}>{ state.strings.noBlockedMessages }</Text> <Text style={styles.emptyLabelText}>{ state.strings.noBlockedMessages }</Text>
</View> </View>
)} )}
{ state.contacts.length !== 0 && ( { state.messages.length !== 0 && (
<FlatList <FlatList
data={state.contacts} data={state.messages}
renderItem={BlockedMessage} renderItem={BlockedMessage}
keyExtractor={item => item.messageId} keyExtractor={item => `${item.cardId}.${item.channelId}.${item.topicId}`}
/> />
)} )}
</View> </View>

View File

@ -98,6 +98,32 @@ export function useSettings() {
} }
}; };
const setTopicItem = (item) => {
const { cardId, channelId, topicId, detail } = item;
if (cardId) {
const contact = card.state.cards.get(cardId);
const { handle, node, imageSet } = contact?.card?.profile || {};
return {
cardId: cardId,
channelId: channelId,
topicId: topicId,
handle: `${handle} / ${node}`,
logo: imageSet ? card.actions.getCardImageUrl(cardId) : 'avatar',
created: detail?.created,
}
}
else {
const { handle, node } = profile?.state.identity || {};
return {
channelId: channelId,
topicId: topicId,
handle: `${handle} / ${node}`,
logo: profile?.state?.imageUrl ? profile.state.imageUrl : 'avatar',
created: detail?.created,
}
}
};
useEffect(() => { useEffect(() => {
const contacts = Array.from(card.state.cards.values()); const contacts = Array.from(card.state.cards.values());
const filtered = contacts.filter(contact => contact.card.blocked); const filtered = contacts.filter(contact => contact.card.blocked);
@ -195,8 +221,20 @@ export function useSettings() {
hideBlockedTopics: () => { hideBlockedTopics: () => {
updateState({ blockedTopics: false }); updateState({ blockedTopics: false });
}, },
showBlockedMessages: () => { showBlockedMessages: async () => {
updateState({ blockedMessages: true }); const cardMessages = await card.actions.getFlaggedTopics();
const channelMessages = await channel.actions.getFlaggedTopics();
const merged = cardMessages.map(setTopicItem).concat(channelMessages.map(setTopicItem));
const sortedMerge = merged.sort((a, b) => {
if (a.created === b.created) {
return 0;
}
if (a.created < b.created) {
return -1;
}
return 1;
});
updateState({ blockedMessages: true, messages: sortedMerge });
}, },
hideBlockedMessages: () => { hideBlockedMessages: () => {
updateState({ blockedMessages: false }); updateState({ blockedMessages: false });
@ -326,6 +364,16 @@ export function useSettings() {
await channel.actions.clearChannelFlag(channelId); await channel.actions.clearChannelFlag(channelId);
} }
}, },
unblockMessage: async ({ cardId, channelId, topicId }) => {
if (cardId) {
await card.actions.clearTopicFlag(cardId, channelId, topicId);
updateState({ messages: state.messages.filter(item => item.cardId !== cardId || item.channelId !== channelId || item.topicId !== topicId) });
}
else {
await channel.actions.clearTopicFlag(channelId, topicId);
updateState({ messages: state.messages.filter(item => item.channelId !== channelId || item.topicId !== topicId) });
}
},
}; };
return { state, actions }; return { state, actions };