mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-26 20:34:50 +00:00
option to auto-accept contact requests (#296)
This commit is contained in:
@@ -40,6 +40,7 @@ module Simplex.Chat.Store
|
||||
getUserContactLinkConnections,
|
||||
deleteUserContactLink,
|
||||
getUserContactLink,
|
||||
updateUserContactLinkAutoAccept,
|
||||
createOrUpdateContactRequest,
|
||||
getContactRequest,
|
||||
getContactRequestIdByName,
|
||||
@@ -555,22 +556,42 @@ deleteUserContactLink st userId =
|
||||
[":user_id" := userId]
|
||||
DB.execute db "DELETE FROM user_contact_links WHERE user_id = ? AND local_display_name = ''" (Only userId)
|
||||
|
||||
getUserContactLink :: StoreMonad m => SQLiteStore -> UserId -> m ConnReqContact
|
||||
getUserContactLink :: StoreMonad m => SQLiteStore -> UserId -> m (ConnReqContact, Bool)
|
||||
getUserContactLink st userId =
|
||||
liftIOEither . withTransaction st $ \db ->
|
||||
connReq
|
||||
<$> DB.query
|
||||
getUserContactLink_ db userId
|
||||
|
||||
getUserContactLink_ :: DB.Connection -> UserId -> IO (Either StoreError (ConnReqContact, Bool))
|
||||
getUserContactLink_ db userId =
|
||||
firstRow id SEUserContactLinkNotFound $
|
||||
DB.query
|
||||
db
|
||||
[sql|
|
||||
SELECT conn_req_contact, auto_accept
|
||||
FROM user_contact_links
|
||||
WHERE user_id = ?
|
||||
AND local_display_name = ''
|
||||
|]
|
||||
(Only userId)
|
||||
|
||||
updateUserContactLinkAutoAccept :: StoreMonad m => SQLiteStore -> UserId -> Bool -> m (ConnReqContact, Bool)
|
||||
updateUserContactLinkAutoAccept st userId autoAccept = do
|
||||
liftIOEither . withTransaction st $ \db -> runExceptT $ do
|
||||
(cReqUri, _) <- ExceptT $ getUserContactLink_ db userId
|
||||
liftIO $ updateUserContactLinkAutoAccept_ db
|
||||
pure (cReqUri, autoAccept)
|
||||
where
|
||||
updateUserContactLinkAutoAccept_ :: DB.Connection -> IO ()
|
||||
updateUserContactLinkAutoAccept_ db =
|
||||
DB.execute
|
||||
db
|
||||
[sql|
|
||||
SELECT conn_req_contact
|
||||
FROM user_contact_links
|
||||
UPDATE user_contact_links
|
||||
SET auto_accept = ?
|
||||
WHERE user_id = ?
|
||||
AND local_display_name = ''
|
||||
|]
|
||||
(Only userId)
|
||||
where
|
||||
connReq [Only cReq] = Right cReq
|
||||
connReq _ = Left SEUserContactLinkNotFound
|
||||
(autoAccept, userId)
|
||||
|
||||
createOrUpdateContactRequest :: StoreMonad m => SQLiteStore -> UserId -> Int64 -> InvitationId -> Profile -> Maybe XContactId -> m (Either Contact UserContactRequest)
|
||||
createOrUpdateContactRequest st userId userContactLinkId invId profile xContactId_ =
|
||||
|
||||
Reference in New Issue
Block a user