Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pydio events #4442

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import Servant.OpenApi (HasOpenApi (toOpenApi))
import Wire.API.Conversation
import Wire.API.Conversation.Action
import Wire.API.Conversation.Protocol
import Wire.API.Conversation.PydioState
import Wire.API.Conversation.Role (RoleName)
import Wire.API.Conversation.Typing
import Wire.API.Error.Galley
Expand Down Expand Up @@ -350,7 +351,8 @@ data ConversationCreated conv = ConversationCreated
nonCreatorMembers :: Set OtherMember,
messageTimer :: Maybe Milliseconds,
receiptMode :: Maybe ReceiptMode,
protocol :: Protocol
protocol :: Protocol,
pydioState :: Maybe PydioState -- TODO: remove Maybe
}
deriving stock (Eq, Show, Generic, Functor)
deriving (ToJSON, FromJSON) via (CustomEncoded (ConversationCreated conv))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Data.UUID qualified as UUID
import Imports
import Wire.API.Conversation
import Wire.API.Conversation.Protocol
import Wire.API.Conversation.PydioState
import Wire.API.Conversation.Role
import Wire.API.Federation.API.Galley
import Wire.API.MLS.CipherSuite
Expand Down Expand Up @@ -70,7 +71,8 @@ testObject_ConversationCreated1 =
],
messageTimer = Just (Ms 1000),
receiptMode = Just (ReceiptMode 42),
protocol = ProtocolProteus
protocol = ProtocolProteus,
pydioState = Nothing
}

testObject_ConversationCreated2 :: ConversationCreated ConvId
Expand All @@ -97,5 +99,6 @@ testObject_ConversationCreated2 =
MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519
)
)
)
),
pydioState = Just PydioPending
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Data.UUID qualified as UUID
import Imports
import Wire.API.Conversation
import Wire.API.Conversation.Protocol
import Wire.API.Conversation.PydioState
import Wire.API.Conversation.Role
import Wire.API.Federation.API.Galley
import Wire.API.MLS.Keys
Expand Down Expand Up @@ -68,7 +69,8 @@ remoteConversation =
cnvmName = Just " 0",
cnvmTeam = Just (Id (fromJust (UUID.fromString "00000001-0000-0001-0000-000100000002"))),
cnvmMessageTimer = Nothing,
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = -2})
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = -2}),
cnvmPydioState = PydioDisabled
},
members =
RemoteConvMembers
Expand Down Expand Up @@ -105,7 +107,8 @@ remoteConversationV2 =
cnvmName = Just " 0",
cnvmTeam = Just (Id (fromJust (UUID.fromString "00000001-0000-0001-0000-000100000002"))),
cnvmMessageTimer = Nothing,
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = -2})
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = -2}),
cnvmPydioState = PydioPending
},
members =
RemoteConvMembers
Expand Down
9 changes: 7 additions & 2 deletions libs/wire-api/src/Wire/API/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import Control.Lens ((?~))
import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Aeson qualified as A
import Data.ByteString.Lazy qualified as LBS
import Data.Default
import Data.Domain
import Data.Id
import Data.List.Extra (disjointOrd)
Expand All @@ -111,6 +112,7 @@ import Imports
import System.Random (randomRIO)
import Wire.API.Conversation.Member
import Wire.API.Conversation.Protocol
import Wire.API.Conversation.PydioState
import Wire.API.Conversation.Role (RoleName, roleNameWireAdmin)
import Wire.API.Event.LeaveReason
import Wire.API.MLS.Group
Expand All @@ -136,7 +138,8 @@ data ConversationMetadata = ConversationMetadata
-- federation.
cnvmTeam :: Maybe TeamId,
cnvmMessageTimer :: Maybe Milliseconds,
cnvmReceiptMode :: Maybe ReceiptMode
cnvmReceiptMode :: Maybe ReceiptMode,
cnvmPydioState :: PydioState
}
deriving stock (Eq, Show, Generic)
deriving (Arbitrary) via (GenericUniform ConversationMetadata)
Expand All @@ -152,7 +155,8 @@ defConversationMetadata mCreator =
cnvmName = Nothing,
cnvmTeam = Nothing,
cnvmMessageTimer = Nothing,
cnvmReceiptMode = Nothing
cnvmReceiptMode = Nothing,
cnvmPydioState = def
}

accessRolesVersionedSchema :: Maybe Version -> ObjectSchema SwaggerDoc (Set AccessRole)
Expand Down Expand Up @@ -212,6 +216,7 @@ conversationMetadataObjectSchema sch =
(description ?~ "Per-conversation message timer (can be null)")
(maybeWithDefault A.Null schema)
<*> cnvmReceiptMode .= optField "receipt_mode" (maybeWithDefault A.Null schema)
<*> cnvmPydioState .= (fromMaybe def <$> optField "pydio_state" schema)

instance ToSchema ConversationMetadata where
schema = object "ConversationMetadata" (conversationMetadataObjectSchema accessRolesSchema)
Expand Down
63 changes: 63 additions & 0 deletions libs/wire-api/src/Wire/API/Conversation/PydioState.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2025 Wire Swiss GmbH <[email protected]>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Wire.API.Conversation.PydioState where

import Cassandra.CQL
import Data.Aeson (FromJSON, ToJSON)
import Data.Default
import Data.OpenApi qualified as S
import Data.Schema
import Imports
import Wire.Arbitrary

data PydioState
= -- | Pydio is not enabled
PydioDisabled
| -- | Pydio is being initialised
PydioPending
| -- | Pydio is ready
PydioReady
deriving stock (Eq, Ord, Show, Generic)
deriving (Arbitrary) via (GenericUniform PydioState)
deriving (FromJSON, ToJSON, S.ToSchema) via Schema PydioState

instance Default PydioState where
def = PydioDisabled

instance ToSchema PydioState where
schema =
enum @Text "PydioState" $
mconcat
[ element "disabled" PydioDisabled,
element "pending" PydioPending,
element "ready" PydioReady
]

instance Cql PydioState where
ctype = Tagged IntColumn

toCql PydioDisabled = CqlInt 0
toCql PydioPending = CqlInt 1
toCql PydioReady = CqlInt 2

fromCql (CqlInt i) = case i of
0 -> pure PydioDisabled
1 -> pure PydioPending
2 -> pure PydioReady
n -> Left $ "unexpected pydio_state: " ++ show n
fromCql _ = Left "pydio_state: int expected"
10 changes: 10 additions & 0 deletions libs/wire-api/src/Wire/API/Event/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Wire.API.Event.Conversation
EventType (..),
EventData (..),
AddCodeResult (..),
isPydioEvent,

-- * Event lenses
_EdMembersJoin,
Expand Down Expand Up @@ -224,6 +225,15 @@ eventDataType (EdMLSWelcome _) = MLSWelcome
eventDataType EdConvDelete = ConvDelete
eventDataType (EdProtocolUpdate _) = ProtocolUpdate

isPydioEvent :: EventType -> Bool
isPydioEvent MemberJoin = True
isPydioEvent MemberLeave = True
isPydioEvent MemberStateUpdate = True
isPydioEvent ConvRename = True
isPydioEvent ConvCreate = True
isPydioEvent ConvDelete = True
isPydioEvent _ = False

--------------------------------------------------------------------------------
-- Event data helpers

Expand Down
12 changes: 8 additions & 4 deletions libs/wire-api/src/Wire/API/Push/V2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Wire.API.Push.V2
pushNativeAps,
pushNativePriority,
pushPayload,
pushIsPydioEvent,
singletonPayload,
Recipient (..),
RecipientClients (..),
Expand Down Expand Up @@ -226,7 +227,7 @@ data Push = Push
-- assumption that no 'ConnId' is used by two 'Recipient's. This is *probably* correct, but
-- not in any contract. (Changing this may require a new version module, since we need to
-- support both the old and the new data type simultaneously during upgrade.)
_pushRecipients :: Range 1 1024 (Set Recipient),
_pushRecipients :: Range 0 1024 (Set Recipient),
-- | Originating user
--
-- 'Nothing' here means that the originating user is on another backend.
Expand Down Expand Up @@ -255,12 +256,13 @@ data Push = Push
-- | Native push priority.
_pushNativePriority :: !Priority,
-- | Opaque payload
_pushPayload :: !(List1 Object)
_pushPayload :: !(List1 Object),
_pushIsPydioEvent :: !Bool
}
deriving (Eq, Show)
deriving (FromJSON, ToJSON, S.ToSchema) via (Schema Push)

newPush :: Maybe UserId -> Range 1 1024 (Set Recipient) -> List1 Object -> Push
newPush :: Maybe UserId -> Range 0 1024 (Set Recipient) -> List1 Object -> Push
newPush from to pload =
Push
{ _pushRecipients = to,
Expand All @@ -272,7 +274,8 @@ newPush from to pload =
_pushNativeEncrypt = True,
_pushNativeAps = Nothing,
_pushNativePriority = HighPriority,
_pushPayload = pload
_pushPayload = pload,
_pushIsPydioEvent = False
}

singletonPayload :: (ToJSONObject a) => a -> List1 Object
Expand All @@ -298,6 +301,7 @@ instance ToSchema Push where
<*> (ifNot (== HighPriority) . _pushNativePriority)
.= maybe_ (fromMaybe HighPriority <$> optField "native_priority" schema)
<*> _pushPayload .= field "payload" schema
<*> _pushIsPydioEvent .= field "is_pydio_event" schema
where
ifNot f a = if f a then Nothing else Just a

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Data.UUID qualified as UUID (fromString)
import Imports
import Wire.API.Conversation
import Wire.API.Conversation.Protocol
import Wire.API.Conversation.PydioState
import Wire.API.Conversation.Role (parseRoleName)

domain :: Domain
Expand All @@ -48,7 +49,8 @@ testObject_ConversationList_20Conversation_user_1 =
cnvmName = Just "",
cnvmTeam = Just (Id (fromJust (UUID.fromString "00000000-0000-0000-0000-000100000001"))),
cnvmMessageTimer = Just (Ms {ms = 4760386328981119}),
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = 0})
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = 0}),
cnvmPydioState = PydioReady
},
cnvProtocol = ProtocolProteus,
cnvMembers =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import Data.UUID qualified as UUID (fromString)
import Imports
import Wire.API.Conversation
import Wire.API.Conversation.Protocol
import Wire.API.Conversation.PydioState
import Wire.API.Conversation.Role (parseRoleName)
import Wire.API.MLS.CipherSuite
import Wire.API.Provider.Service (ServiceRef (ServiceRef, _serviceRefId, _serviceRefProvider))
Expand All @@ -57,7 +58,8 @@ testObject_Conversation_user_1 =
cnvmName = Just " 0",
cnvmTeam = Just (Id (fromJust (UUID.fromString "00000001-0000-0001-0000-000100000002"))),
cnvmMessageTimer = Nothing,
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = -2})
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = -2}),
cnvmPydioState = PydioReady
},
cnvProtocol = ProtocolProteus,
cnvMembers =
Expand Down Expand Up @@ -104,7 +106,8 @@ testObject_Conversation_user_2 =
cnvmName = Just "",
cnvmTeam = Nothing,
cnvmMessageTimer = Just (Ms {ms = 1319272593797015}),
cnvmReceiptMode = Nothing
cnvmReceiptMode = Nothing,
cnvmPydioState = PydioPending
},
cnvProtocol = ProtocolProteus,
cnvMembers =
Expand Down Expand Up @@ -170,7 +173,8 @@ testObject_Conversation_user_3 =
cnvmName = Just "",
cnvmTeam = Just (Id (fromJust (UUID.fromString "00000000-0000-0001-0000-000200000000"))),
cnvmMessageTimer = Just (Ms {ms = 1319272593797015}),
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = 2})
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = 2}),
cnvmPydioState = PydioDisabled
},
cnvMembers =
ConvMembers
Expand Down Expand Up @@ -232,7 +236,8 @@ testObject_Conversation_user_4 =
cnvmName = Just "",
cnvmTeam = Just (Id (fromJust (UUID.fromString "00000000-0000-0001-0000-000200000000"))),
cnvmMessageTimer = Just (Ms {ms = 1319272593797015}),
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = 2})
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = 2}),
cnvmPydioState = PydioDisabled
},
cnvMembers =
ConvMembers
Expand Down Expand Up @@ -272,7 +277,8 @@ testObject_Conversation_user_5 =
cnvmName = Just " 0",
cnvmTeam = Just (Id (fromJust (UUID.fromString "00000001-0000-0001-0000-000100000002"))),
cnvmMessageTimer = Nothing,
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = -2})
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = -2}),
cnvmPydioState = PydioDisabled
},
cnvMembers =
ConvMembers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import Imports
import Wire.API.Conversation
import Wire.API.Conversation.Code
import Wire.API.Conversation.Protocol
import Wire.API.Conversation.PydioState
import Wire.API.Conversation.Role (parseRoleName)
import Wire.API.Conversation.Typing
import Wire.API.Event.Conversation
Expand Down Expand Up @@ -156,7 +157,8 @@ testObject_Event_user_8 =
cnvmName = Just "\a\SO\r",
cnvmTeam = Just (Id (fromJust (UUID.fromString "00000000-0000-0002-0000-000100000001"))),
cnvmMessageTimer = Just (Ms {ms = 283898987885780}),
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = -1})
cnvmReceiptMode = Just (ReceiptMode {unReceiptMode = -1}),
cnvmPydioState = PydioDisabled
},
cnvProtocol = ProtocolProteus,
cnvMembers =
Expand Down
6 changes: 4 additions & 2 deletions libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ testObject_Push_1 =
_pushNativeEncrypt = True,
_pushNativeAps = Nothing,
_pushNativePriority = HighPriority,
_pushPayload = singleton mempty
_pushPayload = singleton mempty,
_pushIsPydioEvent = False
}

testObject_Push_2 :: Push
Expand All @@ -78,5 +79,6 @@ testObject_Push_2 =
_pushPayload =
list1
(KM.fromList [("foo" :: KM.Key) A..= '3', "bar" A..= True])
[KM.fromList [], KM.fromList ["growl" A..= ("foooood" :: Text)], KM.fromList ["lunchtime" A..= ("imminent" :: Text)]]
[KM.fromList [], KM.fromList ["growl" A..= ("foooood" :: Text)], KM.fromList ["lunchtime" A..= ("imminent" :: Text)]],
_pushIsPydioEvent = False
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"message_timer": 4760386328981119,
"name": "",
"protocol": "proteus",
"pydio_state": "ready",
"qualified_id": {
"domain": "golden.example.com",
"id": "00000001-0000-0000-0000-000000000000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"message_timer": null,
"name": " 0",
"protocol": "proteus",
"pydio_state": "ready",
"qualified_id": {
"domain": "golden.example.com",
"id": "00000001-0000-0000-0000-000000000000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"message_timer": 1319272593797015,
"name": "",
"protocol": "proteus",
"pydio_state": "pending",
"qualified_id": {
"domain": "golden.example.com",
"id": "00000000-0000-0000-0000-000000000002"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"message_timer": 1319272593797015,
"name": "",
"protocol": "mls",
"pydio_state": "disabled",
"qualified_id": {
"domain": "golden.example.com",
"id": "00000000-0000-0000-0000-000000000002"
Expand Down
Loading
Loading