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

UNIFY SIMPLEX to NOSTR #1

Merged
merged 180 commits into from
Dec 9, 2024
Merged
Changes from 1 commit
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
78510b6
core, ios: get messages for multiple last notifications; separately g…
spaced4ndy Oct 25, 2024
37b78ed
ios: move Network and servers settings modules to folder (#5110)
spaced4ndy Oct 28, 2024
24090fe
android, desktop: update to Compose 1.7.0 (#5038)
avently Oct 31, 2024
4162bcc
multiplatform: edge to edge design (#5051)
avently Oct 31, 2024
3c8c9d8
website: update jobs page
epoberezkin Nov 2, 2024
ceb17b2
bumped haskell.nix (#5134)
epoberezkin Nov 2, 2024
165143a
Use simplexmq with client_library flag (#5133)
dpwiz Nov 2, 2024
7a741e7
ios: update core library
epoberezkin Nov 2, 2024
9a1166f
Merge branch 'master' into server-operators
epoberezkin Nov 3, 2024
97df069
core: add support for server operators (#4961)
epoberezkin Nov 4, 2024
bdaec30
core: getServerOperators, getUserServers, getUsageConditions apis wip…
spaced4ndy Nov 4, 2024
3b0205b
core: setServerOperators, getUsageConditions api wip (#5145)
spaced4ndy Nov 5, 2024
2da89c2
core: setConditionsNotified, acceptConditions, setUserServers, valida…
spaced4ndy Nov 5, 2024
8396e70
core: validate servers - find servers with duplicate hosts (#5150)
spaced4ndy Nov 6, 2024
ef0f21a
core: operator apis commands (#5155)
spaced4ndy Nov 8, 2024
2d58894
directory service: additional commands (#5159)
epoberezkin Nov 10, 2024
457e128
Merge branch 'master' into server-operators
epoberezkin Nov 10, 2024
8af5453
docs: add control port section (#5164)
shumvgolove Nov 12, 2024
15bac88
desktop, android: user profiles move auth to change actions, show unr…
diogofcunha Nov 13, 2024
60c37f0
ios: user profiles move auth to change actions, show unread counts (#…
diogofcunha Nov 13, 2024
4d82209
core: pagination API to load items around defined or the earliest unr…
diogofcunha Nov 14, 2024
a5061f3
docs: update privacy policy and conditions of use (#5129)
epoberezkin Nov 14, 2024
e45a969
ci: update website build
epoberezkin Nov 14, 2024
807f698
Merge branch 'master' into server-operators
epoberezkin Nov 14, 2024
d42cab8
core: preset operators and servers (#5142)
epoberezkin Nov 14, 2024
1fbf21d
core: validate servers of all user profiles (#5180)
epoberezkin Nov 15, 2024
ff8e29c
core: fix accept conditions query (#5187)
spaced4ndy Nov 15, 2024
feb687d
core: different roles for different protocols (#5185)
epoberezkin Nov 15, 2024
b605ebf
core: remove comments
epoberezkin Nov 15, 2024
6843269
core: 6.2.0.0 (simplexmq: 6.2.0.3)
epoberezkin Nov 17, 2024
a17bfc5
Merge branch 'master' into server-operators
epoberezkin Nov 17, 2024
e645dd9
6.2-beta.0: ios 246, android 251, desktop 75
epoberezkin Nov 17, 2024
feb4ecb
Merge branch 'master' into server-operators
epoberezkin Nov 18, 2024
d1ae3ba
desktop, android: add address card to chat list and remove address fr…
diogofcunha Nov 18, 2024
3d4a47c
Merge branch 'master' into server-operators
epoberezkin Nov 18, 2024
6199857
core: use random servers for each operator (#5192)
epoberezkin Nov 18, 2024
fcae5e9
core: fix validation of operator servers for non current users (#5205)
spaced4ndy Nov 18, 2024
70a2951
ios: server operators ui (#5114)
spaced4ndy Nov 19, 2024
4b9c618
core: remove a separate type to validate servers with invalid address…
epoberezkin Nov 19, 2024
181f72f
ios: texts about operators (#5213)
epoberezkin Nov 19, 2024
58c92ed
ios: rework existing users notice, condition views (#5214)
spaced4ndy Nov 19, 2024
4e37efd
core: update agent servers (#5215)
epoberezkin Nov 20, 2024
e5534c0
ios: improve onboarding animations (#5216)
spaced4ndy Nov 20, 2024
313acef
ios: remove crashing accept button (#5217)
spaced4ndy Nov 20, 2024
29b54ec
ios: rework saving settings (#5219)
spaced4ndy Nov 20, 2024
f3cef7c
ios: remove unused type
spaced4ndy Nov 20, 2024
2b155db
android, desktop: open chat on first unread, "scroll" to quoted items…
avently Nov 20, 2024
927a04d
Merge branch 'master' into server-operators
epoberezkin Nov 20, 2024
522f99a
directory service: notify admins about group registration events (#5223)
epoberezkin Nov 20, 2024
61d7df8
ui: always use private routing by default
epoberezkin Nov 21, 2024
78b3b12
ios: button to open conditions and changes (#5225)
epoberezkin Nov 21, 2024
1083a07
flatpak: update metainfo (#5146)
shumvgolove Nov 22, 2024
bab63d8
ios: fix repeatedly showing updated conditions
spaced4ndy Nov 22, 2024
49d1b26
core: tests for operators api, CLI command to update operators (#5226)
epoberezkin Nov 22, 2024
ea9ee98
android, desktop: better message info screen (#5227)
avently Nov 22, 2024
396fa7f
desktop, android: server operators (#5212)
diogofcunha Nov 22, 2024
b517068
android: fix single operator conditions paddings
spaced4ndy Nov 22, 2024
2adfa0c
android: information icon right of operator logo
spaced4ndy Nov 22, 2024
bff2d7d
android, desktop: highlight quoted messaged on click to scroll to it …
avently Nov 22, 2024
494ef6e
Merge branch 'master' into server-operators
epoberezkin Nov 22, 2024
e47b16f
android: improve layout of operator logo
spaced4ndy Nov 22, 2024
a6f5ba5
android, desktop: smaller info icon, corrections
epoberezkin Nov 22, 2024
76aedb4
core: update simplexmq
epoberezkin Nov 22, 2024
9b71702
ios: move onboarding action cards, paddings (#5231)
epoberezkin Nov 22, 2024
4f640c9
build: use openssl 3.0 (#5183)
epoberezkin Nov 22, 2024
2f0fe50
Merge pull request #5111 from simplex-chat/server-operators
epoberezkin Nov 22, 2024
bda84b0
ci: fix mac & Windows build (#5232)
avently Nov 23, 2024
7bcb514
core: 6.2.0.1 (simplexmq: 6.2.0.4)
epoberezkin Nov 23, 2024
30a24df
ui: update whats new link (#5234)
epoberezkin Nov 23, 2024
909edac
desktop: unsaved changes popup for network and servers when clicking …
diogofcunha Nov 23, 2024
6581e27
6.2-beta.1: ios 247, android 252, desktop 76
epoberezkin Nov 23, 2024
d40d690
desktop (Windows): fix linking with openssl 3 (#5238)
avently Nov 24, 2024
97b472f
blog: operators (#5240)
epoberezkin Nov 25, 2024
e5c83b2
android, desktop: fix operator disabled indication (#5242)
spaced4ndy Nov 25, 2024
cfc21df
ios: address or 1-time link (#5246)
epoberezkin Nov 25, 2024
d912fe0
core: fix pagination indexes (#5241)
spaced4ndy Nov 25, 2024
7a91ed2
android, desktop: view conditions as markdown (#5247)
avently Nov 25, 2024
1f04984
ios: offer to create 1-time link on address views (#5249)
spaced4ndy Nov 26, 2024
345e0ac
ios: onboarding redesign (#5252)
diogofcunha Nov 26, 2024
2589317
ios: view conditions as markdown (#5248)
avently Nov 26, 2024
8c1abcc
android, desktop: scroll to quoted item without known id (#5254)
avently Nov 26, 2024
15fae29
android, desktop: offer to create 1-time link on address views (#5253)
spaced4ndy Nov 27, 2024
41b7ad0
core: apiGetReactionMembers (#5258)
spaced4ndy Nov 27, 2024
9fa968a
ui: fix marking chat read (don't use range api) (#5257)
spaced4ndy Nov 27, 2024
b512d3a
Merge branch 'master' into reaction-members
spaced4ndy Nov 27, 2024
ba7abcf
ios: update onboarding texts (#5255)
epoberezkin Nov 27, 2024
22d7db8
ios: database error screens redesign (#5256)
diogofcunha Nov 27, 2024
d19708e
Merge branch 'master' into reaction-members
diogofcunha Nov 27, 2024
096dec2
ui: translations (#5264)
epoberezkin Nov 27, 2024
6148464
website: translations (#5266)
epoberezkin Nov 27, 2024
c3991aa
website: translations corrections
epoberezkin Nov 28, 2024
13efdf2
core: apiGetReactionMembers api implementation (#5263)
spaced4ndy Nov 28, 2024
68be4b4
core: return member records from apiGetReactionMembers (#5270)
spaced4ndy Nov 28, 2024
9c6e0a7
desktop: fix avatar crop (#5271)
spaced4ndy Nov 28, 2024
9915e55
desktop, android: show group reactions (#5277)
diogofcunha Nov 29, 2024
b0f3f0a
ios: fix alignment on operators review later button and notice (#5280)
diogofcunha Nov 29, 2024
80bd4cd
Merge branch 'master' into reaction-members
epoberezkin Nov 29, 2024
03bc4e5
ios: display reactions in groups by member (#5265)
diogofcunha Nov 30, 2024
879c117
Merge pull request #5259 from simplex-chat/reaction-members
epoberezkin Nov 30, 2024
961bdbf
ios: start/stop chat toggle refactoring (#5275)
avently Nov 30, 2024
4738286
android, desktop: start/stop chat toggle refactoring (#5261)
avently Nov 30, 2024
e9853fe
ios: update alert message for SimpleX address card
epoberezkin Nov 30, 2024
94377d0
android, desktop: bottom bar and update texts in onboarding (#5279)
diogofcunha Nov 30, 2024
2c0de36
ios: large Conditions screen heading during onboarding
epoberezkin Nov 30, 2024
a9e7635
core: disable Flux XFTP servers to prevent unknown server warning for…
epoberezkin Nov 30, 2024
79d5573
cli: fix option --yes-migrate to confirm up migrations automatically,…
epoberezkin Nov 30, 2024
8f32c6a
core: 6.2.0.2
epoberezkin Nov 30, 2024
98a3437
6.2-beta.2: ios 248, android 253, desktop 77
epoberezkin Nov 30, 2024
b8442d9
core: improve performance of marking chat items as read (#5290)
epoberezkin Dec 1, 2024
3143cc9
core: 6.2.0.3
epoberezkin Dec 1, 2024
c488c4f
6.2-beta.3: ios 249, android 254, desktop 78
epoberezkin Dec 1, 2024
5f01dc1
core: support business addresses and chats (#5272)
epoberezkin Dec 2, 2024
5a59fdd
android, desktop: fix Can't represent a width ... and a height ... in…
avently Dec 2, 2024
f6b611a
android, desktop: check existence before deleting database (#5298)
avently Dec 2, 2024
a62ce91
core: fix names created for business request group and member (#5296)
spaced4ndy Dec 2, 2024
6655010
android: show info for Xiaomi users about autostart restrictions (#5295)
avently Dec 2, 2024
a588e70
android: alert round corners (#5299)
avently Dec 2, 2024
bc96000
ios: support business addresses and chats (#5300)
spaced4ndy Dec 2, 2024
92967df
ios: disable autocorrect add group member search (#5301)
diogofcunha Dec 2, 2024
c04e952
desktop: onboarding improvements (#5294)
diogofcunha Dec 2, 2024
e61babd
android, desktop: preserving long message when failed to send (#5297)
avently Dec 2, 2024
9d99273
core, ios: improve business address (connection plan, repeat requests…
epoberezkin Dec 3, 2024
85e7a13
desktop: show group message reaction on right click (#5304)
diogofcunha Dec 3, 2024
43fa4c4
docs: update FAQ (#5179)
Narasimha-sc Dec 3, 2024
a0b8cf6
android, desktop: support business addresses and chats (#5302)
spaced4ndy Dec 3, 2024
29b9abf
ui: translations (#5267)
epoberezkin Dec 3, 2024
a1e2562
website: translations (#5306)
epoberezkin Dec 3, 2024
6593de8
ios: make more texts different for groups and business chats (#5307)
spaced4ndy Dec 3, 2024
247d12f
android, desktop: make more texts different for groups and business c…
spaced4ndy Dec 3, 2024
a182cf5
ui, site: v6.2 whats new, business (#5309)
epoberezkin Dec 3, 2024
f3be723
ios: export localizations
epoberezkin Dec 3, 2024
b9777c9
core: 6.2.0.4 (simplexmq: 6.2.0.5)
epoberezkin Dec 3, 2024
3acc69c
6.2-beta.4: ios 250, android 255, desktop 79
epoberezkin Dec 3, 2024
6ff7d4a
core: fix business chat state on accept (fixes icon) (#5312)
spaced4ndy Dec 4, 2024
4f1cf6e
docs: business page, technical advice (#5314)
shumvgolove Dec 4, 2024
89f3804
core: update business chat profile (#5313)
epoberezkin Dec 4, 2024
219381f
android, desktop: don't load new messages when pressing quote while …
avently Dec 4, 2024
ee146cd
android, desktop, core: option to show toolbar in chat at the top in …
avently Dec 4, 2024
3fa1d7b
core: fix cli servers override (#5317)
spaced4ndy Dec 4, 2024
892f649
ios: fix contact cards opening empty page on connection 2 (#5319)
spaced4ndy Dec 4, 2024
009d132
android: fix simplex chat team contact card opening empty page on con…
spaced4ndy Dec 4, 2024
c1c17d1
core: 6.2.0.5 (simplexmq: 6.2.0.6)
epoberezkin Dec 4, 2024
c1a0943
6.2-beta.5: ios 251, android 256, desktop 80
epoberezkin Dec 4, 2024
4f8a70a
android, desktop: allow to scan QR multiple times after fail (#5323)
avently Dec 5, 2024
97cd268
core: take address lock before reading contact request data (to preve…
spaced4ndy Dec 5, 2024
5f66c29
ios: fix open from notification and connected directly chat item chat…
diogofcunha Dec 5, 2024
de76e27
android, desktop: displaying deleted message with file in chat list (…
avently Dec 5, 2024
60e0e45
core: only update business chat preferences (#5325)
epoberezkin Dec 5, 2024
e9bf229
core: 6.2.0.6
epoberezkin Dec 5, 2024
69e23ad
android, desktop: don't show unwanted notifications (#5328)
spaced4ndy Dec 5, 2024
ff50470
ui: translations (#5330)
epoberezkin Dec 5, 2024
586671c
website: translations (#5331)
epoberezkin Dec 5, 2024
bd2ca74
ui: update "server operators privacy" in onboarding
epoberezkin Dec 5, 2024
886dc56
ui: update business chat info type
epoberezkin Dec 5, 2024
5ef14ca
6.2-beta.6: ios 253, android 258, desktop 81
epoberezkin Dec 5, 2024
19e2ceb
android, desktop: remove footer in Run chat section when chat is running
epoberezkin Dec 6, 2024
9b82cc3
core: fix feature items when updating preferences in business chats
epoberezkin Dec 6, 2024
9242731
ios: ask for confirmation of save on group preferences sheet dismiss …
diogofcunha Dec 6, 2024
2e431c5
ios: fix some real time updates in group members (#5332)
diogofcunha Dec 6, 2024
945c501
ui: improve pending connection texts (#5333)
spaced4ndy Dec 6, 2024
f408988
ios: fix oneHandUI setting becoming enabled on import (#5335)
spaced4ndy Dec 6, 2024
1408d75
ios: use async getServerOperators api (#5334)
spaced4ndy Dec 6, 2024
ae8ad5c
ios: operators info on onboarding (#5336)
spaced4ndy Dec 6, 2024
7d43a43
ios: ask for confirmation of save on contact preferences sheet dismis…
diogofcunha Dec 6, 2024
df1a471
ios: remove all unsafe warnings in group preferences save (#5340)
diogofcunha Dec 6, 2024
3625814
ios: export localizations, add translations (#5339)
spaced4ndy Dec 6, 2024
e0c2272
android, desktop: operators info on onboarding (#5341)
spaced4ndy Dec 6, 2024
615c483
android: onboarding small design adjustments (#5346)
diogofcunha Dec 7, 2024
83f0bd9
android, desktop: onboarding button multiline layout (#5348)
avently Dec 7, 2024
cbb3da8
core: 6.2.0.7 (simplexmq: 6.2.0.7)
epoberezkin Dec 7, 2024
fe0d811
ui: operator information (#5343)
epoberezkin Dec 7, 2024
ea4927c
core: 6.2.0.7 updated version
epoberezkin Dec 7, 2024
93319d9
website: translations (#5350)
epoberezkin Dec 7, 2024
7d6c7c5
ui: translations (#5338)
epoberezkin Dec 7, 2024
307211a
android, desktop: landscape calls on Android and better local camera …
avently Dec 7, 2024
7c86484
ios: update library
epoberezkin Dec 7, 2024
df30bb9
ui: add translations
epoberezkin Dec 7, 2024
f0781ad
desktop: fix opening operators on onboarding (#5351)
spaced4ndy Dec 7, 2024
febea09
android, desktop: remove duplicate translation key
epoberezkin Dec 7, 2024
33bc539
6.2: ios 254, android 259, desktop 82
epoberezkin Dec 7, 2024
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
Prev Previous commit
Next Next commit
core: getServerOperators, getUserServers, getUsageConditions apis wip (
spaced4ndy authored Nov 4, 2024
commit bdaec30fa084e4c18964035d432abc42a55288a7
31 changes: 17 additions & 14 deletions src/Simplex/Chat.hs
Original file line number Diff line number Diff line change
@@ -1489,8 +1489,7 @@ processChatCommand' vr = \case
APIGetUserProtoServers userId (AProtocolType p) -> withUserId userId $ \user -> withServerProtocol p $ do
cfg@ChatConfig {defaultServers} <- asks config
srvs <- withFastStore' (`getProtocolServers` user)
ts <- liftIO getCurrentTime
operators <- withFastStore' $ \db -> getServerOperators db ts
operators <- withFastStore $ \db -> getServerOperators db
let servers = AUPS $ UserProtoServers p (useServers cfg p srvs) (cfgServers p defaultServers)
pure $ CRUserProtoServers {user, servers, operators}
GetUserProtoServers aProtocol -> withUser $ \User {userId} ->
@@ -1508,27 +1507,31 @@ processChatCommand' vr = \case
lift $ CRServerTestResult user srv <$> withAgent' (\a -> testProtocolServer a (aUserId user) server)
TestProtoServer srv -> withUser $ \User {userId} ->
processChatCommand $ APITestProtoServer userId srv
APIGetServerOperators -> pure $ chatCmdError Nothing "not supported"
APIGetServerOperators -> do
operators <- withFastStore $ \db -> getServerOperators db
let conditionsAction = usageConditionsAction operators
pure $ CRServerOperators operators conditionsAction
APISetServerOperators _operators -> pure $ chatCmdError Nothing "not supported"
APIGetUserServers userId -> withUserId userId $ \user ->
pure $ chatCmdError (Just user) "not supported"
APIGetUserServers userId -> withUserId userId $ \user -> do
(operators, smpServers, xftpServers) <- withFastStore $ \db -> do
operators <- getServerOperators db
smpServers <- liftIO $ getServers db user SPSMP
xftpServers <- liftIO $ getServers db user SPXFTP
pure (operators, smpServers, xftpServers)
let userServers = groupByOperator operators smpServers xftpServers
pure $ CRUserServers user userServers
where
getServers :: (ProtocolTypeI p) => DB.Connection -> User -> SProtocolType p -> IO [ServerCfg p]
getServers db user _p = getProtocolServers db user
APISetUserServers userId _userServers -> withUserId userId $ \user ->
pure $ chatCmdError (Just user) "not supported"
APIValidateServers _userServers ->
-- response is CRUserServersValidation
pure $ chatCmdError Nothing "not supported"
APIGetUsageConditions -> do
usageConditions <- withFastStore $ \db -> getCurrentUsageConditions db
-- TODO
-- get current conditions
-- get latest accepted conditions (from operators)
ts <- liftIO getCurrentTime
let usageConditions =
UsageConditions
{ conditionsId = 1,
conditionsCommit = "abc",
notifiedAt = Nothing,
createdAt = ts
}
pure
CRUsageConditions
{ usageConditions = usageConditions,
2 changes: 1 addition & 1 deletion src/Simplex/Chat/Controller.hs
Original file line number Diff line number Diff line change
@@ -589,7 +589,7 @@ data ChatResponse
| CRUserProtoServers {user :: User, servers :: AUserProtoServers, operators :: [ServerOperator]}
| CRServerTestResult {user :: User, testServer :: AProtoServerWithAuth, testFailure :: Maybe ProtocolTestFailure}
| CRServerOperators {operators :: [ServerOperator], conditionsAction :: UsageConditionsAction}
| CRUserServers {userServers :: [UserServers]}
| CRUserServers {user :: User, userServers :: [UserServers]}
| CRUserServersValidation {serverErrors :: [UserServersError]}
| CRUsageConditions {usageConditions :: UsageConditions, conditionsText :: Text, acceptedConditions :: Maybe UsageConditions}
| CRChatItemTTL {user :: User, chatItemTTL :: Maybe Int64}
38 changes: 30 additions & 8 deletions src/Simplex/Chat/Operators.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

@@ -12,18 +13,20 @@ import qualified Data.Aeson.Encoding as JE
import qualified Data.Aeson.TH as JQ
import Data.FileEmbed
import Data.Int (Int64)
import Data.List.NonEmpty (NonEmpty)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import Data.Time.Clock (UTCTime)
import Database.SQLite.Simple.FromField (FromField (..))
import Database.SQLite.Simple.ToField (ToField (..))
import Language.Haskell.TH.Syntax (lift)
import Simplex.Chat.Operators.Conditions
import Simplex.Chat.Types.Util (textParseJSON)
import Simplex.Messaging.Agent.Env.SQLite (OperatorId, ServerRoles)
import Simplex.Messaging.Agent.Env.SQLite (OperatorId, ServerCfg (..), ServerRoles)
import Simplex.Messaging.Encoding.String
import Simplex.Messaging.Parsers (defaultJSON, dropPrefix, fromTextField_, sumTypeJSON)
import Simplex.Messaging.Protocol (ProtoServerWithAuth, ProtocolType (..))
import Simplex.Messaging.Protocol (ProtocolType (..))
import Simplex.Messaging.Util (safeDecodeUtf8)

usageConditionsCommit :: Text
@@ -72,8 +75,8 @@ data UsageConditionsAction
deriving (Show)

-- TODO UI logic
usageConditionsAction :: UsageConditionsAction
usageConditionsAction = UCAAccepted []
usageConditionsAction :: [ServerOperator] -> UsageConditionsAction
usageConditionsAction _operators = UCAAccepted []

data ConditionsAcceptance
= CAAccepted {acceptedAt :: UTCTime}
@@ -93,12 +96,31 @@ data ServerOperator = ServerOperator
deriving (Show)

data UserServers = UserServers
{ operator :: ServerOperator,
smpServers :: NonEmpty (ProtoServerWithAuth 'PSMP),
xftpServers :: NonEmpty (ProtoServerWithAuth 'PXFTP)
{ operator :: Maybe ServerOperator,
smpServers :: [ServerCfg 'PSMP],
xftpServers :: [ServerCfg 'PXFTP]
}
deriving (Show)

groupByOperator :: [ServerOperator] -> [ServerCfg 'PSMP] -> [ServerCfg 'PXFTP] -> [UserServers]
groupByOperator srvOperators smpSrvs xftpSrvs =
map createOperatorServers (M.toList combinedMap)
where
srvOperatorId :: ServerCfg p -> Maybe Int64
srvOperatorId ServerCfg {operator} = operator
operatorMap :: Map (Maybe Int64) (Maybe ServerOperator)
operatorMap = M.fromList [(Just (operatorId op), Just op) | op <- srvOperators] `M.union` M.singleton Nothing Nothing
initialMap :: Map (Maybe Int64) ([ServerCfg 'PSMP], [ServerCfg 'PXFTP])
initialMap = M.fromList [(key, ([], [])) | key <- M.keys operatorMap]
smpsMap = foldr (\server acc -> M.adjust (\(smps, xftps) -> (server : smps, xftps)) (srvOperatorId server) acc) initialMap smpSrvs
combinedMap = foldr (\server acc -> M.adjust (\(smps, xftps) -> (smps, server : xftps)) (srvOperatorId server) acc) smpsMap xftpSrvs
createOperatorServers (key, (groupedSmps, groupedXftps)) =
UserServers
{ operator = fromMaybe Nothing (M.lookup key operatorMap),
smpServers = groupedSmps,
xftpServers = groupedXftps
}

$(JQ.deriveJSON defaultJSON ''UsageConditions)

$(JQ.deriveJSON (sumTypeJSON $ dropPrefix "CA") ''ConditionsAcceptance)
71 changes: 57 additions & 14 deletions src/Simplex/Chat/Store/Profiles.hs
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ module Simplex.Chat.Store.Profiles
-- overwriteOperatorsAndServers,
overwriteProtocolServers,
getServerOperators,
getCurrentUsageConditions,
createCall,
deleteCalls,
getCalls,
@@ -73,7 +74,8 @@ import qualified Data.List.NonEmpty as L
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import Data.Text.Encoding (decodeLatin1, encodeUtf8)
import Data.Time.Clock (UTCTime (..), getCurrentTime)
import Data.Time (addUTCTime)
import Data.Time.Clock (UTCTime (..), getCurrentTime, nominalDay)
import Database.SQLite.Simple (NamedParam (..), Only (..), (:.) (..))
import Database.SQLite.Simple.QQ (sql)
import Simplex.Chat.Call
@@ -540,7 +542,7 @@ getProtocolServers db User {userId} =

-- overwriteOperatorsAndServers :: forall p. ProtocolTypeI p => DB.Connection -> User -> Maybe [ServerOperator] -> [ServerCfg p] -> ExceptT StoreError IO [ServerCfg p]
-- overwriteOperatorsAndServers db user@User {userId} operators_ servers = do
overwriteProtocolServers :: forall p. ProtocolTypeI p => DB.Connection -> User -> [ServerCfg p] -> ExceptT StoreError IO ()
overwriteProtocolServers :: forall p. ProtocolTypeI p => DB.Connection -> User -> [ServerCfg p] -> ExceptT StoreError IO ()
overwriteProtocolServers db User {userId} servers =
-- liftIO $ mapM_ (updateServerOperators_ db) operators_
checkConstraint SEUniqueID . ExceptT $ do
@@ -556,25 +558,66 @@ overwriteProtocolServers db User {userId} servers =
VALUES (?,?,?,?,?,?,?,?,?,?,?)
|]
((protocol, host, port, keyHash, safeDecodeUtf8 . unBasicAuth <$> auth_) :. (preset, tested, enabled, userId, currentTs, currentTs))
pure $ Right ()
-- Right <$> getProtocolServers db user
pure $ Right ()
where
protocol = decodeLatin1 $ strEncode $ protocolTypeI @p

getServerOperators :: DB.Connection -> UTCTime -> IO [ServerOperator]
getServerOperators db ts =
map toOperator
<$> DB.query_
getServerOperators :: DB.Connection -> ExceptT StoreError IO [ServerOperator]
getServerOperators db = do
conditions <- getCurrentUsageConditions db
liftIO $
map (toOperator conditions)
<$> DB.query_
db
[sql|
SELECT
so.server_operator_id, so.server_operator_tag, so.trade_name, so.legal_name,
so.server_domains, so.enabled, so.role_storage, so.role_proxy,
LastOperatorConditions.conditions_commit, LastOperatorConditions.accepted_at
FROM server_operators so
LEFT JOIN (
SELECT server_operator_id, conditions_commit, accepted_at, MAX(operator_usage_conditions_id)
FROM operator_usage_conditions
GROUP BY server_operator_id
) LastOperatorConditions ON LastOperatorConditions.server_operator_id = so.server_operator_id
|]
where
toOperator ::
UsageConditions ->
( (OperatorId, Maybe OperatorTag, Text, Maybe Text, Text, Bool, Bool, Bool)
:. (Maybe Text, Maybe UTCTime)
) ->
ServerOperator
toOperator
UsageConditions {conditionsCommit, createdAt}
( (operatorId, operatorTag, tradeName, legalName, domains, enabled, storage, proxy)
:. (operatorConditionsCommit_, acceptedAt_)
) =
let roles = ServerRoles {storage, proxy}
acceptedConditions = case (operatorConditionsCommit_, acceptedAt_) of
(Nothing, _) -> CARequired Nothing
(Just operatorConditionsCommit, Just acceptedAt)
| conditionsCommit == operatorConditionsCommit -> CAAccepted acceptedAt
_ -> CARequired (Just $ conditionsDeadline createdAt)
in ServerOperator {operatorId, operatorTag, tradeName, legalName, serverDomains = [domains], acceptedConditions, enabled, roles}
conditionsDeadline :: UTCTime -> UTCTime
conditionsDeadline = addUTCTime (31 * nominalDay)

getCurrentUsageConditions :: DB.Connection -> ExceptT StoreError IO UsageConditions
getCurrentUsageConditions db =
ExceptT . firstRow toUsageConditions SEUsageConditionsNotFound $
DB.query_
db
[sql|
SELECT server_operator_id, server_operator_tag, trade_name, legal_name, server_domains, enabled, role_storage, role_proxy
FROM server_operators;
SELECT usage_conditions_id, conditions_commit, notified_at, created_at
FROM usage_conditions
ORDER BY usage_conditions_id DESC LIMIT 1
|]
where
-- TODO get conditions state
toOperator (operatorId, operatorTag, tradeName, legalName, domains, enabled, storage, proxy) =
let roles = ServerRoles {storage, proxy}
in ServerOperator {operatorId, operatorTag, tradeName, legalName, serverDomains = [domains], acceptedConditions = CAAccepted ts, enabled, roles}

toUsageConditions :: (Int64, Text, Maybe UTCTime, UTCTime) -> UsageConditions
toUsageConditions (conditionsId, conditionsCommit, notifiedAt, createdAt) =
UsageConditions {conditionsId, conditionsCommit, notifiedAt, createdAt}

-- updateServerOperators_ :: DB.Connection -> [ServerOperator] -> IO [ServerOperator]
-- updateServerOperators_ db operators = do
1 change: 1 addition & 0 deletions src/Simplex/Chat/Store/Shared.hs
Original file line number Diff line number Diff line change
@@ -127,6 +127,7 @@ data StoreError
| SERemoteCtrlNotFound {remoteCtrlId :: RemoteCtrlId}
| SERemoteCtrlDuplicateCA
| SEProhibitedDeleteUser {userId :: UserId, contactId :: ContactId}
| SEUsageConditionsNotFound
deriving (Show, Exception)

$(J.deriveJSON (sumTypeJSON $ dropPrefix "SE") ''StoreError)