Skip to content

Commit 63d6831

Browse files
committed
refactor: latest changes
1 parent c5b772e commit 63d6831

7 files changed

Lines changed: 92 additions & 93 deletions

File tree

libs/wire-api/src/Wire/API/Meeting.hs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ data NewMeeting = NewMeeting
7979
{ startDate :: UTCTime,
8080
endDate :: UTCTime,
8181
schedule :: Maybe Text,
82-
conversationId :: Maybe (Qualified ConvId),
8382
title :: Text,
8483
invitedEmails :: [EmailAddress]
8584
}
@@ -94,7 +93,6 @@ instance ToSchema NewMeeting where
9493
<$> (.startDate) .= field "start_date" utcTimeSchema
9594
<*> (.endDate) .= field "end_date" utcTimeSchema
9695
<*> (.schedule) .= maybe_ (optField "schedule" schema)
97-
<*> (.conversationId) .= maybe_ (optField "qualified_conversation" schema)
9896
<*> (.title) .= field "title" schema
9997
<*> (.invitedEmails) .= field "invited_emails" (array schema)
10098

@@ -119,15 +117,15 @@ instance ToSchema UpdateMeeting where
119117
<*> (.schedule) .= maybe_ (optField "schedule" schema)
120118

121119
-- | Request to add/remove invited email
122-
newtype InviteByEmail = InviteByEmail
123-
{ email :: EmailAddress
120+
newtype MeetingEmailsInvitation = MeetingEmailsInvitation
121+
{ emails :: [EmailAddress]
124122
}
125123
deriving stock (Eq, Show, Generic)
126-
deriving (ToJSON, FromJSON, S.ToSchema) via (Schema InviteByEmail)
127-
deriving (Arbitrary) via (GenericUniform InviteByEmail)
124+
deriving (ToJSON, FromJSON, S.ToSchema) via (Schema MeetingEmailsInvitation)
125+
deriving (Arbitrary) via (GenericUniform MeetingEmailsInvitation)
128126

129-
instance ToSchema InviteByEmail where
127+
instance ToSchema MeetingEmailsInvitation where
130128
schema =
131-
objectWithDocModifier "InviteByEmail" (description ?~ "Email invitation") $
132-
InviteByEmail
133-
<$> (.email) .= field "email" schema
129+
objectWithDocModifier "MeetingEmailsInvitation" (description ?~ "Emails invitation") $
130+
MeetingEmailsInvitation
131+
<$> (.emails) .= field "emails" (array schema)

libs/wire-api/src/Wire/API/Routes/Public/Galley/Meetings.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Wire.API.Meeting
2525
import Wire.API.Routes.MultiVerb
2626
import Wire.API.Routes.Named
2727
import Wire.API.Routes.Public
28+
import Wire.API.User.Identity (EmailAddress)
2829

2930
type MeetingsAPI =
3031
Named
@@ -100,7 +101,7 @@ type MeetingsAPI =
100101
:> "invitations"
101102
:> CanThrow 'MeetingNotFound
102103
:> CanThrow 'AccessDenied
103-
:> ReqBody '[JSON] InviteByEmail
104+
:> ReqBody '[JSON] MeetingEmailsInvitation
104105
:> MultiVerb
105106
'POST
106107
'[JSON]
@@ -117,9 +118,10 @@ type MeetingsAPI =
117118
:> "invitations"
118119
:> CanThrow 'MeetingNotFound
119120
:> CanThrow 'AccessDenied
120-
:> ReqBody '[JSON] InviteByEmail
121+
:> Capture "email" EmailAddress
122+
:> "delete"
121123
:> MultiVerb
122-
'DELETE
124+
'POST
123125
'[JSON]
124126
'[RespondEmpty 200 "Invitation removed"]
125127
()

libs/wire-subsystems/src/Wire/MeetingsStore.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ data MeetingsStore m a where
5858
DeleteMeeting ::
5959
Qualified MeetingId ->
6060
MeetingsStore m ()
61-
AddInvitedEmail ::
61+
AddInvitedEmails ::
6262
Qualified MeetingId ->
63-
EmailAddress ->
63+
[EmailAddress] ->
6464
MeetingsStore m ()
65-
RemoveInvitedEmail ::
65+
RemoveInvitedEmails ::
6666
Qualified MeetingId ->
67-
EmailAddress ->
67+
[EmailAddress] ->
6868
MeetingsStore m ()
6969
-- Cleanup operations
7070
GetOldMeetings ::

libs/wire-subsystems/src/Wire/MeetingsStore/Postgres.hs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import Polysemy
3939
import Polysemy.Error (Error, throw)
4040
import Polysemy.Input
4141
import Wire.API.Meeting qualified as API
42+
import Wire.API.PostgresMarshall
4243
import Wire.API.User.Identity (EmailAddress, emailAddressText, fromEmail)
4344
import Wire.MeetingsStore
4445

@@ -62,10 +63,10 @@ interpretMeetingsStoreToPostgres =
6263
updateMeetingImpl meetingId title startDate endDate schedule
6364
DeleteMeeting meetingId ->
6465
deleteMeetingImpl meetingId
65-
AddInvitedEmail meetingId email ->
66-
addInvitedEmailImpl meetingId email
67-
RemoveInvitedEmail meetingId email ->
68-
removeInvitedEmailImpl meetingId email
66+
AddInvitedEmails meetingId email ->
67+
addInvitedEmailsImpl meetingId email
68+
RemoveInvitedEmails meetingId emails ->
69+
removeInvitedEmailsImpl meetingId emails
6970
GetOldMeetings cutoffTime batchSize ->
7071
getOldMeetingsImpl cutoffTime batchSize
7172
DeleteMeetingBatch meetingIds ->
@@ -284,52 +285,53 @@ deleteMeetingImpl qMeetingId = do
284285
WHERE domain = ($1 :: text) AND id :: text = ($2 :: text)
285286
|]
286287

287-
addInvitedEmailImpl ::
288+
addInvitedEmailsImpl ::
288289
( Member (Input Pool) r,
289290
Member (Embed IO) r,
290291
Member (Error UsageError) r
291292
) =>
292293
Qualified API.MeetingId ->
293-
EmailAddress ->
294+
[EmailAddress] ->
294295
Sem r ()
295-
addInvitedEmailImpl qMeetingId email = do
296+
addInvitedEmailsImpl qMeetingId emails = do
296297
pool <- input
297298
result <- liftIO $ use pool session
298299
either throw pure result
299300
where
300301
session :: Session ()
301-
session = statement (fromEmail email, _domainText (qDomain qMeetingId), UUID.toText (API.unMeetingId (qUnqualified qMeetingId))) addEmailStatement
302+
session = statement (fromEmail <$> emails, _domainText (qDomain qMeetingId), UUID.toText (API.unMeetingId (qUnqualified qMeetingId))) addEmailStatement
302303

303-
addEmailStatement :: Statement (Text, Text, Text) ()
304+
addEmailStatement :: Statement ([Text], Text, Text) ()
304305
addEmailStatement =
305-
[resultlessStatement|
306+
lmapPG @_ @(V.Vector _, _, _)
307+
[resultlessStatement|
306308
UPDATE meetings
307-
SET invited_emails = array_append(invited_emails, $1 :: text)
309+
SET invited_emails = array_cat(invited_emails, $1 :: text[])
308310
WHERE domain = ($2 :: text) AND id :: text = ($3 :: text)
309-
AND NOT ($1 :: text = ANY(invited_emails))
310311
|]
311312

312-
removeInvitedEmailImpl ::
313+
removeInvitedEmailsImpl ::
313314
( Member (Input Pool) r,
314315
Member (Embed IO) r,
315316
Member (Error UsageError) r
316317
) =>
317318
Qualified API.MeetingId ->
318-
EmailAddress ->
319+
[EmailAddress] ->
319320
Sem r ()
320-
removeInvitedEmailImpl qMeetingId email = do
321+
removeInvitedEmailsImpl qMeetingId emails = do
321322
pool <- input
322323
result <- liftIO $ use pool session
323324
either throw pure result
324325
where
325326
session :: Session ()
326-
session = statement (fromEmail email, _domainText (qDomain qMeetingId), UUID.toText (API.unMeetingId (qUnqualified qMeetingId))) removeEmailStatement
327+
session = statement (fromEmail <$> emails, _domainText (qDomain qMeetingId), UUID.toText (API.unMeetingId (qUnqualified qMeetingId))) removeEmailStatement
327328

328-
removeEmailStatement :: Statement (Text, Text, Text) ()
329+
removeEmailStatement :: Statement ([Text], Text, Text) ()
329330
removeEmailStatement =
330-
[resultlessStatement|
331-
UPDATE meetings
332-
SET invited_emails = array_remove(invited_emails, $1 :: text)
331+
lmapPG @_ @(V.Vector _, _, _)
332+
[resultlessStatement|
333+
UPDATE meetings M
334+
SET invited_emails = (SELECT array(SELECT unnest(M.invited_emails) EXCEPT SELECT unnest($1 :: text[])))
333335
WHERE domain = ($2 :: text) AND id :: text = ($3 :: text)
334336
|]
335337

libs/wire-subsystems/src/Wire/MeetingsSubsystem.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ data MeetingsSubsystem m a where
4848
Local UserId ->
4949
Qualified MeetingId ->
5050
MeetingsSubsystem m Bool
51-
AddInvitedEmail ::
51+
AddInvitedEmails ::
5252
Local UserId ->
5353
Qualified MeetingId ->
54-
EmailAddress ->
54+
[EmailAddress] ->
5555
MeetingsSubsystem m Bool
56-
RemoveInvitedEmail ::
56+
RemoveInvitedEmails ::
5757
Local UserId ->
5858
Qualified MeetingId ->
59-
EmailAddress ->
59+
[EmailAddress] ->
6060
MeetingsSubsystem m Bool
6161
-- Cleanup operation
6262
CleanupOldMeetings ::

libs/wire-subsystems/src/Wire/MeetingsSubsystem/Interpreter.hs

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ interpretMeetingsSubsystem = interpret $ \case
5353
updateMeetingImpl zUser meetingId update
5454
DeleteMeeting zUser meetingId ->
5555
deleteMeetingImpl zUser meetingId
56-
AddInvitedEmail zUser meetingId email ->
57-
addInvitedEmailImpl zUser meetingId email
58-
RemoveInvitedEmail zUser meetingId email ->
59-
removeInvitedEmailImpl zUser meetingId email
56+
AddInvitedEmails zUser meetingId emails ->
57+
addInvitedEmailsImpl zUser meetingId emails
58+
RemoveInvitedEmails zUser meetingId emails ->
59+
removeInvitedEmailsImpl zUser meetingId emails
6060
CleanupOldMeetings cutoffTime batchSize ->
6161
cleanupOldMeetingsImpl cutoffTime batchSize
6262

@@ -73,43 +73,39 @@ createMeetingImpl zUser newMeeting = do
7373
meetingId <- liftIO $ MeetingId <$> UUIDV4.nextRandom
7474
let qMeetingId = tUntagged (qualifyAs zUser meetingId)
7575

76-
-- Use provided conversation or create a new one with MeetingConversation type
77-
qConvId <- case newMeeting.conversationId of
78-
Just cid -> pure cid
79-
Nothing -> do
80-
-- Generate new conversation ID
81-
convId <- liftIO $ randomId
82-
let lConvId = qualifyAs zUser convId
76+
-- Generate new conversation ID
77+
convId <- liftIO $ randomId
78+
let lConvId = qualifyAs zUser convId
8379

84-
-- Create conversation metadata for a meeting
85-
let metadata =
86-
ConversationMetadata
87-
{ cnvmType = RegularConv,
88-
cnvmCreator = Just (tUnqualified zUser),
89-
cnvmAccess = [],
90-
cnvmAccessRoles = Set.empty,
91-
cnvmName = Just newMeeting.title,
92-
cnvmTeam = Nothing,
93-
cnvmMessageTimer = Nothing,
94-
cnvmReceiptMode = Nothing,
95-
cnvmGroupConvType = Just MeetingConversation,
96-
cnvmChannelAddPermission = Nothing,
97-
cnvmCellsState = CellsDisabled,
98-
cnvmParent = Nothing
99-
}
80+
-- Create conversation metadata for a meeting
81+
let metadata =
82+
ConversationMetadata
83+
{ cnvmType = RegularConv,
84+
cnvmCreator = Just (tUnqualified zUser),
85+
cnvmAccess = [],
86+
cnvmAccessRoles = Set.empty,
87+
cnvmName = Just newMeeting.title,
88+
cnvmTeam = Nothing,
89+
cnvmMessageTimer = Nothing,
90+
cnvmReceiptMode = Nothing,
91+
cnvmGroupConvType = Just MeetingConversation,
92+
cnvmChannelAddPermission = Nothing,
93+
cnvmCellsState = CellsDisabled,
94+
cnvmParent = Nothing
95+
}
10096

101-
-- Create conversation with the meeting creator as the only member (admin role)
102-
let newConv =
103-
NewConversation
104-
{ metadata = metadata,
105-
users = UserList [(tUnqualified zUser, roleNameWireAdmin)] [],
106-
protocol = BaseProtocolProteusTag,
107-
groupId = Nothing
108-
}
97+
-- Create conversation with the meeting creator as the only member (admin role)
98+
let newConv =
99+
NewConversation
100+
{ metadata = metadata,
101+
users = UserList [(tUnqualified zUser, roleNameWireAdmin)] [],
102+
protocol = BaseProtocolProteusTag,
103+
groupId = Nothing
104+
}
109105

110-
-- Store the conversation
111-
storedConv <- ConvStore.upsertConversation lConvId newConv
112-
pure $ tUntagged (qualifyAs zUser storedConv.id_)
106+
-- Store the conversation
107+
storedConv <- ConvStore.upsertConversation lConvId newConv
108+
let qConvId = tUntagged (qualifyAs zUser storedConv.id_)
113109

114110
-- Determine trial status
115111
-- TODO: Check if user is a paying customer via Feature
@@ -248,13 +244,13 @@ deleteMeetingImpl zUser meetingId = do
248244

249245
pure True
250246

251-
addInvitedEmailImpl ::
247+
addInvitedEmailsImpl ::
252248
(Member Store.MeetingsStore r) =>
253249
Local UserId ->
254250
Qualified MeetingId ->
255-
EmailAddress ->
251+
[EmailAddress] ->
256252
Sem r Bool
257-
addInvitedEmailImpl zUser meetingId email = do
253+
addInvitedEmailsImpl zUser meetingId emails = do
258254
-- Get existing meeting
259255
maybeMeeting <- Store.getMeeting meetingId
260256
case maybeMeeting of
@@ -265,16 +261,16 @@ addInvitedEmailImpl zUser meetingId email = do
265261
then pure False
266262
else do
267263
-- Add invited email
268-
Store.addInvitedEmail meetingId email
264+
Store.addInvitedEmails meetingId emails
269265
pure True
270266

271-
removeInvitedEmailImpl ::
267+
removeInvitedEmailsImpl ::
272268
(Member Store.MeetingsStore r) =>
273269
Local UserId ->
274270
Qualified MeetingId ->
275-
EmailAddress ->
271+
[EmailAddress] ->
276272
Sem r Bool
277-
removeInvitedEmailImpl zUser meetingId email = do
273+
removeInvitedEmailsImpl zUser meetingId emails = do
278274
-- Get existing meeting
279275
maybeMeeting <- Store.getMeeting meetingId
280276
case maybeMeeting of
@@ -285,7 +281,7 @@ removeInvitedEmailImpl zUser meetingId email = do
285281
then pure False
286282
else do
287283
-- Remove invited email
288-
Store.removeInvitedEmail meetingId email
284+
Store.removeInvitedEmails meetingId emails
289285
pure True
290286

291287
cleanupOldMeetingsImpl ::

services/galley/src/Galley/API/Meetings.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import Polysemy
3535
import Wire.API.Error
3636
import Wire.API.Error.Galley
3737
import Wire.API.Meeting
38+
import Wire.API.User.Identity (EmailAddress)
3839
import Wire.MeetingsSubsystem qualified as Meetings
3940

4041
createMeeting ::
@@ -116,11 +117,11 @@ addMeetingInvitation ::
116117
Local UserId ->
117118
Domain ->
118119
MeetingId ->
119-
InviteByEmail ->
120+
MeetingEmailsInvitation ->
120121
Sem r ()
121-
addMeetingInvitation zUser domain meetingId (InviteByEmail email) = do
122+
addMeetingInvitation zUser domain meetingId (MeetingEmailsInvitation emails) = do
122123
let qMeetingId = Qualified meetingId domain
123-
success <- Meetings.addInvitedEmail zUser qMeetingId email
124+
success <- Meetings.addInvitedEmails zUser qMeetingId emails
124125
unless success $ throwS @'MeetingNotFound
125126

126127
removeMeetingInvitation ::
@@ -130,9 +131,9 @@ removeMeetingInvitation ::
130131
Local UserId ->
131132
Domain ->
132133
MeetingId ->
133-
InviteByEmail ->
134+
EmailAddress ->
134135
Sem r ()
135-
removeMeetingInvitation zUser domain meetingId (InviteByEmail email) = do
136+
removeMeetingInvitation zUser domain meetingId email = do
136137
let qMeetingId = Qualified meetingId domain
137-
success <- Meetings.removeInvitedEmail zUser qMeetingId email
138+
success <- Meetings.removeInvitedEmails zUser qMeetingId [email]
138139
unless success $ throwS @'MeetingNotFound

0 commit comments

Comments
 (0)