mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-03-14 09:45:42 +00:00
core: clear connection verification status (#1540)
This commit is contained in:
parent
73e5fff8f5
commit
146d5f99bc
4 changed files with 29 additions and 15 deletions
|
@ -1166,12 +1166,16 @@ processChatCommand = \case
|
|||
getGroupAndMemberId user gName mName >>= processChatCommand . uncurry cmd
|
||||
getConnectionCode :: ConnId -> m Text
|
||||
getConnectionCode connId = verificationCode <$> withAgent (`getConnectionRatchetAdHash` connId)
|
||||
verifyConnectionCode :: User -> Connection -> Text -> m ChatResponse
|
||||
verifyConnectionCode user conn@Connection {connId} code = do
|
||||
verifyConnectionCode :: User -> Connection -> Maybe Text -> m ChatResponse
|
||||
verifyConnectionCode user conn@Connection {connId} (Just code) = do
|
||||
code' <- getConnectionCode $ aConnId conn
|
||||
let verified = sameVerificationCode code code'
|
||||
when verified . withStore' $ \db -> setConnectionVerified db user connId $ Just code'
|
||||
pure $ CRCodeVerification verified code'
|
||||
pure $ CRConnectionVerified verified code'
|
||||
verifyConnectionCode user conn@Connection {connId} _ = do
|
||||
code' <- getConnectionCode $ aConnId conn
|
||||
withStore' $ \db -> setConnectionVerified db user connId Nothing
|
||||
pure $ CRConnectionVerified False code'
|
||||
getSentChatItemIdByText :: User -> ChatRef -> ByteString -> m Int64
|
||||
getSentChatItemIdByText user@User {userId, localDisplayName} (ChatRef cType cId) msg = case cType of
|
||||
CTDirect -> withStore $ \db -> getDirectChatItemIdByText db userId cId SMDSnd (safeDecodeUtf8 msg)
|
||||
|
@ -3441,12 +3445,12 @@ chatCommandP =
|
|||
"/switch " *> char_ '@' *> (SwitchContact <$> displayName),
|
||||
"/_get code @" *> (APIGetContactCode <$> A.decimal),
|
||||
"/_get code #" *> (APIGetGroupMemberCode <$> A.decimal <* A.space <*> A.decimal),
|
||||
"/_verify code @" *> (APIVerifyContact <$> A.decimal <* A.space <*> textP),
|
||||
"/_verify code #" *> (APIVerifyGroupMember <$> A.decimal <* A.space <*> A.decimal <* A.space <*> textP),
|
||||
"/_verify code @" *> (APIVerifyContact <$> A.decimal <*> optional (A.space *> textP)),
|
||||
"/_verify code #" *> (APIVerifyGroupMember <$> A.decimal <* A.space <*> A.decimal <*> optional (A.space *> textP)),
|
||||
"/code " *> char_ '@' *> (GetContactCode <$> displayName),
|
||||
"/code #" *> (GetGroupMemberCode <$> displayName <* A.space <* char_ '@' <*> displayName),
|
||||
"/verify " *> char_ '@' *> (VerifyContact <$> displayName <* A.space <*> textP),
|
||||
"/verify #" *> (VerifyGroupMember <$> displayName <* A.space <* char_ '@' <*> displayName <* A.space <*> textP),
|
||||
"/verify " *> char_ '@' *> (VerifyContact <$> displayName <*> optional (A.space *> textP)),
|
||||
"/verify #" *> (VerifyGroupMember <$> displayName <* A.space <* char_ '@' <*> displayName <*> optional (A.space *> textP)),
|
||||
("/help files" <|> "/help file" <|> "/hf") $> ChatHelp HSFiles,
|
||||
("/help groups" <|> "/help group" <|> "/hg") $> ChatHelp HSGroups,
|
||||
("/help address" <|> "/ha") $> ChatHelp HSMyAddress,
|
||||
|
|
|
@ -202,8 +202,8 @@ data ChatCommand
|
|||
| APISwitchGroupMember GroupId GroupMemberId
|
||||
| APIGetContactCode ContactId
|
||||
| APIGetGroupMemberCode GroupId GroupMemberId
|
||||
| APIVerifyContact ContactId Text
|
||||
| APIVerifyGroupMember GroupId GroupMemberId Text
|
||||
| APIVerifyContact ContactId (Maybe Text)
|
||||
| APIVerifyGroupMember GroupId GroupMemberId (Maybe Text)
|
||||
| ShowMessages ChatName Bool
|
||||
| ContactInfo ContactName
|
||||
| GroupMemberInfo GroupName ContactName
|
||||
|
@ -211,8 +211,8 @@ data ChatCommand
|
|||
| SwitchGroupMember GroupName ContactName
|
||||
| GetContactCode ContactName
|
||||
| GetGroupMemberCode GroupName ContactName
|
||||
| VerifyContact ContactName Text
|
||||
| VerifyGroupMember GroupName ContactName Text
|
||||
| VerifyContact ContactName (Maybe Text)
|
||||
| VerifyGroupMember GroupName ContactName (Maybe Text)
|
||||
| ChatHelp HelpSection
|
||||
| Welcome
|
||||
| AddContact
|
||||
|
@ -288,7 +288,7 @@ data ChatResponse
|
|||
| CRGroupMemberSwitch {groupInfo :: GroupInfo, member :: GroupMember, switchProgress :: SwitchProgress}
|
||||
| CRContactCode {contact :: Contact, connectionCode :: Text}
|
||||
| CRGroupMemberCode {groupInfo :: GroupInfo, member :: GroupMember, connectionCode :: Text}
|
||||
| CRCodeVerification {verified :: Bool, expectedCode :: Text}
|
||||
| CRConnectionVerified {verified :: Bool, expectedCode :: Text}
|
||||
| CRNewChatItem {chatItem :: AChatItem}
|
||||
| CRChatItemStatusUpdated {chatItem :: AChatItem}
|
||||
| CRChatItemUpdated {chatItem :: AChatItem}
|
||||
|
|
|
@ -74,7 +74,7 @@ responseToView user_ testView ts = \case
|
|||
CRGroupMemberInfo g m cStats -> viewGroupMemberInfo g m cStats
|
||||
CRContactSwitch ct progress -> viewContactSwitch ct progress
|
||||
CRGroupMemberSwitch g m progress -> viewGroupMemberSwitch g m progress
|
||||
CRCodeVerification verified code -> [plain $ if verified then "connection verified" else "error: current connection code is " <> code]
|
||||
CRConnectionVerified verified code -> [plain $ if verified then "connection verified" else "connection not verified, current code is " <> code]
|
||||
CRContactCode ct code -> viewContactCode ct code testView
|
||||
CRGroupMemberCode g m code -> viewGroupMemberCode g m code testView
|
||||
CRNewChatItem (AChatItem _ _ chat item) -> unmuted chat item $ viewChatItem chat item False ts
|
||||
|
|
|
@ -4637,12 +4637,17 @@ testMarkContactVerified =
|
|||
aCode <- getTermLine bob
|
||||
bCode `shouldBe` aCode
|
||||
alice ##> "/verify bob 123"
|
||||
alice <##. "error: current connection code is "
|
||||
alice <##. "connection not verified, current code is "
|
||||
alice ##> ("/verify bob " <> aCode)
|
||||
alice <## "connection verified"
|
||||
alice ##> "/i bob"
|
||||
bobInfo alice
|
||||
alice <## "connection verified"
|
||||
alice ##> "/verify bob"
|
||||
alice <##. "connection not verified, current code is "
|
||||
alice ##> "/i bob"
|
||||
bobInfo alice
|
||||
alice <## "connection not verified, use /code command to see security code"
|
||||
where
|
||||
bobInfo alice = do
|
||||
alice <## "contact ID: 2"
|
||||
|
@ -4663,12 +4668,17 @@ testMarkGroupMemberVerified =
|
|||
aCode <- getTermLine bob
|
||||
bCode `shouldBe` aCode
|
||||
alice ##> "/verify #team bob 123"
|
||||
alice <##. "error: current connection code is "
|
||||
alice <##. "connection not verified, current code is "
|
||||
alice ##> ("/verify #team bob " <> aCode)
|
||||
alice <## "connection verified"
|
||||
alice ##> "/i #team bob"
|
||||
bobInfo alice
|
||||
alice <## "connection verified"
|
||||
alice ##> "/verify #team bob"
|
||||
alice <##. "connection not verified, current code is "
|
||||
alice ##> "/i #team bob"
|
||||
bobInfo alice
|
||||
alice <## "connection not verified, use /code command to see security code"
|
||||
where
|
||||
bobInfo alice = do
|
||||
alice <## "group ID: 1"
|
||||
|
|
Loading…
Add table
Reference in a new issue