3803 use email visibility to display only the shared information backend (#3871)
* update dto * wip * compute thread visibility * fix bugs * fix bug * improve typing * working * update according to comments * use string
This commit is contained in:
@@ -495,6 +495,7 @@ export type TimelineThread = {
|
||||
participantCount: Scalars['Float'];
|
||||
read: Scalars['Boolean'];
|
||||
subject: Scalars['String'];
|
||||
visibility: Scalars['String'];
|
||||
};
|
||||
|
||||
export type TimelineThreadParticipant = {
|
||||
@@ -710,9 +711,9 @@ export type RelationEdge = {
|
||||
|
||||
export type ParticipantFragmentFragment = { __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string };
|
||||
|
||||
export type TimelineThreadFragmentFragment = { __typename?: 'TimelineThread', id: string, read: boolean, lastMessageReceivedAt: string, lastMessageBody: string, subject: string, numberOfMessagesInThread: number, participantCount: number, firstParticipant: { __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }, lastTwoParticipants: Array<{ __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }> };
|
||||
export type TimelineThreadFragmentFragment = { __typename?: 'TimelineThread', id: string, read: boolean, visibility: string, lastMessageReceivedAt: string, lastMessageBody: string, subject: string, numberOfMessagesInThread: number, participantCount: number, firstParticipant: { __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }, lastTwoParticipants: Array<{ __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }> };
|
||||
|
||||
export type TimelineThreadsWithTotalFragmentFragment = { __typename?: 'TimelineThreadsWithTotal', totalNumberOfThreads: number, timelineThreads: Array<{ __typename?: 'TimelineThread', id: string, read: boolean, lastMessageReceivedAt: string, lastMessageBody: string, subject: string, numberOfMessagesInThread: number, participantCount: number, firstParticipant: { __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }, lastTwoParticipants: Array<{ __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }> }> };
|
||||
export type TimelineThreadsWithTotalFragmentFragment = { __typename?: 'TimelineThreadsWithTotal', totalNumberOfThreads: number, timelineThreads: Array<{ __typename?: 'TimelineThread', id: string, read: boolean, visibility: string, lastMessageReceivedAt: string, lastMessageBody: string, subject: string, numberOfMessagesInThread: number, participantCount: number, firstParticipant: { __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }, lastTwoParticipants: Array<{ __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }> }> };
|
||||
|
||||
export type GetTimelineThreadsFromCompanyIdQueryVariables = Exact<{
|
||||
companyId: Scalars['ID'];
|
||||
@@ -721,7 +722,7 @@ export type GetTimelineThreadsFromCompanyIdQueryVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type GetTimelineThreadsFromCompanyIdQuery = { __typename?: 'Query', getTimelineThreadsFromCompanyId: { __typename?: 'TimelineThreadsWithTotal', totalNumberOfThreads: number, timelineThreads: Array<{ __typename?: 'TimelineThread', id: string, read: boolean, lastMessageReceivedAt: string, lastMessageBody: string, subject: string, numberOfMessagesInThread: number, participantCount: number, firstParticipant: { __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }, lastTwoParticipants: Array<{ __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }> }> } };
|
||||
export type GetTimelineThreadsFromCompanyIdQuery = { __typename?: 'Query', getTimelineThreadsFromCompanyId: { __typename?: 'TimelineThreadsWithTotal', totalNumberOfThreads: number, timelineThreads: Array<{ __typename?: 'TimelineThread', id: string, read: boolean, visibility: string, lastMessageReceivedAt: string, lastMessageBody: string, subject: string, numberOfMessagesInThread: number, participantCount: number, firstParticipant: { __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }, lastTwoParticipants: Array<{ __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }> }> } };
|
||||
|
||||
export type GetTimelineThreadsFromPersonIdQueryVariables = Exact<{
|
||||
personId: Scalars['ID'];
|
||||
@@ -730,7 +731,9 @@ export type GetTimelineThreadsFromPersonIdQueryVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type GetTimelineThreadsFromPersonIdQuery = { __typename?: 'Query', getTimelineThreadsFromPersonId: { __typename?: 'TimelineThreadsWithTotal', totalNumberOfThreads: number, timelineThreads: Array<{ __typename?: 'TimelineThread', id: string, read: boolean, lastMessageReceivedAt: string, lastMessageBody: string, subject: string, numberOfMessagesInThread: number, participantCount: number, firstParticipant: { __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }, lastTwoParticipants: Array<{ __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }> }> } };
|
||||
export type GetTimelineThreadsFromPersonIdQuery = { __typename?: 'Query', getTimelineThreadsFromPersonId: { __typename?: 'TimelineThreadsWithTotal', totalNumberOfThreads: number, timelineThreads: Array<{ __typename?: 'TimelineThread', id: string, read: boolean, visibility: string, lastMessageReceivedAt: string, lastMessageBody: string, subject: string, numberOfMessagesInThread: number, participantCount: number, firstParticipant: { __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }, lastTwoParticipants: Array<{ __typename?: 'TimelineThreadParticipant', personId?: string | null, workspaceMemberId?: string | null, firstName: string, lastName: string, displayName: string, avatarUrl: string, handle: string }> }> } };
|
||||
|
||||
export type TimelineThreadFragment = { __typename?: 'TimelineThread', id: string, subject: string, lastMessageReceivedAt: string };
|
||||
|
||||
export type CreateEventMutationVariables = Exact<{
|
||||
type: Scalars['String'];
|
||||
@@ -898,6 +901,7 @@ export const TimelineThreadFragmentFragmentDoc = gql`
|
||||
fragment TimelineThreadFragment on TimelineThread {
|
||||
id
|
||||
read
|
||||
visibility
|
||||
firstParticipant {
|
||||
...ParticipantFragment
|
||||
}
|
||||
@@ -919,6 +923,13 @@ export const TimelineThreadsWithTotalFragmentFragmentDoc = gql`
|
||||
}
|
||||
}
|
||||
${TimelineThreadFragmentFragmentDoc}`;
|
||||
export const TimelineThreadFragmentDoc = gql`
|
||||
fragment timelineThread on TimelineThread {
|
||||
id
|
||||
subject
|
||||
lastMessageReceivedAt
|
||||
}
|
||||
`;
|
||||
export const AuthTokenFragmentFragmentDoc = gql`
|
||||
fragment AuthTokenFragment on AuthToken {
|
||||
token
|
||||
|
||||
+1
@@ -6,6 +6,7 @@ export const timelineThreadFragment = gql`
|
||||
fragment TimelineThreadFragment on TimelineThread {
|
||||
id
|
||||
read
|
||||
visibility
|
||||
firstParticipant {
|
||||
...ParticipantFragment
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ export class TimelineThread {
|
||||
@Field()
|
||||
read: boolean;
|
||||
|
||||
@Field()
|
||||
visibility: string;
|
||||
|
||||
@Field()
|
||||
firstParticipant: TimelineThreadParticipant;
|
||||
|
||||
|
||||
@@ -317,6 +317,53 @@ export class TimelineMessagingService {
|
||||
return messageThreadIdAcc;
|
||||
}, {});
|
||||
|
||||
const threadVisibility:
|
||||
| {
|
||||
id: string;
|
||||
visibility: 'metadata' | 'subject' | 'share_everything';
|
||||
}[]
|
||||
| undefined = await workspaceDataSource?.query(
|
||||
`
|
||||
SELECT
|
||||
"messageThread".id,
|
||||
"messageChannel".visibility
|
||||
FROM
|
||||
${dataSourceMetadata.schema}."messageThread" "messageThread"
|
||||
LEFT JOIN
|
||||
${dataSourceMetadata.schema}."message" message ON "message"."messageThreadId" = "messageThread".id
|
||||
LEFT JOIN
|
||||
${dataSourceMetadata.schema}."messageChannelMessageAssociation" "messageChannelMessageAssociation" ON "messageChannelMessageAssociation"."messageId" = message.id
|
||||
LEFT JOIN
|
||||
${dataSourceMetadata.schema}."messageChannel" "messageChannel" ON "messageChannel".id = "messageChannelMessageAssociation"."messageChannelId"
|
||||
WHERE
|
||||
"messageThread".id = ANY($1)
|
||||
`,
|
||||
[messageThreadIds],
|
||||
);
|
||||
|
||||
const visibilityValues = ['metadata', 'subject', 'share_everything'];
|
||||
|
||||
const threadVisibilityByThreadId:
|
||||
| {
|
||||
[key: string]: 'metadata' | 'subject' | 'share_everything';
|
||||
}
|
||||
| undefined = threadVisibility?.reduce(
|
||||
(threadVisibilityAcc, threadVisibility) => {
|
||||
threadVisibilityAcc[threadVisibility.id] =
|
||||
visibilityValues[
|
||||
Math.max(
|
||||
visibilityValues.indexOf(threadVisibility.visibility),
|
||||
visibilityValues.indexOf(
|
||||
threadVisibilityAcc[threadVisibility.id] ?? 'metadata',
|
||||
),
|
||||
)
|
||||
];
|
||||
|
||||
return threadVisibilityAcc;
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
const timelineThreads = messageThreadIds.map((messageThreadId) => {
|
||||
const threadParticipants = threadParticipantsByThreadId[messageThreadId];
|
||||
|
||||
@@ -364,6 +411,7 @@ export class TimelineMessagingService {
|
||||
lastTwoParticipants,
|
||||
lastMessageReceivedAt: thread.lastMessageReceivedAt,
|
||||
lastMessageBody: thread.lastMessageBody,
|
||||
visibility: threadVisibilityByThreadId?.[messageThreadId] ?? 'metadata',
|
||||
subject: threadSubject,
|
||||
numberOfMessagesInThread: numberOfMessages,
|
||||
participantCount: threadParticipants.length,
|
||||
|
||||
Reference in New Issue
Block a user