feat: `showThreadsInMainChannel` Preference (#29302)

pull/29639/head^2
Douglas Fabris 3 years ago committed by GitHub
parent f7d2e27eec
commit 0645f42e12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      .changeset/slimy-olives-march.md
  2. 13
      apps/meteor/app/ui-utils/client/lib/RoomHistoryManager.ts
  3. 3
      apps/meteor/client/components/message/variants/threadPreview/ThreadMessagePreviewBody.tsx
  4. 16
      apps/meteor/client/views/account/preferences/PreferencesMessagesSection.tsx
  5. 9
      apps/meteor/client/views/room/MessageList/hooks/useMessages.ts
  6. 4
      apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
  7. 6
      apps/meteor/server/settings/accounts.ts
  8. 1
      apps/meteor/tests/end-to-end/api/00-miscellaneous.js
  9. 5
      packages/rest-typings/src/v1/users/UsersSetPreferenceParamsPOST.ts

@ -0,0 +1,6 @@
---
'@rocket.chat/rest-typings': minor
'@rocket.chat/meteor': minor
---
Reintroduce an user preference to allow users to see all thread messages in the main channel

@ -8,6 +8,7 @@ import type { MutableRefObject } from 'react';
import { waitForElement } from '../../../../client/lib/utils/waitForElement';
import { readMessage } from './readMessages';
import { getUserPreference } from '../../../utils/client';
import { getConfig } from '../../../../client/lib/utils/getConfig';
import { ChatMessage, ChatSubscription } from '../../../models/client';
import { callWithErrorHandling } from '../../../../client/lib/utils/callWithErrorHandling';
@ -140,7 +141,15 @@ class RoomHistoryManagerClass extends Emitter {
({ ls } = subscription);
}
const result = await callWithErrorHandling('loadHistory', rid, room.oldestTs, limit, ls ? String(ls) : undefined, false);
const showThreadsInMainChannel = getUserPreference(Meteor.userId(), 'showThreadsInMainChannel', false);
const result = await callWithErrorHandling(
'loadHistory',
rid,
room.oldestTs,
limit,
ls ? String(ls) : undefined,
showThreadsInMainChannel,
);
if (!result) {
throw new Error('loadHistory returned nothing');
@ -174,7 +183,7 @@ class RoomHistoryManagerClass extends Emitter {
room.loaded = 0;
}
const visibleMessages = messages.filter((msg) => !msg.tmid || msg.tshow);
const visibleMessages = messages.filter((msg) => !msg.tmid || showThreadsInMainChannel || msg.tshow);
room.loaded += visibleMessages.length;

@ -26,6 +26,9 @@ const ThreadMessagePreviewBody = ({ message }: ThreadMessagePreviewBodyProps): R
) {
mdTokens?.shift();
}
if (message.attachments && message.msg === '') {
return <>{t('Message_with_attachment')}</>;
}
if (!isEncryptedMessage || message.e2e === 'done') {
return mdTokens ? (
<GazzodownText>

@ -9,6 +9,7 @@ import type { FormSectionProps } from './AccountPreferencesPage';
type Values = {
unreadAlert: boolean;
showThreadsInMainChannel: boolean;
alsoSendThreadToChannel: 'default' | 'always' | 'never';
useEmojis: boolean;
convertAsciiEmoji: boolean;
@ -30,6 +31,7 @@ const PreferencesMessagesSection = ({ onChange, commitRef, ...props }: FormSecti
const settings = {
unreadAlert: useUserPreference('unreadAlert'),
showThreadsInMainChannel: useUserPreference('showThreadsInMainChannel'),
alsoSendThreadToChannel: useUserPreference('alsoSendThreadToChannel'),
useEmojis: useUserPreference('useEmojis'),
convertAsciiEmoji: useUserPreference('convertAsciiEmoji'),
@ -48,6 +50,7 @@ const PreferencesMessagesSection = ({ onChange, commitRef, ...props }: FormSecti
const {
unreadAlert,
showThreadsInMainChannel,
alsoSendThreadToChannel,
useEmojis,
convertAsciiEmoji,
@ -64,6 +67,7 @@ const PreferencesMessagesSection = ({ onChange, commitRef, ...props }: FormSecti
const {
handleUnreadAlert,
handleShowThreadsInMainChannel,
handleAlsoSendThreadToChannel,
handleUseEmojis,
handleConvertAsciiEmoji,
@ -121,6 +125,18 @@ const PreferencesMessagesSection = ({ onChange, commitRef, ...props }: FormSecti
),
[handleUnreadAlert, t, unreadAlert],
)}
{useMemo(
() => (
<Field display='flex' flexDirection='row' justifyContent='spaceBetween' flexGrow={1}>
<Field.Label>{t('Always_show_thread_replies_in_main_channel')}</Field.Label>
<Field.Row>
<ToggleSwitch checked={showThreadsInMainChannel} onChange={handleShowThreadsInMainChannel} />
</Field.Row>
<Field.Hint>{t('Accounts_Default_User_Preferences_showThreadsInMainChannel_Description')}</Field.Hint>
</Field>
),
[handleShowThreadsInMainChannel, showThreadsInMainChannel, t],
)}
{useMemo(
() => (
<Field>

@ -1,6 +1,6 @@
import type { IRoom, IMessage, MessageTypesValues } from '@rocket.chat/core-typings';
import { useStableArray } from '@rocket.chat/fuselage-hooks';
import { useSetting } from '@rocket.chat/ui-contexts';
import { useSetting, useUserPreference } from '@rocket.chat/ui-contexts';
import type { Mongo } from 'meteor/mongo';
import { useCallback, useMemo } from 'react';
@ -16,6 +16,7 @@ const mergeHideSysMessages = (
};
export const useMessages = ({ rid }: { rid: IRoom['_id'] }): IMessage[] => {
const showThreadsInMainChannel = useUserPreference<boolean>('showThreadsInMainChannel', false);
const hideSysMesSetting = useSetting<MessageTypesValues[]>('Hide_System_Messages') ?? [];
const room = useRoom();
const hideRoomSysMes: Array<MessageTypesValues> = Array.isArray(room.sysMes) ? room.sysMes : [];
@ -27,9 +28,11 @@ export const useMessages = ({ rid }: { rid: IRoom['_id'] }): IMessage[] => {
rid,
_hidden: { $ne: true },
t: { $nin: hideSysMessages },
$or: [{ tmid: { $exists: false } }, { tshow: { $eq: true } }],
...(!showThreadsInMainChannel && {
$or: [{ tmid: { $exists: false } }, { tshow: { $eq: true } }],
}),
}),
[rid, hideSysMessages],
[rid, hideSysMessages, showThreadsInMainChannel],
);
return useReactiveValue(

@ -91,6 +91,7 @@
"Accounts_Default_User_Preferences_desktopNotifications": "Desktop Notifications Default Alert",
"Accounts_Default_User_Preferences_pushNotifications": "Push Notifications Default Alert",
"Accounts_Default_User_Preferences_not_available": "Failed to retrieve User Preferences because they haven't been set up by the user yet",
"Accounts_Default_User_Preferences_showThreadsInMainChannel_Description": "When enabled, all replies under a thread will also be displayed directly in the main room. When disabled, thread replies will be displayed based on the sender's choice.",
"Accounts_DefaultUsernamePrefixSuggestion": "Default Username Prefix Suggestion",
"Accounts_denyUnverifiedEmail": "Deny unverified email",
"Accounts_Directory_DefaultView": "Default Directory Listing",
@ -395,6 +396,7 @@
"Also_send_thread_message_to_channel_behavior": "Also send thread message to channel behavior",
"Also_send_to_channel": "Also send to channel",
"Always_open_in_new_window": "Always Open in New Window",
"Always_show_thread_replies_in_main_channel": "Always show thread replies in main channel",
"Analytics": "Analytics",
"Analytics_Description": "See how users interact with your workspace.",
"Analytics_features_enabled": "Features Enabled",
@ -3335,6 +3337,7 @@
"Message_Attachments_Thumbnails_Enabled": "Enable image thumbnails to save bandwith",
"Message_Attachments_Thumbnails_Width": "Thumbnail's max width (in pixels)",
"Message_Attachments_Thumbnails_Height": "Thumbnail's max height (in pixels)",
"Message_with_attachment": "Message with attachment",
"Report_sent": "Report sent",
"Message_Attachments_Thumbnails_EnabledDesc": "Thumbnails will be served instead of the original image to reduce bandwith usage. Images at original resolution can be downloaded using the icon next to the attachment's name.",
"Message_Attachments_Strip_Exif": "Remove EXIF metadata from supported files",
@ -4582,7 +4585,6 @@
"Show_default_content": "Show default content",
"Show_email_field": "Show email field",
"Show_mentions": "Show badge for mentions",
"Show_Message_In_Main_Thread": "Show thread messages in the main thread",
"Show_more": "Show more",
"Show_name_field": "Show name field",
"show_offline_users": "show offline users",

@ -572,6 +572,12 @@ export const createAccountSettings = () =>
i18nLabel: 'Sort_By',
});
await this.add('Accounts_Default_User_Preferences_showThreadsInMainChannel', false, {
type: 'boolean',
public: true,
i18nLabel: 'Always_show_thread_replies_in_main_channel',
});
await this.add('Accounts_Default_User_Preferences_alsoSendThreadToChannel', 'default', {
type: 'select',
values: [

@ -142,6 +142,7 @@ describe('miscellaneous', function () {
// 'language',
'newRoomNotification',
'newMessageNotification',
'showThreadsInMainChannel',
// 'clockMode',
'useEmojis',
'convertAsciiEmoji',

@ -24,6 +24,7 @@ export type UsersSetPreferencesParamsPOST = {
highlights?: string[];
alsoSendThreadToChannel?: 'never' | 'always' | 'default';
desktopNotificationRequireInteraction?: boolean;
showThreadsInMainChannel?: boolean;
hideUsernames?: boolean;
hideRoles?: boolean;
displayAvatars?: boolean;
@ -124,6 +125,10 @@ const UsersSetPreferencesParamsPostSchema = {
},
nullable: true,
},
showThreadsInMainChannel: {
type: 'boolean',
nullable: true,
},
desktopNotificationRequireInteraction: {
type: 'boolean',
nullable: true,

Loading…
Cancel
Save