diff --git a/src/Simplex/Chat/Operators.hs b/src/Simplex/Chat/Operators.hs index c55578256f..3775383f9b 100644 --- a/src/Simplex/Chat/Operators.hs +++ b/src/Simplex/Chat/Operators.hs @@ -62,7 +62,7 @@ import Simplex.Messaging.Util (atomicModifyIORef'_, safeDecodeUtf8) -- Change the conditions only in a release whose What's new announces the change: -- the apps show changed conditions as a link in What's new, also in a release without other news. -- The notice is recorded when What's new is shown, and the conditions are accepted automatically --- 31 days later, if the notice was shown within 14 days after the app added the conditions to the database. +-- 31 days later. usageConditionsCommit :: Text usageConditionsCommit = "5cb85b913989aa4dc618a0a47ffb9a758e44f375" @@ -119,7 +119,7 @@ data ServerOperatorConditions = ServerOperatorConditions deriving (Show) usageConditionsAction :: [ServerOperator] -> UsageConditions -> UTCTime -> Maybe UsageConditionsAction -usageConditionsAction operators UsageConditions {createdAt, notifiedAt} now = do +usageConditionsAction operators UsageConditions {notifiedAt} now = do let enabledOperators = filter (\ServerOperator {enabled} -> enabled) operators if | null enabledOperators -> Nothing @@ -128,18 +128,12 @@ usageConditionsAction operators UsageConditions {createdAt, notifiedAt} now = do in Just $ UCAAccepted acceptedForOperators | otherwise -> let acceptForOperators = filter (not . conditionsAccepted) enabledOperators - deadline = conditionsRequiredOrDeadline createdAt (fromMaybe now notifiedAt) + deadline = Just $ conditionsDeadline (fromMaybe now notifiedAt) showNotice = isNothing notifiedAt in Just $ UCAReview acceptForOperators deadline showNotice -conditionsRequiredOrDeadline :: UTCTime -> UTCTime -> Maybe UTCTime -conditionsRequiredOrDeadline createdAt notifiedAtOrNow = - if notifiedAtOrNow < addUTCTime (14 * nominalDay) createdAt - then Just $ conditionsDeadline notifiedAtOrNow - else Nothing -- required - where - conditionsDeadline :: UTCTime -> UTCTime - conditionsDeadline = addUTCTime (31 * nominalDay) +conditionsDeadline :: UTCTime -> UTCTime +conditionsDeadline = addUTCTime (31 * nominalDay) data ConditionsAcceptance = CAAccepted {acceptedAt :: Maybe UTCTime, autoAccepted :: Bool} diff --git a/src/Simplex/Chat/Store/Profiles.hs b/src/Simplex/Chat/Store/Profiles.hs index fcb74edbdf..e607d04fb7 100644 --- a/src/Simplex/Chat/Store/Profiles.hs +++ b/src/Simplex/Chat/Store/Profiles.hs @@ -899,7 +899,7 @@ toServerOperator ((operatorId, operatorTag, tradeName, legalName, domains, BI en serverRolesXFTP (BI storage, BI proxy) = ServerRoles {storage, proxy, names = False} getOperatorConditions_ :: DB.Connection -> ServerOperator -> UsageConditions -> Maybe UsageConditions -> UTCTime -> IO ConditionsAcceptance -getOperatorConditions_ db ServerOperator {operatorId} UsageConditions {conditionsCommit = currentCommit, createdAt, notifiedAt} latestAcceptedConds_ now = do +getOperatorConditions_ db ServerOperator {operatorId} UsageConditions {conditionsCommit = currentCommit, notifiedAt} latestAcceptedConds_ now = do case latestAcceptedConds_ of Nothing -> pure $ CARequired Nothing -- no conditions accepted by any operator Just UsageConditions {conditionsCommit = latestAcceptedCommit} -> do @@ -918,7 +918,7 @@ getOperatorConditions_ db ServerOperator {operatorId} UsageConditions {condition pure $ case operatorAcceptedConds_ of Just (operatorCommit, acceptedAt_, BI autoAccept) | operatorCommit /= latestAcceptedCommit -> CARequired Nothing -- TODO should we consider this operator disabled? - | currentCommit /= latestAcceptedCommit -> CARequired $ conditionsRequiredOrDeadline createdAt (fromMaybe now notifiedAt) + | currentCommit /= latestAcceptedCommit -> CARequired $ Just $ conditionsDeadline (fromMaybe now notifiedAt) | otherwise -> CAAccepted acceptedAt_ autoAccept _ -> CARequired Nothing -- no conditions were accepted for this operator diff --git a/tests/OperatorTests.hs b/tests/OperatorTests.hs index c7ce5e8206..c8956775bf 100644 --- a/tests/OperatorTests.hs +++ b/tests/OperatorTests.hs @@ -16,6 +16,8 @@ module OperatorTests (operatorTests) where import Data.Bifunctor (second) import qualified Data.List.NonEmpty as L +import Data.Time.Calendar (fromGregorian) +import Data.Time.Clock (UTCTime (..), addUTCTime, nominalDay) import Simplex.Chat import Simplex.Chat.Controller (ChatConfig (..), PresetServers (..)) import Simplex.Chat.Operators @@ -34,6 +36,17 @@ operatorTests = describe "managing server operators" $ do validateServersTest updatedServersTest perServerRolesTest + conditionsDeadlineTest + +conditionsDeadlineTest :: Spec +conditionsDeadlineTest = describe "usage conditions deadline" $ + it "should set the deadline 31 days after the notice, also after a late notice" $ do + let created = UTCTime (fromGregorian 2026 11 1) 0 + notified = addUTCTime (20 * nominalDay) created + conditions = UsageConditions {conditionsId = 2, conditionsCommit = usageConditionsCommit, notifiedAt = Just notified, createdAt = created} + case usageConditionsAction [operatorSimpleXChat {operatorId = DBEntityId 1}] conditions (addUTCTime nominalDay notified) of + Just UCAReview {deadline} -> deadline `shouldBe` Just (addUTCTime (31 * nominalDay) notified) + action -> expectationFailure $ show action validateServersTest :: Spec validateServersTest = describe "validate user servers" $ do