瀏覽代碼

auth modal

Viktoriia 3 月之前
父節點
當前提交
08283319c3

+ 1 - 0
src/modules/api/chat/chat-api.ts

@@ -146,6 +146,7 @@ export interface PostSendGroupMessage {
 export interface PostSendMessageReturn extends ResponseType {
   message_id: number;
   attachment?: any;
+  need_authentication_or_friend?: 0 | 1;
 }
 
 export interface PostMessagesReceivedOrRead {

+ 21 - 0
src/screens/InAppScreens/MessagesScreen/ChatScreen/index.tsx

@@ -169,6 +169,10 @@ const ChatScreen = ({ route }: { route: any }) => {
   };
 
   useEffect(() => {
+    if (!Audio || !Audio.setAudioModeAsync) {
+      return;
+    }
+
     Audio.setAudioModeAsync({
       allowsRecordingIOS: false,
       staysActiveInBackground: false,
@@ -1411,6 +1415,23 @@ const ChatScreen = ({ route }: { route: any }) => {
         },
         {
           onSuccess: (res) => {
+            if (res.need_authentication_or_friend === 1) {
+              setModalInfo({
+                visible: true,
+                type: 'success',
+                message:
+                  'Only legit NomadManias and friends can send messages.\nBefriend this traveller first or become Legit!',
+                action: () =>
+                  Linking.openURL('https://nomadmania.com/blog-authentication/').catch((err) =>
+                    console.error('Failed to open auth URL:', err)
+                  ),
+                buttonTitle: 'OK',
+                title: 'Oops!'
+              });
+
+              setMessages((messages ?? []).filter((msg) => msg._id === message._id));
+              return;
+            }
             const newMessage = {
               _id: res.message_id,
               text: message.text,

+ 4 - 0
src/screens/InAppScreens/MessagesScreen/GroupChatScreen/index.tsx

@@ -205,6 +205,10 @@ const GroupChatScreen = ({ route }: { route: any }) => {
   };
 
   useEffect(() => {
+    if (!Audio || !Audio.setAudioModeAsync) {
+      return;
+    }
+
     Audio.setAudioModeAsync({
       allowsRecordingIOS: false,
       staysActiveInBackground: false,

+ 0 - 1
src/utils/request.ts

@@ -52,7 +52,6 @@ export const setupInterceptors = ({
           showErrorWithDelay(response.data.result_description, true, false);
           return response;
         } else if (
-          // todo: response.data.auth_needed === 1
           response.data.result_description ===
           'Only authenticated users are allowed to send messages.'
         ) {