Skip to content

Commit

Permalink
add textStatus to user record
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanwire committed Jul 12, 2024
1 parent 345e1e5 commit e98d199
Show file tree
Hide file tree
Showing 28 changed files with 142 additions and 32 deletions.
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
21 changes: 21 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,8 @@
module Wire.API.User.Profile
( Name (..),
mkName,
TextStatus (..),
mkTextStatus,
ColourId (..),
defaultAccentId,

Expand Down Expand Up @@ -72,6 +74,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,16 @@

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

import Data.Domain (Domain (Domain, _domainText))
import Data.Domain
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 +44,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 = Nothing,
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 1},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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 = Nothing,
profilePict = Pict {fromPict = []},
profileAssets = [],
profileAccentId = ColourId {fromColourId = 2},
Expand All @@ -61,6 +62,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 @@ -24,18 +24,12 @@ import Data.UUID qualified as UUID (fromString)
import Imports (Maybe (Just, Nothing), fromJust)
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 +39,7 @@ testObject_UserUpdate_user_2 :: UserUpdate
testObject_UserUpdate_user_2 =
UserUpdate
{ uupName = Just (Name {fromName = "~\RSK\1033973w\EMd\156648\59199g"}),
uupTextStatus = Just (TextStatus {fromTextStatus = "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 @@ -56,6 +56,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 +84,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 = Nothing,
userPict = Pict {fromPict = []},
userAssets =
[ ImageAsset (AssetKeyV3 (Id (fromJust (UUID.fromString "5cd81cc4-c643-4e9c-849c-c596a88c27fd"))) AssetExpiring) Nothing,
Expand Down Expand Up @@ -117,6 +119,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 +154,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 +190,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 @@ -41,6 +41,7 @@ profile1 =
UserProfile
{ profileQualifiedId = Qualified user1 domain1,
profileName = Name "user1",
profileTextStatus = Nothing,
profilePict = Pict [],
profileAssets = [],
profileAccentId = ColourId 0,
Expand All @@ -57,6 +58,7 @@ profile2 =
UserProfile
{ profileQualifiedId = Qualified user2 domain2,
profileName = Name "user2",
profileTextStatus = Nothing,
profilePict = Pict [],
profileAssets = [],
profileAccentId = ColourId 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,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 +203,7 @@ alice =
},
userIdentity = Nothing,
userDisplayName = Name "alice",
userTextStatus = Nothing,
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 1},
Expand Down Expand Up @@ -229,6 +231,7 @@ bob =
},
userIdentity = Nothing,
userDisplayName = Name "bob",
userTextStatus = Nothing,
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 2},
Expand Down
3 changes: 2 additions & 1 deletion libs/wire-api/test/golden/testObject_UserUpdate_user_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
}
],
"name": "~\u001eK󼛵w\u0019d𦏨g",
"picture": []
"picture": [],
"text_status": "text status"
}
2 changes: 1 addition & 1 deletion libs/wire-api/test/unit/Test/Wire/API/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ testUserProfile = do
uid <- Id <$> UUID.nextRandom
let domain = Domain "example.com"
let colour = ColourId 0
let userProfile = UserProfile (Qualified uid domain) (Name "name") (Pict []) [] colour False Nothing Nothing Nothing Nothing Nothing UserLegalHoldNoConsent defSupportedProtocols
let userProfile = UserProfile (Qualified uid domain) (Name "name") Nothing (Pict []) [] colour False Nothing Nothing Nothing Nothing Nothing UserLegalHoldNoConsent defSupportedProtocols
let profileJSONAsText = show $ Aeson.encode userProfile
let msg = "toJSON encoding must not convert Nothing to null, but instead omit those json fields for backwards compatibility. UserProfileJSON:" <> profileJSONAsText
assertBool msg (not $ "null" `isInfixOf` profileJSONAsText)
Expand Down
2 changes: 2 additions & 0 deletions libs/wire-subsystems/src/Wire/StoredUser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Wire.Arbitrary
data StoredUser = StoredUser
{ id :: UserId,
name :: Name,
textStatus :: Maybe TextStatus,
pict :: Maybe Pict,
email :: Maybe Email,
phone :: Maybe Phone,
Expand Down Expand Up @@ -80,6 +81,7 @@ mkUserFromStored domain defaultLocale storedUser =
{ userQualifiedId = (Qualified storedUser.id domain),
userIdentity = storedUser.identity,
userDisplayName = storedUser.name,
userTextStatus = storedUser.textStatus,
userPict = (fromMaybe noPict storedUser.pict),
userAssets = (fromMaybe [] storedUser.assets),
userAccentId = storedUser.accentId,
Expand Down
3 changes: 2 additions & 1 deletion libs/wire-subsystems/src/Wire/UserStore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Wire.StoredUser
-- | see 'UserProfileUpdate'.
data StoredUserUpdate = MkStoredUserUpdate
{ name :: Maybe Name,
textStatus :: Maybe TextStatus,
pict :: Maybe Pict,
assets :: Maybe [Asset],
accentId :: Maybe ColourId,
Expand All @@ -29,7 +30,7 @@ data StoredUserUpdate = MkStoredUserUpdate
deriving (Arbitrary) via GenericUniform StoredUserUpdate

instance Default StoredUserUpdate where
def = MkStoredUserUpdate Nothing Nothing Nothing Nothing Nothing Nothing
def = MkStoredUserUpdate Nothing Nothing Nothing Nothing Nothing Nothing Nothing

-- | Update user handle (this involves several http requests for locking the required handle).
-- The old/previous handle (for deciding idempotency).
Expand Down
6 changes: 5 additions & 1 deletion libs/wire-subsystems/src/Wire/UserStore/Cassandra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ updateUserImpl uid update =
setType BatchLogged
setConsistency LocalQuorum
for_ update.name \n -> addPrepQuery userDisplayNameUpdate (n, uid)
for_ update.textStatus \s -> addPrepQuery userTextStatusUpdate (s, uid)
for_ update.pict \p -> addPrepQuery userPictUpdate (p, uid)
for_ update.assets \a -> addPrepQuery userAssetsUpdate (a, uid)
for_ update.locale \a -> addPrepQuery userLocaleUpdate (a.lLanguage, a.lCountry, uid)
Expand Down Expand Up @@ -127,14 +128,17 @@ lookupLocaleImpl u = do

selectUser :: PrepQuery R (Identity UserId) (TupleType StoredUser)
selectUser =
"SELECT id, name, picture, email, phone, sso_id, accent_id, assets, \
"SELECT id, name, text_status, picture, email, phone, sso_id, accent_id, assets, \
\activated, status, expires, language, country, provider, service, \
\handle, team, managed_by, supported_protocols \
\FROM user where id = ?"

userDisplayNameUpdate :: PrepQuery W (Name, UserId) ()
userDisplayNameUpdate = "UPDATE user SET name = ? WHERE id = ?"

userTextStatusUpdate :: PrepQuery W (TextStatus, UserId) ()
userTextStatusUpdate = "UPDATE user SET text_status = ? WHERE id = ?"

userPictUpdate :: PrepQuery W (Pict, UserId) ()
userPictUpdate = "UPDATE user SET picture = ? WHERE id = ?"

Expand Down
2 changes: 2 additions & 0 deletions libs/wire-subsystems/src/Wire/UserSubsystem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ data UpdateOriginType
-- operations).
data UserProfileUpdate = MkUserProfileUpdate
{ name :: Maybe Name,
textStatus :: Maybe TextStatus,
pict :: Maybe Pict, -- DEPRECATED
assets :: Maybe [Asset],
accentId :: Maybe ColourId,
Expand All @@ -44,6 +45,7 @@ instance Default UserProfileUpdate where
def =
MkUserProfileUpdate
{ name = Nothing,
textStatus = Nothing,
pict = Nothing, -- DEPRECATED
assets = Nothing,
accentId = Nothing,
Expand Down
2 changes: 2 additions & 0 deletions libs/wire-subsystems/src/Wire/UserSubsystem/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ storedUserUpdate :: UserProfileUpdate -> StoredUserUpdate
storedUserUpdate update =
MkStoredUserUpdate
{ name = update.name,
textStatus = update.textStatus,
pict = update.pict,
assets = update.assets,
accentId = update.accentId,
Expand All @@ -388,6 +389,7 @@ mkProfileUpdateEvent uid update =
UserUpdated $
(emptyUserUpdatedData uid)
{ eupName = update.name,
eupTextStatus = update.textStatus,
eupPict = update.pict,
eupAccentId = update.accentId,
eupAssets = update.assets,
Expand Down
Loading

0 comments on commit e98d199

Please sign in to comment.