|
@@ -23,8 +23,8 @@ import { SheetManager } from 'react-native-actions-sheet';
|
|
|
import MoreModal from './Components/MoreModal';
|
|
|
import SearchIcon from 'assets/icons/search.svg';
|
|
|
import { storage, StoreType } from 'src/storage';
|
|
|
-import { usePostGetChatsListQuery } from '@api/chat';
|
|
|
-import { Chat } from './types';
|
|
|
+import { usePostGetBlockedQuery, usePostGetChatsListQuery } from '@api/chat';
|
|
|
+import { Blocked, Chat } from './types';
|
|
|
|
|
|
import PinIcon from 'assets/icons/messages/pin.svg';
|
|
|
import { formatDate } from './utils';
|
|
@@ -32,6 +32,8 @@ import { routes } from './constants';
|
|
|
import { styles } from './styles';
|
|
|
import { useChatStore } from 'src/stores/chatStore';
|
|
|
import BellSlashIcon from 'assets/icons/messages/bell-slash.svg';
|
|
|
+import BanIcon from 'assets/icons/messages/ban.svg';
|
|
|
+import SwipeableBlockedRow from './Components/SwipeableBlockedRow';
|
|
|
|
|
|
const MessagesScreen = () => {
|
|
|
const navigation = useNavigation();
|
|
@@ -39,12 +41,15 @@ const MessagesScreen = () => {
|
|
|
const [chats, setChats] = useState<Chat[]>([]);
|
|
|
const [index, setIndex] = useState(0);
|
|
|
const { data: chatsData, refetch } = usePostGetChatsListQuery(token, index === 2 ? 1 : 0, true);
|
|
|
+ const { data: blockedData, refetch: refetchBlocked } = usePostGetBlockedQuery(token, true);
|
|
|
+ const [blocked, setBlocked] = useState<Blocked[]>([]);
|
|
|
|
|
|
const [filteredChats, setFilteredChats] = useState<{
|
|
|
all: Chat[];
|
|
|
unread: Chat[];
|
|
|
archived: Chat[];
|
|
|
- }>({ all: [], unread: [], archived: [] });
|
|
|
+ blocked: Blocked[];
|
|
|
+ }>({ all: [], unread: [], archived: [], blocked: [] });
|
|
|
const [search, setSearch] = useState('');
|
|
|
const openRowRef = useRef<any>(null);
|
|
|
const { isWarningModalVisible, setIsWarningModalVisible } = useChatStore();
|
|
@@ -75,15 +80,34 @@ const MessagesScreen = () => {
|
|
|
}
|
|
|
}, [chatsData]);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (blockedData && blockedData.blocked) {
|
|
|
+ setBlocked(blockedData.blocked);
|
|
|
+ }
|
|
|
+ }, [blockedData]);
|
|
|
+
|
|
|
useFocusEffect(
|
|
|
useCallback(() => {
|
|
|
refetch();
|
|
|
}, [])
|
|
|
);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ const intervalId = setInterval(() => {
|
|
|
+ refetch();
|
|
|
+ }, 5000);
|
|
|
+
|
|
|
+ return () => clearInterval(intervalId);
|
|
|
+ }, [refetch]);
|
|
|
+
|
|
|
const filterChatsByTab = () => {
|
|
|
let filteredList = chats;
|
|
|
|
|
|
+ if (index === 3) {
|
|
|
+ setFilteredChats((prev) => ({ ...prev, blocked }));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if (index === 1) {
|
|
|
filteredList = chats.filter((chat) => chat.unread_count > 0);
|
|
|
}
|
|
@@ -103,7 +127,7 @@ const MessagesScreen = () => {
|
|
|
|
|
|
useEffect(() => {
|
|
|
filterChatsByTab();
|
|
|
- }, [chats, index]);
|
|
|
+ }, [chats, index, blocked]);
|
|
|
|
|
|
const searchFilter = (text: string) => {
|
|
|
if (text) {
|
|
@@ -135,6 +159,7 @@ const MessagesScreen = () => {
|
|
|
token={token}
|
|
|
onRowOpen={handleRowOpen}
|
|
|
refetch={refetch}
|
|
|
+ refetchBlocked={refetchBlocked}
|
|
|
>
|
|
|
<TouchableHighlight
|
|
|
activeOpacity={0.8}
|
|
@@ -205,6 +230,58 @@ const MessagesScreen = () => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+ const renderBlockedItem = ({ item }: { item: Blocked }) => {
|
|
|
+ return (
|
|
|
+ <SwipeableBlockedRow
|
|
|
+ data={{
|
|
|
+ id: item.id,
|
|
|
+ first_name: item.first_name,
|
|
|
+ last_name: item.last_name,
|
|
|
+ avatar: item.avatar
|
|
|
+ }}
|
|
|
+ token={token}
|
|
|
+ onRowOpen={handleRowOpen}
|
|
|
+ refetchBlocked={refetchBlocked}
|
|
|
+ >
|
|
|
+ <TouchableHighlight
|
|
|
+ activeOpacity={0.8}
|
|
|
+ onPress={() =>
|
|
|
+ navigation.navigate(
|
|
|
+ ...([NAVIGATION_PAGES.PUBLIC_PROFILE_VIEW, { userId: item.id }] as never)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ underlayColor={Colors.FILL_LIGHT}
|
|
|
+ >
|
|
|
+ <View style={[styles.chatItem, { alignItems: 'center' }]}>
|
|
|
+ {item.avatar ? (
|
|
|
+ <Image
|
|
|
+ source={{ uri: API_HOST + item.avatar }}
|
|
|
+ style={[styles.avatar, { width: 30, height: 30, borderRadius: 15 }]}
|
|
|
+ />
|
|
|
+ ) : (
|
|
|
+ <AvatarWithInitials
|
|
|
+ text={item.first_name[0] + item.last_name[0]}
|
|
|
+ flag={API_HOST + item?.flag}
|
|
|
+ size={30}
|
|
|
+ fontSize={12}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+
|
|
|
+ <View style={{ flex: 1, gap: 6 }}>
|
|
|
+ <View style={[styles.rowContainer, { alignItems: 'center' }]}>
|
|
|
+ <Text style={styles.chatName}>{item.first_name + ' ' + item.last_name}</Text>
|
|
|
+
|
|
|
+ <View style={{ flexDirection: 'row', alignItems: 'center', gap: 6 }}>
|
|
|
+ <BanIcon height={12} fill={Colors.RED} />
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ </TouchableHighlight>
|
|
|
+ </SwipeableBlockedRow>
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<PageWrapper style={{ flex: 1, marginLeft: 0, marginRight: 0, gap: 12 }}>
|
|
|
<View style={styles.header}>
|
|
@@ -234,19 +311,33 @@ const MessagesScreen = () => {
|
|
|
setIndex={setIndex}
|
|
|
routes={routes}
|
|
|
tabBarStyle={{ paddingHorizontal: '4%' }}
|
|
|
- renderScene={({ route }: { route: { key: keyof typeof filteredChats } }) => (
|
|
|
- <FlashList
|
|
|
- viewabilityConfig={{
|
|
|
- waitForInteraction: true,
|
|
|
- itemVisiblePercentThreshold: 50,
|
|
|
- minimumViewTime: 1000
|
|
|
- }}
|
|
|
- data={filteredChats[route.key]}
|
|
|
- renderItem={renderChatItem}
|
|
|
- keyExtractor={(item, index) => `${item.uid}-${index}`}
|
|
|
- estimatedItemSize={78}
|
|
|
- />
|
|
|
- )}
|
|
|
+ renderScene={({ route }: { route: { key: keyof typeof filteredChats } }) =>
|
|
|
+ route.key === 'blocked' ? (
|
|
|
+ <FlashList
|
|
|
+ viewabilityConfig={{
|
|
|
+ waitForInteraction: true,
|
|
|
+ itemVisiblePercentThreshold: 50,
|
|
|
+ minimumViewTime: 1000
|
|
|
+ }}
|
|
|
+ data={filteredChats[route.key]}
|
|
|
+ renderItem={renderBlockedItem}
|
|
|
+ keyExtractor={(item, index) => `${item.id}-${index}`}
|
|
|
+ estimatedItemSize={50}
|
|
|
+ />
|
|
|
+ ) : (
|
|
|
+ <FlashList
|
|
|
+ viewabilityConfig={{
|
|
|
+ waitForInteraction: true,
|
|
|
+ itemVisiblePercentThreshold: 50,
|
|
|
+ minimumViewTime: 1000
|
|
|
+ }}
|
|
|
+ data={filteredChats[route.key]}
|
|
|
+ renderItem={renderChatItem}
|
|
|
+ keyExtractor={(item, index) => `${item.uid}-${index}`}
|
|
|
+ estimatedItemSize={78}
|
|
|
+ />
|
|
|
+ )
|
|
|
+ }
|
|
|
/>
|
|
|
|
|
|
<SearchModal />
|