mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-07-12 05:18:57 +00:00
ad23da63d0
* core: supporter badges using anonymous BBS credentials * badges in profiles * badge in profiles * process badges * update simplexmq * update simplexmq * change types * fix migration * migration * update simplexmq * fix bot API, schema * fix postgresql build * refactor * postgresql schema * correctly set badges in all cases * badges ffi * plan, bot types * FFI * FFI: export badge symbols * add extra field * refactor badge types to GADT * configurable badge key * add badge to profile, test * ui: badge images * generate badge key and sign badge * badge sign in CLI * fix commands, ui * rename badges * Binary * image size, migration * update badge images, add public key * send badges in more cases * update UI, tests * bot types, schema * postgres schema * tone down badges * revert formula * refactor badges * smaller badges * badge position * better badge position * simpler * position * move position * update simplexmq * show badge after name * badge layout * fix badge * debug badge height * shift badge * fix badge in member name * bigger badge * badge layout * differentiate badge colors * more avatars for the user's profiles * refactor * remove color filter * alerts * multiple keys, old expired * use new BBS api * update badge keys, bot api * presentation header * simplify * parser * update iOS images * update public keys * query plans * update simplexmq * refactor badge types * simplexmq * bot api types * update simplexmq - commoncrypto flag * update simplexmq * pass commoncrypto flag to simplexmq in nix iOS build * ios ui * update core library, fixes * badge layout * badge size * badge gap * remove extensions * simplify * share badge in more events, reverify badge if verification failed * larger files with badges * allow sending larger files * simpler * update simplexmq * better decoder for badge keys * update simplexmq --------- Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> Co-authored-by: shum <github.shum@liber.li>
94 lines
3.4 KiB
Haskell
94 lines
3.4 KiB
Haskell
{-# LANGUAGE CPP #-}
|
|
{-# LANGUAGE DuplicateRecordFields #-}
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Bots.BroadcastTests where
|
|
|
|
import Broadcast.Bot
|
|
import Broadcast.Options
|
|
import ChatClient
|
|
import ChatTests.DBUtils
|
|
import ChatTests.Utils
|
|
import Control.Concurrent (forkIO, killThread, threadDelay)
|
|
import Control.Exception (bracket)
|
|
import Simplex.Chat.Bot.KnownContacts
|
|
import Simplex.Chat.Core
|
|
import Simplex.Chat.Options (CoreChatOpts (..))
|
|
import Simplex.Chat.Options.DB
|
|
import Simplex.Chat.Types (ChatPeerType (..), Profile (..))
|
|
import Test.Hspec hiding (it)
|
|
#if !defined(dbPostgres)
|
|
import System.FilePath ((</>))
|
|
#endif
|
|
|
|
broadcastBotTests :: SpecWith TestParams
|
|
broadcastBotTests = do
|
|
it "should broadcast message" testBroadcastMessages
|
|
|
|
withBroadcastBot :: BroadcastBotOpts -> IO () -> IO ()
|
|
withBroadcastBot opts test =
|
|
bracket (forkIO bot) killThread (\_ -> threadDelay 500000 >> test)
|
|
where
|
|
bot = simplexChatCore testCfg (mkChatOpts opts) $ broadcastBot opts
|
|
|
|
broadcastBotProfile :: Profile
|
|
broadcastBotProfile = Profile {displayName = "broadcast_bot", fullName = "Broadcast Bot", shortDescr = Nothing, image = Nothing, contactLink = Nothing, peerType = Just CPTBot, preferences = Nothing, badge = Nothing}
|
|
|
|
mkBotOpts :: TestParams -> [KnownContact] -> BroadcastBotOpts
|
|
mkBotOpts ps publishers =
|
|
BroadcastBotOpts
|
|
{ coreOptions =
|
|
testCoreOpts
|
|
{ dbOptions =
|
|
(dbOptions testCoreOpts)
|
|
#if defined(dbPostgres)
|
|
{dbSchemaPrefix = "client_" <> botDbPrefix}
|
|
#else
|
|
{dbFilePrefix = tmpPath ps </> botDbPrefix}
|
|
#endif
|
|
|
|
},
|
|
botDisplayName = "broadcast_bot",
|
|
publishers,
|
|
welcomeMessage = defaultWelcomeMessage publishers,
|
|
prohibitedMessage = defaultWelcomeMessage publishers
|
|
}
|
|
|
|
botDbPrefix :: FilePath
|
|
botDbPrefix = "broadcast_bot"
|
|
|
|
testBroadcastMessages :: HasCallStack => TestParams -> IO ()
|
|
testBroadcastMessages ps = do
|
|
botLink <-
|
|
withNewTestChat ps botDbPrefix broadcastBotProfile $ \bc_bot ->
|
|
withNewTestChat ps "alice" aliceProfile $ \alice -> do
|
|
connectUsers bc_bot alice
|
|
bc_bot ##> "/ad"
|
|
getContactLink bc_bot True
|
|
let botOpts = mkBotOpts ps [KnownContact 2 "alice"]
|
|
withBroadcastBot botOpts $
|
|
withTestChat ps "alice" $ \alice ->
|
|
withNewTestChat ps "bob" bobProfile $ \bob ->
|
|
withNewTestChat ps "cath" cathProfile $ \cath -> do
|
|
alice <## "subscribed 1 connections on server localhost"
|
|
bob `connectVia` botLink
|
|
bob #> "@broadcast_bot hello"
|
|
bob <# "broadcast_bot> > hello"
|
|
bob <## " Hello! I am a broadcast bot."
|
|
bob <## "I broadcast messages to all connected users from @alice."
|
|
cath `connectVia` botLink
|
|
alice #> "@broadcast_bot hello all!"
|
|
alice <# "broadcast_bot> hello all!" -- we broadcast to the sender too, /feed is used by bot
|
|
bob <# "broadcast_bot> hello all!"
|
|
cath <# "broadcast_bot> hello all!"
|
|
alice <# "broadcast_bot> > hello all!"
|
|
alice <## " Forwarded to 3 contact(s), 0 errors"
|
|
where
|
|
cc `connectVia` botLink = do
|
|
cc ##> ("/c " <> botLink)
|
|
cc <## "connection request sent!"
|
|
cc <## "broadcast_bot (Broadcast Bot): contact is connected"
|
|
cc <# "broadcast_bot> Hello! I am a broadcast bot."
|
|
cc <## "I broadcast messages to all connected users from @alice."
|