From 1dbe4ecdefedf5540c4e5ecc3d80f9aba0650a08 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Tue, 24 Feb 2026 18:31:10 +0100 Subject: [PATCH] Improve colors buttons connect-actions.tsx --- backend/api/src/app.ts | 4 ++-- .../src/create-private-user-message-channel.ts | 18 +++++++++++++++++- backend/api/src/get-connection-interests.ts | 7 +++++-- .../messaging/new-message-button.tsx | 6 +++++- web/components/profile/connect-actions.tsx | 8 ++++---- web/styles/globals.css | 4 ++-- 6 files changed, 35 insertions(+), 12 deletions(-) diff --git a/backend/api/src/app.ts b/backend/api/src/app.ts index 14b6d3a9..c0dbe3a2 100644 --- a/backend/api/src/app.ts +++ b/backend/api/src/app.ts @@ -58,7 +58,7 @@ import {deleteBookmarkedSearch} from './delete-bookmarked-search' import {deleteCompatibilityAnswer} from './delete-compatibility-answer' import {deleteMe} from './delete-me' import {getCompatibilityQuestions} from './get-compatibililty-questions' -import {getConnectionInterests} from './get-connection-interests' +import {getConnectionInterestsEndpoint} from './get-connection-interests' import {getCurrentPrivateUser} from './get-current-private-user' import {getEvents} from './get-events' import {getLikesAndShips} from './get-likes-and-ships' @@ -377,7 +377,7 @@ const handlers: {[k in APIPath]: APIHandler} = { 'update-user-locale': updateUserLocale, 'update-private-user-message-channel': updatePrivateUserMessageChannel, 'update-profile': updateProfile, - 'get-connection-interests': getConnectionInterests, + 'get-connection-interests': getConnectionInterestsEndpoint, 'update-connection-interest': updateConnectionInterests, 'user/by-id/:id': getUser, 'user/by-id/:id/block': blockUser, diff --git a/backend/api/src/create-private-user-message-channel.ts b/backend/api/src/create-private-user-message-channel.ts index 01c35daf..7dc613c8 100644 --- a/backend/api/src/create-private-user-message-channel.ts +++ b/backend/api/src/create-private-user-message-channel.ts @@ -1,8 +1,10 @@ +import {getConnectionInterests} from 'api/get-connection-interests' import {APIError, APIHandler} from 'api/helpers/endpoint' import {addUsersToPrivateMessageChannel} from 'api/helpers/private-messages' import {filterDefined} from 'common/util/array' import * as admin from 'firebase-admin' import {uniq} from 'lodash' +import {getProfile} from 'shared/profiles/supabase' import {createSupabaseDirectClient} from 'shared/supabase/init' import {getPrivateUser, getUser} from 'shared/utils' @@ -39,7 +41,21 @@ export const createPrivateUserMessageChannel: APIHandler< user.blockedUserIds.some((blockedId: string) => userIds.includes(blockedId)), ) ) { - throw new APIError(403, 'One of the users has blocked another user in the list') + throw new APIError(403, `One of the users has blocked another user in the list`) + } + + for (const u of toPrivateUsers) { + const p = await getProfile(u.id) + if (p && !p.allow_direct_messaging) { + const {interests, targetInterests} = await getConnectionInterests( + {targetUserId: u.id}, + auth.uid, + ) + const matches = interests.filter((interest: string[]) => targetInterests.includes(interest)) + if (matches.length > 0) continue + const failedUser = await getUser(u.id) + throw new APIError(403, `${failedUser?.username} has disabled direct messaging`) + } } const currentChannel = await pg.oneOrNone( diff --git a/backend/api/src/get-connection-interests.ts b/backend/api/src/get-connection-interests.ts index 371d4c03..1971fa84 100644 --- a/backend/api/src/get-connection-interests.ts +++ b/backend/api/src/get-connection-interests.ts @@ -1,12 +1,15 @@ import {APIHandler} from 'api/helpers/endpoint' import {createSupabaseDirectClient} from 'shared/supabase/init' -export const getConnectionInterests: APIHandler<'get-connection-interests'> = async ( +export const getConnectionInterestsEndpoint: APIHandler<'get-connection-interests'> = async ( props, auth, ) => { + return getConnectionInterests(props, auth.uid) +} + +export const getConnectionInterests = async (props: any, userId: string) => { const {targetUserId} = props - const userId = auth.uid if (!targetUserId) { throw new Error('Missing target user ID') diff --git a/web/components/messaging/new-message-button.tsx b/web/components/messaging/new-message-button.tsx index 09f0d25b..bfd807a4 100644 --- a/web/components/messaging/new-message-button.tsx +++ b/web/components/messaging/new-message-button.tsx @@ -1,6 +1,7 @@ import {PlusIcon} from '@heroicons/react/solid' import clsx from 'clsx' import {DisplayUser} from 'common/api/user-types' +import {APIError} from 'common/api/utils' import {buildArray} from 'common/util/array' import {useRouter} from 'next/router' import {useState} from 'react' @@ -33,13 +34,15 @@ function MessageModal(props: {open: boolean; setOpen: (open: boolean) => void}) const privateUser = usePrivateUser() const router = useRouter() const t = useT() + const [errorText, setErrorText] = useState('') const [users, setUsers] = useState([]) const createChannel = async () => { const res = await api('create-private-user-message-channel', { userIds: users.map((user) => user.id), - }).catch((e) => { + }).catch((e: APIError) => { console.error(e) + setErrorText(String(e)) return }) if (!res) { @@ -61,6 +64,7 @@ function MessageModal(props: {open: boolean; setOpen: (open: boolean) => void}) .concat(buildArray(privateUser?.id))} /> + {errorText &&

{errorText}

}