load own names

This commit is contained in:
Evgeny @ SimpleX Chat
2026-06-28 08:49:50 +00:00
parent 38a360ce93
commit 3084df657e
3 changed files with 41 additions and 33 deletions
+4 -16
View File
@@ -4208,18 +4208,12 @@ processChatCommand cxt nm = \case
verified (con sl cReq, plan)
where
knownLinkPlans = withFastStore $ \db ->
ownLinkPlan db >>= \case
Just r -> pure (Just r)
liftIO (getUserContactLinkViaTarget db user nameOrLink') >>= \case
Just UserContactLink {connLinkContact = CCLink cReq _} -> pure $ Just (knownCon cReq, CPContactAddress CAPOwnLink)
Nothing ->
getContactToConnect db cxt user nameOrLink' >>= \case
Just (cReq, ct') -> pure $ if contactDeleted ct' then Nothing else Just (knownCon cReq, CPContactAddress (CAPKnown ct'))
Nothing -> (gPlan =<<) <$> getGroupToConnect db cxt user nameOrLink'
ownLinkPlan db = case nameOrLink' of
CTLink sl ->
liftIO (getUserContactLinkViaShortLink db user sl) >>= \case
Just UserContactLink {connLinkContact = CCLink cReq _} -> pure $ Just (knownCon cReq, CPContactAddress CAPOwnLink)
Nothing -> pure Nothing
CTName _ -> pure Nothing
CCTGroup -> groupShortLinkPlan
CCTChannel -> groupShortLinkPlan
CCTRelay -> throwCmdError "chat relay links are not supported in this version"
@@ -4271,15 +4265,9 @@ processChatCommand cxt nm = \case
Just GroupShortLinkData {groupProfile = GroupProfile {publicGroup = Just PublicGroupProfile {groupType}}} -> groupType /= GTChannel
_ -> False
knownLinkPlans = withFastStore $ \db ->
ownGroupLinkPlan db >>= \case
Just r -> pure (Just r)
liftIO (getGroupInfoViaUserTarget db cxt user nameOrLink') >>= \case
Just (cReq, g) -> pure $ Just (knownCon cReq, CPGroupLink (GLPOwnLink g))
Nothing -> (gPlan =<<) <$> getGroupToConnect db cxt user nameOrLink'
ownGroupLinkPlan db = case nameOrLink' of
CTLink sl ->
liftIO (getGroupInfoViaUserShortLink db cxt user sl) >>= \case
Just (cReq, g) -> pure $ Just (knownCon cReq, CPGroupLink (GLPOwnLink g))
Nothing -> pure Nothing
CTName _ -> pure Nothing
resolveKnownGroup g = do
sl <- resolveSLink
(fd@FixedLinkData {rootKey = rk}, cData@(ContactLinkData _ UserContactData {owners})) <- getShortLinkConnReq' nm user sl
+25 -12
View File
@@ -42,7 +42,7 @@ module Simplex.Chat.Store.Groups
setGroupInvitationChatItemId,
getGroup,
getGroupInfoByUserContactLinkConnReq,
getGroupInfoViaUserShortLink,
getGroupInfoViaUserTarget,
getGroupViaShortLinkToConnect,
getGroupInfoByGroupLinkHash,
updateGroupProfile,
@@ -2753,21 +2753,34 @@ getGroupInfoByUserContactLinkConnReq db cxt user@User {userId} (cReqSchema1, cRe
(userId, cReqSchema1, cReqSchema2)
maybe (pure Nothing) (fmap eitherToMaybe . runExceptT . getGroupInfo db cxt user) groupId_
getGroupInfoViaUserShortLink :: DB.Connection -> StoreCxt -> User -> ShortLinkContact -> IO (Maybe (ConnReqContact, GroupInfo))
getGroupInfoViaUserShortLink db cxt user@User {userId} shortLink = fmap eitherToMaybe $ runExceptT $ do
-- own hosted group found by the target: by its address short link, or (for a name) by the group's registered name
getGroupInfoViaUserTarget :: DB.Connection -> StoreCxt -> User -> ContactNameOrLink -> IO (Maybe (ConnReqContact, GroupInfo))
getGroupInfoViaUserTarget db cxt user@User {userId} target = fmap eitherToMaybe $ runExceptT $ do
(cReq, groupId) <- ExceptT getConnReqGroup
(cReq,) <$> getGroupInfo db cxt user groupId
where
getConnReqGroup =
firstRow' toConnReqGroupId (SEInternalError "group link not found") $
DB.query
db
[sql|
SELECT conn_req_contact, group_id
FROM user_contact_links
WHERE user_id = ? AND short_link_contact = ?
|]
(userId, shortLink)
firstRow' toConnReqGroupId (SEInternalError "group link not found") $ case target of
CTLink shortLink ->
DB.query
db
[sql|
SELECT conn_req_contact, group_id
FROM user_contact_links
WHERE user_id = ? AND short_link_contact = ?
|]
(userId, shortLink)
CTName ni ->
DB.query
db
[sql|
SELECT ucl.conn_req_contact, ucl.group_id
FROM user_contact_links ucl
JOIN groups g ON g.group_id = ucl.group_id
JOIN group_profiles gp ON gp.group_profile_id = g.group_profile_id
WHERE ucl.user_id = ? AND gp.group_domain = ?
|]
(userId, ni)
toConnReqGroupId = \case
-- cReq is "not null", group_id is nullable
(cReq, Just groupId) -> Right (cReq, groupId)
+12 -5
View File
@@ -55,7 +55,7 @@ module Simplex.Chat.Store.Profiles
getUserContactLinkById,
getGroupLinkInfo,
getUserContactLinkByConnReq,
getUserContactLinkViaShortLink,
getUserContactLinkViaTarget,
setUserContactLinkShortLink,
getContactWithoutConnViaAddress,
getContactWithoutConnViaShortAddress,
@@ -562,10 +562,17 @@ getUserContactLinkByConnReq db User {userId} (cReqSchema1, cReqSchema2) =
maybeFirstRow toUserContactLink $
DB.query db (userContactLinkQuery <> " WHERE user_id = ? AND conn_req_contact IN (?,?)") (userId, cReqSchema1, cReqSchema2)
getUserContactLinkViaShortLink :: DB.Connection -> User -> ShortLinkContact -> IO (Maybe UserContactLink)
getUserContactLinkViaShortLink db User {userId} shortLink =
maybeFirstRow toUserContactLink $
DB.query db (userContactLinkQuery <> " WHERE user_id = ? AND short_link_contact = ?") (userId, shortLink)
-- own contact address found by the target: by its short link, or (for a name) when it is this user's own registered address name
getUserContactLinkViaTarget :: DB.Connection -> User -> ContactNameOrLink -> IO (Maybe UserContactLink)
getUserContactLinkViaTarget db User {userId, profile = LocalProfile {contactDomain}} = \case
CTLink shortLink ->
maybeFirstRow toUserContactLink $
DB.query db (userContactLinkQuery <> " WHERE user_id = ? AND short_link_contact = ?") (userId, shortLink)
CTName ni
| contactDomain == Just ni ->
maybeFirstRow toUserContactLink $
DB.query db (userContactLinkQuery <> " WHERE user_id = ? AND group_id IS NULL") (Only userId)
| otherwise -> pure Nothing
userContactLinkQuery :: Query
userContactLinkQuery =