Skip to content

Commit

Permalink
Also notify just joined members
Browse files Browse the repository at this point in the history
  • Loading branch information
pcapriotti committed May 31, 2021
1 parent b19d94a commit 574f339
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions services/galley/src/Galley/API/Federation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
module Galley.API.Federation where

import Control.Arrow (first)
import Data.Containers.ListUtils (nubOrd)
import Data.Qualified (Qualified (..))
import qualified Galley.API.Mapping as Mapping
import Galley.API.Util (pushConversationEvent, viewFederationDomain)
Expand Down Expand Up @@ -51,8 +52,9 @@ updateConversationMemberships :: ConversationMemberUpdate -> Galley ()
updateConversationMemberships cmu = do
localDomain <- viewFederationDomain
let localUsers = filter ((== localDomain) . qDomain . fst) (cmuUsersAdd cmu)
localUserIds = map (qUnqualified . fst) localUsers
when (not (null localUsers)) $ do
Data.addLocalMembersToRemoteConv (map (qUnqualified . fst) localUsers) (cmuConvId cmu)
Data.addLocalMembersToRemoteConv localUserIds (cmuConvId cmu)
-- FUTUREWORK: the resulting event should have qualified users and conversations
let mems = SimpleMembers (map (uncurry SimpleMember . first qUnqualified) (cmuUsersAdd cmu))
let event =
Expand All @@ -63,5 +65,7 @@ updateConversationMemberships cmu = do
(cmuTime cmu)
(EdMembersJoin mems)

-- send notifications
let targets = nubOrd $ cmuAlreadyPresentUsers cmu <> localUserIds
-- FUTUREWORK: support bots?
pushConversationEvent event (cmuAlreadyPresentUsers cmu) []
pushConversationEvent event targets []
11 changes: 8 additions & 3 deletions services/galley/test/integration/API/Federation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ tests s =
test s "POST /federation/get-conversations : Conversations user is not a part of are excluded from result" getConversationsNotPartOf,
test
s
"POST /federation/update-conversation-memberships : Add local user"
"POST /federation/update-conversation-memberships : Add local user to remote conversation"
addLocalUser,
test
s
"POST /federation/update-conversation-memberships : Notify local user"
"POST /federation/update-conversation-memberships : Notify local user about other members joining"
notifyLocalUser
]

Expand Down Expand Up @@ -117,6 +117,7 @@ getConversationsNotPartOf = do
addLocalUser :: TestM ()
addLocalUser = do
localDomain <- viewFederationDomain
c <- view tsCannon
alice <- randomUser
let qalice = Qualified alice localDomain
let dom = Domain "bobland.example.com"
Expand All @@ -135,7 +136,11 @@ addLocalUser = do
FedGalley.cmuUsersAdd = [(qalice, roleNameWireMember)],
FedGalley.cmuUsersRemove = []
}
FedGalley.updateConversationMemberships fedGalleyClient cmu
WS.bracketR c alice $ \ws -> do
FedGalley.updateConversationMemberships fedGalleyClient cmu
void . liftIO $
WS.assertMatch (5 # Second) ws $
wsAssertMemberJoinWithRole conv bob [alice] roleNameWireMember
cassState <- view tsCass
convs <-
Cql.runClient cassState
Expand Down

0 comments on commit 574f339

Please sign in to comment.