From 341b1ee286ec93e2444e68dddae3a852b17a896b Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Wed, 18 Sep 2024 11:48:20 +0200 Subject: [PATCH 01/32] WIP: move gundeck internal API to wire-api --- libs/wire-api/src/Wire/API/CannonId.hs | 13 + libs/wire-api/src/Wire/API/Presence.hs | 57 +++ libs/wire-api/src/Wire/API/Push/V2.hs | 330 ++++++++++++++++++ .../src/Wire/API/Routes/Internal/Gundeck.hs | 74 ++++ libs/wire-api/wire-api.cabal | 5 + 5 files changed, 479 insertions(+) create mode 100644 libs/wire-api/src/Wire/API/CannonId.hs create mode 100644 libs/wire-api/src/Wire/API/Presence.hs create mode 100644 libs/wire-api/src/Wire/API/Push/V2.hs create mode 100644 libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs diff --git a/libs/wire-api/src/Wire/API/CannonId.hs b/libs/wire-api/src/Wire/API/CannonId.hs new file mode 100644 index 00000000000..751b23ed4b5 --- /dev/null +++ b/libs/wire-api/src/Wire/API/CannonId.hs @@ -0,0 +1,13 @@ +module Wire.API.CannonId where + +import Data.Aeson +import Imports +import Web.HttpApiData + +newtype CannonId = CannonId + { cannonId :: Text + } + deriving (Eq, Ord, Show, FromJSON, ToJSON) + +instance FromHttpApiData CannonId where + parseUrlPiece = pure . CannonId diff --git a/libs/wire-api/src/Wire/API/Presence.hs b/libs/wire-api/src/Wire/API/Presence.hs new file mode 100644 index 00000000000..66255e318d9 --- /dev/null +++ b/libs/wire-api/src/Wire/API/Presence.hs @@ -0,0 +1,57 @@ +module Wire.API.Presence where + +import Data.Aeson +import Data.Aeson.Types +import Data.ByteString.Lazy qualified as Lazy +import Data.Id +import Data.Misc (Milliseconds) +import Data.Text qualified as Text +import Imports +import Network.URI + +-- | This is created in gundeck by cannon every time the client opens a new websocket connection. +-- (That's why we always have a 'ConnId' from the most recent connection by that client.) +data Presence = Presence + { userId :: !UserId, + connId :: !ConnId, + -- | cannon instance hosting the presence + resource :: !URI, + -- | This is 'Nothing' if either (a) the presence is older + -- than mandatory end-to-end encryption, or (b) the client is + -- operating the team settings pages without the need for + -- end-to-end crypto. + clientId :: !(Maybe ClientId), + createdAt :: !Milliseconds, + -- | REFACTOR: temp. addition to ease migration + __field :: !Lazy.ByteString + } + deriving (Eq, Ord, Show) + +instance ToJSON Presence where + toJSON p = + object + [ "user_id" .= userId p, + "device_id" .= connId p, + "resource" .= String (Text.pack (show (resource p))), + "client_id" .= clientId p, + "created_at" .= createdAt p + ] + +instance FromJSON Presence where + parseJSON = withObject "Presence" $ \o -> + Presence + <$> o .: "user_id" + <*> o .: "device_id" + <*> explicitParseField uriFromJSON o "resource" + <*> o .:? "client_id" + <*> o .:? "created_at" .!= 0 + <*> pure "" + +uriFromJSON :: Value -> Parser URI +uriFromJSON = withText "URI" (p . Text.unpack) + where + p :: (MonadFail m) => String -> m URI + p = maybe (fail "Invalid URI") pure . parseURI + +uriToJSON :: URI -> Value +uriToJSON uri = String $ Text.pack (show uri) diff --git a/libs/wire-api/src/Wire/API/Push/V2.hs b/libs/wire-api/src/Wire/API/Push/V2.hs new file mode 100644 index 00000000000..8529e6806b9 --- /dev/null +++ b/libs/wire-api/src/Wire/API/Push/V2.hs @@ -0,0 +1,330 @@ +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeApplications #-} + +module Wire.API.Push.V2 + ( Push (..), + newPush, + pushRecipients, + pushOrigin, + pushConnections, + pushOriginConnection, + pushTransient, + pushNativeIncludeOrigin, + pushNativeEncrypt, + pushNativeAps, + pushNativePriority, + pushPayload, + singletonPayload, + Recipient (..), + RecipientClients (..), + recipient, + recipientId, + recipientRoute, + recipientClients, + Route (..), + ApsData, + ApsLocKey (..), + ApsSound (..), + apsData, + apsLocKey, + apsLocArgs, + apsSound, + apsBadge, + + -- * Priority (re-export) + Priority (..), + + -- * PushToken (re-export) + PushTokenList (..), + PushToken, + pushToken, + tokenTransport, + tokenApp, + tokenClient, + token, + + -- * PushToken fields (re-export) + Token (..), + Transport (..), + AppName (..), + ) +where + +import Control.Lens (makeLenses) +import Data.Aeson (FromJSON (..), Object, ToJSON (..)) +import Data.Id +import Data.Json.Util +import Data.List1 +import Data.List1 qualified as List1 +import Data.Range +import Data.Schema +import Data.Set qualified as Set +import Imports +import Wire.API.Message (Priority (..)) +import Wire.API.Push.V2.Token +import Wire.Arbitrary + +----------------------------------------------------------------------------- +-- Route + +data Route + = -- | Sends notification on all channels including push notifications to + -- mobile clients. Note that transient messages never cause a push + -- notification. + RouteAny + | -- | Avoids causing push notification for mobile clients. + RouteDirect + deriving (Eq, Ord, Enum, Bounded, Show, Generic) + deriving (Arbitrary) via GenericUniform Route + +instance ToSchema Route + +-- instance FromJSON Route where +-- parseJSON (String "any") = pure RouteAny +-- parseJSON (String "direct") = pure RouteDirect +-- parseJSON x = fail $ "Invalid routing: " ++ show (encode x) +-- +-- instance ToJSON Route where +-- toJSON RouteAny = String "any" +-- toJSON RouteDirect = String "direct" + +----------------------------------------------------------------------------- +-- Recipient + +data Recipient = Recipient + { _recipientId :: !UserId, + _recipientRoute :: !Route, + _recipientClients :: !RecipientClients + } + deriving (Show, Eq, Ord, Generic) + +data RecipientClients + = -- | All clients of some user + RecipientClientsAll + | -- | An explicit list of clients + RecipientClientsSome (List1 ClientId) + deriving (Eq, Show, Ord, Generic) + deriving (Arbitrary) via GenericUniform RecipientClients + +instance Semigroup RecipientClients where + RecipientClientsAll <> _ = RecipientClientsAll + _ <> RecipientClientsAll = RecipientClientsAll + RecipientClientsSome cs1 <> RecipientClientsSome cs2 = + RecipientClientsSome (cs1 <> cs2) + +makeLenses ''Recipient + +recipient :: UserId -> Route -> Recipient +recipient u r = Recipient u r RecipientClientsAll + +instance ToSchema Recipient + +-- instance FromJSON Recipient where +-- parseJSON = withObject "Recipient" $ \p -> +-- Recipient +-- <$> p .: "user_id" +-- <*> p .: "route" +-- <*> p .:? "clients" .!= RecipientClientsAll +-- +-- instance ToJSON Recipient where +-- toJSON (Recipient u r c) = +-- object $ +-- "user_id" +-- .= u +-- # "route" +-- .= r +-- # "clients" +-- .= c +-- # [] + +instance ToSchema RecipientClients + +-- "All clients" is encoded in the API as an empty list. +-- instance FromJSON RecipientClients where +-- parseJSON x = +-- parseJSON @[ClientId] x >>= \case +-- [] -> pure RecipientClientsAll +-- c : cs -> pure (RecipientClientsSome (list1 c cs)) +-- +-- instance ToJSON RecipientClients where +-- toJSON = +-- toJSON . \case +-- RecipientClientsAll -> [] +-- RecipientClientsSome cs -> toList cs + +----------------------------------------------------------------------------- +-- ApsData + +newtype ApsSound = ApsSound {fromSound :: Text} + deriving (Eq, Show, ToJSON, FromJSON, Arbitrary) + +newtype ApsLocKey = ApsLocKey {fromLocKey :: Text} + deriving (Eq, Show, ToJSON, FromJSON, Arbitrary) + +data ApsData = ApsData + { _apsLocKey :: !ApsLocKey, + _apsLocArgs :: [Text], + _apsSound :: !(Maybe ApsSound), + _apsBadge :: !Bool + } + deriving (Eq, Show, Generic) + deriving (Arbitrary) via GenericUniform ApsData + +makeLenses ''ApsData + +apsData :: ApsLocKey -> [Text] -> ApsData +apsData lk la = ApsData lk la Nothing True + +instance ToSchema ApsData + +-- instance ToJSON ApsData where +-- toJSON (ApsData k a s b) = +-- object $ +-- "loc_key" +-- .= k +-- # "loc_args" +-- .= a +-- # "sound" +-- .= s +-- # "badge" +-- .= b +-- # [] +-- +-- instance FromJSON ApsData where +-- parseJSON = withObject "ApsData" $ \o -> +-- ApsData +-- <$> o .: "loc_key" +-- <*> o .:? "loc_args" .!= [] +-- <*> o .:? "sound" +-- <*> o .:? "badge" .!= True + +----------------------------------------------------------------------------- +-- Push + +data Push = Push + { -- | Recipients + -- + -- REFACTOR: '_pushRecipients' should be @Set (Recipient, Maybe (NonEmptySet ConnId))@, and + -- '_pushConnections' should go away. Rationale: the current setup only works under the + -- 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), + -- | Originating user + -- + -- 'Nothing' here means that the originating user is on another backend. + -- + -- REFACTOR: where is this required, and for what? or can it be removed? (see also: #531) + _pushOrigin :: !(Maybe UserId), + -- | Destination connections. If empty, ignore. Otherwise, filter the connections derived + -- from '_pushRecipients' and only push to those contained in this set. + -- + -- REFACTOR: change this to @_pushConnectionWhitelist :: Maybe (Set ConnId)@. + _pushConnections :: !(Set ConnId), + -- | Originating connection, if any. + _pushOriginConnection :: !(Maybe ConnId), + -- | Transient payloads are not forwarded to the notification stream. + _pushTransient :: !Bool, + -- | Whether to send native notifications to other clients + -- of the originating user, if he is among the recipients. + _pushNativeIncludeOrigin :: !Bool, + -- | Should native push payloads be encrypted? + -- + -- REFACTOR: this make no sense any more since native push notifications have no more payload. + -- https://github.com/wireapp/wire-server/pull/546 + _pushNativeEncrypt :: !Bool, + -- | APNs-specific metadata (needed eg. in "Brig.IO.Intra.toApsData"). + _pushNativeAps :: !(Maybe ApsData), + -- | Native push priority. + _pushNativePriority :: !Priority, + -- | Opaque payload + _pushPayload :: !(List1 Object) + } + deriving (Eq, Show) + +makeLenses ''Push + +newPush :: Maybe UserId -> Range 1 1024 (Set Recipient) -> List1 Object -> Push +newPush from to pload = + Push + { _pushRecipients = to, + _pushOrigin = from, + _pushConnections = Set.empty, + _pushOriginConnection = Nothing, + _pushTransient = False, + _pushNativeIncludeOrigin = True, + _pushNativeEncrypt = True, + _pushNativeAps = Nothing, + _pushNativePriority = HighPriority, + _pushPayload = pload + } + +singletonPayload :: (ToJSONObject a) => a -> List1 Object +singletonPayload = List1.singleton . toJSONObject + +instance ToSchema Push where + schema = + object "Push" $ + Push + <$> _pushRecipients .= field "recipients" (set schema) + <*> _pushOrigin .= maybe_ (optField "origin" schema) + <*> (ifNot Set.null . _pushConnections) + .= maybe_ (fmap (fromMaybe mempty) (optField "connections" (set schema))) + <*> _pushOriginConnection .= maybe_ (optField "origin_connection" schema) + <*> (ifNot not . _pushTransient) + .= maybe_ + (fmap (fromMaybe False) (optField "transient" schema)) + <*> (ifNot id . _pushNativeIncludeOrigin) + .= maybe_ (fmap (fromMaybe True) (optField "native_include_origin" schema)) + <*> (ifNot id . _pushNativeEncrypt) + .= maybe_ (fmap (fromMaybe True) (optField "native_encrypt" schema)) + <*> _pushNativeAps .= maybe_ (optField "native_aps" schema) + <*> (ifNot (== HighPriority) . _pushNativePriority) + .= maybe_ (fromMaybe HighPriority <$> optField "native_priority" schema) + <*> _pushPayload .= field "payload" schema + where + ifNot f a = if f a then Nothing else Just a + +-- instance FromJSON Push where +-- parseJSON = withObject "Push" $ \p -> +-- Push +-- <$> p .: "recipients" +-- <*> p .:? "origin" +-- <*> p .:? "connections" .!= Set.empty +-- <*> p .:? "origin_connection" +-- <*> p .:? "transient" .!= False +-- <*> p .:? "native_include_origin" .!= True +-- <*> p .:? "native_encrypt" .!= True +-- <*> p .:? "native_aps" +-- <*> p .:? "native_priority" .!= HighPriority +-- <*> p .: "payload" +-- +-- instance ToJSON Push where +-- toJSON p = +-- object $ +-- "recipients" +-- .= _pushRecipients p +-- # "origin" +-- .= _pushOrigin p +-- # "connections" +-- .= ifNot Set.null (_pushConnections p) +-- # "origin_connection" +-- .= _pushOriginConnection p +-- # "transient" +-- .= ifNot not (_pushTransient p) +-- # "native_include_origin" +-- .= ifNot id (_pushNativeIncludeOrigin p) +-- # "native_encrypt" +-- .= ifNot id (_pushNativeEncrypt p) +-- # "native_aps" +-- .= _pushNativeAps p +-- # "native_priority" +-- .= ifNot (== HighPriority) (_pushNativePriority p) +-- # "payload" +-- .= _pushPayload p +-- # [] +-- where +-- ifNot f a = if f a then Nothing else Just a diff --git a/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs b/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs new file mode 100644 index 00000000000..d00a9904399 --- /dev/null +++ b/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs @@ -0,0 +1,74 @@ +module Wire.API.Routes.Internal.Gundeck where + +import Control.Lens ((.~)) +import Data.Aeson +import Data.CommaSeparatedList +import Data.Id +import Data.OpenApi hiding (HasServer, Header) +import Data.Typeable +import Imports +import Network.URI +import Network.Wai +import Servant +import Servant.OpenApi +import Servant.Server +import Servant.Server.Internal.Delayed +import Servant.Server.Internal.DelayedIO +import Servant.Server.Internal.ErrorFormatter +import Wire.API.CannonId +import Wire.API.Presence +import Wire.API.Push.V2 +import Wire.API.Push.V2.Token +import Wire.API.Routes.Public + +-- | this can be replaced by `ReqBody '[JSON] Presence` once the fix in cannon from +-- https://github.com/wireapp/wire-server/pull/4246 has been deployed everywhere. +data ReqBodyHack + +-- | cloned from instance for ReqBody'. +instance + ( HasServer api context, + HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters + ) => + HasServer (ReqBodyHack :> api) context + where + type ServerT (ReqBodyHack :> api) m = Presence -> ServerT api m + + hoistServerWithContext _ pc nt s = hoistServerWithContext (Proxy :: Proxy api) pc nt . s + + route Proxy context subserver = + route (Proxy :: Proxy api) context $ + addBodyCheck subserver ctCheck bodyCheck + where + rep = typeRep (Proxy :: Proxy ReqBodyHack) + formatError = bodyParserErrorFormatter $ getContextEntry (mkContextWithErrorFormatter context) + + ctCheck = pure eitherDecode + + -- Body check, we get a body parsing functions as the first argument. + bodyCheck f = withRequest $ \request -> do + mrqbody <- f <$> liftIO (lazyRequestBody request) + case mrqbody of + Left e -> delayedFailFatal $ formatError rep request e + Right v -> pure v + +type InternalAPI = + "i" + :> ( ("status" :> Get '[JSON] NoContent) + :<|> ("push" :> "v2" :> ReqBody '[JSON] [Push] :> Post '[JSON] NoContent) + :<|> ( "presences" + :> ( (QueryParam' [Required, Strict] "ids" (CommaSeparatedList UserId) :> Get '[JSON] [Presence]) + :<|> (Capture "uid" UserId :> Get '[JSON] [Presence]) + :<|> (ReqBodyHack :> Post '[JSON] (Headers '[Header "Location" URI] NoContent)) + :<|> (Capture "uid" UserId :> "devices" :> Capture "did" ConnId :> "cannons" :> Capture "cannon" CannonId :> Delete '[JSON] NoContent) + ) + ) + :<|> (ZUser :> "clients" :> Capture "cid" ClientId :> Delete '[JSON] NoContent) + :<|> (ZUser :> "user" :> Delete '[JSON] NoContent) + :<|> ("push-tokens" :> Capture "uid" UserId :> Get '[JSON] PushTokenList) + ) + +swaggerDoc :: OpenApi +swaggerDoc = + toOpenApi (Proxy @InternalAPI) + & info . title .~ "Wire-Server internal gundeck API" diff --git a/libs/wire-api/wire-api.cabal b/libs/wire-api/wire-api.cabal index 1b768dd1fc8..4998577bd41 100644 --- a/libs/wire-api/wire-api.cabal +++ b/libs/wire-api/wire-api.cabal @@ -74,6 +74,7 @@ library Wire.API.Bot Wire.API.Bot.Service Wire.API.Call.Config + Wire.API.CannonId Wire.API.Connection Wire.API.Conversation Wire.API.Conversation.Action @@ -136,6 +137,7 @@ library Wire.API.Notification Wire.API.OAuth Wire.API.Password + Wire.API.Presence Wire.API.Properties Wire.API.Provider Wire.API.Provider.Bot @@ -143,6 +145,7 @@ library Wire.API.Provider.Service Wire.API.Provider.Service.Tag Wire.API.Push.Token + Wire.API.Push.V2 Wire.API.Push.V2.Token Wire.API.RawJson Wire.API.Routes.API @@ -164,6 +167,7 @@ library Wire.API.Routes.Internal.Galley.ConversationsIntra Wire.API.Routes.Internal.Galley.TeamFeatureNoConfigMulti Wire.API.Routes.Internal.Galley.TeamsIntra + Wire.API.Routes.Internal.Gundeck Wire.API.Routes.Internal.LegalHold Wire.API.Routes.Internal.Spar Wire.API.Routes.LowLevelStream @@ -300,6 +304,7 @@ library , metrics-wai , mime >=0.4 , mtl + , network-uri , openapi3 , pem >=0.2 , polysemy From e6914de6e3999921036603f59bb4c8b32f44f90f Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Fri, 27 Sep 2024 14:27:32 +0200 Subject: [PATCH 02/32] do CannonId --- libs/wire-api/src/Wire/API/CannonId.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/wire-api/src/Wire/API/CannonId.hs b/libs/wire-api/src/Wire/API/CannonId.hs index 751b23ed4b5..fb537887876 100644 --- a/libs/wire-api/src/Wire/API/CannonId.hs +++ b/libs/wire-api/src/Wire/API/CannonId.hs @@ -1,6 +1,8 @@ module Wire.API.CannonId where import Data.Aeson +import Data.OpenApi +import Data.Proxy import Imports import Web.HttpApiData @@ -9,5 +11,8 @@ newtype CannonId = CannonId } deriving (Eq, Ord, Show, FromJSON, ToJSON) +instance ToParamSchema CannonId where + toParamSchema _ = toParamSchema (Proxy @Text) + instance FromHttpApiData CannonId where parseUrlPiece = pure . CannonId From 21b1e7ecd3751278ff2d1f6117bb5d81df561687 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Fri, 27 Sep 2024 14:41:01 +0200 Subject: [PATCH 03/32] do Presence --- libs/wire-api/src/Wire/API/Presence.hs | 55 +++++++++++++----------- services/gundeck/src/Gundeck/Presence.hs | 1 + 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/libs/wire-api/src/Wire/API/Presence.hs b/libs/wire-api/src/Wire/API/Presence.hs index 66255e318d9..3e018ee037d 100644 --- a/libs/wire-api/src/Wire/API/Presence.hs +++ b/libs/wire-api/src/Wire/API/Presence.hs @@ -1,10 +1,13 @@ -module Wire.API.Presence where +module Wire.API.Presence (Presence (..)) where -import Data.Aeson -import Data.Aeson.Types +import Control.Lens ((?~)) +import Data.Aeson qualified as A +import Data.Aeson.Types qualified as A import Data.ByteString.Lazy qualified as Lazy import Data.Id import Data.Misc (Milliseconds) +import Data.OpenApi qualified as S +import Data.Schema import Data.Text qualified as Text import Imports import Network.URI @@ -26,32 +29,34 @@ data Presence = Presence __field :: !Lazy.ByteString } deriving (Eq, Ord, Show) + deriving (A.FromJSON, A.ToJSON, S.ToSchema) via (Schema Presence) -instance ToJSON Presence where - toJSON p = - object - [ "user_id" .= userId p, - "device_id" .= connId p, - "resource" .= String (Text.pack (show (resource p))), - "client_id" .= clientId p, - "created_at" .= createdAt p - ] +instance ToSchema Presence where + schema = + object "Presence" $ + ( Presence + <$> userId .= field "user_id" schema + <*> connId .= field "device_id" schema + <*> resource .= field "resource" uriSchema + <*> clientId .= maybe_ (optField "client_id" schema) + <*> createdAt .= field "created_at" schema + ) + <&> ($ ("" :: Lazy.ByteString)) -instance FromJSON Presence where - parseJSON = withObject "Presence" $ \o -> - Presence - <$> o .: "user_id" - <*> o .: "device_id" - <*> explicitParseField uriFromJSON o "resource" - <*> o .:? "client_id" - <*> o .:? "created_at" .!= 0 - <*> pure "" +uriSchema :: ValueSchema NamedSwaggerDoc URI +uriSchema = mkSchema desc uriFromJSON (Just . uriToJSON) + where + desc :: NamedSwaggerDoc + desc = + swaggerDoc @Text + & (S.schema . S.type_ ?~ S.OpenApiString) + & (S.schema . S.description ?~ "Valid URI.") -uriFromJSON :: Value -> Parser URI -uriFromJSON = withText "URI" (p . Text.unpack) +uriFromJSON :: A.Value -> A.Parser URI +uriFromJSON = A.withText "URI" (p . Text.unpack) where p :: (MonadFail m) => String -> m URI p = maybe (fail "Invalid URI") pure . parseURI -uriToJSON :: URI -> Value -uriToJSON uri = String $ Text.pack (show uri) +uriToJSON :: URI -> A.Value +uriToJSON uri = A.String $ Text.pack (show uri) diff --git a/services/gundeck/src/Gundeck/Presence.hs b/services/gundeck/src/Gundeck/Presence.hs index ed69bb50515..258536866a3 100644 --- a/services/gundeck/src/Gundeck/Presence.hs +++ b/services/gundeck/src/Gundeck/Presence.hs @@ -30,6 +30,7 @@ import Gundeck.Presence.Data qualified as Data import Gundeck.Types import Imports import Servant.API +import Wire.API.CannonId listH :: UserId -> Gundeck [Presence] listH = runWithDefaultRedis . Data.list From 99318a5dde46ec948d402747e3f57c0efc46a346 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Fri, 27 Sep 2024 15:12:54 +0200 Subject: [PATCH 04/32] do Push.V2 --- libs/wire-api/src/Wire/API/Push/V2.hs | 196 +++++++++++--------------- 1 file changed, 83 insertions(+), 113 deletions(-) diff --git a/libs/wire-api/src/Wire/API/Push/V2.hs b/libs/wire-api/src/Wire/API/Push/V2.hs index 8529e6806b9..968a795397f 100644 --- a/libs/wire-api/src/Wire/API/Push/V2.hs +++ b/libs/wire-api/src/Wire/API/Push/V2.hs @@ -53,12 +53,15 @@ module Wire.API.Push.V2 ) where -import Control.Lens (makeLenses) +import Control.Lens (makeLenses, (?~)) import Data.Aeson (FromJSON (..), Object, ToJSON (..)) +import Data.Aeson qualified as A +import Data.Aeson.Types qualified as A import Data.Id import Data.Json.Util import Data.List1 import Data.List1 qualified as List1 +import Data.OpenApi qualified as S import Data.Range import Data.Schema import Data.Set qualified as Set @@ -79,17 +82,15 @@ data Route RouteDirect deriving (Eq, Ord, Enum, Bounded, Show, Generic) deriving (Arbitrary) via GenericUniform Route + deriving (FromJSON, ToJSON, S.ToSchema) via (Schema Route) -instance ToSchema Route - --- instance FromJSON Route where --- parseJSON (String "any") = pure RouteAny --- parseJSON (String "direct") = pure RouteDirect --- parseJSON x = fail $ "Invalid routing: " ++ show (encode x) --- --- instance ToJSON Route where --- toJSON RouteAny = String "any" --- toJSON RouteDirect = String "direct" +instance ToSchema Route where + schema = + enum @Text "Route" $ + mconcat + [ element "any" RouteAny, + element "direct" RouteDirect + ] ----------------------------------------------------------------------------- -- Recipient @@ -100,6 +101,7 @@ data Recipient = Recipient _recipientClients :: !RecipientClients } deriving (Show, Eq, Ord, Generic) + deriving (FromJSON, ToJSON, S.ToSchema) via (Schema Recipient) data RecipientClients = -- | All clients of some user @@ -108,6 +110,7 @@ data RecipientClients RecipientClientsSome (List1 ClientId) deriving (Eq, Show, Ord, Generic) deriving (Arbitrary) via GenericUniform RecipientClients + deriving (FromJSON, ToJSON, S.ToSchema) via (Schema RecipientClients) instance Semigroup RecipientClients where RecipientClientsAll <> _ = RecipientClientsAll @@ -115,55 +118,73 @@ instance Semigroup RecipientClients where RecipientClientsSome cs1 <> RecipientClientsSome cs2 = RecipientClientsSome (cs1 <> cs2) +instance ToSchema Recipient where + schema = + object "Recipient" $ + Recipient + <$> _recipientId .= field "user_id" schema + <*> _recipientRoute .= field "route" schema + <*> _recipientClients .= field "clients" schema + +instance ToSchema RecipientClients where + schema = mkSchema d i o + where + d :: NamedSwaggerDoc + d = + swaggerDoc @[ClientId] + & (S.schema . S.type_ ?~ S.OpenApiArray) + & (S.schema . S.description ?~ "List of clientIds. Empty means `all clients`.") + + i :: A.Value -> A.Parser RecipientClients + i v = + parseJSON @[ClientId] v >>= \case + [] -> pure RecipientClientsAll + c : cs -> pure (RecipientClientsSome (list1 c cs)) + + o :: RecipientClients -> Maybe A.Value + o = + pure . toJSON . \case + RecipientClientsSome cs -> toList cs + RecipientClientsAll -> [] + makeLenses ''Recipient recipient :: UserId -> Route -> Recipient recipient u r = Recipient u r RecipientClientsAll -instance ToSchema Recipient - --- instance FromJSON Recipient where --- parseJSON = withObject "Recipient" $ \p -> --- Recipient --- <$> p .: "user_id" --- <*> p .: "route" --- <*> p .:? "clients" .!= RecipientClientsAll --- --- instance ToJSON Recipient where --- toJSON (Recipient u r c) = --- object $ --- "user_id" --- .= u --- # "route" --- .= r --- # "clients" --- .= c --- # [] - -instance ToSchema RecipientClients - --- "All clients" is encoded in the API as an empty list. --- instance FromJSON RecipientClients where --- parseJSON x = --- parseJSON @[ClientId] x >>= \case --- [] -> pure RecipientClientsAll --- c : cs -> pure (RecipientClientsSome (list1 c cs)) --- --- instance ToJSON RecipientClients where --- toJSON = --- toJSON . \case --- RecipientClientsAll -> [] --- RecipientClientsSome cs -> toList cs - ----------------------------------------------------------------------------- -- ApsData newtype ApsSound = ApsSound {fromSound :: Text} deriving (Eq, Show, ToJSON, FromJSON, Arbitrary) +instance ToSchema ApsSound where + schema = + mkSchema d i o + where + d = + swaggerDoc @Text + & (S.schema . S.type_ ?~ S.OpenApiString) + & (S.schema . S.description ?~ "ApsSound") + + i = A.withText "ApsSound" (pure . ApsSound) + o = pure . A.String . fromSound + newtype ApsLocKey = ApsLocKey {fromLocKey :: Text} deriving (Eq, Show, ToJSON, FromJSON, Arbitrary) +instance ToSchema ApsLocKey where + schema = + mkSchema d i o + where + d = + swaggerDoc @Text + & (S.schema . S.type_ ?~ S.OpenApiString) + & (S.schema . S.description ?~ "ApsLocKey") + + i = A.withText "ApsLocKey" (pure . ApsLocKey) + o = pure . A.String . fromLocKey + data ApsData = ApsData { _apsLocKey :: !ApsLocKey, _apsLocArgs :: [Text], @@ -172,34 +193,23 @@ data ApsData = ApsData } deriving (Eq, Show, Generic) deriving (Arbitrary) via GenericUniform ApsData - -makeLenses ''ApsData + deriving (FromJSON, ToJSON, S.ToSchema) via (Schema ApsData) apsData :: ApsLocKey -> [Text] -> ApsData apsData lk la = ApsData lk la Nothing True -instance ToSchema ApsData - --- instance ToJSON ApsData where --- toJSON (ApsData k a s b) = --- object $ --- "loc_key" --- .= k --- # "loc_args" --- .= a --- # "sound" --- .= s --- # "badge" --- .= b --- # [] --- --- instance FromJSON ApsData where --- parseJSON = withObject "ApsData" $ \o -> --- ApsData --- <$> o .: "loc_key" --- <*> o .:? "loc_args" .!= [] --- <*> o .:? "sound" --- <*> o .:? "badge" .!= True +instance ToSchema ApsData where + schema = + object "ApsData" $ + ApsData + <$> _apsLocKey .= field "loc_key" schema + <*> withDefault "loc_args" _apsLocArgs (array schema) [] + <*> _apsSound .= maybe_ (optField "sound" schema) + <*> withDefault "badge" _apsBadge schema True + where + withDefault fn f s def = ((Just . f) .= maybe_ (optField fn s)) <&> maybe def id + +makeLenses ''ApsData ----------------------------------------------------------------------------- -- Push @@ -244,8 +254,7 @@ data Push = Push _pushPayload :: !(List1 Object) } deriving (Eq, Show) - -makeLenses ''Push + deriving (FromJSON, ToJSON, S.ToSchema) via (Schema Push) newPush :: Maybe UserId -> Range 1 1024 (Set Recipient) -> List1 Object -> Push newPush from to pload = @@ -269,7 +278,7 @@ instance ToSchema Push where schema = object "Push" $ Push - <$> _pushRecipients .= field "recipients" (set schema) + <$> (fromRange . _pushRecipients) .= field "recipients" (rangedSchema (set schema)) <*> _pushOrigin .= maybe_ (optField "origin" schema) <*> (ifNot Set.null . _pushConnections) .= maybe_ (fmap (fromMaybe mempty) (optField "connections" (set schema))) @@ -288,43 +297,4 @@ instance ToSchema Push where where ifNot f a = if f a then Nothing else Just a --- instance FromJSON Push where --- parseJSON = withObject "Push" $ \p -> --- Push --- <$> p .: "recipients" --- <*> p .:? "origin" --- <*> p .:? "connections" .!= Set.empty --- <*> p .:? "origin_connection" --- <*> p .:? "transient" .!= False --- <*> p .:? "native_include_origin" .!= True --- <*> p .:? "native_encrypt" .!= True --- <*> p .:? "native_aps" --- <*> p .:? "native_priority" .!= HighPriority --- <*> p .: "payload" --- --- instance ToJSON Push where --- toJSON p = --- object $ --- "recipients" --- .= _pushRecipients p --- # "origin" --- .= _pushOrigin p --- # "connections" --- .= ifNot Set.null (_pushConnections p) --- # "origin_connection" --- .= _pushOriginConnection p --- # "transient" --- .= ifNot not (_pushTransient p) --- # "native_include_origin" --- .= ifNot id (_pushNativeIncludeOrigin p) --- # "native_encrypt" --- .= ifNot id (_pushNativeEncrypt p) --- # "native_aps" --- .= _pushNativeAps p --- # "native_priority" --- .= ifNot (== HighPriority) (_pushNativePriority p) --- # "payload" --- .= _pushPayload p --- # [] --- where --- ifNot f a = if f a then Nothing else Just a +makeLenses ''Push From abf771c0a67bb7a7196f9d7ee8c38689a25f1697 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Fri, 27 Sep 2024 15:16:17 +0200 Subject: [PATCH 05/32] rm internal routing table, ReqBodyHack in services/gundeck. --- services/gundeck/src/Gundeck/API/Internal.hs | 55 +------------------- 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/services/gundeck/src/Gundeck/API/Internal.hs b/services/gundeck/src/Gundeck/API/Internal.hs index 49c2448bd3a..83c82dd48e0 100644 --- a/services/gundeck/src/Gundeck/API/Internal.hs +++ b/services/gundeck/src/Gundeck/API/Internal.hs @@ -43,62 +43,9 @@ import Servant.Server.Internal.Delayed import Servant.Server.Internal.DelayedIO import Servant.Server.Internal.ErrorFormatter import Wire.API.Push.Token qualified as PushTok +import Wire.API.Routes.Internal.Gundeck import Wire.API.Routes.Public --- | this can be replaced by `ReqBody '[JSON] Presence` once the fix in cannon from --- https://github.com/wireapp/wire-server/pull/4246 has been deployed everywhere. -data ReqBodyHack - --- | cloned from instance for ReqBody'. -instance - ( HasServer api context, - HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters - ) => - HasServer (ReqBodyHack :> api) context - where - type ServerT (ReqBodyHack :> api) m = Presence -> ServerT api m - - hoistServerWithContext _ pc nt s = hoistServerWithContext (Proxy :: Proxy api) pc nt . s - - route Proxy context subserver = - route (Proxy :: Proxy api) context $ - addBodyCheck subserver ctCheck bodyCheck - where - rep = typeRep (Proxy :: Proxy ReqBodyHack) - formatError = bodyParserErrorFormatter $ getContextEntry (mkContextWithErrorFormatter context) - - ctCheck = pure eitherDecode - - -- Body check, we get a body parsing functions as the first argument. - bodyCheck f = withRequest $ \request -> do - mrqbody <- f <$> liftIO (lazyRequestBody request) - case mrqbody of - Left e -> delayedFailFatal $ formatError rep request e - Right v -> pure v - --- | cloned from instance for ReqBody'. -instance - (RoutesToPaths rest) => - RoutesToPaths (ReqBodyHack :> rest) - where - getRoutes = getRoutes @rest - -type GundeckInternalAPI = - "i" - :> ( ("status" :> Get '[JSON] NoContent) - :<|> ("push" :> "v2" :> ReqBody '[JSON] [Push] :> Post '[JSON] NoContent) - :<|> ( "presences" - :> ( (QueryParam' [Required, Strict] "ids" (CommaSeparatedList UserId) :> Get '[JSON] [Presence]) - :<|> (Capture "uid" UserId :> Get '[JSON] [Presence]) - :<|> (ReqBodyHack :> Verb 'POST 201 '[JSON] (Headers '[Header "Location" GD.URI] NoContent)) - :<|> (Capture "uid" UserId :> "devices" :> Capture "did" ConnId :> "cannons" :> Capture "cannon" CannonId :> Delete '[JSON] NoContent) - ) - ) - :<|> (ZUser :> "clients" :> Capture "cid" ClientId :> Delete '[JSON] NoContent) - :<|> (ZUser :> "user" :> Delete '[JSON] NoContent) - :<|> ("push-tokens" :> Capture "uid" UserId :> Get '[JSON] PushTokenList) - ) - servantSitemap :: ServerT GundeckInternalAPI Gundeck servantSitemap = statusH From 0be6bcedaceaa79853fb6f8bdfdc1fc194a9bcba Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Fri, 27 Sep 2024 16:03:19 +0200 Subject: [PATCH 06/32] do Routes.Internal.Gundeck. this makes wire-api compile. --- .../src/Wire/API/Routes/Internal/Gundeck.hs | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs b/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs index d00a9904399..72014dce771 100644 --- a/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs +++ b/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs @@ -1,28 +1,37 @@ +{-# OPTIONS_GHC -Wno-orphans #-} + module Wire.API.Routes.Internal.Gundeck where -import Control.Lens ((.~)) +import Control.Lens ((%~), (.~), (?~)) import Data.Aeson import Data.CommaSeparatedList +import Data.HashMap.Strict.InsOrd qualified as InsOrdHashMap import Data.Id -import Data.OpenApi hiding (HasServer, Header) +import Data.Metrics.Servant +import Data.OpenApi qualified as S hiding (HasServer, Header) +import Data.OpenApi.Declare qualified as S +import Data.Text qualified as Text import Data.Typeable import Imports import Network.URI import Network.Wai import Servant +import Servant.API.Description import Servant.OpenApi -import Servant.Server +import Servant.OpenApi.Internal import Servant.Server.Internal.Delayed import Servant.Server.Internal.DelayedIO import Servant.Server.Internal.ErrorFormatter import Wire.API.CannonId import Wire.API.Presence import Wire.API.Push.V2 -import Wire.API.Push.V2.Token import Wire.API.Routes.Public -- | this can be replaced by `ReqBody '[JSON] Presence` once the fix in cannon from -- https://github.com/wireapp/wire-server/pull/4246 has been deployed everywhere. +-- +-- Background: Cannon.WS.regInfo called gundeck without setting the content-type header here. +-- wai-routes and wai-predicates were able to work with that; servant is less lenient. data ReqBodyHack -- | cloned from instance for ReqBody'. @@ -52,6 +61,28 @@ instance Left e -> delayedFailFatal $ formatError rep request e Right v -> pure v +-- | cloned from instance for ReqBody'. +instance (RoutesToPaths route) => RoutesToPaths (ReqBodyHack :> route) where + getRoutes = getRoutes @route + +-- | cloned from instance for ReqBody'. +instance (HasOpenApi sub) => HasOpenApi (ReqBodyHack :> sub) where + toOpenApi _ = + toOpenApi (Proxy @sub) + & addRequestBody reqBody + & addDefaultResponse400 tname + & S.components . S.schemas %~ (<> defs) + where + tname = "body" + transDesc "" = Nothing + transDesc desc = Just (Text.pack desc) + (defs, ref) = S.runDeclare (S.declareSchemaRef (Proxy @Presence)) mempty + reqBody = + (mempty :: S.RequestBody) + & S.description .~ transDesc (reflectDescription (Proxy :: Proxy '[])) + & S.required ?~ True + & S.content .~ InsOrdHashMap.fromList [(t, mempty & S.schema ?~ ref) | t <- allContentType (Proxy :: Proxy '[JSON])] + type InternalAPI = "i" :> ( ("status" :> Get '[JSON] NoContent) @@ -68,7 +99,13 @@ type InternalAPI = :<|> ("push-tokens" :> Capture "uid" UserId :> Get '[JSON] PushTokenList) ) -swaggerDoc :: OpenApi +instance S.ToParamSchema URI where + toParamSchema _ = + S.toParamSchema (Proxy @Text) + & S.type_ ?~ S.OpenApiString + & S.description ?~ "Valid URI" + +swaggerDoc :: S.OpenApi swaggerDoc = toOpenApi (Proxy @InternalAPI) - & info . title .~ "Wire-Server internal gundeck API" + & S.info . S.title .~ "Wire-Server internal gundeck API" From ad5e05efc2bfa4e9734a0021382682684fd8b6ba Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Fri, 27 Sep 2024 16:38:59 +0200 Subject: [PATCH 07/32] Resolve confusion between 3 different data types all called `URI`. --- libs/gundeck-types/gundeck-types.cabal | 2 - .../gundeck-types/src/Gundeck/Types/Common.hs | 49 ---- .../src/Gundeck/Types/Presence.hs | 48 +--- .../src/Gundeck/Types/Push/V2.hs | 244 +----------------- libs/wire-api/src/Wire/API/Presence.hs | 41 ++- .../src/Wire/API/Routes/Internal/Gundeck.hs | 11 +- 6 files changed, 42 insertions(+), 353 deletions(-) diff --git a/libs/gundeck-types/gundeck-types.cabal b/libs/gundeck-types/gundeck-types.cabal index 86c33f01a4a..6f306c9cf87 100644 --- a/libs/gundeck-types/gundeck-types.cabal +++ b/libs/gundeck-types/gundeck-types.cabal @@ -74,9 +74,7 @@ library , base >=4 && <5 , bytestring >=0.10 , bytestring-conversion >=0.2 - , containers >=0.5 , imports - , lens >=4.11 , network-uri >=2.6 , servant , text >=0.11 diff --git a/libs/gundeck-types/src/Gundeck/Types/Common.hs b/libs/gundeck-types/src/Gundeck/Types/Common.hs index 6649db94ba3..3b38816acc3 100644 --- a/libs/gundeck-types/src/Gundeck/Types/Common.hs +++ b/libs/gundeck-types/src/Gundeck/Types/Common.hs @@ -18,52 +18,3 @@ -- with this program. If not, see . module Gundeck.Types.Common where - -import Data.Aeson -import Data.Attoparsec.ByteString (takeByteString) -import Data.ByteString.Char8 qualified as Bytes -import Data.ByteString.Conversion -import Data.Text qualified as Text -import Data.Text.Encoding (decodeUtf8) -import Imports -import Network.URI qualified as Net -import Servant.API (FromHttpApiData (parseUrlPiece), ToHttpApiData (toUrlPiece)) - -newtype CannonId = CannonId - { cannonId :: Text - } - deriving - ( Eq, - Ord, - Show, - FromJSON, - ToJSON, - FromByteString, - ToByteString - ) - -instance FromHttpApiData CannonId where - parseUrlPiece = pure . CannonId - -newtype URI = URI - { fromURI :: Net.URI - } - deriving (Eq, Ord, Show) - -instance FromJSON URI where - parseJSON = withText "URI" (parse . Text.unpack) - -instance ToJSON URI where - toJSON uri = String $ Text.pack (show (fromURI uri)) - -instance ToByteString URI where - builder = builder . show . fromURI - -instance FromByteString URI where - parser = takeByteString >>= parse . Bytes.unpack - -instance ToHttpApiData URI where - toUrlPiece = decodeUtf8 . toByteString' - -parse :: (MonadFail m) => String -> m URI -parse = maybe (fail "Invalid URI") (pure . URI) . Net.parseURI diff --git a/libs/gundeck-types/src/Gundeck/Types/Presence.hs b/libs/gundeck-types/src/Gundeck/Types/Presence.hs index 04aa78b28ca..340cd2eee21 100644 --- a/libs/gundeck-types/src/Gundeck/Types/Presence.hs +++ b/libs/gundeck-types/src/Gundeck/Types/Presence.hs @@ -18,52 +18,8 @@ -- with this program. If not, see . module Gundeck.Types.Presence - ( module Gundeck.Types.Presence, - module Common, + ( module Wire.API.Presence, ) where -import Data.Aeson -import Data.ByteString.Lazy qualified as Lazy -import Data.Id -import Data.Misc (Milliseconds) -import Gundeck.Types.Common as Common -import Imports - --- | This is created in gundeck by cannon every time the client opens a new websocket connection. --- (That's why we always have a 'ConnId' from the most recent connection by that client.) -data Presence = Presence - { userId :: !UserId, - connId :: !ConnId, - -- | cannon instance hosting the presence - resource :: !URI, - -- | This is 'Nothing' if either (a) the presence is older - -- than mandatory end-to-end encryption, or (b) the client is - -- operating the team settings pages without the need for - -- end-to-end crypto. - clientId :: !(Maybe ClientId), - createdAt :: !Milliseconds, - -- | REFACTOR: temp. addition to ease migration - __field :: !Lazy.ByteString - } - deriving (Eq, Ord, Show) - -instance ToJSON Presence where - toJSON p = - object - [ "user_id" .= userId p, - "device_id" .= connId p, - "resource" .= resource p, - "client_id" .= clientId p, - "created_at" .= createdAt p - ] - -instance FromJSON Presence where - parseJSON = withObject "Presence" $ \o -> - Presence - <$> o .: "user_id" - <*> o .: "device_id" - <*> o .: "resource" - <*> o .:? "client_id" - <*> o .:? "created_at" .!= 0 - <*> pure "" +import Wire.API.Presence -- TODO: drop this module entirely! diff --git a/libs/gundeck-types/src/Gundeck/Types/Push/V2.hs b/libs/gundeck-types/src/Gundeck/Types/Push/V2.hs index b9539ae81ac..2138664f2a6 100644 --- a/libs/gundeck-types/src/Gundeck/Types/Push/V2.hs +++ b/libs/gundeck-types/src/Gundeck/Types/Push/V2.hs @@ -71,246 +71,4 @@ module Gundeck.Types.Push.V2 ) where -import Control.Lens (makeLenses) -import Data.Aeson -import Data.Id -import Data.Json.Util -import Data.List1 -import Data.List1 qualified as List1 -import Data.Range -import Data.Set qualified as Set -import Imports -import Wire.API.Message (Priority (..)) -import Wire.API.Push.V2.Token -import Wire.Arbitrary - ------------------------------------------------------------------------------ --- Route - -data Route - = -- | Sends notification on all channels including push notifications to - -- mobile clients. Note that transient messages never cause a push - -- notification. - RouteAny - | -- | Avoids causing push notification for mobile clients. - RouteDirect - deriving (Eq, Ord, Enum, Bounded, Show, Generic) - deriving (Arbitrary) via GenericUniform Route - -instance FromJSON Route where - parseJSON (String "any") = pure RouteAny - parseJSON (String "direct") = pure RouteDirect - parseJSON x = fail $ "Invalid routing: " ++ show (encode x) - -instance ToJSON Route where - toJSON RouteAny = String "any" - toJSON RouteDirect = String "direct" - ------------------------------------------------------------------------------ --- Recipient - -data Recipient = Recipient - { _recipientId :: !UserId, - _recipientRoute :: !Route, - _recipientClients :: !RecipientClients - } - deriving (Show, Eq, Ord, Generic) - -data RecipientClients - = -- | All clients of some user - RecipientClientsAll - | -- | An explicit list of clients - RecipientClientsSome (List1 ClientId) - deriving (Eq, Show, Ord, Generic) - deriving (Arbitrary) via GenericUniform RecipientClients - -instance Semigroup RecipientClients where - RecipientClientsAll <> _ = RecipientClientsAll - _ <> RecipientClientsAll = RecipientClientsAll - RecipientClientsSome cs1 <> RecipientClientsSome cs2 = - RecipientClientsSome (cs1 <> cs2) - -makeLenses ''Recipient - -recipient :: UserId -> Route -> Recipient -recipient u r = Recipient u r RecipientClientsAll - -instance FromJSON Recipient where - parseJSON = withObject "Recipient" $ \p -> - Recipient - <$> p .: "user_id" - <*> p .: "route" - <*> p .:? "clients" .!= RecipientClientsAll - -instance ToJSON Recipient where - toJSON (Recipient u r c) = - object $ - "user_id" - .= u - # "route" - .= r - # "clients" - .= c - # [] - --- "All clients" is encoded in the API as an empty list. -instance FromJSON RecipientClients where - parseJSON x = - parseJSON @[ClientId] x >>= \case - [] -> pure RecipientClientsAll - c : cs -> pure (RecipientClientsSome (list1 c cs)) - -instance ToJSON RecipientClients where - toJSON = - toJSON . \case - RecipientClientsAll -> [] - RecipientClientsSome cs -> toList cs - ------------------------------------------------------------------------------ --- ApsData - -newtype ApsSound = ApsSound {fromSound :: Text} - deriving (Eq, Show, ToJSON, FromJSON, Arbitrary) - -newtype ApsLocKey = ApsLocKey {fromLocKey :: Text} - deriving (Eq, Show, ToJSON, FromJSON, Arbitrary) - -data ApsData = ApsData - { _apsLocKey :: !ApsLocKey, - _apsLocArgs :: [Text], - _apsSound :: !(Maybe ApsSound), - _apsBadge :: !Bool - } - deriving (Eq, Show, Generic) - deriving (Arbitrary) via GenericUniform ApsData - -makeLenses ''ApsData - -apsData :: ApsLocKey -> [Text] -> ApsData -apsData lk la = ApsData lk la Nothing True - -instance ToJSON ApsData where - toJSON (ApsData k a s b) = - object $ - "loc_key" - .= k - # "loc_args" - .= a - # "sound" - .= s - # "badge" - .= b - # [] - -instance FromJSON ApsData where - parseJSON = withObject "ApsData" $ \o -> - ApsData - <$> o .: "loc_key" - <*> o .:? "loc_args" .!= [] - <*> o .:? "sound" - <*> o .:? "badge" .!= True - ------------------------------------------------------------------------------ --- Push - -data Push = Push - { -- | Recipients - -- - -- REFACTOR: '_pushRecipients' should be @Set (Recipient, Maybe (NonEmptySet ConnId))@, and - -- '_pushConnections' should go away. Rationale: the current setup only works under the - -- 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), - -- | Originating user - -- - -- 'Nothing' here means that the originating user is on another backend. - -- - -- REFACTOR: where is this required, and for what? or can it be removed? (see also: #531) - _pushOrigin :: !(Maybe UserId), - -- | Destination connections. If empty, ignore. Otherwise, filter the connections derived - -- from '_pushRecipients' and only push to those contained in this set. - -- - -- REFACTOR: change this to @_pushConnectionWhitelist :: Maybe (Set ConnId)@. - _pushConnections :: !(Set ConnId), - -- | Originating connection, if any. - _pushOriginConnection :: !(Maybe ConnId), - -- | Transient payloads are not forwarded to the notification stream. - _pushTransient :: !Bool, - -- | Whether to send native notifications to other clients - -- of the originating user, if he is among the recipients. - _pushNativeIncludeOrigin :: !Bool, - -- | Should native push payloads be encrypted? - -- - -- REFACTOR: this make no sense any more since native push notifications have no more payload. - -- https://github.com/wireapp/wire-server/pull/546 - _pushNativeEncrypt :: !Bool, - -- | APNs-specific metadata (needed eg. in "Brig.IO.Intra.toApsData"). - _pushNativeAps :: !(Maybe ApsData), - -- | Native push priority. - _pushNativePriority :: !Priority, - -- | Opaque payload - _pushPayload :: !(List1 Object) - } - deriving (Eq, Show) - -makeLenses ''Push - -newPush :: Maybe UserId -> Range 1 1024 (Set Recipient) -> List1 Object -> Push -newPush from to pload = - Push - { _pushRecipients = to, - _pushOrigin = from, - _pushConnections = Set.empty, - _pushOriginConnection = Nothing, - _pushTransient = False, - _pushNativeIncludeOrigin = True, - _pushNativeEncrypt = True, - _pushNativeAps = Nothing, - _pushNativePriority = HighPriority, - _pushPayload = pload - } - -singletonPayload :: (ToJSONObject a) => a -> List1 Object -singletonPayload = List1.singleton . toJSONObject - -instance FromJSON Push where - parseJSON = withObject "Push" $ \p -> - Push - <$> p .: "recipients" - <*> p .:? "origin" - <*> p .:? "connections" .!= Set.empty - <*> p .:? "origin_connection" - <*> p .:? "transient" .!= False - <*> p .:? "native_include_origin" .!= True - <*> p .:? "native_encrypt" .!= True - <*> p .:? "native_aps" - <*> p .:? "native_priority" .!= HighPriority - <*> p .: "payload" - -instance ToJSON Push where - toJSON p = - object $ - "recipients" - .= _pushRecipients p - # "origin" - .= _pushOrigin p - # "connections" - .= ifNot Set.null (_pushConnections p) - # "origin_connection" - .= _pushOriginConnection p - # "transient" - .= ifNot not (_pushTransient p) - # "native_include_origin" - .= ifNot id (_pushNativeIncludeOrigin p) - # "native_encrypt" - .= ifNot id (_pushNativeEncrypt p) - # "native_aps" - .= _pushNativeAps p - # "native_priority" - .= ifNot (== HighPriority) (_pushNativePriority p) - # "payload" - .= _pushPayload p - # [] - where - ifNot f a = if f a then Nothing else Just a +import Wire.API.Push.V2 -- TODO: just remove this module... diff --git a/libs/wire-api/src/Wire/API/Presence.hs b/libs/wire-api/src/Wire/API/Presence.hs index 3e018ee037d..91dfa1f0ce2 100644 --- a/libs/wire-api/src/Wire/API/Presence.hs +++ b/libs/wire-api/src/Wire/API/Presence.hs @@ -1,16 +1,51 @@ -module Wire.API.Presence (Presence (..)) where +module Wire.API.Presence (Presence (..), URI (..)) where import Control.Lens ((?~)) import Data.Aeson qualified as A import Data.Aeson.Types qualified as A +import Data.Attoparsec.ByteString (takeByteString) +import Data.ByteString.Char8 qualified as Bytes +import Data.ByteString.Conversion import Data.ByteString.Lazy qualified as Lazy import Data.Id import Data.Misc (Milliseconds) import Data.OpenApi qualified as S +import Data.Proxy import Data.Schema import Data.Text qualified as Text +import Data.Text.Encoding (decodeUtf8) import Imports -import Network.URI +import Network.URI qualified as Net +import Servant.API (ToHttpApiData (toUrlPiece)) + +newtype URI = URI -- maybe we should use Network.URI, and toss this newtype? servant should have all these instances for us these days. + { fromURI :: Net.URI + } + deriving (Eq, Ord, Show) + +instance A.FromJSON URI where + parseJSON = A.withText "URI" (parse . Text.unpack) + +instance A.ToJSON URI where + toJSON uri = A.String $ Text.pack (show (fromURI uri)) + +instance ToByteString URI where + builder = builder . show . fromURI + +instance FromByteString URI where + parser = takeByteString >>= parse . Bytes.unpack + +instance ToHttpApiData URI where + toUrlPiece = decodeUtf8 . toByteString' + +instance S.ToParamSchema URI where + toParamSchema _ = + S.toParamSchema (Proxy @Text) + & S.type_ ?~ S.OpenApiString + & S.description ?~ "Valid URI" + +parse :: (MonadFail m) => String -> m URI +parse = maybe (fail "Invalid URI") (pure . URI) . Net.parseURI -- | This is created in gundeck by cannon every time the client opens a new websocket connection. -- (That's why we always have a 'ConnId' from the most recent connection by that client.) @@ -56,7 +91,7 @@ uriFromJSON :: A.Value -> A.Parser URI uriFromJSON = A.withText "URI" (p . Text.unpack) where p :: (MonadFail m) => String -> m URI - p = maybe (fail "Invalid URI") pure . parseURI + p = maybe (fail "Invalid URI") pure . parse uriToJSON :: URI -> A.Value uriToJSON uri = A.String $ Text.pack (show uri) diff --git a/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs b/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs index 72014dce771..c8fac671f9b 100644 --- a/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs +++ b/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs @@ -1,5 +1,3 @@ -{-# OPTIONS_GHC -Wno-orphans #-} - module Wire.API.Routes.Internal.Gundeck where import Control.Lens ((%~), (.~), (?~)) @@ -13,9 +11,8 @@ import Data.OpenApi.Declare qualified as S import Data.Text qualified as Text import Data.Typeable import Imports -import Network.URI import Network.Wai -import Servant +import Servant hiding (URI (..)) import Servant.API.Description import Servant.OpenApi import Servant.OpenApi.Internal @@ -99,12 +96,6 @@ type InternalAPI = :<|> ("push-tokens" :> Capture "uid" UserId :> Get '[JSON] PushTokenList) ) -instance S.ToParamSchema URI where - toParamSchema _ = - S.toParamSchema (Proxy @Text) - & S.type_ ?~ S.OpenApiString - & S.description ?~ "Valid URI" - swaggerDoc :: S.OpenApi swaggerDoc = toOpenApi (Proxy @InternalAPI) From 84404d19d63e2eac3de821b1dd975f9262a08da5 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Fri, 27 Sep 2024 16:41:31 +0200 Subject: [PATCH 08/32] rm unused imports. --- services/gundeck/src/Gundeck/API/Internal.hs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/services/gundeck/src/Gundeck/API/Internal.hs b/services/gundeck/src/Gundeck/API/Internal.hs index 83c82dd48e0..f7e214ce46a 100644 --- a/services/gundeck/src/Gundeck/API/Internal.hs +++ b/services/gundeck/src/Gundeck/API/Internal.hs @@ -23,28 +23,18 @@ where import Cassandra qualified import Control.Lens (view) -import Data.Aeson (eitherDecode) -import Data.CommaSeparatedList import Data.Id -import Data.Metrics.Servant -import Data.Typeable import Gundeck.Client qualified as Client import Gundeck.Monad import Gundeck.Presence qualified as Presence import Gundeck.Push qualified as Push import Gundeck.Push.Data qualified as PushTok import Gundeck.Push.Native.Types qualified as PushTok -import Gundeck.Types.Presence as GD import Gundeck.Types.Push.V2 import Imports -import Network.Wai (lazyRequestBody) import Servant -import Servant.Server.Internal.Delayed -import Servant.Server.Internal.DelayedIO -import Servant.Server.Internal.ErrorFormatter import Wire.API.Push.Token qualified as PushTok import Wire.API.Routes.Internal.Gundeck -import Wire.API.Routes.Public servantSitemap :: ServerT GundeckInternalAPI Gundeck servantSitemap = From ee4554e27d6ba271b0f329d24e3ea93531455064 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Fri, 27 Sep 2024 16:41:55 +0200 Subject: [PATCH 09/32] fix trivial compiler errors. --- libs/wire-api/src/Wire/API/Presence.hs | 2 +- services/gundeck/src/Gundeck/API/Internal.hs | 4 ++-- services/gundeck/src/Gundeck/Run.hs | 10 +++++----- services/gundeck/test/integration/API.hs | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libs/wire-api/src/Wire/API/Presence.hs b/libs/wire-api/src/Wire/API/Presence.hs index 91dfa1f0ce2..54e16ef50ea 100644 --- a/libs/wire-api/src/Wire/API/Presence.hs +++ b/libs/wire-api/src/Wire/API/Presence.hs @@ -1,4 +1,4 @@ -module Wire.API.Presence (Presence (..), URI (..)) where +module Wire.API.Presence (Presence (..), URI (..), parse) where import Control.Lens ((?~)) import Data.Aeson qualified as A diff --git a/services/gundeck/src/Gundeck/API/Internal.hs b/services/gundeck/src/Gundeck/API/Internal.hs index f7e214ce46a..45ea344d37c 100644 --- a/services/gundeck/src/Gundeck/API/Internal.hs +++ b/services/gundeck/src/Gundeck/API/Internal.hs @@ -16,7 +16,7 @@ -- with this program. If not, see . module Gundeck.API.Internal - ( type GundeckInternalAPI, + ( type InternalAPI, servantSitemap, ) where @@ -36,7 +36,7 @@ import Servant import Wire.API.Push.Token qualified as PushTok import Wire.API.Routes.Internal.Gundeck -servantSitemap :: ServerT GundeckInternalAPI Gundeck +servantSitemap :: ServerT InternalAPI Gundeck servantSitemap = statusH :<|> pushH diff --git a/services/gundeck/src/Gundeck/Run.hs b/services/gundeck/src/Gundeck/Run.hs index 5543f0a8ad7..b978b9d6b13 100644 --- a/services/gundeck/src/Gundeck/Run.hs +++ b/services/gundeck/src/Gundeck/Run.hs @@ -31,7 +31,7 @@ import Data.Metrics.Servant qualified as Metrics import Data.Proxy (Proxy (Proxy)) import Data.Text (unpack) import Database.Redis qualified as Redis -import Gundeck.API.Internal as Internal (GundeckInternalAPI, servantSitemap) +import Gundeck.API.Internal as Internal (InternalAPI, servantSitemap) import Gundeck.API.Public as Public (servantSitemap) import Gundeck.Aws qualified as Aws import Gundeck.Env @@ -92,7 +92,7 @@ run o = withTracer \tracer -> do versionMiddleware (foldMap expandVersionExp (o ^. settings . disabledAPIVersions)) . otelMiddleWare . requestIdMiddleware (e ^. applog) defaultRequestIdHeaderName - . Metrics.servantPrometheusMiddleware (Proxy @(GundeckAPI :<|> GundeckInternalAPI)) + . Metrics.servantPrometheusMiddleware (Proxy @(GundeckAPI :<|> InternalAPI)) . GZip.gunzip . GZip.gzip GZip.def . catchErrors (e ^. applog) defaultRequestIdHeaderName @@ -101,10 +101,10 @@ mkApp :: Env -> Wai.Application mkApp env0 req cont = do let rid = getRequestId defaultRequestIdHeaderName req env = reqId .~ rid $ env0 - Servant.serve (Proxy @(GundeckAPI :<|> GundeckInternalAPI)) (servantSitemap' env) req cont + Servant.serve (Proxy @(GundeckAPI :<|> InternalAPI)) (servantSitemap' env) req cont -servantSitemap' :: Env -> Servant.Server (GundeckAPI :<|> GundeckInternalAPI) -servantSitemap' env = Servant.hoistServer (Proxy @(GundeckAPI :<|> GundeckInternalAPI)) toServantHandler (Public.servantSitemap :<|> Internal.servantSitemap) +servantSitemap' :: Env -> Servant.Server (GundeckAPI :<|> InternalAPI) +servantSitemap' env = Servant.hoistServer (Proxy @(GundeckAPI :<|> InternalAPI)) toServantHandler (Public.servantSitemap :<|> Internal.servantSitemap) where toServantHandler :: Gundeck a -> Handler a toServantHandler m = Handler . ExceptT $ Right <$> runDirect env m diff --git a/services/gundeck/test/integration/API.hs b/services/gundeck/test/integration/API.hs index e5e3a3cdbcc..d09a1a7abfa 100644 --- a/services/gundeck/test/integration/API.hs +++ b/services/gundeck/test/integration/API.hs @@ -53,7 +53,6 @@ import Data.UUID.V4 import Gundeck.Options hiding (bulkPush) import Gundeck.Options qualified as O import Gundeck.Types -import Gundeck.Types.Common qualified import Imports import Network.HTTP.Client qualified as Http import Network.URI (parseURI) @@ -66,6 +65,7 @@ import Test.Tasty.HUnit import TestSetup import Util (runRedisProxy, withEnvOverrides, withSettingsOverrides) import Wire.API.Internal.Notification +import Wire.API.Presence import Prelude qualified tests :: IO TestSetup -> TestTree @@ -871,7 +871,7 @@ testRedisMigration :: TestM () testRedisMigration = do uid <- randomUser con <- randomConnId - cannonURI <- Gundeck.Types.Common.parse "http://cannon.example" + cannonURI <- Wire.API.Presence.parse "http://cannon.example" let presence = Presence uid con cannonURI Nothing 1 "" redis2 <- view tsRedis2 From 63c1fd57762c1d5f524efda367df59cddf9df5b1 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Fri, 27 Sep 2024 16:47:47 +0200 Subject: [PATCH 10/32] rm /libs/gundeck-types --- cabal.project | 1 - libs/gundeck-types/.ormolu | 1 - libs/gundeck-types/LICENSE | 661 ------------------ libs/gundeck-types/default.nix | 42 -- libs/gundeck-types/gundeck-types.cabal | 84 --- libs/gundeck-types/src/Gundeck/Types.hs | 25 - .../gundeck-types/src/Gundeck/Types/Common.hs | 20 - libs/gundeck-types/src/Gundeck/Types/Event.hs | 43 -- .../src/Gundeck/Types/Presence.hs | 25 - libs/gundeck-types/src/Gundeck/Types/Push.hs | 23 - .../src/Gundeck/Types/Push/V2.hs | 74 -- libs/wire-api/default.nix | 2 + libs/wire-api/wire-api.cabal | 1 + libs/wire-subsystems/default.nix | 3 - .../src/Wire/GundeckAPIAccess.hs | 2 +- .../src/Wire/NotificationSubsystem.hs | 2 +- .../Wire/NotificationSubsystem/Interpreter.hs | 4 +- .../NotificationSubsystem/InterpreterSpec.hs | 2 +- libs/wire-subsystems/wire-subsystems.cabal | 2 - nix/local-haskell-packages.nix | 1 - services/brig/brig.cabal | 1 - services/brig/default.nix | 2 - services/brig/src/Brig/API/Federation.hs | 2 +- services/brig/src/Brig/IO/Intra.hs | 4 +- services/cannon/cannon.cabal | 1 - services/cannon/default.nix | 2 - services/cannon/src/Cannon/WS.hs | 2 +- services/galley/default.nix | 2 - services/galley/galley.cabal | 1 - services/galley/src/Galley/API/Action.hs | 2 +- services/galley/src/Galley/API/Create.hs | 2 +- services/galley/src/Galley/API/Federation.hs | 2 +- services/galley/src/Galley/API/Internal.hs | 2 +- .../galley/src/Galley/API/MLS/Propagate.hs | 2 +- services/galley/src/Galley/API/MLS/Welcome.hs | 2 +- services/galley/src/Galley/API/Push.hs | 2 +- services/galley/src/Galley/API/Util.hs | 2 +- services/gundeck/default.nix | 5 - services/gundeck/gundeck.cabal | 5 +- services/gundeck/src/Gundeck/API/Internal.hs | 2 +- services/gundeck/src/Gundeck/Aws.hs | 4 +- services/gundeck/src/Gundeck/Aws/Arn.hs | 2 +- services/gundeck/src/Gundeck/Instances.hs | 2 +- services/gundeck/src/Gundeck/Presence.hs | 6 +- services/gundeck/src/Gundeck/Presence/Data.hs | 2 +- services/gundeck/src/Gundeck/Push.hs | 5 +- services/gundeck/src/Gundeck/Push/Data.hs | 2 +- services/gundeck/src/Gundeck/Push/Native.hs | 3 +- .../src/Gundeck/Push/Native/Serialise.hs | 2 +- .../gundeck/src/Gundeck/Push/Native/Types.hs | 2 +- .../gundeck/src/Gundeck/Push/Websocket.hs | 2 +- services/gundeck/src/Gundeck/React.hs | 3 +- services/gundeck/test/bench/Main.hs | 2 +- services/gundeck/test/integration/API.hs | 3 +- services/gundeck/test/unit/Aws/Arn.hs | 2 +- services/gundeck/test/unit/Json.hs | 2 +- services/gundeck/test/unit/MockGundeck.hs | 3 +- services/gundeck/test/unit/Native.hs | 2 +- .../gundeck/test/unit/ParseExistsError.hs | 2 +- services/gundeck/test/unit/Push.hs | 3 +- 60 files changed, 52 insertions(+), 1065 deletions(-) delete mode 120000 libs/gundeck-types/.ormolu delete mode 100644 libs/gundeck-types/LICENSE delete mode 100644 libs/gundeck-types/default.nix delete mode 100644 libs/gundeck-types/gundeck-types.cabal delete mode 100644 libs/gundeck-types/src/Gundeck/Types.hs delete mode 100644 libs/gundeck-types/src/Gundeck/Types/Common.hs delete mode 100644 libs/gundeck-types/src/Gundeck/Types/Event.hs delete mode 100644 libs/gundeck-types/src/Gundeck/Types/Presence.hs delete mode 100644 libs/gundeck-types/src/Gundeck/Types/Push.hs delete mode 100644 libs/gundeck-types/src/Gundeck/Types/Push/V2.hs diff --git a/cabal.project b/cabal.project index ed3bbc74931..e698e014c46 100644 --- a/cabal.project +++ b/cabal.project @@ -11,7 +11,6 @@ packages: , libs/dns-util/ , libs/deriving-swagger2/ , libs/galley-types/ - , libs/gundeck-types/ , libs/hscim/ , libs/http2-manager/ , libs/imports/ diff --git a/libs/gundeck-types/.ormolu b/libs/gundeck-types/.ormolu deleted file mode 120000 index 157b212d7cd..00000000000 --- a/libs/gundeck-types/.ormolu +++ /dev/null @@ -1 +0,0 @@ -../../.ormolu \ No newline at end of file diff --git a/libs/gundeck-types/LICENSE b/libs/gundeck-types/LICENSE deleted file mode 100644 index dba13ed2ddf..00000000000 --- a/libs/gundeck-types/LICENSE +++ /dev/null @@ -1,661 +0,0 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. - - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. - - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. - - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU Affero General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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 . - -Also add information on how to contact you by electronic and paper mail. - - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -. diff --git a/libs/gundeck-types/default.nix b/libs/gundeck-types/default.nix deleted file mode 100644 index 6c440616b9a..00000000000 --- a/libs/gundeck-types/default.nix +++ /dev/null @@ -1,42 +0,0 @@ -# WARNING: GENERATED FILE, DO NOT EDIT. -# This file is generated by running hack/bin/generate-local-nix-packages.sh and -# must be regenerated whenever local packages are added or removed, or -# dependencies are added or removed. -{ mkDerivation -, aeson -, attoparsec -, base -, bytestring -, bytestring-conversion -, containers -, gitignoreSource -, imports -, lens -, lib -, network-uri -, servant -, text -, types-common -, wire-api -}: -mkDerivation { - pname = "gundeck-types"; - version = "1.45.0"; - src = gitignoreSource ./.; - libraryHaskellDepends = [ - aeson - attoparsec - base - bytestring - bytestring-conversion - containers - imports - lens - network-uri - servant - text - types-common - wire-api - ]; - license = lib.licenses.agpl3Only; -} diff --git a/libs/gundeck-types/gundeck-types.cabal b/libs/gundeck-types/gundeck-types.cabal deleted file mode 100644 index 6f306c9cf87..00000000000 --- a/libs/gundeck-types/gundeck-types.cabal +++ /dev/null @@ -1,84 +0,0 @@ -cabal-version: 1.12 -name: gundeck-types -version: 1.45.0 -description: API types of Gundeck. -category: Network -author: Wire Swiss GmbH -maintainer: Wire Swiss GmbH -copyright: (c) 2017 Wire Swiss GmbH -license: AGPL-3 -license-file: LICENSE -build-type: Simple - -library - exposed-modules: - Gundeck.Types - Gundeck.Types.Common - Gundeck.Types.Event - Gundeck.Types.Presence - Gundeck.Types.Push - Gundeck.Types.Push.V2 - - other-modules: Paths_gundeck_types - hs-source-dirs: src - default-extensions: - AllowAmbiguousTypes - BangPatterns - ConstraintKinds - DataKinds - DefaultSignatures - DeriveFunctor - DeriveGeneric - DeriveLift - DeriveTraversable - DerivingStrategies - DerivingVia - DuplicateRecordFields - EmptyCase - FlexibleContexts - FlexibleInstances - FunctionalDependencies - GADTs - InstanceSigs - KindSignatures - LambdaCase - MultiParamTypeClasses - MultiWayIf - NamedFieldPuns - NoImplicitPrelude - OverloadedRecordDot - OverloadedStrings - PackageImports - PatternSynonyms - PolyKinds - QuasiQuotes - RankNTypes - ScopedTypeVariables - StandaloneDeriving - TupleSections - TypeApplications - TypeFamilies - TypeFamilyDependencies - TypeOperators - UndecidableInstances - ViewPatterns - - ghc-options: - -O2 -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates - -Wpartial-fields -fwarn-tabs -optP-Wno-nonportable-include-path - -Wredundant-constraints -Wunused-packages - - build-depends: - aeson >=2.0.1.0 - , attoparsec >=0.10 - , base >=4 && <5 - , bytestring >=0.10 - , bytestring-conversion >=0.2 - , imports - , network-uri >=2.6 - , servant - , text >=0.11 - , types-common >=0.16 - , wire-api - - default-language: GHC2021 diff --git a/libs/gundeck-types/src/Gundeck/Types.hs b/libs/gundeck-types/src/Gundeck/Types.hs deleted file mode 100644 index 2658731e13e..00000000000 --- a/libs/gundeck-types/src/Gundeck/Types.hs +++ /dev/null @@ -1,25 +0,0 @@ --- This file is part of the Wire Server implementation. --- --- Copyright (C) 2022 Wire Swiss GmbH --- --- 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 . - -module Gundeck.Types - ( module G, - ) -where - -import Gundeck.Types.Event as G -import Gundeck.Types.Presence as G -import Gundeck.Types.Push as G diff --git a/libs/gundeck-types/src/Gundeck/Types/Common.hs b/libs/gundeck-types/src/Gundeck/Types/Common.hs deleted file mode 100644 index 3b38816acc3..00000000000 --- a/libs/gundeck-types/src/Gundeck/Types/Common.hs +++ /dev/null @@ -1,20 +0,0 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving #-} - --- This file is part of the Wire Server implementation. --- --- Copyright (C) 2022 Wire Swiss GmbH --- --- 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 . - -module Gundeck.Types.Common where diff --git a/libs/gundeck-types/src/Gundeck/Types/Event.hs b/libs/gundeck-types/src/Gundeck/Types/Event.hs deleted file mode 100644 index a5d1ebf688e..00000000000 --- a/libs/gundeck-types/src/Gundeck/Types/Event.hs +++ /dev/null @@ -1,43 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - --- This file is part of the Wire Server implementation. --- --- Copyright (C) 2022 Wire Swiss GmbH --- --- 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 . - -module Gundeck.Types.Event where - -import Data.Aeson -import Data.Aeson.KeyMap qualified as KeyMap -import Data.Json.Util -import Gundeck.Types.Push -import Imports - -newtype PushRemove = PushRemove PushToken - deriving (Eq, Show) - -instance FromJSON PushRemove where - parseJSON = withObject "push-removed object" $ \o -> - PushRemove <$> o .: "token" - -instance ToJSON PushRemove where - toJSON = Object . toJSONObject - -instance ToJSONObject PushRemove where - toJSONObject (PushRemove t) = - KeyMap.fromList - [ "type" .= ("user.push-remove" :: Text), - "token" .= t - ] diff --git a/libs/gundeck-types/src/Gundeck/Types/Presence.hs b/libs/gundeck-types/src/Gundeck/Types/Presence.hs deleted file mode 100644 index 340cd2eee21..00000000000 --- a/libs/gundeck-types/src/Gundeck/Types/Presence.hs +++ /dev/null @@ -1,25 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - --- This file is part of the Wire Server implementation. --- --- Copyright (C) 2022 Wire Swiss GmbH --- --- 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 . - -module Gundeck.Types.Presence - ( module Wire.API.Presence, - ) -where - -import Wire.API.Presence -- TODO: drop this module entirely! diff --git a/libs/gundeck-types/src/Gundeck/Types/Push.hs b/libs/gundeck-types/src/Gundeck/Types/Push.hs deleted file mode 100644 index fcd4d6af18c..00000000000 --- a/libs/gundeck-types/src/Gundeck/Types/Push.hs +++ /dev/null @@ -1,23 +0,0 @@ --- This file is part of the Wire Server implementation. --- --- Copyright (C) 2022 Wire Swiss GmbH --- --- 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 . - -module Gundeck.Types.Push - ( module V2, - ) -where - -import Gundeck.Types.Push.V2 as V2 diff --git a/libs/gundeck-types/src/Gundeck/Types/Push/V2.hs b/libs/gundeck-types/src/Gundeck/Types/Push/V2.hs deleted file mode 100644 index 2138664f2a6..00000000000 --- a/libs/gundeck-types/src/Gundeck/Types/Push/V2.hs +++ /dev/null @@ -1,74 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TypeApplications #-} - --- This file is part of the Wire Server implementation. --- --- Copyright (C) 2022 Wire Swiss GmbH --- --- 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 . - -module Gundeck.Types.Push.V2 - ( Push (..), - newPush, - pushRecipients, - pushOrigin, - pushConnections, - pushOriginConnection, - pushTransient, - pushNativeIncludeOrigin, - pushNativeEncrypt, - pushNativeAps, - pushNativePriority, - pushPayload, - singletonPayload, - Recipient (..), - RecipientClients (..), - recipient, - recipientId, - recipientRoute, - recipientClients, - Route (..), - ApsData, - ApsLocKey (..), - ApsSound (..), - apsData, - apsLocKey, - apsLocArgs, - apsSound, - apsBadge, - - -- * Priority (re-export) - Priority (..), - - -- * PushToken (re-export) - PushTokenList (..), - PushToken, - pushToken, - tokenTransport, - tokenApp, - tokenClient, - token, - - -- * PushToken fields (re-export) - Token (..), - Transport (..), - AppName (..), - ) -where - -import Wire.API.Push.V2 -- TODO: just remove this module... diff --git a/libs/wire-api/default.nix b/libs/wire-api/default.nix index 1f765bee115..2fd02d1acf6 100644 --- a/libs/wire-api/default.nix +++ b/libs/wire-api/default.nix @@ -63,6 +63,7 @@ , metrics-wai , mime , mtl +, network-uri , openapi3 , pem , polysemy @@ -169,6 +170,7 @@ mkDerivation { metrics-wai mime mtl + network-uri openapi3 pem polysemy diff --git a/libs/wire-api/wire-api.cabal b/libs/wire-api/wire-api.cabal index 4998577bd41..d484454f8ec 100644 --- a/libs/wire-api/wire-api.cabal +++ b/libs/wire-api/wire-api.cabal @@ -97,6 +97,7 @@ library Wire.API.Event.Conversation Wire.API.Event.FeatureConfig Wire.API.Event.Federation + Wire.API.Event.Gundeck Wire.API.Event.LeaveReason Wire.API.Event.Team Wire.API.FederationStatus diff --git a/libs/wire-subsystems/default.nix b/libs/wire-subsystems/default.nix index 17d3f312a20..ead2f2a9c9d 100644 --- a/libs/wire-subsystems/default.nix +++ b/libs/wire-subsystems/default.nix @@ -28,7 +28,6 @@ , extended , extra , gitignoreSource -, gundeck-types , HaskellNet , HaskellNet-SSL , HsOpenSSL @@ -117,7 +116,6 @@ mkDerivation { exceptions extended extra - gundeck-types HaskellNet HaskellNet-SSL HsOpenSSL @@ -180,7 +178,6 @@ mkDerivation { data-default errors extended - gundeck-types hspec imports iso639 diff --git a/libs/wire-subsystems/src/Wire/GundeckAPIAccess.hs b/libs/wire-subsystems/src/Wire/GundeckAPIAccess.hs index 1d0666880cf..c153cf22364 100644 --- a/libs/wire-subsystems/src/Wire/GundeckAPIAccess.hs +++ b/libs/wire-subsystems/src/Wire/GundeckAPIAccess.hs @@ -5,11 +5,11 @@ module Wire.GundeckAPIAccess where import Bilge import Data.ByteString.Conversion import Data.Id -import Gundeck.Types.Push.V2 qualified as V2 import Imports import Network.HTTP.Types import Polysemy import Util.Options +import Wire.API.Push.V2 qualified as V2 import Wire.Rpc data GundeckAPIAccess m a where diff --git a/libs/wire-subsystems/src/Wire/NotificationSubsystem.hs b/libs/wire-subsystems/src/Wire/NotificationSubsystem.hs index 96d9d4c221b..5e1c35b5fbb 100644 --- a/libs/wire-subsystems/src/Wire/NotificationSubsystem.hs +++ b/libs/wire-subsystems/src/Wire/NotificationSubsystem.hs @@ -7,9 +7,9 @@ import Control.Lens (makeLenses) import Data.Aeson import Data.Id import Data.List.NonEmpty (NonEmpty ((:|))) -import Gundeck.Types hiding (Push (..), Recipient, newPush) import Imports import Polysemy +import Wire.API.Push.V2 hiding (Push (..), Recipient, newPush) import Wire.Arbitrary data Recipient = Recipient diff --git a/libs/wire-subsystems/src/Wire/NotificationSubsystem/Interpreter.hs b/libs/wire-subsystems/src/Wire/NotificationSubsystem/Interpreter.hs index 7f14c802389..1b0d4dd6c25 100644 --- a/libs/wire-subsystems/src/Wire/NotificationSubsystem/Interpreter.hs +++ b/libs/wire-subsystems/src/Wire/NotificationSubsystem/Interpreter.hs @@ -11,8 +11,6 @@ import Data.Proxy import Data.Range import Data.Set qualified as Set import Data.Time.Clock.DiffTime -import Gundeck.Types hiding (Push (..), Recipient, newPush) -import Gundeck.Types.Push.V2 qualified as V2 import Imports import Numeric.Natural (Natural) import Polysemy @@ -22,6 +20,8 @@ import Polysemy.Error import Polysemy.Input import Polysemy.TinyLog qualified as P import System.Logger.Class as Log +import Wire.API.Push.V2 hiding (Push (..), Recipient, newPush) +import Wire.API.Push.V2 qualified as V2 import Wire.API.Team.Member import Wire.GundeckAPIAccess (GundeckAPIAccess) import Wire.GundeckAPIAccess qualified as GundeckAPIAccess diff --git a/libs/wire-subsystems/test/unit/Wire/NotificationSubsystem/InterpreterSpec.hs b/libs/wire-subsystems/test/unit/Wire/NotificationSubsystem/InterpreterSpec.hs index 1c633c201ab..9486394b019 100644 --- a/libs/wire-subsystems/test/unit/Wire/NotificationSubsystem/InterpreterSpec.hs +++ b/libs/wire-subsystems/test/unit/Wire/NotificationSubsystem/InterpreterSpec.hs @@ -10,7 +10,6 @@ import Data.Range (fromRange, toRange) import Data.Set qualified as Set import Data.String.Conversions import Data.Time.Clock.DiffTime -import Gundeck.Types.Push.V2 qualified as V2 import Imports import Numeric.Natural (Natural) import Polysemy @@ -21,6 +20,7 @@ import System.Timeout (timeout) import Test.Hspec import Test.QuickCheck import Test.QuickCheck.Instances () +import Wire.API.Push.V2 qualified as V2 import Wire.GundeckAPIAccess import Wire.GundeckAPIAccess qualified as GundeckAPIAccess import Wire.NotificationSubsystem diff --git a/libs/wire-subsystems/wire-subsystems.cabal b/libs/wire-subsystems/wire-subsystems.cabal index 011bd1e528c..668e20b9a17 100644 --- a/libs/wire-subsystems/wire-subsystems.cabal +++ b/libs/wire-subsystems/wire-subsystems.cabal @@ -168,7 +168,6 @@ library , exceptions , extended , extra - , gundeck-types , HaskellNet , HaskellNet-SSL , HsOpenSSL @@ -275,7 +274,6 @@ test-suite wire-subsystems-tests , data-default , errors , extended - , gundeck-types , hspec , imports , iso639 diff --git a/nix/local-haskell-packages.nix b/nix/local-haskell-packages.nix index 38c381258a4..ce662af5cca 100644 --- a/nix/local-haskell-packages.nix +++ b/nix/local-haskell-packages.nix @@ -12,7 +12,6 @@ dns-util = hself.callPackage ../libs/dns-util/default.nix { inherit gitignoreSource; }; extended = hself.callPackage ../libs/extended/default.nix { inherit gitignoreSource; }; galley-types = hself.callPackage ../libs/galley-types/default.nix { inherit gitignoreSource; }; - gundeck-types = hself.callPackage ../libs/gundeck-types/default.nix { inherit gitignoreSource; }; hscim = hself.callPackage ../libs/hscim/default.nix { inherit gitignoreSource; }; http2-manager = hself.callPackage ../libs/http2-manager/default.nix { inherit gitignoreSource; }; imports = hself.callPackage ../libs/imports/default.nix { inherit gitignoreSource; }; diff --git a/services/brig/brig.cabal b/services/brig/brig.cabal index bc322581589..103cfd80c8a 100644 --- a/services/brig/brig.cabal +++ b/services/brig/brig.cabal @@ -246,7 +246,6 @@ library , filepath >=1.3 , fsnotify >=0.4 , galley-types >=0.75.3 - , gundeck-types >=1.32.1 , hashable >=1.2 , hs-opentelemetry-instrumentation-wai , hs-opentelemetry-sdk diff --git a/services/brig/default.nix b/services/brig/default.nix index a52f5219eb8..ac7206ad390 100644 --- a/services/brig/default.nix +++ b/services/brig/default.nix @@ -49,7 +49,6 @@ , fsnotify , galley-types , gitignoreSource -, gundeck-types , hashable , hs-opentelemetry-instrumentation-wai , hs-opentelemetry-sdk @@ -204,7 +203,6 @@ mkDerivation { filepath fsnotify galley-types - gundeck-types hashable hs-opentelemetry-instrumentation-wai hs-opentelemetry-sdk diff --git a/services/brig/src/Brig/API/Federation.hs b/services/brig/src/Brig/API/Federation.hs index 35ebe1568b3..8a96e6c2d33 100644 --- a/services/brig/src/Brig/API/Federation.hs +++ b/services/brig/src/Brig/API/Federation.hs @@ -45,7 +45,6 @@ import Data.List.NonEmpty (nonEmpty) import Data.Qualified import Data.Range import Data.Set (fromList, (\\)) -import Gundeck.Types.Push qualified as Push import Imports hiding ((\\)) import Network.Wai.Utilities.Error ((!>>)) import Polysemy @@ -57,6 +56,7 @@ import Wire.API.Federation.API.Common import Wire.API.Federation.Endpoint import Wire.API.Federation.Version import Wire.API.MLS.KeyPackage +import Wire.API.Push.V2 qualified as Push import Wire.API.Routes.FederationDomainConfig as FD import Wire.API.Routes.Internal.Brig.Connection import Wire.API.Routes.Named diff --git a/services/brig/src/Brig/IO/Intra.hs b/services/brig/src/Brig/IO/Intra.hs index 8309190c88f..d4eef4df895 100644 --- a/services/brig/src/Brig/IO/Intra.hs +++ b/services/brig/src/Brig/IO/Intra.hs @@ -77,8 +77,6 @@ import Data.Proxy import Data.Qualified import Data.Range import Data.Time.Clock (UTCTime) -import Gundeck.Types.Push.V2 (RecipientClients (RecipientClientsAll)) -import Gundeck.Types.Push.V2 qualified as V2 import Imports import Network.HTTP.Types.Method import Network.HTTP.Types.Status @@ -91,6 +89,8 @@ import Wire.API.Conversation hiding (Member) import Wire.API.Event.Conversation (Connect (Connect)) import Wire.API.Federation.API.Brig import Wire.API.Federation.Error +import Wire.API.Push.V2 (RecipientClients (RecipientClientsAll)) +import Wire.API.Push.V2 qualified as V2 import Wire.API.Routes.Internal.Galley.ConversationsIntra import Wire.API.Routes.Internal.Galley.TeamsIntra (GuardLegalholdPolicyConflicts (GuardLegalholdPolicyConflicts)) import Wire.API.Team.LegalHold (LegalholdProtectee) diff --git a/services/cannon/cannon.cabal b/services/cannon/cannon.cabal index b85fd137f9d..1eb1b4cdd26 100644 --- a/services/cannon/cannon.cabal +++ b/services/cannon/cannon.cabal @@ -90,7 +90,6 @@ library , exceptions >=0.6 , extended , extra - , gundeck-types , hashable >=1.2 , hs-opentelemetry-instrumentation-wai , hs-opentelemetry-sdk diff --git a/services/cannon/default.nix b/services/cannon/default.nix index db254e8b235..c0e94ff02f7 100644 --- a/services/cannon/default.nix +++ b/services/cannon/default.nix @@ -17,7 +17,6 @@ , extended , extra , gitignoreSource -, gundeck-types , hashable , hs-opentelemetry-instrumentation-wai , hs-opentelemetry-sdk @@ -73,7 +72,6 @@ mkDerivation { exceptions extended extra - gundeck-types hashable hs-opentelemetry-instrumentation-wai hs-opentelemetry-sdk diff --git a/services/cannon/src/Cannon/WS.hs b/services/cannon/src/Cannon/WS.hs index f551434b599..0ad9820df96 100644 --- a/services/cannon/src/Cannon/WS.hs +++ b/services/cannon/src/Cannon/WS.hs @@ -66,7 +66,6 @@ import Data.Id (ClientId, ConnId (..), UserId) import Data.List.Extra (chunksOf) import Data.Text.Encoding (decodeUtf8) import Data.Timeout (TimeoutUnit (..), (#)) -import Gundeck.Types import Imports hiding (threadDelay) import Network.HTTP.Types.Method import Network.HTTP.Types.Status @@ -76,6 +75,7 @@ import System.Logger qualified as Logger import System.Logger.Class hiding (Error, Settings, close, (.=)) import System.Random.MWC (GenIO, uniform) import UnliftIO.Async (async, cancel, pooledMapConcurrentlyN_) +import Wire.API.Presence ----------------------------------------------------------------------------- -- Key diff --git a/services/galley/default.nix b/services/galley/default.nix index 38bf97f86de..337edc485eb 100644 --- a/services/galley/default.nix +++ b/services/galley/default.nix @@ -42,7 +42,6 @@ , galley-types , generics-sop , gitignoreSource -, gundeck-types , hex , hs-opentelemetry-instrumentation-wai , hs-opentelemetry-sdk @@ -167,7 +166,6 @@ mkDerivation { extra galley-types generics-sop - gundeck-types hex hs-opentelemetry-instrumentation-wai hs-opentelemetry-sdk diff --git a/services/galley/galley.cabal b/services/galley/galley.cabal index abec40e3606..d0f0d567a5e 100644 --- a/services/galley/galley.cabal +++ b/services/galley/galley.cabal @@ -317,7 +317,6 @@ library , extra >=1.3 , galley-types >=0.65.0 , generics-sop - , gundeck-types >=1.35.2 , hex , hs-opentelemetry-instrumentation-wai , hs-opentelemetry-sdk diff --git a/services/galley/src/Galley/API/Action.hs b/services/galley/src/Galley/API/Action.hs index 62f1f5120f3..e96f060855e 100644 --- a/services/galley/src/Galley/API/Action.hs +++ b/services/galley/src/Galley/API/Action.hs @@ -91,7 +91,6 @@ import Galley.Options import Galley.Types.Conversations.Members import Galley.Types.UserList import Galley.Validation -import Gundeck.Types.Push.V2 qualified as PushV2 import Imports hiding ((\\)) import Network.AMQP qualified as Q import Polysemy @@ -116,6 +115,7 @@ import Wire.API.Federation.API.Galley import Wire.API.Federation.API.Galley qualified as F import Wire.API.Federation.Error import Wire.API.FederationStatus +import Wire.API.Push.V2 qualified as PushV2 import Wire.API.Routes.Internal.Brig.Connection import Wire.API.Team.Feature import Wire.API.Team.LegalHold diff --git a/services/galley/src/Galley/API/Create.hs b/services/galley/src/Galley/API/Create.hs index fa65410616d..4b71e3fcf85 100644 --- a/services/galley/src/Galley/API/Create.hs +++ b/services/galley/src/Galley/API/Create.hs @@ -63,7 +63,6 @@ import Galley.Types.Teams (notTeamMember) import Galley.Types.ToUserRole import Galley.Types.UserList import Galley.Validation -import Gundeck.Types.Push.V2 qualified as PushV2 import Imports hiding ((\\)) import Polysemy import Polysemy.Error @@ -76,6 +75,7 @@ import Wire.API.Error.Galley import Wire.API.Event.Conversation import Wire.API.Federation.Error import Wire.API.FederationStatus +import Wire.API.Push.V2 qualified as PushV2 import Wire.API.Routes.Public.Galley.Conversation import Wire.API.Routes.Public.Util import Wire.API.Team diff --git a/services/galley/src/Galley/API/Federation.hs b/services/galley/src/Galley/API/Federation.hs index a78652408fe..a6ae06e0339 100644 --- a/services/galley/src/Galley/API/Federation.hs +++ b/services/galley/src/Galley/API/Federation.hs @@ -63,7 +63,6 @@ import Galley.Options import Galley.Types.Conversations.Members import Galley.Types.Conversations.One2One import Galley.Types.UserList (UserList (UserList)) -import Gundeck.Types.Push.V2 (RecipientClients (..)) import Imports import Polysemy import Polysemy.Error @@ -94,6 +93,7 @@ import Wire.API.MLS.Keys import Wire.API.MLS.Serialisation import Wire.API.MLS.SubConversation import Wire.API.Message +import Wire.API.Push.V2 (RecipientClients (..)) import Wire.API.Routes.Named import Wire.API.ServantProto import Wire.API.User (BaseProtocolTag (..)) diff --git a/services/galley/src/Galley/API/Internal.hs b/services/galley/src/Galley/API/Internal.hs index d6f731aa195..fff8e161a7d 100644 --- a/services/galley/src/Galley/API/Internal.hs +++ b/services/galley/src/Galley/API/Internal.hs @@ -68,7 +68,6 @@ import Galley.Options hiding (brig) import Galley.Queue qualified as Q import Galley.Types.Conversations.Members (RemoteMember (rmId)) import Galley.Types.UserList -import Gundeck.Types.Push.V2 qualified as PushV2 import Imports hiding (head) import Network.AMQP qualified as Q import Polysemy @@ -87,6 +86,7 @@ import Wire.API.Event.LeaveReason import Wire.API.Federation.API import Wire.API.Federation.API.Galley import Wire.API.Federation.Error +import Wire.API.Push.V2 qualified as PushV2 import Wire.API.Routes.API import Wire.API.Routes.Internal.Brig.EJPD import Wire.API.Routes.Internal.Galley diff --git a/services/galley/src/Galley/API/MLS/Propagate.hs b/services/galley/src/Galley/API/MLS/Propagate.hs index b0fe16e6c8c..d256ab23cec 100644 --- a/services/galley/src/Galley/API/MLS/Propagate.hs +++ b/services/galley/src/Galley/API/MLS/Propagate.hs @@ -31,7 +31,6 @@ import Galley.Data.Services import Galley.Effects import Galley.Effects.BackendNotificationQueueAccess import Galley.Types.Conversations.Members -import Gundeck.Types.Push.V2 (RecipientClients (..)) import Imports import Network.AMQP qualified as Q import Polysemy @@ -47,6 +46,7 @@ import Wire.API.MLS.Message import Wire.API.MLS.Serialisation import Wire.API.MLS.SubConversation import Wire.API.Message +import Wire.API.Push.V2 (RecipientClients (..)) import Wire.NotificationSubsystem -- | Propagate a message. diff --git a/services/galley/src/Galley/API/MLS/Welcome.hs b/services/galley/src/Galley/API/MLS/Welcome.hs index c9a182d890b..c661a9dc5f5 100644 --- a/services/galley/src/Galley/API/MLS/Welcome.hs +++ b/services/galley/src/Galley/API/MLS/Welcome.hs @@ -33,7 +33,6 @@ import Data.Time import Galley.API.Push import Galley.Effects.ExternalAccess import Galley.Effects.FederatorAccess -import Gundeck.Types.Push.V2 (RecipientClients (..)) import Imports import Network.Wai.Utilities.JSONResponse import Polysemy @@ -52,6 +51,7 @@ import Wire.API.MLS.Serialisation import Wire.API.MLS.SubConversation import Wire.API.MLS.Welcome import Wire.API.Message +import Wire.API.Push.V2 (RecipientClients (..)) import Wire.NotificationSubsystem sendWelcomes :: diff --git a/services/galley/src/Galley/API/Push.hs b/services/galley/src/Galley/API/Push.hs index 5d379999bf0..79a70c56281 100644 --- a/services/galley/src/Galley/API/Push.hs +++ b/services/galley/src/Galley/API/Push.hs @@ -37,13 +37,13 @@ import Data.Map qualified as Map import Data.Qualified import Galley.Data.Services import Galley.Effects.ExternalAccess -import Gundeck.Types.Push (RecipientClients (RecipientClientsSome), Route (..)) import Imports import Polysemy import Polysemy.TinyLog import System.Logger.Class qualified as Log import Wire.API.Event.Conversation import Wire.API.Message +import Wire.API.Push.V2 (RecipientClients (RecipientClientsSome), Route (..)) import Wire.NotificationSubsystem data MessagePush diff --git a/services/galley/src/Galley/API/Util.hs b/services/galley/src/Galley/API/Util.hs index fac4e08102f..617c7c231cc 100644 --- a/services/galley/src/Galley/API/Util.hs +++ b/services/galley/src/Galley/API/Util.hs @@ -59,7 +59,6 @@ import Galley.Types.Conversations.Members import Galley.Types.Conversations.Roles import Galley.Types.Teams import Galley.Types.UserList -import Gundeck.Types.Push.V2 qualified as PushV2 import Imports hiding (forkIO) import Network.AMQP qualified as Q import Polysemy @@ -79,6 +78,7 @@ import Wire.API.Federation.API import Wire.API.Federation.API.Galley import Wire.API.Federation.Error import Wire.API.Password +import Wire.API.Push.V2 qualified as PushV2 import Wire.API.Routes.Public.Galley.Conversation import Wire.API.Routes.Public.Util import Wire.API.Team.Feature diff --git a/services/gundeck/default.nix b/services/gundeck/default.nix index d797346cf43..3f2f5a7d004 100644 --- a/services/gundeck/default.nix +++ b/services/gundeck/default.nix @@ -28,7 +28,6 @@ , extra , foldl , gitignoreSource -, gundeck-types , hedis , hs-opentelemetry-instrumentation-wai , hs-opentelemetry-sdk @@ -114,7 +113,6 @@ mkDerivation { extended extra foldl - gundeck-types hedis hs-opentelemetry-instrumentation-wai hs-opentelemetry-sdk @@ -166,7 +164,6 @@ mkDerivation { containers exceptions extended - gundeck-types HsOpenSSL http-client http-client-tls @@ -204,7 +201,6 @@ mkDerivation { bytestring-conversion containers exceptions - gundeck-types HsOpenSSL imports lens @@ -229,7 +225,6 @@ mkDerivation { amazonka base criterion - gundeck-types HsOpenSSL imports lens diff --git a/services/gundeck/gundeck.cabal b/services/gundeck/gundeck.cabal index b2e14c44908..19ce66fb3e2 100644 --- a/services/gundeck/gundeck.cabal +++ b/services/gundeck/gundeck.cabal @@ -131,7 +131,6 @@ library , extended , extra >=1.1 , foldl - , gundeck-types >=1.0 , hedis >=0.14.0 , hs-opentelemetry-instrumentation-wai , hs-opentelemetry-sdk @@ -304,7 +303,6 @@ executable gundeck-integration , containers , exceptions , gundeck - , gundeck-types , HsOpenSSL , http-client , http-client-tls @@ -540,7 +538,6 @@ test-suite gundeck-tests , containers , exceptions , gundeck - , gundeck-types , HsOpenSSL , imports , lens @@ -620,7 +617,6 @@ benchmark gundeck-bench , base , criterion , gundeck - , gundeck-types , HsOpenSSL , imports , lens @@ -628,5 +624,6 @@ benchmark gundeck-bench , text , types-common , uuid + , wire-api default-language: GHC2021 diff --git a/services/gundeck/src/Gundeck/API/Internal.hs b/services/gundeck/src/Gundeck/API/Internal.hs index 45ea344d37c..58a1043cd4b 100644 --- a/services/gundeck/src/Gundeck/API/Internal.hs +++ b/services/gundeck/src/Gundeck/API/Internal.hs @@ -30,10 +30,10 @@ import Gundeck.Presence qualified as Presence import Gundeck.Push qualified as Push import Gundeck.Push.Data qualified as PushTok import Gundeck.Push.Native.Types qualified as PushTok -import Gundeck.Types.Push.V2 import Imports import Servant import Wire.API.Push.Token qualified as PushTok +import Wire.API.Push.V2 import Wire.API.Routes.Internal.Gundeck servantSitemap :: ServerT InternalAPI Gundeck diff --git a/services/gundeck/src/Gundeck/Aws.hs b/services/gundeck/src/Gundeck/Aws.hs index 21d4ada077b..71014205f40 100644 --- a/services/gundeck/src/Gundeck/Aws.hs +++ b/services/gundeck/src/Gundeck/Aws.hs @@ -83,8 +83,6 @@ import Gundeck.Aws.Sns import Gundeck.Instances () import Gundeck.Options (Opts) import Gundeck.Options qualified as O -import Gundeck.Types.Push hiding (token) -import Gundeck.Types.Push qualified as Push import Imports import Network.HTTP.Client import Network.HTTP.Types @@ -94,6 +92,8 @@ import System.Logger.Class import UnliftIO.Async import UnliftIO.Exception import Util.Options +import Wire.API.Push.V2 hiding (token) +import Wire.API.Push.V2 qualified as Push data Error where EndpointNotFound :: EndpointArn -> Error diff --git a/services/gundeck/src/Gundeck/Aws/Arn.hs b/services/gundeck/src/Gundeck/Aws/Arn.hs index 0ff914c5d57..6723ba223af 100644 --- a/services/gundeck/src/Gundeck/Aws/Arn.hs +++ b/services/gundeck/src/Gundeck/Aws/Arn.hs @@ -57,8 +57,8 @@ import Control.Foldl qualified as Foldl import Control.Lens import Data.Attoparsec.Text import Data.Text qualified as Text -import Gundeck.Types (AppName (..), Transport (..)) import Imports +import Wire.API.Push.V2 (AppName (..), Transport (..)) newtype ArnEnv = ArnEnv {arnEnvText :: Text} deriving (Show, ToText, FromJSON) diff --git a/services/gundeck/src/Gundeck/Instances.hs b/services/gundeck/src/Gundeck/Instances.hs index 83ab2a692b4..ee225e82aed 100644 --- a/services/gundeck/src/Gundeck/Instances.hs +++ b/services/gundeck/src/Gundeck/Instances.hs @@ -31,8 +31,8 @@ import Data.Id import Data.Text.Encoding qualified as Text import Data.UUID qualified as Uuid import Gundeck.Aws.Arn (EndpointArn) -import Gundeck.Types import Imports +import Wire.API.Push.V2 instance Cql Transport where ctype = Tagged IntColumn diff --git a/services/gundeck/src/Gundeck/Presence.hs b/services/gundeck/src/Gundeck/Presence.hs index 258536866a3..aa8fb778095 100644 --- a/services/gundeck/src/Gundeck/Presence.hs +++ b/services/gundeck/src/Gundeck/Presence.hs @@ -27,10 +27,10 @@ import Data.CommaSeparatedList import Data.Id import Gundeck.Monad import Gundeck.Presence.Data qualified as Data -import Gundeck.Types import Imports -import Servant.API +import Servant.API hiding (URI) import Wire.API.CannonId +import Wire.API.Presence listH :: UserId -> Gundeck [Presence] listH = runWithDefaultRedis . Data.list @@ -38,7 +38,7 @@ listH = runWithDefaultRedis . Data.list listAllH :: CommaSeparatedList UserId -> Gundeck [Presence] listAllH uids = concat <$> runWithDefaultRedis (Data.listAll (fromCommaSeparatedList uids)) -addH :: Presence -> Gundeck (Headers '[Header "Location" Gundeck.Types.URI] NoContent) +addH :: Presence -> Gundeck (Headers '[Header "Location" URI] NoContent) addH p = do Data.add p pure (addHeader (resource p) NoContent) diff --git a/services/gundeck/src/Gundeck/Presence/Data.hs b/services/gundeck/src/Gundeck/Presence/Data.hs index bfe1773ba9c..6173ace303d 100644 --- a/services/gundeck/src/Gundeck/Presence/Data.hs +++ b/services/gundeck/src/Gundeck/Presence/Data.hs @@ -35,10 +35,10 @@ import Data.List.NonEmpty qualified as NonEmpty import Data.Misc (Milliseconds) import Database.Redis import Gundeck.Monad (Gundeck, posixTime, runWithAdditionalRedis) -import Gundeck.Types import Gundeck.Util.Redis import Imports import System.Logger.Class (MonadLogger) +import Wire.API.Presence -- Note [Migration] --------------------------------------------------------- -- diff --git a/services/gundeck/src/Gundeck/Push.hs b/services/gundeck/src/Gundeck/Push.hs index 6f3bcbcf684..d7a738ad0e9 100644 --- a/services/gundeck/src/Gundeck/Push.hs +++ b/services/gundeck/src/Gundeck/Push.hs @@ -60,8 +60,6 @@ import Gundeck.Push.Native qualified as Native import Gundeck.Push.Native.Types import Gundeck.Push.Websocket qualified as Web import Gundeck.ThreadBudget -import Gundeck.Types -import Gundeck.Types.Presence qualified as Presence import Gundeck.Util import Imports import Network.HTTP.Types @@ -69,7 +67,10 @@ import Network.Wai.Utilities import System.Logger.Class (msg, val, (+++), (.=), (~~)) import System.Logger.Class qualified as Log import Wire.API.Internal.Notification +import Wire.API.Presence (Presence (..)) +import Wire.API.Presence qualified as Presence import Wire.API.Push.Token qualified as Public +import Wire.API.Push.V2 push :: [Push] -> Gundeck () push ps = do diff --git a/services/gundeck/src/Gundeck/Push/Data.hs b/services/gundeck/src/Gundeck/Push/Data.hs index 5c3fc33cd34..01adce9b11d 100644 --- a/services/gundeck/src/Gundeck/Push/Data.hs +++ b/services/gundeck/src/Gundeck/Push/Data.hs @@ -30,10 +30,10 @@ import Data.ByteString.Conversion import Data.Id (ClientId, ConnId, UserId) import Gundeck.Instances () import Gundeck.Push.Native.Types -import Gundeck.Types hiding (token) import Imports hiding (lookup) import System.Logger.Class (MonadLogger, field, msg, val, (~~)) import System.Logger.Class qualified as Log +import Wire.API.Push.V2 hiding (token) lookup :: (MonadClient m, MonadLogger m) => UserId -> Consistency -> m [Address] lookup u c = foldM mk [] =<< retry x1 (query q (params c (Identity u))) diff --git a/services/gundeck/src/Gundeck/Push/Native.hs b/services/gundeck/src/Gundeck/Push/Native.hs index 0b9c6660eb4..3353568de84 100644 --- a/services/gundeck/src/Gundeck/Push/Native.hs +++ b/services/gundeck/src/Gundeck/Push/Native.hs @@ -39,14 +39,15 @@ import Gundeck.Options import Gundeck.Push.Data qualified as Data import Gundeck.Push.Native.Serialise import Gundeck.Push.Native.Types as Types -import Gundeck.Types import Gundeck.Util import Imports import Prometheus qualified as Prom import System.Logger.Class (MonadLogger, field, msg, val, (.=), (~~)) import System.Logger.Class qualified as Log import UnliftIO (handleAny, mapConcurrently, pooledMapConcurrentlyN_) +import Wire.API.Event.Gundeck import Wire.API.Internal.Notification +import Wire.API.Push.V2 push :: NativePush -> [Address] -> Gundeck () push _ [] = pure () diff --git a/services/gundeck/src/Gundeck/Push/Native/Serialise.hs b/services/gundeck/src/Gundeck/Push/Native/Serialise.hs index 648a888f834..6be13d4d80b 100644 --- a/services/gundeck/src/Gundeck/Push/Native/Serialise.hs +++ b/services/gundeck/src/Gundeck/Push/Native/Serialise.hs @@ -32,8 +32,8 @@ import Data.Text.Encoding (encodeUtf8) import Data.Text.Lazy qualified as LT import Data.Text.Lazy.Builder qualified as LTB import Gundeck.Push.Native.Types -import Gundeck.Types import Imports +import Wire.API.Push.V2 serialise :: (HasCallStack) => NativePush -> UserId -> Transport -> Either Failure LT.Text serialise (NativePush nid prio _aps) uid transport = do diff --git a/services/gundeck/src/Gundeck/Push/Native/Types.hs b/services/gundeck/src/Gundeck/Push/Native/Types.hs index b58726da4a6..cf28f90ebbb 100644 --- a/services/gundeck/src/Gundeck/Push/Native/Types.hs +++ b/services/gundeck/src/Gundeck/Push/Native/Types.hs @@ -44,9 +44,9 @@ where import Control.Lens (Lens', makeLenses, (^.)) import Data.Id (ClientId, ConnId, UserId) import Gundeck.Aws.Arn -import Gundeck.Types import Imports import Wire.API.Internal.Notification +import Wire.API.Push.V2 -- | Native push address information of a device. data Address = Address diff --git a/services/gundeck/src/Gundeck/Push/Websocket.hs b/services/gundeck/src/Gundeck/Push/Websocket.hs index 1c9d4730c51..97600d2720d 100644 --- a/services/gundeck/src/Gundeck/Push/Websocket.hs +++ b/services/gundeck/src/Gundeck/Push/Websocket.hs @@ -41,7 +41,6 @@ import Data.Set qualified as Set import Data.Time.Clock.POSIX import Gundeck.Monad import Gundeck.Presence.Data qualified as Presence -import Gundeck.Types.Presence import Gundeck.Util import Imports import Network.HTTP.Client (HttpExceptionContent (..)) @@ -54,6 +53,7 @@ import System.Logger.Class qualified as Log import UnliftIO (handleAny, mapConcurrently) import Wire.API.Internal.BulkPush import Wire.API.Internal.Notification +import Wire.API.Presence class (Monad m, MonadThrow m, Log.MonadLogger m) => MonadBulkPush m where mbpBulkSend :: URI -> BulkPushRequest -> m (URI, Either SomeException BulkPushResponse) diff --git a/services/gundeck/src/Gundeck/React.hs b/services/gundeck/src/Gundeck/React.hs index 9ffdf521cca..098eefa1288 100644 --- a/services/gundeck/src/Gundeck/React.hs +++ b/services/gundeck/src/Gundeck/React.hs @@ -41,12 +41,13 @@ import Gundeck.Options (notificationTTL, settings) import Gundeck.Push.Data qualified as Push import Gundeck.Push.Native.Types import Gundeck.Push.Websocket qualified as Web -import Gundeck.Types import Gundeck.Util import Imports import System.Logger.Class (Msg, msg, val, (+++), (.=), (~~)) import System.Logger.Class qualified as Log +import Wire.API.Event.Gundeck import Wire.API.Internal.Notification +import Wire.API.Push.V2 onEvent :: Event -> Gundeck () onEvent ev = case ev ^. evType of diff --git a/services/gundeck/test/bench/Main.hs b/services/gundeck/test/bench/Main.hs index 79fd1d6a9a7..c18d2b26932 100644 --- a/services/gundeck/test/bench/Main.hs +++ b/services/gundeck/test/bench/Main.hs @@ -33,10 +33,10 @@ import Gundeck.Options import Gundeck.Push.Native.Serialise import Gundeck.Push.Native.Types import Gundeck.ThreadBudget.Internal -import Gundeck.Types.Push import Imports import OpenSSL (withOpenSSL) import System.Random (randomRIO) +import Wire.API.Push.V2 main :: IO () main = withOpenSSL $ do diff --git a/services/gundeck/test/integration/API.hs b/services/gundeck/test/integration/API.hs index d09a1a7abfa..a9fedf99269 100644 --- a/services/gundeck/test/integration/API.hs +++ b/services/gundeck/test/integration/API.hs @@ -52,7 +52,6 @@ import Data.UUID qualified as UUID import Data.UUID.V4 import Gundeck.Options hiding (bulkPush) import Gundeck.Options qualified as O -import Gundeck.Types import Imports import Network.HTTP.Client qualified as Http import Network.URI (parseURI) @@ -64,8 +63,10 @@ import Test.Tasty import Test.Tasty.HUnit import TestSetup import Util (runRedisProxy, withEnvOverrides, withSettingsOverrides) +import Wire.API.Event.Gundeck import Wire.API.Internal.Notification import Wire.API.Presence +import Wire.API.Push.V2 import Prelude qualified tests :: IO TestSetup -> TestTree diff --git a/services/gundeck/test/unit/Aws/Arn.hs b/services/gundeck/test/unit/Aws/Arn.hs index 9d20bfaeec0..dde384d6b35 100644 --- a/services/gundeck/test/unit/Aws/Arn.hs +++ b/services/gundeck/test/unit/Aws/Arn.hs @@ -3,10 +3,10 @@ module Aws.Arn where import Amazonka.Data.Text import Control.Lens import Gundeck.Aws.Arn -import Gundeck.Types import Imports import Test.Tasty import Test.Tasty.HUnit +import Wire.API.Push.V2 tests :: TestTree tests = diff --git a/services/gundeck/test/unit/Json.hs b/services/gundeck/test/unit/Json.hs index b83dbf006be..b84b925c4f1 100644 --- a/services/gundeck/test/unit/Json.hs +++ b/services/gundeck/test/unit/Json.hs @@ -22,13 +22,13 @@ import Data.Aeson import Data.Aeson.KeyMap (fromList) import Data.Id import Data.List1 -import Gundeck.Types.Push import Imports import Test.Tasty import Test.Tasty.HUnit import Test.Tasty.QuickCheck import Wire.API.Internal.BulkPush import Wire.API.Internal.Notification +import Wire.API.Push.V2 tests :: TestTree tests = diff --git a/services/gundeck/test/unit/MockGundeck.hs b/services/gundeck/test/unit/MockGundeck.hs index d662a62aa10..e1c345fed73 100644 --- a/services/gundeck/test/unit/MockGundeck.hs +++ b/services/gundeck/test/unit/MockGundeck.hs @@ -67,7 +67,6 @@ import Gundeck.Options import Gundeck.Push import Gundeck.Push.Native as Native import Gundeck.Push.Websocket as Web -import Gundeck.Types hiding (recipient) import Imports import Network.URI qualified as URI import System.Logger.Class as Log hiding (trace) @@ -75,6 +74,8 @@ import Test.QuickCheck as QC import Test.QuickCheck.Instances () import Wire.API.Internal.BulkPush import Wire.API.Internal.Notification +import Wire.API.Presence +import Wire.API.Push.V2 hiding (recipient) ---------------------------------------------------------------------- -- env diff --git a/services/gundeck/test/unit/Native.hs b/services/gundeck/test/unit/Native.hs index 2e525f7cf1f..5b0d4daf1b9 100644 --- a/services/gundeck/test/unit/Native.hs +++ b/services/gundeck/test/unit/Native.hs @@ -28,11 +28,11 @@ import Data.Text.Encoding qualified as T import Data.Text.Lazy.Encoding qualified as LT import Gundeck.Push.Native.Serialise import Gundeck.Push.Native.Types -import Gundeck.Types.Push import Imports import Test.Tasty import Test.Tasty.QuickCheck import Wire.API.Internal.Notification +import Wire.API.Push.V2 tests :: TestTree tests = diff --git a/services/gundeck/test/unit/ParseExistsError.hs b/services/gundeck/test/unit/ParseExistsError.hs index 1c370be3eed..02ae7fd1408 100644 --- a/services/gundeck/test/unit/ParseExistsError.hs +++ b/services/gundeck/test/unit/ParseExistsError.hs @@ -3,10 +3,10 @@ module ParseExistsError where import Amazonka.Types import Gundeck.Aws import Gundeck.Aws.Arn -import Gundeck.Types.Push.V2 (Transport (APNS)) import Imports import Test.Tasty import Test.Tasty.HUnit +import Wire.API.Push.V2 (Transport (APNS)) tests :: TestTree tests = diff --git a/services/gundeck/test/unit/Push.hs b/services/gundeck/test/unit/Push.hs index 3214c72bdca..a65b85445e6 100644 --- a/services/gundeck/test/unit/Push.hs +++ b/services/gundeck/test/unit/Push.hs @@ -23,7 +23,6 @@ module Push where import Data.Aeson qualified as Aeson import Gundeck.Push (pushAll, pushAny) import Gundeck.Push.Websocket as Web (bulkPush) -import Gundeck.Types import Imports import MockGundeck import Test.QuickCheck @@ -31,6 +30,8 @@ import Test.QuickCheck.Instances () import Test.Tasty import Test.Tasty.QuickCheck import Wire.API.Internal.Notification +import Wire.API.Presence +import Wire.API.Push.V2 tests :: TestTree tests = From 26e58bfc874b338836eae1ce7948927b7701b12e Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Fri, 27 Sep 2024 17:51:20 +0200 Subject: [PATCH 11/32] fix trivial compiler errors. --- libs/wire-api/src/Wire/API/Push/V2.hs | 2 +- services/gundeck/default.nix | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/wire-api/src/Wire/API/Push/V2.hs b/libs/wire-api/src/Wire/API/Push/V2.hs index 968a795397f..257664c9eb0 100644 --- a/libs/wire-api/src/Wire/API/Push/V2.hs +++ b/libs/wire-api/src/Wire/API/Push/V2.hs @@ -207,7 +207,7 @@ instance ToSchema ApsData where <*> _apsSound .= maybe_ (optField "sound" schema) <*> withDefault "badge" _apsBadge schema True where - withDefault fn f s def = ((Just . f) .= maybe_ (optField fn s)) <&> maybe def id + withDefault fn f s def = ((Just . f) .= maybe_ (optField fn s)) <&> fromMaybe def makeLenses ''ApsData diff --git a/services/gundeck/default.nix b/services/gundeck/default.nix index 3f2f5a7d004..7629d0712c5 100644 --- a/services/gundeck/default.nix +++ b/services/gundeck/default.nix @@ -232,6 +232,7 @@ mkDerivation { text types-common uuid + wire-api ]; description = "Push Notification Hub"; license = lib.licenses.agpl3Only; From 4bdcd0fc391dcbddfecc4d6bccfa49c422a8d6e2 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Fri, 27 Sep 2024 18:03:00 +0200 Subject: [PATCH 12/32] Add gundeck internal routes to swagger docs. --- services/brig/src/Brig/API/Public.hs | 2 ++ services/brig/src/Brig/API/Public/Swagger.hs | 1 + 2 files changed, 3 insertions(+) diff --git a/services/brig/src/Brig/API/Public.hs b/services/brig/src/Brig/API/Public.hs index fc460854766..eee6481237c 100644 --- a/services/brig/src/Brig/API/Public.hs +++ b/services/brig/src/Brig/API/Public.hs @@ -113,6 +113,7 @@ import Wire.API.Routes.Internal.Brig qualified as BrigInternalAPI import Wire.API.Routes.Internal.Cannon qualified as CannonInternalAPI import Wire.API.Routes.Internal.Cargohold qualified as CargoholdInternalAPI import Wire.API.Routes.Internal.Galley qualified as GalleyInternalAPI +import Wire.API.Routes.Internal.Gundeck qualified as GundeckInternalAPI import Wire.API.Routes.Internal.Spar qualified as SparInternalAPI import Wire.API.Routes.MultiTablePaging qualified as Public import Wire.API.Routes.Named (Named (Named)) @@ -198,6 +199,7 @@ internalEndpointsSwaggerDocsAPIs = :<|> internalEndpointsSwaggerDocsAPI @"cargohold" "cargohold" 9094 CargoholdInternalAPI.swaggerDoc :<|> internalEndpointsSwaggerDocsAPI @"galley" "galley" 9095 GalleyInternalAPI.swaggerDoc :<|> internalEndpointsSwaggerDocsAPI @"spar" "spar" 9098 SparInternalAPI.swaggerDoc + :<|> internalEndpointsSwaggerDocsAPI @"gundeck" "gundeck" 9096 GundeckInternalAPI.swaggerDoc -- | Serves Swagger docs for public endpoints -- diff --git a/services/brig/src/Brig/API/Public/Swagger.hs b/services/brig/src/Brig/API/Public/Swagger.hs index 92304d5dfa0..ebe1287c905 100644 --- a/services/brig/src/Brig/API/Public/Swagger.hs +++ b/services/brig/src/Brig/API/Public/Swagger.hs @@ -54,6 +54,7 @@ type InternalEndpointsSwaggerDocsAPI = :<|> VersionedSwaggerDocsAPIBase "cargohold" :<|> VersionedSwaggerDocsAPIBase "galley" :<|> VersionedSwaggerDocsAPIBase "spar" + :<|> VersionedSwaggerDocsAPIBase "gundeck" ) type NotificationSchemasAPI = "api" :> "event-notification-schemas" :> Get '[JSON] [S.Definitions S.Schema] From 03a05f44e17e9dc2321febc8118f691f186fa991 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Mon, 30 Sep 2024 07:45:26 +0200 Subject: [PATCH 13/32] Add gundeck internal swagger to docs. --- docs/src/understand/api-client-perspective/swagger.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/src/understand/api-client-perspective/swagger.md b/docs/src/understand/api-client-perspective/swagger.md index b466fc7f8b8..773a89fe071 100644 --- a/docs/src/understand/api-client-perspective/swagger.md +++ b/docs/src/understand/api-client-perspective/swagger.md @@ -75,6 +75,8 @@ Internal APIs are not under version control. endpoints](https://staging-nginz-https.zinfra.io/api-internal/swagger-ui/cargohold) - [`galley` - **internal** (private) endpoints](https://staging-nginz-https.zinfra.io/api-internal/swagger-ui/galley) + - [`gundeck` - **internal** (private) + endpoints](https://staging-nginz-https.zinfra.io/api-internal/swagger-ui/gundeck) - [`spar` - **internal** (private) endpoints](https://staging-nginz-https.zinfra.io/api-internal/swagger-ui/spar) From 1101bfd3706ab82cdcaf3c7d46431f30b508ad76 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Mon, 30 Sep 2024 08:08:33 +0200 Subject: [PATCH 14/32] Add FUTUREWORKs. --- libs/wire-api/src/Wire/API/Presence.hs | 3 ++- libs/wire-api/src/Wire/API/Push/V2.hs | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/wire-api/src/Wire/API/Presence.hs b/libs/wire-api/src/Wire/API/Presence.hs index 54e16ef50ea..841cfcfa28c 100644 --- a/libs/wire-api/src/Wire/API/Presence.hs +++ b/libs/wire-api/src/Wire/API/Presence.hs @@ -18,7 +18,8 @@ import Imports import Network.URI qualified as Net import Servant.API (ToHttpApiData (toUrlPiece)) -newtype URI = URI -- maybe we should use Network.URI, and toss this newtype? servant should have all these instances for us these days. +-- FUTUREWORK: use Network.URI and toss this newtype. servant should have all these instances for us these days. +newtype URI = URI { fromURI :: Net.URI } deriving (Eq, Ord, Show) diff --git a/libs/wire-api/src/Wire/API/Push/V2.hs b/libs/wire-api/src/Wire/API/Push/V2.hs index 257664c9eb0..85907f99c82 100644 --- a/libs/wire-api/src/Wire/API/Push/V2.hs +++ b/libs/wire-api/src/Wire/API/Push/V2.hs @@ -95,6 +95,8 @@ instance ToSchema Route where ----------------------------------------------------------------------------- -- Recipient +-- FUTUREWORK: this is a duplicate of the type in "Wire.NotificationSubsystem" (even though +-- the latter lacks a few possibly deprecated fields). consolidate! data Recipient = Recipient { _recipientId :: !UserId, _recipientRoute :: !Route, @@ -214,6 +216,8 @@ makeLenses ''ApsData ----------------------------------------------------------------------------- -- Push +-- FUTUREWORK: this is a duplicate of the type in "Wire.NotificationSubsystem" (even though +-- the latter lacks a few possibly deprecated fields). consolidate! data Push = Push { -- | Recipients -- From a43a739c7b4c98171111621150bf7058d778adbc Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Mon, 30 Sep 2024 08:42:44 +0200 Subject: [PATCH 15/32] Add golden tests. --- .../golden/Test/Wire/API/Golden/Manual.hs | 30 +++++++ .../Test/Wire/API/Golden/Manual/ApsData.hs | 33 ++++++++ .../Test/Wire/API/Golden/Manual/CannonId.hs | 34 ++++++++ .../Test/Wire/API/Golden/Manual/Presence.hs | 47 +++++++++++ .../Test/Wire/API/Golden/Manual/Push.hs | 82 +++++++++++++++++++ .../Test/Wire/API/Golden/Manual/PushRemove.hs | 27 ++++++ .../test/golden/testObject_ApsData_1.json | 5 ++ .../test/golden/testObject_ApsData_2.json | 9 ++ .../test/golden/testObject_ApsData_3.json | 9 ++ .../test/golden/testObject_ApsData_4.json | 9 ++ .../test/golden/testObject_ApsData_5.json | 9 ++ .../test/golden/testObject_CannonId_1.json | 1 + .../test/golden/testObject_CannonId_2.json | 1 + .../test/golden/testObject_CannonId_3.json | 1 + .../test/golden/testObject_CannonId_4.json | 1 + .../test/golden/testObject_CannonId_5.json | 1 + .../test/golden/testObject_Presence_1.json | 6 ++ .../test/golden/testObject_Presence_2.json | 7 ++ .../test/golden/testObject_Presence_3.json | 7 ++ .../test/golden/testObject_Presence_4.json | 7 ++ .../test/golden/testObject_Presence_5.json | 7 ++ .../test/golden/testObject_PushRemove_1.json | 9 ++ .../test/golden/testObject_Push_1.json | 13 +++ .../test/golden/testObject_Push_2.json | 51 ++++++++++++ .../test/golden/testObject_Push_3.json | 51 ++++++++++++ .../test/golden/testObject_Push_4.json | 51 ++++++++++++ .../test/golden/testObject_Push_5.json | 51 ++++++++++++ libs/wire-api/wire-api.cabal | 5 ++ 28 files changed, 564 insertions(+) create mode 100644 libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs create mode 100644 libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/CannonId.hs create mode 100644 libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs create mode 100644 libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs create mode 100644 libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/PushRemove.hs create mode 100644 libs/wire-api/test/golden/testObject_ApsData_1.json create mode 100644 libs/wire-api/test/golden/testObject_ApsData_2.json create mode 100644 libs/wire-api/test/golden/testObject_ApsData_3.json create mode 100644 libs/wire-api/test/golden/testObject_ApsData_4.json create mode 100644 libs/wire-api/test/golden/testObject_ApsData_5.json create mode 100644 libs/wire-api/test/golden/testObject_CannonId_1.json create mode 100644 libs/wire-api/test/golden/testObject_CannonId_2.json create mode 100644 libs/wire-api/test/golden/testObject_CannonId_3.json create mode 100644 libs/wire-api/test/golden/testObject_CannonId_4.json create mode 100644 libs/wire-api/test/golden/testObject_CannonId_5.json create mode 100644 libs/wire-api/test/golden/testObject_Presence_1.json create mode 100644 libs/wire-api/test/golden/testObject_Presence_2.json create mode 100644 libs/wire-api/test/golden/testObject_Presence_3.json create mode 100644 libs/wire-api/test/golden/testObject_Presence_4.json create mode 100644 libs/wire-api/test/golden/testObject_Presence_5.json create mode 100644 libs/wire-api/test/golden/testObject_PushRemove_1.json create mode 100644 libs/wire-api/test/golden/testObject_Push_1.json create mode 100644 libs/wire-api/test/golden/testObject_Push_2.json create mode 100644 libs/wire-api/test/golden/testObject_Push_3.json create mode 100644 libs/wire-api/test/golden/testObject_Push_4.json create mode 100644 libs/wire-api/test/golden/testObject_Push_5.json diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual.hs index 2d5c43f18fb..23a815c705b 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual.hs @@ -20,6 +20,8 @@ module Test.Wire.API.Golden.Manual where import Imports import Test.Tasty import Test.Wire.API.Golden.Manual.Activate_user +import Test.Wire.API.Golden.Manual.ApsData +import Test.Wire.API.Golden.Manual.CannonId import Test.Wire.API.Golden.Manual.ClientCapability import Test.Wire.API.Golden.Manual.ClientCapabilityList import Test.Wire.API.Golden.Manual.Contact @@ -42,6 +44,9 @@ import Test.Wire.API.Golden.Manual.ListUsersById import Test.Wire.API.Golden.Manual.LoginId_user import Test.Wire.API.Golden.Manual.Login_user import Test.Wire.API.Golden.Manual.MLSKeys +import Test.Wire.API.Golden.Manual.Presence +import Test.Wire.API.Golden.Manual.Push +import Test.Wire.API.Golden.Manual.PushRemove import Test.Wire.API.Golden.Manual.QualifiedUserClientPrekeyMap import Test.Wire.API.Golden.Manual.SearchResultContact import Test.Wire.API.Golden.Manual.SendActivationCode_user @@ -276,6 +281,31 @@ tests = (testObject_Login_user_4, "testObject_Login_user_4.json"), (testObject_Login_user_5, "testObject_Login_user_5.json") ], + testGroup "ApsData" $ + testObjects + [ (testObject_ApsData_1, "testObject_ApsData_1.json"), + (testObject_ApsData_2, "testObject_ApsData_2.json") + ], + testGroup "CannonId" $ + testObjects + [ (testObject_CannonId_1, "testObject_CannonId_1.json"), + (testObject_CannonId_2, "testObject_CannonId_2.json"), + (testObject_CannonId_3, "testObject_CannonId_3.json") + ], + testGroup "Presence" $ + testObjects + [ (testObject_Presence_1, "testObject_Presence_1.json"), + (testObject_Presence_2, "testObject_Presence_2.json") + ], + testGroup "Push" $ + testObjects + [ (testObject_Push_1, "testObject_Push_1.json"), + (testObject_Push_2, "testObject_Push_2.json") + ], + testGroup "PushRemove" $ + testObjects + [ (testObject_PushRemove_1, "testObject_PushRemove_1.json") + ], testGroup "Activate" $ testObjects [ (testObject_Activate_user_1, "testObject_Activate_user_1.json"), diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs new file mode 100644 index 00000000000..910e3099b1d --- /dev/null +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs @@ -0,0 +1,33 @@ +-- This file is part of the Wire Server implementation. +-- +-- Copyright (C) 2022 Wire Swiss GmbH +-- +-- 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 . + +module Test.Wire.API.Golden.Manual.ApsData + ( testObject_ApsData_1, + testObject_ApsData_2, + ) +where + +import Imports +import Wire.API.Push.V2 + +testObject_ApsData_1 :: ApsData +testObject_ApsData_1 = + apsData (ApsLocKey mempty) mempty + +testObject_ApsData_2 :: ApsData +testObject_ApsData_2 = + apsData (ApsLocKey "asdf") ["1", "22", "333"] diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/CannonId.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/CannonId.hs new file mode 100644 index 00000000000..9f9de73dbab --- /dev/null +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/CannonId.hs @@ -0,0 +1,34 @@ +-- This file is part of the Wire Server implementation. +-- +-- Copyright (C) 2022 Wire Swiss GmbH +-- +-- 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 . + +module Test.Wire.API.Golden.Manual.CannonId + ( testObject_CannonId_1, + testObject_CannonId_2, + testObject_CannonId_3, + ) +where + +import Wire.API.CannonId + +testObject_CannonId_1 :: CannonId +testObject_CannonId_1 = CannonId "" + +testObject_CannonId_2 :: CannonId +testObject_CannonId_2 = CannonId "sdfiou" + +testObject_CannonId_3 :: CannonId +testObject_CannonId_3 = CannonId "1!_*`'\"" diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs new file mode 100644 index 00000000000..78a022b165b --- /dev/null +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs @@ -0,0 +1,47 @@ +-- This file is part of the Wire Server implementation. +-- +-- Copyright (C) 2022 Wire Swiss GmbH +-- +-- 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 . + +module Test.Wire.API.Golden.Manual.Presence + ( testObject_Presence_1, + testObject_Presence_2, + ) +where + +import Data.Id +import Data.UUID qualified as UUID +import Imports +import Wire.API.Presence + +testObject_Presence_1 :: Presence +testObject_Presence_1 = + Presence + (Id . fromJust $ UUID.fromString "174ccaea-7f26-11ef-86cc-27bb6bf3b319") + (ConnId "wef") + (fromJust $ parse "http://example.com/") + Nothing + 0 + "" + +testObject_Presence_2 :: Presence +testObject_Presence_2 = + Presence + (Id . fromJust $ UUID.fromString "174ccaea-7f26-11ef-86cc-37bb6bf3b319") + (ConnId "wef3") + (fromJust $ parse "http://example.com/3") + (Just (ClientId 1)) + 12323 + "" -- __field always has to be "", see ToSchema instance. diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs new file mode 100644 index 00000000000..fb91cd9cfc6 --- /dev/null +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs @@ -0,0 +1,82 @@ +-- This file is part of the Wire Server implementation. +-- +-- Copyright (C) 2022 Wire Swiss GmbH +-- +-- 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 . + +module Test.Wire.API.Golden.Manual.Push + ( testObject_Push_1, + testObject_Push_2, + ) +where + +import Data.Aeson qualified as A +import Data.Aeson.KeyMap qualified as KM +import Data.Id +import Data.List1 +import Data.Range +import Data.Set qualified as Set +import Data.UUID qualified as UUID +import Imports +import Wire.API.Push.V2 + +rcp1, rcp2, rcp3 :: Recipient +rcp1 = + Recipient + (Id . fromJust $ UUID.fromString "15441ff8-7f14-11ef-aeec-bbe21dc8a204") + RouteAny + RecipientClientsAll +rcp2 = + Recipient + (Id . fromJust $ UUID.fromString "2e18540e-7f14-11ef-9886-d3c2ff21d3d1") + RouteDirect + (RecipientClientsSome (list1 (ClientId 0) [])) +rcp3 = + Recipient + (Id . fromJust $ UUID.fromString "316924ee-7f14-11ef-b6a2-036a4f646914") + RouteDirect + (RecipientClientsSome (list1 (ClientId 234) [ClientId 123])) + +testObject_Push_1 :: Push +testObject_Push_1 = + Push + { _pushRecipients = unsafeRange (Set.fromList [rcp1]), + _pushOrigin = Nothing, + _pushConnections = mempty, + _pushOriginConnection = Nothing, + _pushTransient = False, + _pushNativeIncludeOrigin = False, + _pushNativeEncrypt = True, + _pushNativeAps = Nothing, + _pushNativePriority = HighPriority, + _pushPayload = singleton mempty + } + +testObject_Push_2 :: Push +testObject_Push_2 = + Push + { _pushRecipients = unsafeRange (Set.fromList [rcp2, rcp3]), + _pushOrigin = Just (Id . fromJust $ UUID.fromString "dec9b47a-7f12-11ef-b634-6710e7ae3d33"), + _pushConnections = Set.fromList [ConnId "sdf", ConnId "mempty", ConnId "wire-client"], + _pushOriginConnection = Just (ConnId "123"), + _pushTransient = True, + _pushNativeIncludeOrigin = True, + _pushNativeEncrypt = False, + _pushNativeAps = Just (apsData (ApsLocKey "asdf") ["1", "22", "333"]), + _pushNativePriority = LowPriority, + _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)]] + } diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/PushRemove.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/PushRemove.hs new file mode 100644 index 00000000000..bf4a823e47d --- /dev/null +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/PushRemove.hs @@ -0,0 +1,27 @@ +-- This file is part of the Wire Server implementation. +-- +-- Copyright (C) 2022 Wire Swiss GmbH +-- +-- 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 . + +module Test.Wire.API.Golden.Manual.PushRemove + ( testObject_PushRemove_1, + ) +where + +import Test.Wire.API.Golden.Manual.Token (testObject_Token_1) +import Wire.API.Event.Gundeck + +testObject_PushRemove_1 :: PushRemove +testObject_PushRemove_1 = PushRemove testObject_Token_1 diff --git a/libs/wire-api/test/golden/testObject_ApsData_1.json b/libs/wire-api/test/golden/testObject_ApsData_1.json new file mode 100644 index 00000000000..f367522277f --- /dev/null +++ b/libs/wire-api/test/golden/testObject_ApsData_1.json @@ -0,0 +1,5 @@ +{ + "badge": true, + "loc_args": [], + "loc_key": "" +} diff --git a/libs/wire-api/test/golden/testObject_ApsData_2.json b/libs/wire-api/test/golden/testObject_ApsData_2.json new file mode 100644 index 00000000000..67ccf502971 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_ApsData_2.json @@ -0,0 +1,9 @@ +{ + "badge": true, + "loc_args": [ + "1", + "22", + "333" + ], + "loc_key": "asdf" +} diff --git a/libs/wire-api/test/golden/testObject_ApsData_3.json b/libs/wire-api/test/golden/testObject_ApsData_3.json new file mode 100644 index 00000000000..67ccf502971 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_ApsData_3.json @@ -0,0 +1,9 @@ +{ + "badge": true, + "loc_args": [ + "1", + "22", + "333" + ], + "loc_key": "asdf" +} diff --git a/libs/wire-api/test/golden/testObject_ApsData_4.json b/libs/wire-api/test/golden/testObject_ApsData_4.json new file mode 100644 index 00000000000..67ccf502971 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_ApsData_4.json @@ -0,0 +1,9 @@ +{ + "badge": true, + "loc_args": [ + "1", + "22", + "333" + ], + "loc_key": "asdf" +} diff --git a/libs/wire-api/test/golden/testObject_ApsData_5.json b/libs/wire-api/test/golden/testObject_ApsData_5.json new file mode 100644 index 00000000000..67ccf502971 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_ApsData_5.json @@ -0,0 +1,9 @@ +{ + "badge": true, + "loc_args": [ + "1", + "22", + "333" + ], + "loc_key": "asdf" +} diff --git a/libs/wire-api/test/golden/testObject_CannonId_1.json b/libs/wire-api/test/golden/testObject_CannonId_1.json new file mode 100644 index 00000000000..e16c76dff88 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_CannonId_1.json @@ -0,0 +1 @@ +"" diff --git a/libs/wire-api/test/golden/testObject_CannonId_2.json b/libs/wire-api/test/golden/testObject_CannonId_2.json new file mode 100644 index 00000000000..5149c12b38f --- /dev/null +++ b/libs/wire-api/test/golden/testObject_CannonId_2.json @@ -0,0 +1 @@ +"sdfiou" diff --git a/libs/wire-api/test/golden/testObject_CannonId_3.json b/libs/wire-api/test/golden/testObject_CannonId_3.json new file mode 100644 index 00000000000..56bcab3744e --- /dev/null +++ b/libs/wire-api/test/golden/testObject_CannonId_3.json @@ -0,0 +1 @@ +"1!_*`'\"" diff --git a/libs/wire-api/test/golden/testObject_CannonId_4.json b/libs/wire-api/test/golden/testObject_CannonId_4.json new file mode 100644 index 00000000000..5149c12b38f --- /dev/null +++ b/libs/wire-api/test/golden/testObject_CannonId_4.json @@ -0,0 +1 @@ +"sdfiou" diff --git a/libs/wire-api/test/golden/testObject_CannonId_5.json b/libs/wire-api/test/golden/testObject_CannonId_5.json new file mode 100644 index 00000000000..5149c12b38f --- /dev/null +++ b/libs/wire-api/test/golden/testObject_CannonId_5.json @@ -0,0 +1 @@ +"sdfiou" diff --git a/libs/wire-api/test/golden/testObject_Presence_1.json b/libs/wire-api/test/golden/testObject_Presence_1.json new file mode 100644 index 00000000000..f55001d521b --- /dev/null +++ b/libs/wire-api/test/golden/testObject_Presence_1.json @@ -0,0 +1,6 @@ +{ + "created_at": 0, + "device_id": "wef", + "resource": "http://example.com/", + "user_id": "174ccaea-7f26-11ef-86cc-27bb6bf3b319" +} diff --git a/libs/wire-api/test/golden/testObject_Presence_2.json b/libs/wire-api/test/golden/testObject_Presence_2.json new file mode 100644 index 00000000000..be0b1e54ebb --- /dev/null +++ b/libs/wire-api/test/golden/testObject_Presence_2.json @@ -0,0 +1,7 @@ +{ + "client_id": "1", + "created_at": 12323, + "device_id": "wef3", + "resource": "http://example.com/3", + "user_id": "174ccaea-7f26-11ef-86cc-37bb6bf3b319" +} diff --git a/libs/wire-api/test/golden/testObject_Presence_3.json b/libs/wire-api/test/golden/testObject_Presence_3.json new file mode 100644 index 00000000000..cda26a2fd27 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_Presence_3.json @@ -0,0 +1,7 @@ +{ + "client_id": "1", + "created_at": 12323, + "device_id": "wef3", + "resource": "URI {fromURI = http://example.com/3}", + "user_id": "174ccaea-7f26-11ef-86cc-37bb6bf3b319" +} diff --git a/libs/wire-api/test/golden/testObject_Presence_4.json b/libs/wire-api/test/golden/testObject_Presence_4.json new file mode 100644 index 00000000000..cda26a2fd27 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_Presence_4.json @@ -0,0 +1,7 @@ +{ + "client_id": "1", + "created_at": 12323, + "device_id": "wef3", + "resource": "URI {fromURI = http://example.com/3}", + "user_id": "174ccaea-7f26-11ef-86cc-37bb6bf3b319" +} diff --git a/libs/wire-api/test/golden/testObject_Presence_5.json b/libs/wire-api/test/golden/testObject_Presence_5.json new file mode 100644 index 00000000000..cda26a2fd27 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_Presence_5.json @@ -0,0 +1,7 @@ +{ + "client_id": "1", + "created_at": 12323, + "device_id": "wef3", + "resource": "URI {fromURI = http://example.com/3}", + "user_id": "174ccaea-7f26-11ef-86cc-37bb6bf3b319" +} diff --git a/libs/wire-api/test/golden/testObject_PushRemove_1.json b/libs/wire-api/test/golden/testObject_PushRemove_1.json new file mode 100644 index 00000000000..6fdce76e9d4 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_PushRemove_1.json @@ -0,0 +1,9 @@ +{ + "token": { + "app": "j{𛂚\u0001_􈷉M", + "client": "6", + "token": "K", + "transport": "APNS_VOIP_SANDBOX" + }, + "type": "user.push-remove" +} diff --git a/libs/wire-api/test/golden/testObject_Push_1.json b/libs/wire-api/test/golden/testObject_Push_1.json new file mode 100644 index 00000000000..9680be52df8 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_Push_1.json @@ -0,0 +1,13 @@ +{ + "native_include_origin": false, + "payload": [ + {} + ], + "recipients": [ + { + "clients": [], + "route": "any", + "user_id": "15441ff8-7f14-11ef-aeec-bbe21dc8a204" + } + ] +} diff --git a/libs/wire-api/test/golden/testObject_Push_2.json b/libs/wire-api/test/golden/testObject_Push_2.json new file mode 100644 index 00000000000..39e924962e7 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_Push_2.json @@ -0,0 +1,51 @@ +{ + "connections": [ + "mempty", + "sdf", + "wire-client" + ], + "native_aps": { + "badge": true, + "loc_args": [ + "1", + "22", + "333" + ], + "loc_key": "asdf" + }, + "native_encrypt": false, + "native_priority": "low", + "origin": "dec9b47a-7f12-11ef-b634-6710e7ae3d33", + "origin_connection": "123", + "payload": [ + { + "bar": true, + "foo": "3" + }, + {}, + { + "growl": "foooood" + }, + { + "lunchtime": "imminent" + } + ], + "recipients": [ + { + "clients": [ + "0" + ], + "route": "direct", + "user_id": "2e18540e-7f14-11ef-9886-d3c2ff21d3d1" + }, + { + "clients": [ + "ea", + "7b" + ], + "route": "direct", + "user_id": "316924ee-7f14-11ef-b6a2-036a4f646914" + } + ], + "transient": true +} diff --git a/libs/wire-api/test/golden/testObject_Push_3.json b/libs/wire-api/test/golden/testObject_Push_3.json new file mode 100644 index 00000000000..39e924962e7 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_Push_3.json @@ -0,0 +1,51 @@ +{ + "connections": [ + "mempty", + "sdf", + "wire-client" + ], + "native_aps": { + "badge": true, + "loc_args": [ + "1", + "22", + "333" + ], + "loc_key": "asdf" + }, + "native_encrypt": false, + "native_priority": "low", + "origin": "dec9b47a-7f12-11ef-b634-6710e7ae3d33", + "origin_connection": "123", + "payload": [ + { + "bar": true, + "foo": "3" + }, + {}, + { + "growl": "foooood" + }, + { + "lunchtime": "imminent" + } + ], + "recipients": [ + { + "clients": [ + "0" + ], + "route": "direct", + "user_id": "2e18540e-7f14-11ef-9886-d3c2ff21d3d1" + }, + { + "clients": [ + "ea", + "7b" + ], + "route": "direct", + "user_id": "316924ee-7f14-11ef-b6a2-036a4f646914" + } + ], + "transient": true +} diff --git a/libs/wire-api/test/golden/testObject_Push_4.json b/libs/wire-api/test/golden/testObject_Push_4.json new file mode 100644 index 00000000000..39e924962e7 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_Push_4.json @@ -0,0 +1,51 @@ +{ + "connections": [ + "mempty", + "sdf", + "wire-client" + ], + "native_aps": { + "badge": true, + "loc_args": [ + "1", + "22", + "333" + ], + "loc_key": "asdf" + }, + "native_encrypt": false, + "native_priority": "low", + "origin": "dec9b47a-7f12-11ef-b634-6710e7ae3d33", + "origin_connection": "123", + "payload": [ + { + "bar": true, + "foo": "3" + }, + {}, + { + "growl": "foooood" + }, + { + "lunchtime": "imminent" + } + ], + "recipients": [ + { + "clients": [ + "0" + ], + "route": "direct", + "user_id": "2e18540e-7f14-11ef-9886-d3c2ff21d3d1" + }, + { + "clients": [ + "ea", + "7b" + ], + "route": "direct", + "user_id": "316924ee-7f14-11ef-b6a2-036a4f646914" + } + ], + "transient": true +} diff --git a/libs/wire-api/test/golden/testObject_Push_5.json b/libs/wire-api/test/golden/testObject_Push_5.json new file mode 100644 index 00000000000..39e924962e7 --- /dev/null +++ b/libs/wire-api/test/golden/testObject_Push_5.json @@ -0,0 +1,51 @@ +{ + "connections": [ + "mempty", + "sdf", + "wire-client" + ], + "native_aps": { + "badge": true, + "loc_args": [ + "1", + "22", + "333" + ], + "loc_key": "asdf" + }, + "native_encrypt": false, + "native_priority": "low", + "origin": "dec9b47a-7f12-11ef-b634-6710e7ae3d33", + "origin_connection": "123", + "payload": [ + { + "bar": true, + "foo": "3" + }, + {}, + { + "growl": "foooood" + }, + { + "lunchtime": "imminent" + } + ], + "recipients": [ + { + "clients": [ + "0" + ], + "route": "direct", + "user_id": "2e18540e-7f14-11ef-9886-d3c2ff21d3d1" + }, + { + "clients": [ + "ea", + "7b" + ], + "route": "direct", + "user_id": "316924ee-7f14-11ef-b6a2-036a4f646914" + } + ], + "transient": true +} diff --git a/libs/wire-api/wire-api.cabal b/libs/wire-api/wire-api.cabal index d484454f8ec..bf5fbe50f49 100644 --- a/libs/wire-api/wire-api.cabal +++ b/libs/wire-api/wire-api.cabal @@ -371,6 +371,11 @@ test-suite wire-api-golden-tests Test.Wire.API.Golden.Generated.ActivationResponse_user Test.Wire.API.Golden.Generated.AddBot_user Test.Wire.API.Golden.Generated.AddBotResponse_user + Test.Wire.API.Golden.Manual.ApsData + Test.Wire.API.Golden.Manual.CannonId + Test.Wire.API.Golden.Manual.Presence + Test.Wire.API.Golden.Manual.Push + Test.Wire.API.Golden.Manual.PushRemove Test.Wire.API.Golden.Generated.AppName_user Test.Wire.API.Golden.Generated.ApproveLegalHoldForUserRequest_team Test.Wire.API.Golden.Generated.Asset_asset From d59106e4cf6abe7cf6d8a7384c6347a1af816da1 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Mon, 30 Sep 2024 14:47:12 +0200 Subject: [PATCH 16/32] Fix toJSON helper for Presence. --- libs/wire-api/src/Wire/API/Presence.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/wire-api/src/Wire/API/Presence.hs b/libs/wire-api/src/Wire/API/Presence.hs index 841cfcfa28c..3f250d9eadf 100644 --- a/libs/wire-api/src/Wire/API/Presence.hs +++ b/libs/wire-api/src/Wire/API/Presence.hs @@ -95,4 +95,4 @@ uriFromJSON = A.withText "URI" (p . Text.unpack) p = maybe (fail "Invalid URI") pure . parse uriToJSON :: URI -> A.Value -uriToJSON uri = A.String $ Text.pack (show uri) +uriToJSON (URI uri) = A.String . Text.pack $ Net.uriToString id uri mempty From 59ffbc501e9240082ba4f3a9f0c71f7b4d279845 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Mon, 30 Sep 2024 14:54:17 +0200 Subject: [PATCH 17/32] Fix brig swagger handler. --- services/brig/src/Brig/API/Public.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/brig/src/Brig/API/Public.hs b/services/brig/src/Brig/API/Public.hs index eee6481237c..8d3e52b4c0a 100644 --- a/services/brig/src/Brig/API/Public.hs +++ b/services/brig/src/Brig/API/Public.hs @@ -195,11 +195,11 @@ federatedEndpointsSwaggerDocsAPIs = internalEndpointsSwaggerDocsAPIs :: Servant.Server InternalEndpointsSwaggerDocsAPI internalEndpointsSwaggerDocsAPIs = internalEndpointsSwaggerDocsAPI @"brig" "brig" 9082 BrigInternalAPI.swaggerDoc - :<|> internalEndpointsSwaggerDocsAPI @"cannon" "cannon" 9093 CannonInternalAPI.swaggerDoc - :<|> internalEndpointsSwaggerDocsAPI @"cargohold" "cargohold" 9094 CargoholdInternalAPI.swaggerDoc - :<|> internalEndpointsSwaggerDocsAPI @"galley" "galley" 9095 GalleyInternalAPI.swaggerDoc - :<|> internalEndpointsSwaggerDocsAPI @"spar" "spar" 9098 SparInternalAPI.swaggerDoc - :<|> internalEndpointsSwaggerDocsAPI @"gundeck" "gundeck" 9096 GundeckInternalAPI.swaggerDoc + :<|> internalEndpointsSwaggerDocsAPI @"cannon" "cannon" 9083 CannonInternalAPI.swaggerDoc + :<|> internalEndpointsSwaggerDocsAPI @"cargohold" "cargohold" 9084 CargoholdInternalAPI.swaggerDoc + :<|> internalEndpointsSwaggerDocsAPI @"galley" "galley" 9085 GalleyInternalAPI.swaggerDoc + :<|> internalEndpointsSwaggerDocsAPI @"spar" "spar" 9088 SparInternalAPI.swaggerDoc + :<|> internalEndpointsSwaggerDocsAPI @"gundeck" "gundeck" 9086 GundeckInternalAPI.swaggerDoc -- | Serves Swagger docs for public endpoints -- From 9d3649e3815371df4fc153c0cf24deb198a67071 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Mon, 30 Sep 2024 14:55:18 +0200 Subject: [PATCH 18/32] Changelog. --- changelog.d/5-internal/gundeck-internal-swagger | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5-internal/gundeck-internal-swagger diff --git a/changelog.d/5-internal/gundeck-internal-swagger b/changelog.d/5-internal/gundeck-internal-swagger new file mode 100644 index 00000000000..da4ac4f9e1f --- /dev/null +++ b/changelog.d/5-internal/gundeck-internal-swagger @@ -0,0 +1 @@ +Expose gundeck internal API on swagger. Mv some types and routes to wire-api. \ No newline at end of file From 5c76642a0214b71337c37ed7d916227a19ab8633 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Mon, 30 Sep 2024 16:04:03 +0200 Subject: [PATCH 19/32] Make wire-api/test/golden run on develop. Some golden tests were missing at a time when we changed serialization from aeson to schema-profunctor. In order to make sure this didn't break anything, you can take the changes in this commit, copy them into a working-copy based on develop (ideally right this PR), and run golden tests there. The only changes are Nothing-fields that schema-profunctor translates to `"k": null`, whereas aeson (or "Data.Json.Util"?) omits the field altogether. --- .../Test/Wire/API/Golden/Manual/ApsData.hs | 41 +++- .../Test/Wire/API/Golden/Manual/CannonId.hs | 6 +- .../Test/Wire/API/Golden/Manual/Presence.hs | 72 ++++++- .../Test/Wire/API/Golden/Manual/Push.hs | 197 +++++++++++++++++- .../Test/Wire/API/Golden/Manual/PushRemove.hs | 23 +- libs/wire-api/wire-api.cabal | 22 +- 6 files changed, 344 insertions(+), 17 deletions(-) diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs index 910e3099b1d..f365bf68ade 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs @@ -21,8 +21,47 @@ module Test.Wire.API.Golden.Manual.ApsData ) where +import Data.Aeson +import Data.Json.Util import Imports -import Wire.API.Push.V2 + +newtype ApsSound = ApsSound {fromSound :: Text} + deriving (Eq, Show, ToJSON, FromJSON) + +newtype ApsLocKey = ApsLocKey {fromLocKey :: Text} + deriving (Eq, Show, ToJSON, FromJSON) + +data ApsData = ApsData + { _apsLocKey :: !ApsLocKey, + _apsLocArgs :: [Text], + _apsSound :: !(Maybe ApsSound), + _apsBadge :: !Bool + } + deriving (Eq, Show) + +instance ToJSON ApsData where + toJSON (ApsData k a s b) = + object $ + "loc_key" + .= k + # "loc_args" + .= a + # "sound" + .= s + # "badge" + .= b + # [] + +instance FromJSON ApsData where + parseJSON = withObject "ApsData" $ \o -> + ApsData + <$> o .: "loc_key" + <*> o .:? "loc_args" .!= [] + <*> o .:? "sound" + <*> o .:? "badge" .!= True + +apsData :: ApsLocKey -> [Text] -> ApsData +apsData lk la = ApsData lk la Nothing True testObject_ApsData_1 :: ApsData testObject_ApsData_1 = diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/CannonId.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/CannonId.hs index 9f9de73dbab..a6923cc8cbb 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/CannonId.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/CannonId.hs @@ -22,7 +22,11 @@ module Test.Wire.API.Golden.Manual.CannonId ) where -import Wire.API.CannonId +import Data.Aeson +import Imports + +newtype CannonId = CannonId {cannonId :: Text} + deriving (Eq, Show, FromJSON, ToJSON) testObject_CannonId_1 :: CannonId testObject_CannonId_1 = CannonId "" diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs index 78a022b165b..fea637b1a1b 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs @@ -21,10 +21,80 @@ module Test.Wire.API.Golden.Manual.Presence ) where +import Data.Aeson +import Data.Attoparsec.ByteString (takeByteString) +import Data.ByteString.Char8 qualified as Bytes +import Data.ByteString.Conversion +import Data.ByteString.Lazy as Lazy import Data.Id +import Data.Misc +import Data.Text as Text +import Data.Text.Encoding (decodeUtf8) import Data.UUID qualified as UUID import Imports -import Wire.API.Presence +import Network.URI qualified as Net +import Servant.API qualified as Servant + +newtype URI = URI + { fromURI :: Net.URI + } + deriving (Eq, Ord, Show) + +instance FromJSON URI where + parseJSON = withText "URI" (parse . Text.unpack) + +instance ToJSON URI where + toJSON uri = String $ Text.pack (show (fromURI uri)) + +instance ToByteString URI where + builder = builder . show . fromURI + +instance FromByteString URI where + parser = takeByteString >>= parse . Bytes.unpack + +instance Servant.ToHttpApiData URI where + toUrlPiece = decodeUtf8 . toByteString' + +parse :: (MonadFail m) => String -> m URI +parse = maybe (fail "Invalid URI") (pure . URI) . Net.parseURI + +-- | This is created in gundeck by cannon every time the client opens a new websocket connection. +-- (That's why we always have a 'ConnId' from the most recent connection by that client.) +data Presence = Presence + { userId :: !UserId, + connId :: !ConnId, + -- | cannon instance hosting the presence + resource :: !URI, + -- | This is 'Nothing' if either (a) the presence is older + -- than mandatory end-to-end encryption, or (b) the client is + -- operating the team settings pages without the need for + -- end-to-end crypto. + clientId :: !(Maybe ClientId), + createdAt :: !Milliseconds, + -- | REFACTOR: temp. addition to ease migration + __field :: !Lazy.ByteString + } + deriving (Eq, Ord, Show) + +instance ToJSON Presence where + toJSON p = + object + [ "user_id" .= userId p, + "device_id" .= connId p, + "resource" .= resource p, + "client_id" .= clientId p, + "created_at" .= createdAt p + ] + +instance FromJSON Presence where + parseJSON = withObject "Presence" $ \o -> + Presence + <$> o .: "user_id" + <*> o .: "device_id" + <*> o .: "resource" + <*> o .:? "client_id" + <*> o .:? "created_at" .!= 0 + <*> pure "" testObject_Presence_1 :: Presence testObject_Presence_1 = diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs index fb91cd9cfc6..dcac359bbd6 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs @@ -21,15 +21,208 @@ module Test.Wire.API.Golden.Manual.Push ) where -import Data.Aeson qualified as A +import Data.Aeson as A import Data.Aeson.KeyMap qualified as KM import Data.Id +import Data.Json.Util ((#)) import Data.List1 +import Data.OpenApi qualified as S import Data.Range +import Data.Schema qualified as SPF import Data.Set qualified as Set import Data.UUID qualified as UUID import Imports -import Wire.API.Push.V2 + +newtype ApsSound = ApsSound {fromSound :: Text} + deriving (Eq, Show, A.ToJSON, A.FromJSON) + +newtype ApsLocKey = ApsLocKey {fromLocKey :: Text} + deriving (Eq, Show, A.ToJSON, A.FromJSON) + +data ApsData = ApsData + { _apsLocKey :: !ApsLocKey, + _apsLocArgs :: [Text], + _apsSound :: !(Maybe ApsSound), + _apsBadge :: !Bool + } + deriving (Eq, Show, Generic) + +apsData :: ApsLocKey -> [Text] -> ApsData +apsData lk la = ApsData lk la Nothing True + +instance A.ToJSON ApsData where + toJSON (ApsData k a s b) = + A.object $ + [ "loc_key" A..= k, + "loc_args" A..= a, + "sound" A..= s, + "badge" A..= b + ] + +instance A.FromJSON ApsData where + parseJSON = A.withObject "ApsData" $ \o -> + ApsData + <$> o A..: "loc_key" + <*> o A..:? "loc_args" A..!= [] + <*> o A..:? "sound" + <*> o A..:? "badge" A..!= True + +data Priority = LowPriority | HighPriority + deriving stock (Eq, Show, Ord, Enum, Generic) + deriving (A.ToJSON, A.FromJSON, S.ToSchema) via SPF.Schema Priority + +instance SPF.ToSchema Priority where + schema = + SPF.enum @Text "Priority" $ + mconcat + [ SPF.element "low" LowPriority, + SPF.element "high" HighPriority + ] + +data Route = RouteAny | RouteDirect + deriving (Eq, Ord, Enum, Bounded, Show, Generic) + +instance A.FromJSON Route where + parseJSON (A.String "any") = pure RouteAny + parseJSON (A.String "direct") = pure RouteDirect + parseJSON x = fail $ "Invalid routing: " ++ show (A.encode x) + +instance A.ToJSON Route where + toJSON RouteAny = A.String "any" + toJSON RouteDirect = A.String "direct" + +data Recipient = Recipient + { _recipientId :: !UserId, + _recipientRoute :: !Route, + _recipientClients :: !RecipientClients + } + deriving (Show, Eq, Ord, Generic) + +data RecipientClients + = -- | All clients of some user + RecipientClientsAll + | -- | An explicit list of clients + RecipientClientsSome (List1 ClientId) + deriving (Eq, Show, Ord, Generic) + +instance Semigroup RecipientClients where + RecipientClientsAll <> _ = RecipientClientsAll + _ <> RecipientClientsAll = RecipientClientsAll + RecipientClientsSome cs1 <> RecipientClientsSome cs2 = + RecipientClientsSome (cs1 <> cs2) + +instance A.FromJSON Recipient where + parseJSON = A.withObject "Recipient" $ \p -> + Recipient + <$> p A..: "user_id" + <*> p A..: "route" + <*> p A..:? "clients" A..!= RecipientClientsAll + +instance A.ToJSON Recipient where + toJSON (Recipient u r c) = + A.object $ + "user_id" + A..= u + # "route" + A..= r + # "clients" + A..= c + # [] + +-- "All clients" is encoded in the API as an empty list. +instance A.FromJSON RecipientClients where + parseJSON x = + A.parseJSON @[ClientId] x >>= \case + [] -> pure RecipientClientsAll + c : cs -> pure (RecipientClientsSome (list1 c cs)) + +instance A.ToJSON RecipientClients where + toJSON = + A.toJSON . \case + RecipientClientsAll -> [] + RecipientClientsSome cs -> toList cs + +data Push = Push + { -- | Recipients + -- + -- REFACTOR: '_pushRecipients' should be @Set (Recipient, Maybe (NonEmptySet ConnId))@, and + -- '_pushConnections' should go away. Rationale: the current setup only works under the + -- 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), + -- | Originating user + -- + -- 'Nothing' here means that the originating user is on another backend. + -- + -- REFACTOR: where is this required, and for what? or can it be removed? (see also: #531) + _pushOrigin :: !(Maybe UserId), + -- | Destination connections. If empty, ignore. Otherwise, filter the connections derived + -- from '_pushRecipients' and only push to those contained in this set. + -- + -- REFACTOR: change this to @_pushConnectionWhitelist :: Maybe (Set ConnId)@. + _pushConnections :: !(Set ConnId), + -- | Originating connection, if any. + _pushOriginConnection :: !(Maybe ConnId), + -- | Transient payloads are not forwarded to the notification stream. + _pushTransient :: !Bool, + -- | Whether to send native notifications to other clients + -- of the originating user, if he is among the recipients. + _pushNativeIncludeOrigin :: !Bool, + -- | Should native push payloads be encrypted? + -- + -- REFACTOR: this make no sense any more since native push notifications have no more payload. + -- https://github.com/wireapp/wire-server/pull/546 + _pushNativeEncrypt :: !Bool, + -- | APNs-specific metadata (needed eg. in "Brig.IO.Intra.toApsData"). + _pushNativeAps :: !(Maybe ApsData), + -- | Native push priority. + _pushNativePriority :: !Priority, + -- | Opaque payload + _pushPayload :: !(List1 A.Object) + } + deriving (Eq, Show) + +instance FromJSON Push where + parseJSON = withObject "Push" $ \p -> + Push + <$> p .: "recipients" + <*> p .:? "origin" + <*> p .:? "connections" .!= Set.empty + <*> p .:? "origin_connection" + <*> p .:? "transient" .!= False + <*> p .:? "native_include_origin" .!= True + <*> p .:? "native_encrypt" .!= True + <*> p .:? "native_aps" + <*> p .:? "native_priority" .!= HighPriority + <*> p .: "payload" + +instance ToJSON Push where + toJSON p = + object $ + "recipients" + .= _pushRecipients p + # "origin" + .= _pushOrigin p + # "connections" + .= ifNot Set.null (_pushConnections p) + # "origin_connection" + .= _pushOriginConnection p + # "transient" + .= ifNot not (_pushTransient p) + # "native_include_origin" + .= ifNot id (_pushNativeIncludeOrigin p) + # "native_encrypt" + .= ifNot id (_pushNativeEncrypt p) + # "native_aps" + .= _pushNativeAps p + # "native_priority" + .= ifNot (== HighPriority) (_pushNativePriority p) + # "payload" + .= _pushPayload p + # [] + where + ifNot f a = if f a then Nothing else Just a rcp1, rcp2, rcp3 :: Recipient rcp1 = diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/PushRemove.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/PushRemove.hs index bf4a823e47d..4bf7d9192e4 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/PushRemove.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/PushRemove.hs @@ -20,8 +20,29 @@ module Test.Wire.API.Golden.Manual.PushRemove ) where +import Data.Aeson +import Data.Aeson.KeyMap qualified as KeyMap +import Data.Json.Util +import Imports import Test.Wire.API.Golden.Manual.Token (testObject_Token_1) -import Wire.API.Event.Gundeck +import Wire.API.Push.V2.Token testObject_PushRemove_1 :: PushRemove testObject_PushRemove_1 = PushRemove testObject_Token_1 + +newtype PushRemove = PushRemove PushToken + deriving (Eq, Show) + +instance FromJSON PushRemove where + parseJSON = withObject "push-removed object" $ \o -> + PushRemove <$> o .: "token" + +instance ToJSON PushRemove where + toJSON = Object . toJSONObject + +instance ToJSONObject PushRemove where + toJSONObject (PushRemove t) = + KeyMap.fromList + [ "type" .= ("user.push-remove" :: Text), + "token" .= t + ] diff --git a/libs/wire-api/wire-api.cabal b/libs/wire-api/wire-api.cabal index bf5fbe50f49..43568aa295f 100644 --- a/libs/wire-api/wire-api.cabal +++ b/libs/wire-api/wire-api.cabal @@ -74,7 +74,6 @@ library Wire.API.Bot Wire.API.Bot.Service Wire.API.Call.Config - Wire.API.CannonId Wire.API.Connection Wire.API.Conversation Wire.API.Conversation.Action @@ -97,7 +96,6 @@ library Wire.API.Event.Conversation Wire.API.Event.FeatureConfig Wire.API.Event.Federation - Wire.API.Event.Gundeck Wire.API.Event.LeaveReason Wire.API.Event.Team Wire.API.FederationStatus @@ -138,7 +136,6 @@ library Wire.API.Notification Wire.API.OAuth Wire.API.Password - Wire.API.Presence Wire.API.Properties Wire.API.Provider Wire.API.Provider.Bot @@ -146,7 +143,6 @@ library Wire.API.Provider.Service Wire.API.Provider.Service.Tag Wire.API.Push.Token - Wire.API.Push.V2 Wire.API.Push.V2.Token Wire.API.RawJson Wire.API.Routes.API @@ -168,7 +164,6 @@ library Wire.API.Routes.Internal.Galley.ConversationsIntra Wire.API.Routes.Internal.Galley.TeamFeatureNoConfigMulti Wire.API.Routes.Internal.Galley.TeamsIntra - Wire.API.Routes.Internal.Gundeck Wire.API.Routes.Internal.LegalHold Wire.API.Routes.Internal.Spar Wire.API.Routes.LowLevelStream @@ -305,7 +300,6 @@ library , metrics-wai , mime >=0.4 , mtl - , network-uri , openapi3 , pem >=0.2 , polysemy @@ -371,11 +365,6 @@ test-suite wire-api-golden-tests Test.Wire.API.Golden.Generated.ActivationResponse_user Test.Wire.API.Golden.Generated.AddBot_user Test.Wire.API.Golden.Generated.AddBotResponse_user - Test.Wire.API.Golden.Manual.ApsData - Test.Wire.API.Golden.Manual.CannonId - Test.Wire.API.Golden.Manual.Presence - Test.Wire.API.Golden.Manual.Push - Test.Wire.API.Golden.Manual.PushRemove Test.Wire.API.Golden.Generated.AppName_user Test.Wire.API.Golden.Generated.ApproveLegalHoldForUserRequest_team Test.Wire.API.Golden.Generated.Asset_asset @@ -582,6 +571,8 @@ test-suite wire-api-golden-tests Test.Wire.API.Golden.Generated.Wrapped_20_22some_5fint_22_20Int_user Test.Wire.API.Golden.Manual Test.Wire.API.Golden.Manual.Activate_user + Test.Wire.API.Golden.Manual.ApsData + Test.Wire.API.Golden.Manual.CannonId Test.Wire.API.Golden.Manual.ClientCapability Test.Wire.API.Golden.Manual.ClientCapabilityList Test.Wire.API.Golden.Manual.Contact @@ -604,6 +595,9 @@ test-suite wire-api-golden-tests Test.Wire.API.Golden.Manual.Login_user Test.Wire.API.Golden.Manual.LoginId_user Test.Wire.API.Golden.Manual.MLSKeys + Test.Wire.API.Golden.Manual.Presence + Test.Wire.API.Golden.Manual.Push + Test.Wire.API.Golden.Manual.PushRemove Test.Wire.API.Golden.Manual.QualifiedUserClientPrekeyMap Test.Wire.API.Golden.Manual.SearchResultContact Test.Wire.API.Golden.Manual.SendActivationCode_user @@ -633,7 +627,10 @@ test-suite wire-api-golden-tests , iso639 , lens , pem + , attoparsec , proto-lens + , servant + , network-uri , string-conversions , tasty , tasty-hunit @@ -641,6 +638,8 @@ test-suite wire-api-golden-tests , time , types-common >=0.16 , uri-bytestring + , schema-profunctor + , openapi3 , uuid , wire-api , wire-message-proto-lens @@ -693,6 +692,7 @@ test-suite wire-api-tests , containers >=0.5 , crypton , filepath + , servant , hex , hspec , hspec-wai From 1cb043f529111fcb0ce609e1ce140c8f9b6467aa Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Mon, 30 Sep 2024 16:08:56 +0200 Subject: [PATCH 20/32] Revert "Make wire-api/test/golden run on develop." This reverts commit 5c76642a0214b71337c37ed7d916227a19ab8633. --- .../Test/Wire/API/Golden/Manual/ApsData.hs | 41 +--- .../Test/Wire/API/Golden/Manual/CannonId.hs | 6 +- .../Test/Wire/API/Golden/Manual/Presence.hs | 72 +------ .../Test/Wire/API/Golden/Manual/Push.hs | 197 +----------------- .../Test/Wire/API/Golden/Manual/PushRemove.hs | 23 +- libs/wire-api/wire-api.cabal | 22 +- 6 files changed, 17 insertions(+), 344 deletions(-) diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs index f365bf68ade..910e3099b1d 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs @@ -21,47 +21,8 @@ module Test.Wire.API.Golden.Manual.ApsData ) where -import Data.Aeson -import Data.Json.Util import Imports - -newtype ApsSound = ApsSound {fromSound :: Text} - deriving (Eq, Show, ToJSON, FromJSON) - -newtype ApsLocKey = ApsLocKey {fromLocKey :: Text} - deriving (Eq, Show, ToJSON, FromJSON) - -data ApsData = ApsData - { _apsLocKey :: !ApsLocKey, - _apsLocArgs :: [Text], - _apsSound :: !(Maybe ApsSound), - _apsBadge :: !Bool - } - deriving (Eq, Show) - -instance ToJSON ApsData where - toJSON (ApsData k a s b) = - object $ - "loc_key" - .= k - # "loc_args" - .= a - # "sound" - .= s - # "badge" - .= b - # [] - -instance FromJSON ApsData where - parseJSON = withObject "ApsData" $ \o -> - ApsData - <$> o .: "loc_key" - <*> o .:? "loc_args" .!= [] - <*> o .:? "sound" - <*> o .:? "badge" .!= True - -apsData :: ApsLocKey -> [Text] -> ApsData -apsData lk la = ApsData lk la Nothing True +import Wire.API.Push.V2 testObject_ApsData_1 :: ApsData testObject_ApsData_1 = diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/CannonId.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/CannonId.hs index a6923cc8cbb..9f9de73dbab 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/CannonId.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/CannonId.hs @@ -22,11 +22,7 @@ module Test.Wire.API.Golden.Manual.CannonId ) where -import Data.Aeson -import Imports - -newtype CannonId = CannonId {cannonId :: Text} - deriving (Eq, Show, FromJSON, ToJSON) +import Wire.API.CannonId testObject_CannonId_1 :: CannonId testObject_CannonId_1 = CannonId "" diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs index fea637b1a1b..78a022b165b 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs @@ -21,80 +21,10 @@ module Test.Wire.API.Golden.Manual.Presence ) where -import Data.Aeson -import Data.Attoparsec.ByteString (takeByteString) -import Data.ByteString.Char8 qualified as Bytes -import Data.ByteString.Conversion -import Data.ByteString.Lazy as Lazy import Data.Id -import Data.Misc -import Data.Text as Text -import Data.Text.Encoding (decodeUtf8) import Data.UUID qualified as UUID import Imports -import Network.URI qualified as Net -import Servant.API qualified as Servant - -newtype URI = URI - { fromURI :: Net.URI - } - deriving (Eq, Ord, Show) - -instance FromJSON URI where - parseJSON = withText "URI" (parse . Text.unpack) - -instance ToJSON URI where - toJSON uri = String $ Text.pack (show (fromURI uri)) - -instance ToByteString URI where - builder = builder . show . fromURI - -instance FromByteString URI where - parser = takeByteString >>= parse . Bytes.unpack - -instance Servant.ToHttpApiData URI where - toUrlPiece = decodeUtf8 . toByteString' - -parse :: (MonadFail m) => String -> m URI -parse = maybe (fail "Invalid URI") (pure . URI) . Net.parseURI - --- | This is created in gundeck by cannon every time the client opens a new websocket connection. --- (That's why we always have a 'ConnId' from the most recent connection by that client.) -data Presence = Presence - { userId :: !UserId, - connId :: !ConnId, - -- | cannon instance hosting the presence - resource :: !URI, - -- | This is 'Nothing' if either (a) the presence is older - -- than mandatory end-to-end encryption, or (b) the client is - -- operating the team settings pages without the need for - -- end-to-end crypto. - clientId :: !(Maybe ClientId), - createdAt :: !Milliseconds, - -- | REFACTOR: temp. addition to ease migration - __field :: !Lazy.ByteString - } - deriving (Eq, Ord, Show) - -instance ToJSON Presence where - toJSON p = - object - [ "user_id" .= userId p, - "device_id" .= connId p, - "resource" .= resource p, - "client_id" .= clientId p, - "created_at" .= createdAt p - ] - -instance FromJSON Presence where - parseJSON = withObject "Presence" $ \o -> - Presence - <$> o .: "user_id" - <*> o .: "device_id" - <*> o .: "resource" - <*> o .:? "client_id" - <*> o .:? "created_at" .!= 0 - <*> pure "" +import Wire.API.Presence testObject_Presence_1 :: Presence testObject_Presence_1 = diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs index dcac359bbd6..fb91cd9cfc6 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs @@ -21,208 +21,15 @@ module Test.Wire.API.Golden.Manual.Push ) where -import Data.Aeson as A +import Data.Aeson qualified as A import Data.Aeson.KeyMap qualified as KM import Data.Id -import Data.Json.Util ((#)) import Data.List1 -import Data.OpenApi qualified as S import Data.Range -import Data.Schema qualified as SPF import Data.Set qualified as Set import Data.UUID qualified as UUID import Imports - -newtype ApsSound = ApsSound {fromSound :: Text} - deriving (Eq, Show, A.ToJSON, A.FromJSON) - -newtype ApsLocKey = ApsLocKey {fromLocKey :: Text} - deriving (Eq, Show, A.ToJSON, A.FromJSON) - -data ApsData = ApsData - { _apsLocKey :: !ApsLocKey, - _apsLocArgs :: [Text], - _apsSound :: !(Maybe ApsSound), - _apsBadge :: !Bool - } - deriving (Eq, Show, Generic) - -apsData :: ApsLocKey -> [Text] -> ApsData -apsData lk la = ApsData lk la Nothing True - -instance A.ToJSON ApsData where - toJSON (ApsData k a s b) = - A.object $ - [ "loc_key" A..= k, - "loc_args" A..= a, - "sound" A..= s, - "badge" A..= b - ] - -instance A.FromJSON ApsData where - parseJSON = A.withObject "ApsData" $ \o -> - ApsData - <$> o A..: "loc_key" - <*> o A..:? "loc_args" A..!= [] - <*> o A..:? "sound" - <*> o A..:? "badge" A..!= True - -data Priority = LowPriority | HighPriority - deriving stock (Eq, Show, Ord, Enum, Generic) - deriving (A.ToJSON, A.FromJSON, S.ToSchema) via SPF.Schema Priority - -instance SPF.ToSchema Priority where - schema = - SPF.enum @Text "Priority" $ - mconcat - [ SPF.element "low" LowPriority, - SPF.element "high" HighPriority - ] - -data Route = RouteAny | RouteDirect - deriving (Eq, Ord, Enum, Bounded, Show, Generic) - -instance A.FromJSON Route where - parseJSON (A.String "any") = pure RouteAny - parseJSON (A.String "direct") = pure RouteDirect - parseJSON x = fail $ "Invalid routing: " ++ show (A.encode x) - -instance A.ToJSON Route where - toJSON RouteAny = A.String "any" - toJSON RouteDirect = A.String "direct" - -data Recipient = Recipient - { _recipientId :: !UserId, - _recipientRoute :: !Route, - _recipientClients :: !RecipientClients - } - deriving (Show, Eq, Ord, Generic) - -data RecipientClients - = -- | All clients of some user - RecipientClientsAll - | -- | An explicit list of clients - RecipientClientsSome (List1 ClientId) - deriving (Eq, Show, Ord, Generic) - -instance Semigroup RecipientClients where - RecipientClientsAll <> _ = RecipientClientsAll - _ <> RecipientClientsAll = RecipientClientsAll - RecipientClientsSome cs1 <> RecipientClientsSome cs2 = - RecipientClientsSome (cs1 <> cs2) - -instance A.FromJSON Recipient where - parseJSON = A.withObject "Recipient" $ \p -> - Recipient - <$> p A..: "user_id" - <*> p A..: "route" - <*> p A..:? "clients" A..!= RecipientClientsAll - -instance A.ToJSON Recipient where - toJSON (Recipient u r c) = - A.object $ - "user_id" - A..= u - # "route" - A..= r - # "clients" - A..= c - # [] - --- "All clients" is encoded in the API as an empty list. -instance A.FromJSON RecipientClients where - parseJSON x = - A.parseJSON @[ClientId] x >>= \case - [] -> pure RecipientClientsAll - c : cs -> pure (RecipientClientsSome (list1 c cs)) - -instance A.ToJSON RecipientClients where - toJSON = - A.toJSON . \case - RecipientClientsAll -> [] - RecipientClientsSome cs -> toList cs - -data Push = Push - { -- | Recipients - -- - -- REFACTOR: '_pushRecipients' should be @Set (Recipient, Maybe (NonEmptySet ConnId))@, and - -- '_pushConnections' should go away. Rationale: the current setup only works under the - -- 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), - -- | Originating user - -- - -- 'Nothing' here means that the originating user is on another backend. - -- - -- REFACTOR: where is this required, and for what? or can it be removed? (see also: #531) - _pushOrigin :: !(Maybe UserId), - -- | Destination connections. If empty, ignore. Otherwise, filter the connections derived - -- from '_pushRecipients' and only push to those contained in this set. - -- - -- REFACTOR: change this to @_pushConnectionWhitelist :: Maybe (Set ConnId)@. - _pushConnections :: !(Set ConnId), - -- | Originating connection, if any. - _pushOriginConnection :: !(Maybe ConnId), - -- | Transient payloads are not forwarded to the notification stream. - _pushTransient :: !Bool, - -- | Whether to send native notifications to other clients - -- of the originating user, if he is among the recipients. - _pushNativeIncludeOrigin :: !Bool, - -- | Should native push payloads be encrypted? - -- - -- REFACTOR: this make no sense any more since native push notifications have no more payload. - -- https://github.com/wireapp/wire-server/pull/546 - _pushNativeEncrypt :: !Bool, - -- | APNs-specific metadata (needed eg. in "Brig.IO.Intra.toApsData"). - _pushNativeAps :: !(Maybe ApsData), - -- | Native push priority. - _pushNativePriority :: !Priority, - -- | Opaque payload - _pushPayload :: !(List1 A.Object) - } - deriving (Eq, Show) - -instance FromJSON Push where - parseJSON = withObject "Push" $ \p -> - Push - <$> p .: "recipients" - <*> p .:? "origin" - <*> p .:? "connections" .!= Set.empty - <*> p .:? "origin_connection" - <*> p .:? "transient" .!= False - <*> p .:? "native_include_origin" .!= True - <*> p .:? "native_encrypt" .!= True - <*> p .:? "native_aps" - <*> p .:? "native_priority" .!= HighPriority - <*> p .: "payload" - -instance ToJSON Push where - toJSON p = - object $ - "recipients" - .= _pushRecipients p - # "origin" - .= _pushOrigin p - # "connections" - .= ifNot Set.null (_pushConnections p) - # "origin_connection" - .= _pushOriginConnection p - # "transient" - .= ifNot not (_pushTransient p) - # "native_include_origin" - .= ifNot id (_pushNativeIncludeOrigin p) - # "native_encrypt" - .= ifNot id (_pushNativeEncrypt p) - # "native_aps" - .= _pushNativeAps p - # "native_priority" - .= ifNot (== HighPriority) (_pushNativePriority p) - # "payload" - .= _pushPayload p - # [] - where - ifNot f a = if f a then Nothing else Just a +import Wire.API.Push.V2 rcp1, rcp2, rcp3 :: Recipient rcp1 = diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/PushRemove.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/PushRemove.hs index 4bf7d9192e4..bf4a823e47d 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/PushRemove.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/PushRemove.hs @@ -20,29 +20,8 @@ module Test.Wire.API.Golden.Manual.PushRemove ) where -import Data.Aeson -import Data.Aeson.KeyMap qualified as KeyMap -import Data.Json.Util -import Imports import Test.Wire.API.Golden.Manual.Token (testObject_Token_1) -import Wire.API.Push.V2.Token +import Wire.API.Event.Gundeck testObject_PushRemove_1 :: PushRemove testObject_PushRemove_1 = PushRemove testObject_Token_1 - -newtype PushRemove = PushRemove PushToken - deriving (Eq, Show) - -instance FromJSON PushRemove where - parseJSON = withObject "push-removed object" $ \o -> - PushRemove <$> o .: "token" - -instance ToJSON PushRemove where - toJSON = Object . toJSONObject - -instance ToJSONObject PushRemove where - toJSONObject (PushRemove t) = - KeyMap.fromList - [ "type" .= ("user.push-remove" :: Text), - "token" .= t - ] diff --git a/libs/wire-api/wire-api.cabal b/libs/wire-api/wire-api.cabal index 43568aa295f..bf5fbe50f49 100644 --- a/libs/wire-api/wire-api.cabal +++ b/libs/wire-api/wire-api.cabal @@ -74,6 +74,7 @@ library Wire.API.Bot Wire.API.Bot.Service Wire.API.Call.Config + Wire.API.CannonId Wire.API.Connection Wire.API.Conversation Wire.API.Conversation.Action @@ -96,6 +97,7 @@ library Wire.API.Event.Conversation Wire.API.Event.FeatureConfig Wire.API.Event.Federation + Wire.API.Event.Gundeck Wire.API.Event.LeaveReason Wire.API.Event.Team Wire.API.FederationStatus @@ -136,6 +138,7 @@ library Wire.API.Notification Wire.API.OAuth Wire.API.Password + Wire.API.Presence Wire.API.Properties Wire.API.Provider Wire.API.Provider.Bot @@ -143,6 +146,7 @@ library Wire.API.Provider.Service Wire.API.Provider.Service.Tag Wire.API.Push.Token + Wire.API.Push.V2 Wire.API.Push.V2.Token Wire.API.RawJson Wire.API.Routes.API @@ -164,6 +168,7 @@ library Wire.API.Routes.Internal.Galley.ConversationsIntra Wire.API.Routes.Internal.Galley.TeamFeatureNoConfigMulti Wire.API.Routes.Internal.Galley.TeamsIntra + Wire.API.Routes.Internal.Gundeck Wire.API.Routes.Internal.LegalHold Wire.API.Routes.Internal.Spar Wire.API.Routes.LowLevelStream @@ -300,6 +305,7 @@ library , metrics-wai , mime >=0.4 , mtl + , network-uri , openapi3 , pem >=0.2 , polysemy @@ -365,6 +371,11 @@ test-suite wire-api-golden-tests Test.Wire.API.Golden.Generated.ActivationResponse_user Test.Wire.API.Golden.Generated.AddBot_user Test.Wire.API.Golden.Generated.AddBotResponse_user + Test.Wire.API.Golden.Manual.ApsData + Test.Wire.API.Golden.Manual.CannonId + Test.Wire.API.Golden.Manual.Presence + Test.Wire.API.Golden.Manual.Push + Test.Wire.API.Golden.Manual.PushRemove Test.Wire.API.Golden.Generated.AppName_user Test.Wire.API.Golden.Generated.ApproveLegalHoldForUserRequest_team Test.Wire.API.Golden.Generated.Asset_asset @@ -571,8 +582,6 @@ test-suite wire-api-golden-tests Test.Wire.API.Golden.Generated.Wrapped_20_22some_5fint_22_20Int_user Test.Wire.API.Golden.Manual Test.Wire.API.Golden.Manual.Activate_user - Test.Wire.API.Golden.Manual.ApsData - Test.Wire.API.Golden.Manual.CannonId Test.Wire.API.Golden.Manual.ClientCapability Test.Wire.API.Golden.Manual.ClientCapabilityList Test.Wire.API.Golden.Manual.Contact @@ -595,9 +604,6 @@ test-suite wire-api-golden-tests Test.Wire.API.Golden.Manual.Login_user Test.Wire.API.Golden.Manual.LoginId_user Test.Wire.API.Golden.Manual.MLSKeys - Test.Wire.API.Golden.Manual.Presence - Test.Wire.API.Golden.Manual.Push - Test.Wire.API.Golden.Manual.PushRemove Test.Wire.API.Golden.Manual.QualifiedUserClientPrekeyMap Test.Wire.API.Golden.Manual.SearchResultContact Test.Wire.API.Golden.Manual.SendActivationCode_user @@ -627,10 +633,7 @@ test-suite wire-api-golden-tests , iso639 , lens , pem - , attoparsec , proto-lens - , servant - , network-uri , string-conversions , tasty , tasty-hunit @@ -638,8 +641,6 @@ test-suite wire-api-golden-tests , time , types-common >=0.16 , uri-bytestring - , schema-profunctor - , openapi3 , uuid , wire-api , wire-message-proto-lens @@ -692,7 +693,6 @@ test-suite wire-api-tests , containers >=0.5 , crypton , filepath - , servant , hex , hspec , hspec-wai From 3c435c06c75ee1f0ab6949d18194a0dcbd2acb66 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Mon, 30 Sep 2024 16:37:21 +0200 Subject: [PATCH 21/32] make sanitize-pr --- libs/wire-api/wire-api.cabal | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/wire-api/wire-api.cabal b/libs/wire-api/wire-api.cabal index bf5fbe50f49..914a3d5736a 100644 --- a/libs/wire-api/wire-api.cabal +++ b/libs/wire-api/wire-api.cabal @@ -371,11 +371,6 @@ test-suite wire-api-golden-tests Test.Wire.API.Golden.Generated.ActivationResponse_user Test.Wire.API.Golden.Generated.AddBot_user Test.Wire.API.Golden.Generated.AddBotResponse_user - Test.Wire.API.Golden.Manual.ApsData - Test.Wire.API.Golden.Manual.CannonId - Test.Wire.API.Golden.Manual.Presence - Test.Wire.API.Golden.Manual.Push - Test.Wire.API.Golden.Manual.PushRemove Test.Wire.API.Golden.Generated.AppName_user Test.Wire.API.Golden.Generated.ApproveLegalHoldForUserRequest_team Test.Wire.API.Golden.Generated.Asset_asset @@ -582,6 +577,8 @@ test-suite wire-api-golden-tests Test.Wire.API.Golden.Generated.Wrapped_20_22some_5fint_22_20Int_user Test.Wire.API.Golden.Manual Test.Wire.API.Golden.Manual.Activate_user + Test.Wire.API.Golden.Manual.ApsData + Test.Wire.API.Golden.Manual.CannonId Test.Wire.API.Golden.Manual.ClientCapability Test.Wire.API.Golden.Manual.ClientCapabilityList Test.Wire.API.Golden.Manual.Contact @@ -604,6 +601,9 @@ test-suite wire-api-golden-tests Test.Wire.API.Golden.Manual.Login_user Test.Wire.API.Golden.Manual.LoginId_user Test.Wire.API.Golden.Manual.MLSKeys + Test.Wire.API.Golden.Manual.Presence + Test.Wire.API.Golden.Manual.Push + Test.Wire.API.Golden.Manual.PushRemove Test.Wire.API.Golden.Manual.QualifiedUserClientPrekeyMap Test.Wire.API.Golden.Manual.SearchResultContact Test.Wire.API.Golden.Manual.SendActivationCode_user From 3faa8c8ebdeec007a4a2e76fb8ab53b61f5b8e19 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Mon, 30 Sep 2024 17:42:26 +0200 Subject: [PATCH 22/32] Oops, forgot to git-add a new haskell module. --- libs/wire-api/src/Wire/API/Event/Gundeck.hs | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 libs/wire-api/src/Wire/API/Event/Gundeck.hs diff --git a/libs/wire-api/src/Wire/API/Event/Gundeck.hs b/libs/wire-api/src/Wire/API/Event/Gundeck.hs new file mode 100644 index 00000000000..86ec39c2e27 --- /dev/null +++ b/libs/wire-api/src/Wire/API/Event/Gundeck.hs @@ -0,0 +1,24 @@ +module Wire.API.Event.Gundeck where + +import Data.Aeson +import Data.Aeson.KeyMap qualified as KeyMap +import Data.Json.Util +import Imports +import Wire.API.Push.V2.Token + +newtype PushRemove = PushRemove PushToken + deriving (Eq, Show) + +instance FromJSON PushRemove where + parseJSON = withObject "push-removed object" $ \o -> + PushRemove <$> o .: "token" + +instance ToJSON PushRemove where + toJSON = Object . toJSONObject + +instance ToJSONObject PushRemove where + toJSONObject (PushRemove t) = + KeyMap.fromList + [ "type" .= ("user.push-remove" :: Text), + "token" .= t + ] From eebaa055071a7f70b7e63935966dc10829eb2a2b Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Mon, 30 Sep 2024 18:20:30 +0200 Subject: [PATCH 23/32] hi ci From ff8b6229528ab1d3896e112eb8393e508ef03088 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Tue, 1 Oct 2024 07:36:36 +0200 Subject: [PATCH 24/32] rm superflous golden json files. --- .../test/golden/testObject_ApsData_3.json | 9 ---- .../test/golden/testObject_ApsData_4.json | 9 ---- .../test/golden/testObject_ApsData_5.json | 9 ---- .../test/golden/testObject_CannonId_4.json | 1 - .../test/golden/testObject_CannonId_5.json | 1 - .../test/golden/testObject_Presence_3.json | 7 --- .../test/golden/testObject_Presence_4.json | 7 --- .../test/golden/testObject_Presence_5.json | 7 --- .../test/golden/testObject_Push_3.json | 51 ------------------- .../test/golden/testObject_Push_4.json | 51 ------------------- .../test/golden/testObject_Push_5.json | 51 ------------------- 11 files changed, 203 deletions(-) delete mode 100644 libs/wire-api/test/golden/testObject_ApsData_3.json delete mode 100644 libs/wire-api/test/golden/testObject_ApsData_4.json delete mode 100644 libs/wire-api/test/golden/testObject_ApsData_5.json delete mode 100644 libs/wire-api/test/golden/testObject_CannonId_4.json delete mode 100644 libs/wire-api/test/golden/testObject_CannonId_5.json delete mode 100644 libs/wire-api/test/golden/testObject_Presence_3.json delete mode 100644 libs/wire-api/test/golden/testObject_Presence_4.json delete mode 100644 libs/wire-api/test/golden/testObject_Presence_5.json delete mode 100644 libs/wire-api/test/golden/testObject_Push_3.json delete mode 100644 libs/wire-api/test/golden/testObject_Push_4.json delete mode 100644 libs/wire-api/test/golden/testObject_Push_5.json diff --git a/libs/wire-api/test/golden/testObject_ApsData_3.json b/libs/wire-api/test/golden/testObject_ApsData_3.json deleted file mode 100644 index 67ccf502971..00000000000 --- a/libs/wire-api/test/golden/testObject_ApsData_3.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "badge": true, - "loc_args": [ - "1", - "22", - "333" - ], - "loc_key": "asdf" -} diff --git a/libs/wire-api/test/golden/testObject_ApsData_4.json b/libs/wire-api/test/golden/testObject_ApsData_4.json deleted file mode 100644 index 67ccf502971..00000000000 --- a/libs/wire-api/test/golden/testObject_ApsData_4.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "badge": true, - "loc_args": [ - "1", - "22", - "333" - ], - "loc_key": "asdf" -} diff --git a/libs/wire-api/test/golden/testObject_ApsData_5.json b/libs/wire-api/test/golden/testObject_ApsData_5.json deleted file mode 100644 index 67ccf502971..00000000000 --- a/libs/wire-api/test/golden/testObject_ApsData_5.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "badge": true, - "loc_args": [ - "1", - "22", - "333" - ], - "loc_key": "asdf" -} diff --git a/libs/wire-api/test/golden/testObject_CannonId_4.json b/libs/wire-api/test/golden/testObject_CannonId_4.json deleted file mode 100644 index 5149c12b38f..00000000000 --- a/libs/wire-api/test/golden/testObject_CannonId_4.json +++ /dev/null @@ -1 +0,0 @@ -"sdfiou" diff --git a/libs/wire-api/test/golden/testObject_CannonId_5.json b/libs/wire-api/test/golden/testObject_CannonId_5.json deleted file mode 100644 index 5149c12b38f..00000000000 --- a/libs/wire-api/test/golden/testObject_CannonId_5.json +++ /dev/null @@ -1 +0,0 @@ -"sdfiou" diff --git a/libs/wire-api/test/golden/testObject_Presence_3.json b/libs/wire-api/test/golden/testObject_Presence_3.json deleted file mode 100644 index cda26a2fd27..00000000000 --- a/libs/wire-api/test/golden/testObject_Presence_3.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "client_id": "1", - "created_at": 12323, - "device_id": "wef3", - "resource": "URI {fromURI = http://example.com/3}", - "user_id": "174ccaea-7f26-11ef-86cc-37bb6bf3b319" -} diff --git a/libs/wire-api/test/golden/testObject_Presence_4.json b/libs/wire-api/test/golden/testObject_Presence_4.json deleted file mode 100644 index cda26a2fd27..00000000000 --- a/libs/wire-api/test/golden/testObject_Presence_4.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "client_id": "1", - "created_at": 12323, - "device_id": "wef3", - "resource": "URI {fromURI = http://example.com/3}", - "user_id": "174ccaea-7f26-11ef-86cc-37bb6bf3b319" -} diff --git a/libs/wire-api/test/golden/testObject_Presence_5.json b/libs/wire-api/test/golden/testObject_Presence_5.json deleted file mode 100644 index cda26a2fd27..00000000000 --- a/libs/wire-api/test/golden/testObject_Presence_5.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "client_id": "1", - "created_at": 12323, - "device_id": "wef3", - "resource": "URI {fromURI = http://example.com/3}", - "user_id": "174ccaea-7f26-11ef-86cc-37bb6bf3b319" -} diff --git a/libs/wire-api/test/golden/testObject_Push_3.json b/libs/wire-api/test/golden/testObject_Push_3.json deleted file mode 100644 index 39e924962e7..00000000000 --- a/libs/wire-api/test/golden/testObject_Push_3.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "connections": [ - "mempty", - "sdf", - "wire-client" - ], - "native_aps": { - "badge": true, - "loc_args": [ - "1", - "22", - "333" - ], - "loc_key": "asdf" - }, - "native_encrypt": false, - "native_priority": "low", - "origin": "dec9b47a-7f12-11ef-b634-6710e7ae3d33", - "origin_connection": "123", - "payload": [ - { - "bar": true, - "foo": "3" - }, - {}, - { - "growl": "foooood" - }, - { - "lunchtime": "imminent" - } - ], - "recipients": [ - { - "clients": [ - "0" - ], - "route": "direct", - "user_id": "2e18540e-7f14-11ef-9886-d3c2ff21d3d1" - }, - { - "clients": [ - "ea", - "7b" - ], - "route": "direct", - "user_id": "316924ee-7f14-11ef-b6a2-036a4f646914" - } - ], - "transient": true -} diff --git a/libs/wire-api/test/golden/testObject_Push_4.json b/libs/wire-api/test/golden/testObject_Push_4.json deleted file mode 100644 index 39e924962e7..00000000000 --- a/libs/wire-api/test/golden/testObject_Push_4.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "connections": [ - "mempty", - "sdf", - "wire-client" - ], - "native_aps": { - "badge": true, - "loc_args": [ - "1", - "22", - "333" - ], - "loc_key": "asdf" - }, - "native_encrypt": false, - "native_priority": "low", - "origin": "dec9b47a-7f12-11ef-b634-6710e7ae3d33", - "origin_connection": "123", - "payload": [ - { - "bar": true, - "foo": "3" - }, - {}, - { - "growl": "foooood" - }, - { - "lunchtime": "imminent" - } - ], - "recipients": [ - { - "clients": [ - "0" - ], - "route": "direct", - "user_id": "2e18540e-7f14-11ef-9886-d3c2ff21d3d1" - }, - { - "clients": [ - "ea", - "7b" - ], - "route": "direct", - "user_id": "316924ee-7f14-11ef-b6a2-036a4f646914" - } - ], - "transient": true -} diff --git a/libs/wire-api/test/golden/testObject_Push_5.json b/libs/wire-api/test/golden/testObject_Push_5.json deleted file mode 100644 index 39e924962e7..00000000000 --- a/libs/wire-api/test/golden/testObject_Push_5.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "connections": [ - "mempty", - "sdf", - "wire-client" - ], - "native_aps": { - "badge": true, - "loc_args": [ - "1", - "22", - "333" - ], - "loc_key": "asdf" - }, - "native_encrypt": false, - "native_priority": "low", - "origin": "dec9b47a-7f12-11ef-b634-6710e7ae3d33", - "origin_connection": "123", - "payload": [ - { - "bar": true, - "foo": "3" - }, - {}, - { - "growl": "foooood" - }, - { - "lunchtime": "imminent" - } - ], - "recipients": [ - { - "clients": [ - "0" - ], - "route": "direct", - "user_id": "2e18540e-7f14-11ef-9886-d3c2ff21d3d1" - }, - { - "clients": [ - "ea", - "7b" - ], - "route": "direct", - "user_id": "316924ee-7f14-11ef-b6a2-036a4f646914" - } - ], - "transient": true -} From 87a630e19444df63c9bf2ba21cefd2a97832f6b0 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Tue, 1 Oct 2024 08:00:30 +0200 Subject: [PATCH 25/32] Align golden test json files with what was the case before this PR. --- libs/wire-api/test/golden/testObject_Presence_1.json | 1 + libs/wire-api/test/golden/testObject_Push_2.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/wire-api/test/golden/testObject_Presence_1.json b/libs/wire-api/test/golden/testObject_Presence_1.json index f55001d521b..184b9f0809b 100644 --- a/libs/wire-api/test/golden/testObject_Presence_1.json +++ b/libs/wire-api/test/golden/testObject_Presence_1.json @@ -1,4 +1,5 @@ { + "client_id": null, "created_at": 0, "device_id": "wef", "resource": "http://example.com/", diff --git a/libs/wire-api/test/golden/testObject_Push_2.json b/libs/wire-api/test/golden/testObject_Push_2.json index 39e924962e7..cc5e168b15e 100644 --- a/libs/wire-api/test/golden/testObject_Push_2.json +++ b/libs/wire-api/test/golden/testObject_Push_2.json @@ -11,7 +11,8 @@ "22", "333" ], - "loc_key": "asdf" + "loc_key": "asdf", + "sound": null }, "native_encrypt": false, "native_priority": "low", From 050c8878e513420d4147ba900a82f116076aed20 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Tue, 1 Oct 2024 08:11:09 +0200 Subject: [PATCH 26/32] Remove redundant golden tests for ApsData. --- .../golden/Test/Wire/API/Golden/Manual.hs | 6 ---- .../Test/Wire/API/Golden/Manual/ApsData.hs | 33 ------------------- .../test/golden/testObject_ApsData_1.json | 5 --- .../test/golden/testObject_ApsData_2.json | 9 ----- libs/wire-api/wire-api.cabal | 1 - 5 files changed, 54 deletions(-) delete mode 100644 libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs delete mode 100644 libs/wire-api/test/golden/testObject_ApsData_1.json delete mode 100644 libs/wire-api/test/golden/testObject_ApsData_2.json diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual.hs index 23a815c705b..e57d209f02d 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual.hs @@ -20,7 +20,6 @@ module Test.Wire.API.Golden.Manual where import Imports import Test.Tasty import Test.Wire.API.Golden.Manual.Activate_user -import Test.Wire.API.Golden.Manual.ApsData import Test.Wire.API.Golden.Manual.CannonId import Test.Wire.API.Golden.Manual.ClientCapability import Test.Wire.API.Golden.Manual.ClientCapabilityList @@ -281,11 +280,6 @@ tests = (testObject_Login_user_4, "testObject_Login_user_4.json"), (testObject_Login_user_5, "testObject_Login_user_5.json") ], - testGroup "ApsData" $ - testObjects - [ (testObject_ApsData_1, "testObject_ApsData_1.json"), - (testObject_ApsData_2, "testObject_ApsData_2.json") - ], testGroup "CannonId" $ testObjects [ (testObject_CannonId_1, "testObject_CannonId_1.json"), diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs deleted file mode 100644 index 910e3099b1d..00000000000 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/ApsData.hs +++ /dev/null @@ -1,33 +0,0 @@ --- This file is part of the Wire Server implementation. --- --- Copyright (C) 2022 Wire Swiss GmbH --- --- 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 . - -module Test.Wire.API.Golden.Manual.ApsData - ( testObject_ApsData_1, - testObject_ApsData_2, - ) -where - -import Imports -import Wire.API.Push.V2 - -testObject_ApsData_1 :: ApsData -testObject_ApsData_1 = - apsData (ApsLocKey mempty) mempty - -testObject_ApsData_2 :: ApsData -testObject_ApsData_2 = - apsData (ApsLocKey "asdf") ["1", "22", "333"] diff --git a/libs/wire-api/test/golden/testObject_ApsData_1.json b/libs/wire-api/test/golden/testObject_ApsData_1.json deleted file mode 100644 index f367522277f..00000000000 --- a/libs/wire-api/test/golden/testObject_ApsData_1.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "badge": true, - "loc_args": [], - "loc_key": "" -} diff --git a/libs/wire-api/test/golden/testObject_ApsData_2.json b/libs/wire-api/test/golden/testObject_ApsData_2.json deleted file mode 100644 index 67ccf502971..00000000000 --- a/libs/wire-api/test/golden/testObject_ApsData_2.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "badge": true, - "loc_args": [ - "1", - "22", - "333" - ], - "loc_key": "asdf" -} diff --git a/libs/wire-api/wire-api.cabal b/libs/wire-api/wire-api.cabal index 914a3d5736a..1091c12f7f3 100644 --- a/libs/wire-api/wire-api.cabal +++ b/libs/wire-api/wire-api.cabal @@ -577,7 +577,6 @@ test-suite wire-api-golden-tests Test.Wire.API.Golden.Generated.Wrapped_20_22some_5fint_22_20Int_user Test.Wire.API.Golden.Manual Test.Wire.API.Golden.Manual.Activate_user - Test.Wire.API.Golden.Manual.ApsData Test.Wire.API.Golden.Manual.CannonId Test.Wire.API.Golden.Manual.ClientCapability Test.Wire.API.Golden.Manual.ClientCapabilityList From 2b63078275a5ffcf2051e141299dba43026eb2cb Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Tue, 1 Oct 2024 08:11:38 +0200 Subject: [PATCH 27/32] Keep null fields for backwards compat. --- libs/wire-api/src/Wire/API/Presence.hs | 2 +- libs/wire-api/src/Wire/API/Push/V2.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/wire-api/src/Wire/API/Presence.hs b/libs/wire-api/src/Wire/API/Presence.hs index 3f250d9eadf..3de272c0fd2 100644 --- a/libs/wire-api/src/Wire/API/Presence.hs +++ b/libs/wire-api/src/Wire/API/Presence.hs @@ -74,7 +74,7 @@ instance ToSchema Presence where <$> userId .= field "user_id" schema <*> connId .= field "device_id" schema <*> resource .= field "resource" uriSchema - <*> clientId .= maybe_ (optField "client_id" schema) + <*> clientId .= optField "client_id" (maybeWithDefault A.Null schema) -- keep null for backwards compat <*> createdAt .= field "created_at" schema ) <&> ($ ("" :: Lazy.ByteString)) diff --git a/libs/wire-api/src/Wire/API/Push/V2.hs b/libs/wire-api/src/Wire/API/Push/V2.hs index 85907f99c82..1d24c9099d1 100644 --- a/libs/wire-api/src/Wire/API/Push/V2.hs +++ b/libs/wire-api/src/Wire/API/Push/V2.hs @@ -206,7 +206,7 @@ instance ToSchema ApsData where ApsData <$> _apsLocKey .= field "loc_key" schema <*> withDefault "loc_args" _apsLocArgs (array schema) [] - <*> _apsSound .= maybe_ (optField "sound" schema) + <*> _apsSound .= optField "sound" (maybeWithDefault A.Null schema) -- keep null for backwards compat <*> withDefault "badge" _apsBadge schema True where withDefault fn f s def = ((Just . f) .= maybe_ (optField fn s)) <&> fromMaybe def From e875f5cbb607553cab8c3a8d7a489cb19e4b046c Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Tue, 1 Oct 2024 09:58:01 +0200 Subject: [PATCH 28/32] hi ci From dec48736ad09bb554e9fdb4fff04dfaa0530e3bf Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Tue, 1 Oct 2024 10:39:35 +0200 Subject: [PATCH 29/32] hi ci From 1b2f386164b79b644456a86dd7d68d9bf842a685 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Tue, 1 Oct 2024 11:35:20 +0200 Subject: [PATCH 30/32] Fix ToSchema Presence instance. --- libs/wire-api/src/Wire/API/Presence.hs | 2 +- .../test/golden/Test/Wire/API/Golden/FromJSON.hs | 5 ++++- .../golden/Test/Wire/API/Golden/Manual/Presence.hs | 11 +++++++++++ .../test/golden/fromJSON/testObject_Presence_3.json | 6 ++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 libs/wire-api/test/golden/fromJSON/testObject_Presence_3.json diff --git a/libs/wire-api/src/Wire/API/Presence.hs b/libs/wire-api/src/Wire/API/Presence.hs index 3de272c0fd2..d2e8cb6a3d0 100644 --- a/libs/wire-api/src/Wire/API/Presence.hs +++ b/libs/wire-api/src/Wire/API/Presence.hs @@ -75,7 +75,7 @@ instance ToSchema Presence where <*> connId .= field "device_id" schema <*> resource .= field "resource" uriSchema <*> clientId .= optField "client_id" (maybeWithDefault A.Null schema) -- keep null for backwards compat - <*> createdAt .= field "created_at" schema + <*> createdAt .= (fromMaybe 0 <$> (optField "created_at" schema)) ) <&> ($ ("" :: Lazy.ByteString)) diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/FromJSON.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/FromJSON.hs index 9aece18a8cb..7ef64cf58f4 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/FromJSON.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/FromJSON.hs @@ -26,6 +26,7 @@ import Test.Wire.API.Golden.Generated.MemberUpdateData_user import Test.Wire.API.Golden.Generated.NewOtrMessage_user import Test.Wire.API.Golden.Generated.RmClient_user import Test.Wire.API.Golden.Generated.SimpleMember_user +import Test.Wire.API.Golden.Manual.Presence import Test.Wire.API.Golden.Runner import Wire.API.Conversation (Conversation, MemberUpdate, OtherMemberUpdate) import Wire.API.User (NewUser, NewUserPublic) @@ -91,5 +92,7 @@ tests = "testObject_NewUserPublic_user_1-3.json" ], testCase "LockableFeature_ConferenceCallingConfig" $ - testFromJSONObject testObject_LockableFeature_team_14 "testObject_LockableFeature_team_14.json" + testFromJSONObject testObject_LockableFeature_team_14 "testObject_LockableFeature_team_14.json", + testCase "LockableFeature_ConferenceCallingConfig" $ + testFromJSONObject testObject_Presence_3 "testObject_Presence_3.json" ] diff --git a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs index 78a022b165b..97005af0a0d 100644 --- a/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs +++ b/libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Presence.hs @@ -18,6 +18,7 @@ module Test.Wire.API.Golden.Manual.Presence ( testObject_Presence_1, testObject_Presence_2, + testObject_Presence_3, ) where @@ -45,3 +46,13 @@ testObject_Presence_2 = (Just (ClientId 1)) 12323 "" -- __field always has to be "", see ToSchema instance. + +testObject_Presence_3 :: Presence +testObject_Presence_3 = + Presence + (Id . fromJust $ UUID.fromString "174ccaea-7f26-11ef-86cc-37bb6bf3b319") + (ConnId "wef3") + (fromJust $ parse "http://example.com/3") + (Just (ClientId 1)) + 0 + "" -- __field always has to be "", see ToSchema instance. diff --git a/libs/wire-api/test/golden/fromJSON/testObject_Presence_3.json b/libs/wire-api/test/golden/fromJSON/testObject_Presence_3.json new file mode 100644 index 00000000000..1089a740c73 --- /dev/null +++ b/libs/wire-api/test/golden/fromJSON/testObject_Presence_3.json @@ -0,0 +1,6 @@ +{ + "client_id": "1", + "device_id": "wef3", + "resource": "http://example.com/3", + "user_id": "174ccaea-7f26-11ef-86cc-37bb6bf3b319" +} From 3f63924fd9ab63ba34e2a7f482f0402e3597b2fd Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Tue, 1 Oct 2024 11:58:21 +0200 Subject: [PATCH 31/32] hi ci From 56a8d1e75efadc0a76d177b1f7f4112d91eca013 Mon Sep 17 00:00:00 2001 From: Matthias Fischmann Date: Tue, 1 Oct 2024 14:01:01 +0200 Subject: [PATCH 32/32] Post used to return 201. --- libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs b/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs index c8fac671f9b..9287611a5e9 100644 --- a/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs +++ b/libs/wire-api/src/Wire/API/Routes/Internal/Gundeck.hs @@ -87,7 +87,7 @@ type InternalAPI = :<|> ( "presences" :> ( (QueryParam' [Required, Strict] "ids" (CommaSeparatedList UserId) :> Get '[JSON] [Presence]) :<|> (Capture "uid" UserId :> Get '[JSON] [Presence]) - :<|> (ReqBodyHack :> Post '[JSON] (Headers '[Header "Location" URI] NoContent)) + :<|> (ReqBodyHack :> Verb 'POST 201 '[JSON] (Headers '[Header "Location" URI] NoContent)) :<|> (Capture "uid" UserId :> "devices" :> Capture "did" ConnId :> "cannons" :> Capture "cannon" CannonId :> Delete '[JSON] NoContent) ) )