Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(app): drop the duplicated clip path id from the channel icon

Hampusbc19c17adc5f
diff --git a/fluxer_api/src/api/channel/services/message/MessageSendService.ts b/fluxer_api/src/api/channel/services/message/MessageSendService.ts
index 6fcbff712..c83a2ea48 100644
--- a/fluxer_api/src/api/channel/services/message/MessageSendService.ts
+++ b/fluxer_api/src/api/channel/services/message/MessageSendService.ts
@@ -61,6 +61,7 @@ import type {Webhook} from '@app/api/models/Webhook';
import {assertAccountNotLimited} from '@app/api/user/AccountLimit';
import {assertMayStartConversation} from '@app/api/user/NewConversationLimit';
import type {UserRepository} from '@app/api/user/repositories/UserRepository';
+import {systemDmsHidden} from '@app/api/user/services/SystemDmMessage';
import {isContentHidden, isDirectDeliverySuppressed} from '@app/api/user/UserHelpers';
import {assertGuildMemberCanCommunicate} from '@app/api/utils/GuildCommunicationUtils';
import {checkGuildVerificationWithResponse} from '@app/api/utils/GuildVerificationUtils';
@@ -75,6 +76,7 @@ import {GuildNSFWLevel, GuildOperations} from '@fluxer/constants/src/GuildConsta
import {threadWriteBlock} from '@fluxer/constants/src/ThreadPermissionUtils';
import {DELETED_USER_ID, UserFlags} from '@fluxer/constants/src/UserConstants';
import {ValidationErrorCodes} from '@fluxer/constants/src/ValidationErrorCodes';
+import {DirectMessagesDisabledError} from '@fluxer/errors/src/domains/channel/DirectMessagesDisabledError';
import {UnknownChannelError} from '@fluxer/errors/src/domains/channel/UnknownChannelError';
import {UnknownMessageError} from '@fluxer/errors/src/domains/channel/UnknownMessageError';
import {CannotExecuteOnDmError} from '@fluxer/errors/src/domains/core/CannotExecuteOnDmError';
@@ -606,11 +608,12 @@ export class MessageSendService {
const channelId = referencedMessage
? referencedMessage.channelId
: createChannelID(data.message_reference.channel_id!);
- const guildId = isForwardMessage
- ? (referencedChannelGuildId ?? null)
- : guild?.id
- ? createGuildID(BigInt(guild.id))
- : null;
+ let guildId: GuildID | null;
+ if (isForwardMessage) {
+ guildId = referencedChannelGuildId ?? null;
+ } else {
+ guildId = guild?.id ? createGuildID(BigInt(guild.id)) : null;
+ }
return {
message_id: createMessageID(data.message_reference.message_id),
channel_id: channelId,
@@ -648,6 +651,13 @@ export class MessageSendService {
}
assertAccountNotLimited(user);
const {channel, guild, member} = authChannel;
+ if (
+ (channel.type === ChannelTypes.DM || channel.type === ChannelTypes.GROUP_DM) &&
+ user.id !== SYSTEM_USER_ID &&
+ (await systemDmsHidden())
+ ) {
+ throw new DirectMessagesDisabledError();
+ }
const {checkPermission, hasPermission} = forumStarter?.parentAuth ?? authChannel;
const uploadChannelId = forumStarter?.parentAuth.channel.id ?? channelId;
const {canEmbedLinks, canMentionEveryone, canAttachFiles} = await this.checkMessageSendPermissions({
diff --git a/fluxer_api/src/api/channel/tests/DirectMessagesDisabledSend.test.ts b/fluxer_api/src/api/channel/tests/DirectMessagesDisabledSend.test.ts
new file mode 100644
index 000000000..28adef620
--- /dev/null
+++ b/fluxer_api/src/api/channel/tests/DirectMessagesDisabledSend.test.ts
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+import type {TestAccount} from '@app/api/auth/tests/AuthTestUtils';
+import {createTestAccount, setUserACLs} from '@app/api/auth/tests/AuthTestUtils';
+import {
+ createDmChannel,
+ createFriendship,
+ createGroupDmChannel,
+ sendChannelMessage,
+} from '@app/api/channel/tests/ChannelTestUtils';
+import type {ApiTestHarness} from '@app/api/test/ApiTestHarness';
+import {createApiTestHarness} from '@app/api/test/ApiTestHarness';
+import {HTTP_STATUS} from '@app/api/test/TestConstants';
+import {createBuilder} from '@app/api/test/TestRequestBuilder';
+import {AdminACLs} from '@fluxer/constants/src/AdminACLs';
+import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
+import {afterAll, beforeAll, beforeEach, describe, it} from 'vitest';
+
+describe('sending in existing private channels while direct messages are off', () => {
+ let harness: ApiTestHarness;
+
+ beforeAll(async () => {
+ harness = await createApiTestHarness();
+ });
+
+ beforeEach(async () => {
+ await harness.reset();
+ });
+
+ afterAll(async () => {
+ await harness.shutdown();
+ });
+
+ const setDirectMessagesDisabled = async (disabled: boolean): Promise<void> => {
+ const admin = await setUserACLs(harness, await createTestAccount(harness), [
+ AdminACLs.AUTHENTICATE,
+ AdminACLs.INSTANCE_CONFIG_VIEW,
+ AdminACLs.INSTANCE_CONFIG_UPDATE,
+ ]);
+ await createBuilder(harness, admin.token)
+ .patch('/admin/instance/config')
+ .body({policy: {direct_messages_disabled: disabled}})
+ .execute();
+ };
+
+ const expectRefused = async (account: TestAccount, channelId: string): Promise<void> => {
+ await createBuilder(harness, account.token)
+ .post(`/channels/${channelId}/messages`)
+ .body({content: 'still here?'})
+ .expect(HTTP_STATUS.BAD_REQUEST, APIErrorCodes.DIRECT_MESSAGES_DISABLED)
+ .execute();
+ };
+
+ it('refuses messages in an existing DM from both sides', async () => {
+ const alice = await createTestAccount(harness);
+ const bob = await createTestAccount(harness);
+ await createFriendship(harness, alice, bob);
+ const dm = await createDmChannel(harness, alice.token, bob.userId);
+ await sendChannelMessage(harness, alice.token, dm.id, 'before');
+ await sendChannelMessage(harness, bob.token, dm.id, 'before');
+
+ await setDirectMessagesDisabled(true);
+
+ await expectRefused(alice, dm.id);
+ await expectRefused(bob, dm.id);
+ });
+
+ it('refuses messages in an existing group DM', async () => {
+ const alice = await createTestAccount(harness);
+ const bob = await createTestAccount(harness);
+ const carol = await createTestAccount(harness);
+ await createFriendship(harness, alice, bob);
+ await createFriendship(harness, alice, carol);
+ const group = await createGroupDmChannel(harness, alice.token, [bob.userId, carol.userId]);
+ await sendChannelMessage(harness, alice.token, group.id, 'before');
+
+ await setDirectMessagesDisabled(true);
+
+ await expectRefused(alice, group.id);
+ await expectRefused(carol, group.id);
+ });
+
+ it('keeps personal notes working', async () => {
+ const alice = await createTestAccount(harness);
+
+ await setDirectMessagesDisabled(true);
+
+ await sendChannelMessage(harness, alice.token, alice.userId, 'a note to self');
+ });
+});
diff --git a/fluxer_app/src/features/ui/components/icons/TextChannelIcon.tsx b/fluxer_app/src/features/ui/components/icons/TextChannelIcon.tsx
index 2dba72c8f..ac0f468c7 100644
--- a/fluxer_app/src/features/ui/components/icons/TextChannelIcon.tsx
+++ b/fluxer_app/src/features/ui/components/icons/TextChannelIcon.tsx
@@ -16,19 +16,12 @@ export const TextChannelIcon = React.forwardRef<SVGSVGElement, IconProps>(({size
data-flx="ui.icons.text-channel-icon.svg"
{...props}
>
- <g clipPath="url(#clip_text)" data-flx="ui.icons.text-channel-icon.g">
- <path
- fill="currentColor"
- fillRule="evenodd"
- d="M164.193 37.8536c1.186-6.5205 7.433-10.8456 13.953-9.6602 6.521 1.1856 10.846 7.4327 9.661 13.9531L180.197 84H224c6.627 0 12 5.3726 12 12 0 6.627-5.373 12-12 12h-48.167l-7.272 40H208c6.627 0 12 5.373 12 12s-5.373 12-12 12h-43.803l-8.39 46.147c-1.186 6.52-7.433 10.845-13.953 9.66-6.521-1.186-10.846-7.433-9.661-13.953l7.61-41.854h-39.606l-8.3904 46.147c-1.1856 6.52-7.4327 10.845-13.9531 9.66-6.5204-1.186-10.8455-7.433-9.6601-13.953L75.8027 172H32c-6.6274 0-11.9999-5.373-12-12 0-6.627 5.3726-12 12-12h48.167l7.2725-40H48c-6.6274 0-11.9999-5.373-12-12 0-6.6274 5.3726-12 12-12h43.8027l8.3903-46.1464c1.186-6.5205 7.433-10.8456 13.953-9.6602 6.521 1.1856 10.846 7.4327 9.661 13.9531L116.197 84h39.606zM104.561 148h39.606l7.272-40h-39.606z"
- clipRule="evenodd"
- data-flx="ui.icons.text-channel-icon.path"
- />
- </g>
- <defs data-flx="ui.icons.text-channel-icon.defs">
- <clipPath id="clip_text" data-flx="ui.icons.text-channel-icon.clip-text">
- <path fill="currentColor" d="M0 0H256V256H0z" data-flx="ui.icons.text-channel-icon.path--2" />
- </clipPath>
- </defs>
+ <path
+ fill="currentColor"
+ fillRule="evenodd"
+ d="M164.193 37.8536c1.186-6.5205 7.433-10.8456 13.953-9.6602 6.521 1.1856 10.846 7.4327 9.661 13.9531L180.197 84H224c6.627 0 12 5.3726 12 12 0 6.627-5.373 12-12 12h-48.167l-7.272 40H208c6.627 0 12 5.373 12 12s-5.373 12-12 12h-43.803l-8.39 46.147c-1.186 6.52-7.433 10.845-13.953 9.66-6.521-1.186-10.846-7.433-9.661-13.953l7.61-41.854h-39.606l-8.3904 46.147c-1.1856 6.52-7.4327 10.845-13.9531 9.66-6.5204-1.186-10.8455-7.433-9.6601-13.953L75.8027 172H32c-6.6274 0-11.9999-5.373-12-12 0-6.627 5.3726-12 12-12h48.167l7.2725-40H48c-6.6274 0-11.9999-5.373-12-12 0-6.6274 5.3726-12 12-12h43.8027l8.3903-46.1464c1.186-6.5205 7.433-10.8456 13.953-9.6602 6.521 1.1856 10.846 7.4327 9.661 13.9531L116.197 84h39.606zM104.561 148h39.606l7.272-40h-39.606z"
+ clipRule="evenodd"
+ data-flx="ui.icons.text-channel-icon.path"
+ />
</svg>
));