Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WPB-10204 Add text status field to user (profile) data #4155

Merged
merged 6 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/2-features/WPB-10204
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A text status field was added to user and user profile
11 changes: 11 additions & 0 deletions libs/wire-api/src/Wire/API/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ instance (1 <= max) => ToJSON (LimitedQualifiedUserIdList max) where
data UserProfile = UserProfile
{ profileQualifiedId :: Qualified UserId,
profileName :: Name,
profileTextStatus :: Maybe TextStatus,
-- | DEPRECATED
profilePict :: Pict,
profileAssets :: [Asset],
Expand Down Expand Up @@ -508,6 +509,8 @@ instance ToSchema UserProfile where
.= optional (field "id" (deprecatedSchema "qualified_id" schema))
<*> profileName
.= field "name" schema
<*> profileTextStatus
.= maybe_ (optField "text_status" schema)
<*> profilePict
.= (field "picture" schema <|> pure noPict)
<*> profileAssets
Expand Down Expand Up @@ -562,6 +565,8 @@ data User = User
userIdentity :: Maybe UserIdentity,
-- | required; non-unique
userDisplayName :: Name,
-- | text status
userTextStatus :: Maybe TextStatus,
-- | DEPRECATED
userPict :: Pict,
userAssets :: [Asset],
Expand Down Expand Up @@ -605,6 +610,8 @@ userObjectSchema =
.= maybeUserIdentityObjectSchema
<*> userDisplayName
.= field "name" schema
<*> userTextStatus
.= maybe_ (optField "text_status" schema)
<*> userPict
.= (fromMaybe noPict <$> optField "picture" schema)
<*> userAssets
Expand Down Expand Up @@ -692,6 +699,7 @@ mkUserProfileWithEmail memail u legalHoldStatus =
{ profileQualifiedId = userQualifiedId u,
profileHandle = userHandle u,
profileName = userDisplayName u,
profileTextStatus = userTextStatus u,
profilePict = userPict u,
profileAssets = userAssets u,
profileAccentId = userAccentId u,
Expand Down Expand Up @@ -1368,6 +1376,7 @@ instance ToSchema UserSet where

data UserUpdate = UserUpdate
{ uupName :: Maybe Name,
uupTextStatus :: Maybe TextStatus,
-- | DEPRECATED
uupPict :: Maybe Pict,
uupAssets :: Maybe [Asset],
Expand All @@ -1383,6 +1392,8 @@ instance ToSchema UserUpdate where
UserUpdate
<$> uupName
.= maybe_ (optField "name" schema)
<*> uupTextStatus
.= maybe_ (optField "text_status" schema)
<*> uupPict
.= maybe_ (optField "picture" schema)
<*> uupAssets
Expand Down
22 changes: 22 additions & 0 deletions libs/wire-api/src/Wire/API/User/Profile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
module Wire.API.User.Profile
( Name (..),
mkName,
TextStatus,
mkTextStatus,
fromTextStatus,
ColourId (..),
defaultAccentId,

Expand Down Expand Up @@ -72,6 +75,25 @@ instance ToSchema Name where

deriving instance C.Cql Name

--------------------------------------------------------------------------------
-- TextStatus

-- Length is between 1 and 256 characters.
newtype TextStatus = TextStatus
{fromTextStatus :: Text}
deriving stock (Eq, Ord, Show, Generic)
deriving newtype (FromByteString, ToByteString)
deriving (Arbitrary) via (Ranged 1 256 Text)
deriving (FromJSON, ToJSON, S.ToSchema) via Schema TextStatus

mkTextStatus :: Text -> Either String TextStatus
mkTextStatus txt = TextStatus . fromRange <$> checkedEitherMsg @_ @1 @256 "TextStatus" txt

instance ToSchema TextStatus where
schema = TextStatus <$> fromTextStatus .= untypedRangedSchema 1 256 schema

deriving instance C.Cql TextStatus

--------------------------------------------------------------------------------
-- Colour

Expand Down
4 changes: 4 additions & 0 deletions libs/wire-api/src/Wire/API/UserEvent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ data ClientEvent
data UserUpdatedData = UserUpdatedData
{ eupId :: !UserId,
eupName :: !(Maybe Name),
eupTextStatus :: !(Maybe TextStatus),
-- | DEPRECATED
eupPict :: !(Maybe Pict),
eupAccentId :: !(Maybe ColourId),
Expand Down Expand Up @@ -220,6 +221,7 @@ profileUpdated u UserUpdate {..} =
UserUpdated $
(emptyUserUpdatedData u)
{ eupName = uupName,
eupTextStatus = uupTextStatus,
eupPict = uupPict,
eupAccentId = uupAccentId,
eupAssets = uupAssets
Expand All @@ -233,6 +235,7 @@ emptyUserUpdatedData u =
UserUpdatedData
{ eupId = u,
eupName = Nothing,
eupTextStatus = Nothing,
eupPict = Nothing,
eupAccentId = Nothing,
eupAssets = Nothing,
Expand Down Expand Up @@ -273,6 +276,7 @@ eventObjectSchema =
( UserUpdatedData
<$> eupId .= field "id" schema
<*> eupName .= maybe_ (optField "name" schema)
<*> eupTextStatus .= maybe_ (optField "text_status" schema)
<*> eupPict .= maybe_ (optField "picture" schema) -- DEPRECATED
<*> eupAccentId .= maybe_ (optField "accent_id" schema)
<*> eupAssets .= maybe_ (optField "assets" (array schema))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@

module Test.Wire.API.Golden.Generated.SelfProfile_user where

import Data.Domain (Domain (Domain, _domainText))
import Data.Domain
import Data.Either.Combinators (rightToMaybe)
import Data.Handle
import Data.ISO3166_CountryCodes (CountryCode (PA))
import Data.Id (Id (Id))
import Data.Json.Util (readUTCTimeMillis)
import Data.LanguageCodes qualified (ISO639_1 (GL))
import Data.Qualified (Qualified (Qualified, qDomain, qUnqualified))
import Data.UUID qualified as UUID (fromString)
import Imports (Bool (False), Maybe (Just), fromJust)
import Wire.API.Provider.Service (ServiceRef (ServiceRef, _serviceRefId, _serviceRefProvider))
import Data.ISO3166_CountryCodes
import Data.Id
import Data.Json.Util
import Data.LanguageCodes qualified
import Data.Qualified
import Data.UUID qualified as UUID
import Imports
import Wire.API.Provider.Service
import Wire.API.User

testObject_SelfProfile_user_1 :: SelfProfile
Expand All @@ -44,6 +45,7 @@ testObject_SelfProfile_user_1 =
userIdentity =
Just (EmailIdentity (Email {emailLocal = "\a", emailDomain = ""})),
userDisplayName = Name {fromName = "@\1457\2598\66242\US\1104967l+\137302\&6\996495^\162211Mu\t"},
userTextStatus = rightToMaybe $ mkTextStatus "text status",
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 1},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@

module Test.Wire.API.Golden.Generated.UserProfile_user where

import Data.Domain (Domain (Domain, _domainText))
import Data.Domain
import Data.Either.Combinators
import Data.Handle
import Data.Id (Id (Id))
import Data.Json.Util (readUTCTimeMillis)
import Data.LegalHold (UserLegalHoldStatus (..))
import Data.Qualified (Qualified (Qualified, qDomain, qUnqualified))
import Data.UUID qualified as UUID (fromString)
import Imports (Bool (False, True), Maybe (Just, Nothing), fromJust)
import Wire.API.Provider.Service (ServiceRef (ServiceRef, _serviceRefId, _serviceRefProvider))
import Data.Id
import Data.Json.Util
import Data.LegalHold
import Data.Qualified
import Data.UUID qualified as UUID
import Imports
import Wire.API.Provider.Service
import Wire.API.User

testObject_UserProfile_user_1 :: UserProfile
Expand All @@ -39,6 +40,7 @@ testObject_UserProfile_user_1 =
qDomain = Domain {_domainText = "v.ay64d"}
},
profileName = Name {fromName = "\50534\3354]$\169938\183604UV`\nF\f\23427ys'd\bXy\ENQ:\ESC\139288\RSD[<\132982E"},
profileTextStatus = rightToMaybe $ mkTextStatus "text status",
profilePict = Pict {fromPict = []},
profileAssets = [],
profileAccentId = ColourId {fromColourId = 2},
Expand All @@ -61,6 +63,7 @@ testObject_UserProfile_user_2 =
qDomain = Domain {_domainText = "go.7.w-3r8iy2.a"}
},
profileName = Name {fromName = "si4v\999679\ESC^'\12447k\21889\NAK?\1082547\NULBw;\b3*R/\164149lrI"},
profileTextStatus = Nothing,
profilePict = Pict {fromPict = []},
profileAssets = [],
profileAccentId = ColourId {fromColourId = -1},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,18 @@

module Test.Wire.API.Golden.Generated.UserUpdate_user where

import Data.Id (Id (Id))
import Data.UUID qualified as UUID (fromString)
import Imports (Maybe (Just, Nothing), fromJust)
import Data.Either.Combinators
import Data.Id
import Data.UUID qualified as UUID
import Imports
import Wire.API.Asset
import Wire.API.User
( Asset (ImageAsset),
AssetSize (AssetComplete),
ColourId (ColourId, fromColourId),
Name (Name, fromName),
Pict (Pict, fromPict),
UserUpdate (..),
)

testObject_UserUpdate_user_1 :: UserUpdate
testObject_UserUpdate_user_1 =
UserUpdate
{ uupName = Nothing,
uupTextStatus = Nothing,
uupPict = Nothing,
uupAssets = Nothing,
uupAccentId = Nothing
Expand All @@ -45,6 +40,7 @@ testObject_UserUpdate_user_2 :: UserUpdate
testObject_UserUpdate_user_2 =
UserUpdate
{ uupName = Just (Name {fromName = "~\RSK\1033973w\EMd\156648\59199g"}),
uupTextStatus = rightToMaybe $ mkTextStatus "text status",
uupPict = Just (Pict {fromPict = []}),
uupAssets = Just [ImageAsset (AssetKeyV3 (Id (fromJust (UUID.fromString "5cd81cc4-c643-4e9c-849c-c596a88c27fd"))) AssetExpiring) (Just AssetComplete)],
uupAccentId = Just (ColourId {fromColourId = 3})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
module Test.Wire.API.Golden.Generated.User_user where

import Data.Domain (Domain (Domain, _domainText))
import Data.Either.Combinators (rightToMaybe)
import Data.Handle
import Data.ISO3166_CountryCodes
( CountryCode
Expand Down Expand Up @@ -56,6 +57,7 @@ testObject_User_user_1 =
},
userIdentity = Nothing,
userDisplayName = Name {fromName = "\NULuv\996028su\28209lRi"},
userTextStatus = Nothing,
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 1},
Expand Down Expand Up @@ -83,6 +85,7 @@ testObject_User_user_2 =
{ fromName =
"4\1067195\&7\ACK\DC2\DC2\ETBbp\SOH\40601\&0Yr\\\984611vKRg\1048403)\1040186S\983500\1057766:3B\ACK\DC3\ETXT"
},
userTextStatus = rightToMaybe $ mkTextStatus "text status",
userPict = Pict {fromPict = []},
userAssets =
[ ImageAsset (AssetKeyV3 (Id (fromJust (UUID.fromString "5cd81cc4-c643-4e9c-849c-c596a88c27fd"))) AssetExpiring) Nothing,
Expand Down Expand Up @@ -117,6 +120,7 @@ testObject_User_user_3 =
userIdentity = Just (EmailIdentity (Email {emailLocal = "f", emailDomain = "\83115"})),
userDisplayName =
Name {fromName = ",r\EMXEg0$\98187\RS\SI'uS\ETX/\1009222`\228V.J{\fgE(\rK!\SOp8s9gXO\21810Xj\STX\RS\DC2"},
userTextStatus = Nothing,
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = -2},
Expand Down Expand Up @@ -151,6 +155,7 @@ testObject_User_user_4 =
{ fromName =
"^\1025896F\1083260=&o>f<7\SOq|6\DC1\EM\997351\1054148\ESCf\1014774\170183\DC3bnVAj`^L\f\1047425\USLI\ENQ!\1061384\ETB`\1041537\ETXe\26313\SUBK|"
},
userTextStatus = Nothing,
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 0},
Expand Down Expand Up @@ -186,6 +191,7 @@ testObject_User_user_5 =
{ fromName =
"^\1025896F\1083260=&o>f<7\SOq|6\DC1\EM\997351\1054148\ESCf\1014774\170183\DC3bnVAj`^L\f\1047425\USLI\ENQ!\1061384\ETB`\1041537\ETXe\26313\SUBK|"
},
userTextStatus = Nothing,
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 0},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
module Test.Wire.API.Golden.Manual.ListUsersById where

import Data.Domain
import Data.Either.Combinators (rightToMaybe)
import Data.Id
import Data.LegalHold
import Data.Qualified
Expand All @@ -41,6 +42,7 @@ profile1 =
UserProfile
{ profileQualifiedId = Qualified user1 domain1,
profileName = Name "user1",
profileTextStatus = Nothing,
profilePict = Pict [],
profileAssets = [],
profileAccentId = ColourId 0,
Expand All @@ -57,6 +59,7 @@ profile2 =
UserProfile
{ profileQualifiedId = Qualified user2 domain2,
profileName = Name "user2",
profileTextStatus = rightToMaybe $ mkTextStatus "text status",
profilePict = Pict [],
profileAssets = [],
profileAccentId = ColourId 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ where

import Data.Aeson (toJSON)
import Data.Domain
import Data.Either.Combinators (rightToMaybe)
import Data.ISO3166_CountryCodes
import Data.Id
import Data.Json.Util
Expand Down Expand Up @@ -89,6 +90,7 @@ testObject_UserEvent_6 =
( UserUpdatedData
(userId alice)
(Just alice.userDisplayName)
alice.userTextStatus
(Just alice.userPict)
(Just alice.userAccentId)
(Just alice.userAssets)
Expand Down Expand Up @@ -202,6 +204,7 @@ alice =
},
userIdentity = Nothing,
userDisplayName = Name "alice",
userTextStatus = rightToMaybe $ mkTextStatus "text status",
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 1},
Expand Down Expand Up @@ -229,6 +232,7 @@ bob =
},
userIdentity = Nothing,
userDisplayName = Name "bob",
userTextStatus = rightToMaybe $ mkTextStatus "text status",
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 2},
Expand Down
Loading
Loading