Ej/fix message visibility (#11874)
<img width="257" alt="Screenshot 2025-05-05 at 15 30 09" src="https://github.com/user-attachments/assets/5a8e18e0-efc5-4521-9c3a-bf73277ecdf9" /> <img width="257" alt="Screenshot 2025-05-05 at 15 29 05" src="https://github.com/user-attachments/assets/c1a784af-a744-497a-b6ce-ec3a9e8b851a" /> <img width="257" alt="Screenshot 2025-05-05 at 15 33 06" src="https://github.com/user-attachments/assets/c5fabd1d-a125-49d7-aade-0a208a0eff95" /> related to PR https://github.com/twentyhq/twenty/pull/11840 and issue https://github.com/twentyhq/twenty/issues/9826
This commit is contained in:
@ -222,7 +222,7 @@ export class TimelineMessagingService {
|
||||
|
||||
const visibilityValues = Object.values(MessageChannelVisibility);
|
||||
|
||||
const threadVisibilityByThreadIdForWhichWorkspaceMemberIsNotInParticipants:
|
||||
const threadVisibilityByThreadIdForWhichWorkspaceMemberIsNotOwner:
|
||||
| {
|
||||
[key: string]: MessageChannelVisibility;
|
||||
}
|
||||
@ -247,10 +247,10 @@ export class TimelineMessagingService {
|
||||
const threadVisibilityByThreadId: {
|
||||
[key: string]: MessageChannelVisibility;
|
||||
} = messageThreadIds.reduce((threadVisibilityAcc, messageThreadId) => {
|
||||
// If the workspace member is not in the participants of the thread, use the visibility value from the query
|
||||
// If the workspace member is not the owner of the thread, use the visibility value from the query
|
||||
threadVisibilityAcc[messageThreadId] =
|
||||
threadIdsWithoutWorkspaceMember.includes(messageThreadId)
|
||||
? (threadVisibilityByThreadIdForWhichWorkspaceMemberIsNotInParticipants?.[
|
||||
? (threadVisibilityByThreadIdForWhichWorkspaceMemberIsNotOwner?.[
|
||||
messageThreadId
|
||||
] ?? MessageChannelVisibility.METADATA)
|
||||
: MessageChannelVisibility.SHARE_EVERYTHING;
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import { FIELD_RESTRICTED_ADDITIONAL_PERMISSIONS_REQUIRED } from 'twenty-shared/constants';
|
||||
|
||||
import { TimelineThread } from 'src/engine/core-modules/messaging/dtos/timeline-thread.dto';
|
||||
import { extractParticipantSummary } from 'src/engine/core-modules/messaging/utils/extract-participant-summary.util';
|
||||
import { MessageChannelVisibility } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
||||
@ -19,10 +21,23 @@ export const formatThreads = (
|
||||
[key: string]: MessageChannelVisibility;
|
||||
},
|
||||
): TimelineThread[] => {
|
||||
return threads.map((thread) => ({
|
||||
...thread,
|
||||
...extractParticipantSummary(threadParticipantsByThreadId[thread.id]),
|
||||
visibility: threadVisibilityByThreadId[thread.id],
|
||||
read: true,
|
||||
}));
|
||||
return threads.map((thread) => {
|
||||
const visibility = threadVisibilityByThreadId[thread.id];
|
||||
|
||||
return {
|
||||
...thread,
|
||||
subject:
|
||||
visibility === MessageChannelVisibility.SHARE_EVERYTHING ||
|
||||
visibility === MessageChannelVisibility.SUBJECT
|
||||
? thread.subject
|
||||
: FIELD_RESTRICTED_ADDITIONAL_PERMISSIONS_REQUIRED,
|
||||
lastMessageBody:
|
||||
visibility === MessageChannelVisibility.SHARE_EVERYTHING
|
||||
? thread.lastMessageBody
|
||||
: FIELD_RESTRICTED_ADDITIONAL_PERMISSIONS_REQUIRED,
|
||||
...extractParticipantSummary(threadParticipantsByThreadId[thread.id]),
|
||||
visibility,
|
||||
read: true,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user