share address

This commit is contained in:
Evgeny @ SimpleX Chat
2026-07-15 07:21:42 +00:00
parent 48b7523827
commit 9d37a6efc3
8 changed files with 79 additions and 4 deletions
+2
View File
@@ -398,6 +398,7 @@ data ChatCommand
| APIPlanForwardChatItems {fromChatRef :: ChatRef, chatItemIds :: NonEmpty ChatItemId}
| APIForwardChatItems {toChatRef :: ChatRef, sendAsGroup :: ShowGroupAsSender, fromChatRef :: ChatRef, chatItemIds :: NonEmpty ChatItemId, ttl :: Maybe Int}
| APIShareChatMsgContent {shareChatRef :: ChatRef, toSendRef :: SendRef}
| APIShareMyAddress {toSendRef :: SendRef}
| APIUserRead UserId
| UserRead
| APIChatRead {chatRef :: ChatRef}
@@ -563,6 +564,7 @@ data ChatCommand
| ForwardGroupMessage {toChatName :: ChatName, fromGroupName :: GroupName, fromMemberName_ :: Maybe ContactName, forwardedMsg :: Text}
| ForwardLocalMessage {toChatName :: ChatName, forwardedMsg :: Text}
| SharePublicGroup {shareGroupName :: GroupName, toChatName :: ChatName}
| ShareMyAddress {toChatName :: ChatName}
| SendMessage SendName Text
| SendMemberContactMessage GroupName ContactName Text
| AcceptMemberContact ContactName
+23
View File
@@ -1168,6 +1168,15 @@ processChatCommand cxt nm = \case
| asGroup = (CBChannel, smpEncode pgId)
| otherwise = (CBGroup, smpEncode (pgId, memberId))
APIShareChatMsgContent _ _ -> throwCmdError "sharing is only supported for public groups"
APIShareMyAddress _ -> withUser $ \user -> do
UserContactLink {connLinkContact = CCLink _ sl_, addressSettings} <- withFastStore (`getUserAddress` user)
case sl_ of
Nothing -> throwCmdError "your address has no short link to share"
Just connLink -> do
let business = businessAddress addressSettings
profile = userProfileDirect user Nothing Nothing True
text = safeDecodeUtf8 $ strEncode connLink
pure $ CRChatMsgContent user MCChat {text, chatLink = MCLContact {connLink, profile, business}, ownerSig = Nothing}
APIUserRead userId -> withUserId userId $ \user -> withFastStore' (`setUserChatsRead` user) >> ok user
UserRead -> withUser $ \User {userId} -> processChatCommand cxt nm $ APIUserRead userId
APIChatRead chatRef@(ChatRef cType chatId scope_) -> withUser $ \_ -> case cType of
@@ -2447,6 +2456,18 @@ processChatCommand cxt nm = \case
CRChatMsgContent _ mc ->
processChatCommand cxt nm $ APISendMessages sendRef False Nothing False [composedMessage Nothing mc]
r -> pure r
ShareMyAddress toChatName -> withUser $ \user -> do
toChatRef <- getChatRef user toChatName
sendRef <- case toChatRef of
ChatRef CTDirect ctId _ -> pure $ SRDirect ctId
ChatRef CTGroup gId scope_ -> do
gInfo <- withFastStore $ \db -> getGroupInfo db cxt user gId
pure $ SRGroup gId scope_ (useRelays' gInfo)
_ -> throwCmdError "unsupported share target"
processChatCommand cxt nm (APIShareMyAddress sendRef) >>= \case
CRChatMsgContent _ mc ->
processChatCommand cxt nm $ APISendMessages sendRef False Nothing False [composedMessage Nothing mc]
r -> pure r
SendMessage sendName msg -> withUser $ \user -> do
let mc = MCText msg
case sendName of
@@ -5353,6 +5374,7 @@ chatCommandP =
"/_forward plan " *> (APIPlanForwardChatItems <$> chatRefP <*> _strP),
"/_forward " *> (APIForwardChatItems <$> chatRefP <*> (" as_group=" *> onOffP <|> pure False) <* A.space <*> chatRefP <*> _strP <*> sendMessageTTLP),
"/_share chat content " *> (APIShareChatMsgContent <$> chatRefP <* A.space <*> sendRefP),
"/_share address " *> (APIShareMyAddress <$> sendRefP),
"/_read user " *> (APIUserRead <$> A.decimal),
"/read user" $> UserRead,
"/_read chat " *> (APIChatRead <$> chatRefP),
@@ -5550,6 +5572,7 @@ chatCommandP =
ForwardGroupMessage <$> chatNameP <* " <- #" <*> displayNameP <*> pure Nothing <* A.space <*> msgTextP,
ForwardLocalMessage <$> chatNameP <* " <- * " <*> msgTextP,
"/share chat #" *> (SharePublicGroup <$> displayNameP <* A.space <*> chatNameP),
"/share address " *> (ShareMyAddress <$> chatNameP),
SendMessage <$> sendNameP <* A.space <*> msgTextP,
"@#" *> (SendMemberContactMessage <$> displayNameP <* A.space <* char_ '@' <*> displayNameP <* A.space <*> msgTextP),
"/accept_member_contact @" *> (AcceptMemberContact <$> displayNameP),