1 use crate::protocol::Source;
2 use html2md::parse_html;
9 pub mod private_message;
11 pub(crate) fn get_summary_from_string_or_source(
13 source: &Option<Source>,
15 if let Some(source) = &source {
16 Some(source.content.clone())
18 raw.as_ref().map(|s| parse_html(s))
23 pub(crate) mod tests {
25 use background_jobs::QueueHandle;
27 r2d2::{ConnectionManager, Pool},
30 use lemmy_db_schema::{
31 establish_unpooled_connection,
32 get_database_url_from_env,
33 source::secret::Secret,
36 rate_limit::{rate_limiter::RateLimiter, RateLimit},
37 request::build_user_agent,
38 settings::structs::Settings,
41 use lemmy_websocket::{chat_server::ChatServer, LemmyContext};
43 use reqwest_middleware::ClientBuilder;
45 use tokio::sync::Mutex;
47 // TODO: would be nice if we didnt have to use a full context for tests.
48 // or at least write a helper function so this code is shared with main.rs
49 pub(crate) fn init_context(activity_queue: QueueHandle) -> LemmyContext {
50 // call this to run migrations
51 establish_unpooled_connection();
52 let settings = Settings::init().unwrap();
53 let rate_limiter = RateLimit {
54 rate_limiter: Arc::new(Mutex::new(RateLimiter::default())),
55 rate_limit_config: settings.rate_limit.to_owned().unwrap_or_default(),
57 let client = Client::builder()
58 .user_agent(build_user_agent(&settings))
62 let client = ClientBuilder::new(client).build();
65 jwt_secret: "".to_string(),
67 let db_url = match get_database_url_from_env() {
69 Err(_) => settings.get_database_url(),
71 let manager = ConnectionManager::<PgConnection>::new(&db_url);
72 let pool = Pool::builder()
73 .max_size(settings.database.pool_size)
75 .unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
76 async fn x() -> Result<String, LemmyError> {
79 let chat_server = ChatServer::startup(
82 |_, _, _, _| Box::pin(x()),
83 |_, _, _, _| Box::pin(x()),
85 activity_queue.clone(),
90 LemmyContext::create(pool, chat_server, client, activity_queue, settings, secret)