diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index ebbe5c450e..900e5d2e6d 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -159,12 +159,12 @@ processChatCommand user@User {userId, profile} = \case CTGroup -> pure $ CRChatCmdError ChatErrorNotImplemented CTContactRequest -> pure . CRChatError . ChatError $ CECommandError "not supported" APIAcceptContact connReqId -> do - cReq@UserContactRequest {agentInvitationId = AgentInvId invId, localDisplayName = cName, profileId} <- withStore $ \st -> + UserContactRequest {agentInvitationId = AgentInvId invId, localDisplayName = cName, profileId, profile = p} <- withStore $ \st -> getContactRequest st userId connReqId procCmd $ do connId <- withAgent $ \a -> acceptContact a invId . directMessage $ XInfo profile - withStore $ \st -> createAcceptedContact st userId connId cName profileId - pure $ CRAcceptingContactRequest cReq + acceptedContact <- withStore $ \st -> createAcceptedContact st userId connId cName profileId p + pure $ CRAcceptingContactRequest acceptedContact APIRejectContact connReqId -> do cReq@UserContactRequest {agentContactConnId = AgentConnId connId, agentInvitationId = AgentInvId invId} <- withStore $ \st -> diff --git a/src/Simplex/Chat/Controller.hs b/src/Simplex/Chat/Controller.hs index 02ffae68bd..dc718bc059 100644 --- a/src/Simplex/Chat/Controller.hs +++ b/src/Simplex/Chat/Controller.hs @@ -148,7 +148,7 @@ data ChatResponse | CRUserContactLinkCreated {connReqContact :: ConnReqContact} | CRUserContactLinkDeleted | CRReceivedContactRequest {contactRequest :: UserContactRequest} - | CRAcceptingContactRequest {contactRequest :: UserContactRequest} + | CRAcceptingContactRequest {contact :: Contact} | CRLeftMemberUser {groupInfo :: GroupInfo} | CRGroupDeletedUser {groupInfo :: GroupInfo} | CRRcvFileAccepted {fileTransfer :: RcvFileTransfer, filePath :: FilePath} diff --git a/src/Simplex/Chat/Store.hs b/src/Simplex/Chat/Store.hs index 5ec2f3db31..6429b531f2 100644 --- a/src/Simplex/Chat/Store.hs +++ b/src/Simplex/Chat/Store.hs @@ -537,13 +537,14 @@ deleteContactRequest st userId contactRequestId = (userId, userId, contactRequestId) DB.execute db "DELETE FROM contact_requests WHERE user_id = ? AND contact_request_id = ?" (userId, contactRequestId) -createAcceptedContact :: MonadUnliftIO m => SQLiteStore -> UserId -> ConnId -> ContactName -> Int64 -> m () -createAcceptedContact st userId agentConnId localDisplayName profileId = +createAcceptedContact :: MonadUnliftIO m => SQLiteStore -> UserId -> ConnId -> ContactName -> Int64 -> Profile -> m Contact +createAcceptedContact st userId agentConnId localDisplayName profileId profile = liftIO . withTransaction st $ \db -> do DB.execute db "DELETE FROM contact_requests WHERE user_id = ? AND local_display_name = ?" (userId, localDisplayName) DB.execute db "INSERT INTO contacts (user_id, local_display_name, contact_profile_id) VALUES (?,?,?)" (userId, localDisplayName, profileId) contactId <- insertedRowId db - void $ createConnection_ db userId ConnContact (Just contactId) agentConnId Nothing 0 + activeConn <- createConnection_ db userId ConnContact (Just contactId) agentConnId Nothing 0 + pure $ Contact {contactId, localDisplayName, profile, activeConn, viaGroup = Nothing} getLiveSndFileTransfers :: MonadUnliftIO m => SQLiteStore -> User -> m [SndFileTransfer] getLiveSndFileTransfers st User {userId} = @@ -2041,8 +2042,6 @@ getContact :: StoreMonad m => SQLiteStore -> UserId -> Int64 -> m Contact getContact st userId contactId = liftIOEither . withTransaction st $ \db -> getContact_ db userId contactId --- TODO return the last connection that is ready, not any last connection --- requires updating connection status getContact_ :: DB.Connection -> UserId -> Int64 -> IO (Either StoreError Contact) getContact_ db userId contactId = join diff --git a/src/Simplex/Chat/View.hs b/src/Simplex/Chat/View.hs index 230253a44c..35fb1b2141 100644 --- a/src/Simplex/Chat/View.hs +++ b/src/Simplex/Chat/View.hs @@ -60,8 +60,8 @@ responseToView cmd = \case CRInvitation cReq -> r' $ viewConnReqInvitation cReq CRSentConfirmation -> r' ["confirmation sent!"] CRSentInvitation -> r' ["connection request sent!"] - CRContactDeleted Contact {localDisplayName} -> r' [ttyContact localDisplayName <> ": contact is deleted"] - CRAcceptingContactRequest UserContactRequest {localDisplayName = c} -> r' [ttyContact c <> ": accepting contact request..."] + CRContactDeleted Contact {localDisplayName = c} -> r' [ttyContact c <> ": contact is deleted"] + CRAcceptingContactRequest Contact {localDisplayName = c} -> r' [ttyContact c <> ": accepting contact request..."] CRUserContactLinkCreated cReq -> r' $ connReqContact_ "Your new chat address is created!" cReq CRUserContactLinkDeleted -> r' viewUserContactLinkDeleted CRUserAcceptedGroupSent _g -> r' [] -- [ttyGroup' g <> ": joining the group..."]