Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5-internal/WPB-18708
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Include the new group ID in the MLS conversation reset event
4 changes: 4 additions & 0 deletions integration/test/Notifications.hs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ isConnectionNotif status n =
isUserGroupCreatedNotif :: (MakesValue a) => a -> App Bool
isUserGroupCreatedNotif = notifTypeIsEqual "user-group.created"

isConvResetNotif :: (HasCallStack, MakesValue n) => n -> App Bool
isConvResetNotif n =
fieldEquals n "payload.0.type" "conversation.mls-reset"

assertLeaveNotification ::
( HasCallStack,
MakesValue fromUser,
Expand Down
13 changes: 11 additions & 2 deletions integration/test/Test/MLS/Reset.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Test.MLS.Reset where

import API.Galley
import MLS.Util
import Notifications (isConvResetNotif)
import SetupHelpers
import Testlib.Prelude
import Testlib.VersionedFed
Expand All @@ -18,9 +19,17 @@ testResetGroupConversation domain = do
resetConversation alice mlsConv.groupId 0 >>= assertStatus 409
resetConversation bob mlsConv.groupId 0 >>= assertStatus 409
resetConversation charlie mlsConv.groupId mlsConv.epoch >>= assertStatus 404
resetConversation bob mlsConv.groupId mlsConv.epoch >>= assertStatus 200

conv' <- getConversation alice conv >>= getJSON 200
conv' <- withWebSocket alice $ \ws -> do
resetConversation bob mlsConv.groupId mlsConv.epoch >>= assertStatus 200
conv' <- getConversation alice conv >>= getJSON 200

e <- awaitMatch isConvResetNotif ws
e %. "payload.0.data.group_id" `shouldMatch` mlsConv.groupId
e %. "payload.0.data.new_group_id" `shouldMatch` (conv' %. "group_id")

pure conv'

conv' %. "group_id" `shouldNotMatch` (mlsConv.groupId :: String)
conv' %. "epoch" `shouldMatchInt` 0
otherMember <- assertOne =<< asList (conv' %. "members.others")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Data.Range
import Data.Time.Clock
import Imports
import Servant.API
import Wire.API.Conversation
import Wire.API.Conversation.Action
import Wire.API.Federation.Component
import Wire.API.Federation.Endpoint
Expand Down Expand Up @@ -178,7 +179,8 @@ data ConversationUpdate = ConversationUpdate
-- conversation to users.
alreadyPresentUsers :: [UserId],
-- | Information on the specific action that caused the update.
action :: SomeConversationAction
action :: SomeConversationAction,
extraConversationData :: Maybe ExtraConversationData
}
deriving (Eq, Show, Generic)

Expand All @@ -205,7 +207,8 @@ conversationUpdateFromV0 cu =
origUserId = cu.cuOrigUserId,
convId = cu.cuConvId,
alreadyPresentUsers = cu.cuAlreadyPresentUsers,
action = cu.cuAction
action = cu.cuAction,
extraConversationData = Nothing
}

type UserDeletedNotificationMaxConvs = 1000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ testObject_ConversationUpdate1 =
convId =
Id (fromJust (UUID.fromString "00000000-0000-0000-0000-000100000006")),
alreadyPresentUsers = [],
action = SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (qAlice :| [qBob]) roleNameWireAdmin InternalAdd)
action = SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (qAlice :| [qBob]) roleNameWireAdmin InternalAdd),
extraConversationData = Nothing
}

testObject_ConversationUpdate2 :: ConversationUpdate
Expand All @@ -102,5 +103,6 @@ testObject_ConversationUpdate2 =
convId =
Id (fromJust (UUID.fromString "00000000-0000-0000-0000-000100000006")),
alreadyPresentUsers = [chad, dee],
action = SomeConversationAction (sing @'ConversationLeaveTag) ()
action = SomeConversationAction (sing @'ConversationLeaveTag) (),
extraConversationData = Just (ExtraConversationData $ Just $ GroupId "group")
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"alreadyPresentUsers": [],
"convId": "00000000-0000-0000-0000-000100000006",
"extraConversationData": null,
"origUserId": {
"domain": "golden.example.com",
"id": "00000000-0000-0000-0000-000100000007"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"00000fff-0000-aaaa-0000-000100005007"
],
"convId": "00000000-0000-0000-0000-000100000006",
"extraConversationData": {
"group_id": "Z3JvdXA="
},
"origUserId": {
"domain": "golden.example.com",
"id": "00000000-0000-0000-0000-000100000007"
Expand Down
19 changes: 19 additions & 0 deletions libs/wire-api/src/Wire/API/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module Wire.API.Conversation
ConversationMemberUpdate (..),
ConversationRemoveMembers (..),
AddPermissionUpdate (..),
ExtraConversationData (..),

-- * re-exports
module Wire.API.Conversation.Member,
Expand Down Expand Up @@ -1164,6 +1165,24 @@ instance ToSchema AddPermissionUpdate where
$ AddPermissionUpdate
<$> addPermission .= field "add_permission" schema

newtype ExtraConversationData = ExtraConversationData
{ newGroupId :: Maybe GroupId
}
deriving stock (Eq, Show, Generic)
deriving (Arbitrary) via (GenericUniform ExtraConversationData)
deriving (FromJSON, ToJSON, S.ToSchema) via Schema ExtraConversationData

instance Default ExtraConversationData where
def = ExtraConversationData Nothing

instance ToSchema ExtraConversationData where
schema =
objectWithDocModifier
"ExtraConversationData"
(description ?~ "Extra conversation data, used for group conversations")
$ ExtraConversationData
<$> newGroupId .= optField "group_id" (maybeWithDefault A.Null schema)

--------------------------------------------------------------------------------
-- MultiVerb instances

Expand Down
14 changes: 11 additions & 3 deletions libs/wire-api/src/Wire/API/Conversation/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@ conversationActionToEvent ::
UTCTime ->
Qualified UserId ->
Qualified ConvId ->
ExtraConversationData ->
Maybe SubConvId ->
Maybe TeamId ->
ConversationAction tag ->
Event
conversationActionToEvent tag now quid qcnv subconv tid action =
conversationActionToEvent tag now quid qcnv convData subconv tid action =
let edata = case tag of
SConversationJoinTag ->
let ConversationJoin newMembers role joinType = action
Expand All @@ -215,8 +216,15 @@ conversationActionToEvent tag now quid qcnv subconv tid action =
SConversationAccessDataTag -> EdConvAccessUpdate action
SConversationUpdateProtocolTag -> EdProtocolUpdate action
SConversationUpdateAddPermissionTag -> EdAddPermissionUpdate action
SConversationResetTag -> EdConvReset action.groupId
in Event qcnv subconv quid now tid edata
SConversationResetTag -> EdConvReset $ ConversationReset {groupId = action.groupId, newGroupId = convData.newGroupId}
in Event
{ evtConv = qcnv,
evtSubConv = subconv,
evtFrom = quid,
evtTime = now,
evtTeam = tid,
evtData = edata
}

-- | Certain actions need to be performed at the level of the underlying
-- protocol (MLS, mostly) before being applied to conversations. This function
Expand Down
6 changes: 6 additions & 0 deletions libs/wire-api/src/Wire/API/Conversation/Protocol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module Wire.API.Conversation.Protocol
optionalActiveMLSConversationDataSchema,
cnvmlsEpoch,
ProtocolUpdate (..),
getGroupId,
)
where

Expand Down Expand Up @@ -251,3 +252,8 @@ deriving via (Schema ProtocolUpdate) instance FromJSON ProtocolUpdate
deriving via (Schema ProtocolUpdate) instance ToJSON ProtocolUpdate

deriving via (Schema ProtocolUpdate) instance S.ToSchema ProtocolUpdate

getGroupId :: Protocol -> Maybe GroupId
getGroupId (ProtocolMLS mlsData) = Just $ cnvmlsGroupId mlsData
getGroupId (ProtocolMixed mlsData) = Just $ cnvmlsGroupId mlsData
getGroupId _ = Nothing
20 changes: 18 additions & 2 deletions libs/wire-api/src/Wire/API/Event/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module Wire.API.Event.Conversation
Connect (..),
MemberUpdateData (..),
OtrMessage (..),
ConversationReset (..),

-- * re-exports
ConversationReceiptModeUpdate (..),
Expand Down Expand Up @@ -188,7 +189,7 @@ data EventData
| EdConvReceiptModeUpdate ConversationReceiptModeUpdate
| EdConvRename ConversationRename
| EdConvDelete
| EdConvReset GroupId
| EdConvReset ConversationReset
| EdConvAccessUpdate ConversationAccessData
| EdConvMessageTimerUpdate ConversationMessageTimerUpdate
| EdConvCodeUpdate ConversationCodeInfo
Expand Down Expand Up @@ -421,6 +422,21 @@ otrMessageObjectSchema =
"Extra (symmetric) data (i.e. ciphertext, Base64 in JSON) \
\that is common with all other recipients."

data ConversationReset = ConversationReset
{ groupId :: GroupId,
newGroupId :: Maybe GroupId
}
deriving stock (Eq, Show, Generic)
deriving (Arbitrary) via (GenericUniform ConversationReset)
deriving (FromJSON, ToJSON, S.ToSchema) via Schema ConversationReset

instance ToSchema ConversationReset where
schema =
object "ConversationReset" $
ConversationReset
<$> (.groupId) .= field "group_id" schema
<*> (.newGroupId) .= maybe_ (optField "new_group_id" schema)

makePrisms ''EventData

taggedEventDataSchema :: ObjectSchema SwaggerDoc (EventType, EventData)
Expand Down Expand Up @@ -452,7 +468,7 @@ taggedEventDataSchema =
Typing -> tag _EdTyping (unnamed schema)
ConvCodeDelete -> tag _EdConvCodeDelete null_
ConvDelete -> tag _EdConvDelete null_
ConvReset -> tag _EdConvReset (unnamed (object "ConvResetData" (field "group_id" schema)))
ConvReset -> tag _EdConvReset (unnamed schema)
ProtocolUpdate -> tag _EdProtocolUpdate (unnamed (unProtocolUpdate <$> P.ProtocolUpdate .= schema))
AddPermissionUpdate -> tag _EdAddPermissionUpdate (unnamed schema)

Expand Down
2 changes: 1 addition & 1 deletion libs/wire-api/src/Wire/API/MLS/Group/Serialisation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Data.Text.Encoding qualified as T
import Data.UUID qualified as UUID
import Imports
import Web.HttpApiData (FromHttpApiData (parseHeader))
import Wire.API.Conversation
import Wire.API.Conversation hiding (newGroupId)
import Wire.API.MLS.Group
import Wire.API.MLS.SubConversation
import Wire.Arbitrary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ spec = do
origUserId = user,
convId = convId,
alreadyPresentUsers = [],
action = SomeConversationAction SConversationLeaveTag ()
action = SomeConversationAction SConversationLeaveTag (),
extraConversationData = Nothing
}
let update0 = conversationUpdateToV0 update
let bundle =
Expand Down
Loading