From 41c68c82ac2b8ea79d24d41a430fb6aca4a0f68f Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Fri, 18 Aug 2023 14:31:42 +0100 Subject: [PATCH] directory: add to website, send terms, sort search results (#2950) * directory: add to website, send terms, sort search results * corrections --- .../src/Directory/Service.hs | 14 ++++++++------ docs/DIRECTORY.md | 10 ++++++++-- tests/Bots/DirectoryTests.hs | 2 ++ website/langs/en.json | 1 + website/src/_data/docs_dropdown.json | 4 ++++ website/src/_data/docs_sidebar.json | 1 + 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/apps/simplex-directory-service/src/Directory/Service.hs b/apps/simplex-directory-service/src/Directory/Service.hs index f9aa19f71d..09ab424cf0 100644 --- a/apps/simplex-directory-service/src/Directory/Service.hs +++ b/apps/simplex-directory-service/src/Directory/Service.hs @@ -17,12 +17,14 @@ import Control.Concurrent.Async import Control.Concurrent.STM import Control.Monad.Reader import qualified Data.ByteString.Char8 as B -import Data.Time.Clock (getCurrentTime) -import Data.Time.LocalTime (getCurrentTimeZone) +import Data.List (sortOn) import Data.Maybe (fromMaybe, maybeToList) +import Data.Ord (Down(..)) import qualified Data.Set as S import Data.Text (Text) import qualified Data.Text as T +import Data.Time.Clock (getCurrentTime) +import Data.Time.LocalTime (getCurrentTimeZone) import Directory.Events import Directory.Options import Directory.Store @@ -31,7 +33,6 @@ import Simplex.Chat.Bot.KnownContacts import Simplex.Chat.Controller import Simplex.Chat.Core import Simplex.Chat.Messages --- import Simplex.Chat.Messages.CIContent import Simplex.Chat.Options import Simplex.Chat.Protocol (MsgContent (..)) import Simplex.Chat.Types @@ -139,7 +140,8 @@ directoryService st DirectoryOpts {superUsers, serviceName, testing} user@User { sendMessage cc ct $ "Welcome to " <> serviceName <> " service!\n\ \Send a search string to find groups or */help* to learn how to add groups to directory.\n\n\ - \For example, send _privacy_ to find groups about privacy." + \For example, send _privacy_ to find groups about privacy.\n\n\ + \Content and privacy policy: https://simplex.chat/docs/directory.html" deGroupInvitation :: Contact -> GroupInfo -> GroupMemberRole -> GroupMemberRole -> IO () deGroupInvitation ct g@GroupInfo {groupProfile = GroupProfile {displayName, fullName}} fromMemberRole memberRole = do @@ -382,7 +384,7 @@ directoryService st DirectoryOpts {superUsers, serviceName, testing} user@User { DCHelp -> sendMessage cc ct $ "You must be the owner to add the group to the directory:\n\ - \1. Invite " <> serviceName <> " bot to your group as *admin*.\n\ + \1. Invite " <> serviceName <> " bot to your group as *admin* (you can send `/list` to see all groups you submitted).\n\ \2. " <> serviceName <> " bot will create a public group link for the new members to join even when you are offline.\n\ \3. You will then need to add this link to the group welcome message.\n\ \4. Once the link is added, service admins will approve the group (it can take up to 24 hours), and everybody will be able to find it in directory.\n\n\ @@ -394,7 +396,7 @@ directoryService st DirectoryOpts {superUsers, serviceName, testing} user@User { [] -> sendReply "No groups found" gs -> do sendReply $ "Found " <> show (length gs) <> " group(s)" <> if length gs > 10 then ", sending 10." else "" - void . forkIO $ forM_ (take 10 gs) $ + void . forkIO $ forM_ (take 10 $ sortOn (Down . currentMembers . snd) gs) $ \(GroupInfo {groupProfile = p@GroupProfile {image = image_}}, GroupSummary {currentMembers}) -> do let membersStr = "_" <> tshow currentMembers <> " members_" text = groupInfoText p <> "\n" <> membersStr diff --git a/docs/DIRECTORY.md b/docs/DIRECTORY.md index 2370d46aef..a55f4fc510 100644 --- a/docs/DIRECTORY.md +++ b/docs/DIRECTORY.md @@ -1,3 +1,8 @@ +--- +title: SimpleX Directory Service +revision: 18.08.2023 +--- + # SimpleX Directory Service You can use an experimental directory service to discover the groups created and registered by other users. @@ -10,9 +15,10 @@ Please note that your search queries can be kept by the bot as the conversation ## Adding groups to the directory -### How to add the group -To add the group you must be the owner of the group. Once you connect to the directory service and send `/help`, the service will guide you through the process. +### How to add a group + +To add a group you must be its owner. Once you connect to the directory service and send `/help`, the service will guide you through the process. 1. Invite SimpleX Service Directory to the group as `admin` member. You can also set the role to `admin` after inviting the directory service. diff --git a/tests/Bots/DirectoryTests.hs b/tests/Bots/DirectoryTests.hs index 6a7fc84e13..21bdb6577b 100644 --- a/tests/Bots/DirectoryTests.hs +++ b/tests/Bots/DirectoryTests.hs @@ -905,6 +905,8 @@ u `connectVia` dsLink = do u <## "Send a search string to find groups or /help to learn how to add groups to directory." u <## "" u <## "For example, send privacy to find groups about privacy." + u <## "" + u <## "Content and privacy policy: https://simplex.chat/docs/directory.html" joinGroup :: String -> TestCC -> TestCC -> IO () joinGroup gName member host = do diff --git a/website/langs/en.json b/website/langs/en.json index 74ea350e78..8dc9de1198 100644 --- a/website/langs/en.json +++ b/website/langs/en.json @@ -227,6 +227,7 @@ "docs-dropdown-5": "Host XFTP Server", "docs-dropdown-6": "WebRTC servers", "docs-dropdown-7": "Translate SimpleX Chat", + "docs-dropdown-8": "SimpleX Directory Service", "newer-version-of-eng-msg": "There is a newer version of this page in English.", "click-to-see": "Click to see", "menu": "Menu", diff --git a/website/src/_data/docs_dropdown.json b/website/src/_data/docs_dropdown.json index ff05242c81..cdcb595086 100644 --- a/website/src/_data/docs_dropdown.json +++ b/website/src/_data/docs_dropdown.json @@ -4,6 +4,10 @@ "title": "docs-dropdown-1", "url": "/docs/simplex.html" }, + { + "title": "docs-dropdown-8", + "url": "/docs/directory.html" + }, { "title": "docs-dropdown-2", "url": "/docs/android.html" diff --git a/website/src/_data/docs_sidebar.json b/website/src/_data/docs_sidebar.json index f05ae0ab1a..a45f69fb06 100644 --- a/website/src/_data/docs_sidebar.json +++ b/website/src/_data/docs_sidebar.json @@ -18,6 +18,7 @@ "menu": "Reference", "data": [ "SIMPLEX.md", + "DIRECTORY.md", "ANDROID.md", "CLI.md", "SQL.md",