mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-10 23:47:11 +00:00
f0338a03d1
* directory: new commands * better search * search test * return group links in simplex.chat domain, allow both simplex:/ and simplex.chat links in group description
33 lines
1.1 KiB
Haskell
33 lines
1.1 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 -> [(GroupInfo, GroupSummary)] -> [(GroupInfo, GroupSummary)]
|
|
takeTop n = take n . sortOn (Down . currentMembers . snd)
|
|
|
|
takeRecent :: Int -> [(GroupInfo, GroupSummary)] -> [(GroupInfo, GroupSummary)]
|
|
takeRecent n = take n . sortOn (Down . (\GroupInfo {createdAt} -> createdAt) . fst)
|
|
|
|
groupIds :: [(GroupInfo, GroupSummary)] -> Set GroupId
|
|
groupIds = S.fromList . map (\(GroupInfo {groupId}, _) -> groupId)
|
|
|
|
filterNotSent :: Set GroupId -> [(GroupInfo, GroupSummary)] -> [(GroupInfo, GroupSummary)]
|
|
filterNotSent sentGroups = filter (\(GroupInfo {groupId}, _) -> groupId `S.notMember` sentGroups)
|