|
@@ -48,7 +48,8 @@ import {
|
|
|
usePostMessagesReadMutation,
|
|
|
usePostReactToMessageMutation,
|
|
|
usePostSendMessageMutation,
|
|
|
- usePostEditMessageMutation
|
|
|
+ usePostEditMessageMutation,
|
|
|
+ usePostCanSendMessageQuery
|
|
|
} from '@api/chat';
|
|
|
import { CustomMessage, Message, Reaction } from '../types';
|
|
|
import { API_HOST, APP_VERSION, WEBSOCKET_URL } from 'src/constants';
|
|
@@ -106,6 +107,7 @@ const ChatScreen = ({ route }: { route: any }) => {
|
|
|
const [messages, setMessages] = useState<CustomMessage[] | null>();
|
|
|
const navigation = useNavigation();
|
|
|
const [prevThenMessageId, setPrevThenMessageId] = useState<number>(-1);
|
|
|
+ const { data: canSendMessage } = usePostCanSendMessageQuery(token, id, true);
|
|
|
const {
|
|
|
data: chatData,
|
|
|
refetch,
|
|
@@ -182,6 +184,39 @@ const ChatScreen = ({ route }: { route: any }) => {
|
|
|
});
|
|
|
}, []);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (canSendMessage && canSendMessage.need_authentication_or_friend === 1) {
|
|
|
+ setModalInfo({
|
|
|
+ visible: true,
|
|
|
+ type: 'success',
|
|
|
+ message: (
|
|
|
+ <Text>
|
|
|
+ Only legit NomadManias and friends can send messages.{'\n'}Befriend this traveller first
|
|
|
+ or{' '}
|
|
|
+ <Text
|
|
|
+ style={{
|
|
|
+ color: Colors.ORANGE,
|
|
|
+ textDecorationLine: 'underline',
|
|
|
+ textDecorationColor: Colors.ORANGE
|
|
|
+ }}
|
|
|
+ onPress={() =>
|
|
|
+ Linking.openURL('https://nomadmania.com/badges/').catch((err) =>
|
|
|
+ console.error('Failed to open auth URL:', err)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ >
|
|
|
+ become Legit
|
|
|
+ </Text>
|
|
|
+ !
|
|
|
+ </Text>
|
|
|
+ ),
|
|
|
+ action: () => {},
|
|
|
+ buttonTitle: 'OK',
|
|
|
+ title: 'Oops!'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, [canSendMessage]);
|
|
|
+
|
|
|
const onSendMedia = useCallback(
|
|
|
async (files: { uri: string; type: 'image' | 'video' }[]) => {
|
|
|
for (const file of files) {
|
|
@@ -981,7 +1016,11 @@ const ChatScreen = ({ route }: { route: any }) => {
|
|
|
setHasMoreMessages(false);
|
|
|
}
|
|
|
|
|
|
- if (mappedMessages.length === 0 && !modalInfo.visible) {
|
|
|
+ if (
|
|
|
+ mappedMessages.length === 0 &&
|
|
|
+ !modalInfo.visible &&
|
|
|
+ !canSendMessage?.need_authentication_or_friend
|
|
|
+ ) {
|
|
|
setTimeout(() => {
|
|
|
textInputRef.current?.focus();
|
|
|
}, 500);
|
|
@@ -993,7 +1032,11 @@ const ChatScreen = ({ route }: { route: any }) => {
|
|
|
);
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (messages?.length === 0 && !modalInfo.visible) {
|
|
|
+ if (
|
|
|
+ messages?.length === 0 &&
|
|
|
+ !modalInfo.visible &&
|
|
|
+ !canSendMessage?.need_authentication_or_friend
|
|
|
+ ) {
|
|
|
setTimeout(() => {
|
|
|
textInputRef.current?.focus();
|
|
|
}, 500);
|
|
@@ -1440,10 +1483,7 @@ const ChatScreen = ({ route }: { route: any }) => {
|
|
|
!
|
|
|
</Text>
|
|
|
),
|
|
|
- action: () =>
|
|
|
- Linking.openURL('https://nomadmania.com/badges/').catch((err) =>
|
|
|
- console.error('Failed to open auth URL:', err)
|
|
|
- ),
|
|
|
+ action: () => {},
|
|
|
buttonTitle: 'OK',
|
|
|
title: 'Oops!'
|
|
|
});
|