mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-25 20:42:13 +00:00
* docs: bot API commands * generate API commands doc * generate commands docs with parameters and responses * add API types * more types * document all types (with some deviations from JSON encodings) * rename types * interface objects * separator * command syntax * more syntax * API events * event types * fix all type definitions * pre-process types outside of rendering * pre-process event types * overview * pre-process commands * param syntax WIP * syntax for types in command parameters * API error response and chat event * remove unsupported/deprecated command parameters * reorder * syntax for choice * show command errors * event descriptions * python syntax for commands and types (#6099) * python syntax for commands and types * python snippets: convert numbers to string * fixes * update readme, enable all tests * fix operators test * update plans --------- Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com>
33 lines
1.0 KiB
Haskell
33 lines
1.0 KiB
Haskell
{-# LANGUAGE DuplicateRecordFields #-}
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
|
|
|
module Directory.Search where
|
|
|
|
import Data.List (sortOn)
|
|
import Data.Ord (Down (..))
|
|
import Data.Set (Set)
|
|
import qualified Data.Set as S
|
|
import Data.Text (Text)
|
|
import Data.Time.Clock (UTCTime)
|
|
import Simplex.Chat.Types
|
|
|
|
data SearchRequest = SearchRequest
|
|
{ searchType :: SearchType,
|
|
searchTime :: UTCTime,
|
|
sentGroups :: Set GroupId
|
|
}
|
|
|
|
data SearchType = STAll | STRecent | STSearch Text
|
|
|
|
takeTop :: Int -> [GroupInfoSummary] -> [GroupInfoSummary]
|
|
takeTop n = take n . sortOn (\(GIS _ GroupSummary {currentMembers}) -> Down currentMembers)
|
|
|
|
takeRecent :: Int -> [GroupInfoSummary] -> [GroupInfoSummary]
|
|
takeRecent n = take n . sortOn (\(GIS GroupInfo {createdAt} _) -> Down createdAt)
|
|
|
|
groupIds :: [GroupInfoSummary] -> Set GroupId
|
|
groupIds = S.fromList . map (\(GIS GroupInfo {groupId} _) -> groupId)
|
|
|
|
filterNotSent :: Set GroupId -> [GroupInfoSummary] -> [GroupInfoSummary]
|
|
filterNotSent sentGroups = filter (\(GIS GroupInfo {groupId} _) -> groupId `S.notMember` sentGroups)
|