language::Language,
moderator::{ModAdd, ModAddForm},
person::{Person, PersonUpdateForm},
+ tagline::Tagline,
},
traits::Crud,
};
let all_languages = Language::read_all(context.pool()).await?;
let discussion_languages = SiteLanguage::read_local(context.pool()).await?;
+ let taglines_res = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
+ let taglines = taglines_res.is_empty().then_some(taglines_res);
Ok(GetSiteResponse {
site_view,
federated_instances: None,
all_languages,
discussion_languages,
+ taglines,
})
}
}
use crate::sensitive::Sensitive;
use lemmy_db_schema::{
newtypes::{CommentId, CommunityId, LanguageId, PersonId, PostId},
- source::language::Language,
+ source::{language::Language, tagline::Tagline},
ListingType,
ModlogActionType,
SearchType,
pub captcha_difficulty: Option<String>,
pub allowed_instances: Option<Vec<String>>,
pub blocked_instances: Option<Vec<String>>,
+ pub taglines: Option<Vec<String>>,
pub auth: Sensitive<String>,
}
pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
pub all_languages: Vec<Language>,
pub discussion_languages: Vec<LanguageId>,
+ pub taglines: Option<Vec<Tagline>>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
site::{GetSite, GetSiteResponse, MyUserInfo},
utils::{build_federated_instances, get_local_user_settings_view_from_jwt_opt},
};
-use lemmy_db_schema::source::{actor_language::SiteLanguage, language::Language};
+use lemmy_db_schema::source::{actor_language::SiteLanguage, language::Language, tagline::Tagline};
use lemmy_db_views::structs::{LocalUserDiscussionLanguageView, SiteView};
use lemmy_db_views_actor::structs::{
CommunityBlockView,
let all_languages = Language::read_all(context.pool()).await?;
let discussion_languages = SiteLanguage::read_local(context.pool()).await?;
+ let taglines_res = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
+ let taglines = (!taglines_res.is_empty()).then_some(taglines_res);
Ok(GetSiteResponse {
site_view,
federated_instances,
all_languages,
discussion_languages,
+ taglines,
})
}
}
local_site_rate_limit::{LocalSiteRateLimit, LocalSiteRateLimitUpdateForm},
local_user::LocalUser,
site::{Site, SiteUpdateForm},
+ tagline::Tagline,
},
traits::Crud,
utils::{diesel_option_overwrite, diesel_option_overwrite_to_url, naive_now},
.map_err(|e| LemmyError::from_error_message(e, "couldnt_set_all_email_verified"))?;
}
+ let taglines = data.taglines.to_owned();
+ Tagline::replace(context.pool(), local_site.id, taglines).await?;
+
let site_view = SiteView::read_local(context.pool()).await?;
let rate_limit_config =
pub mod registration_application;
pub mod secret;
pub mod site;
+pub mod tagline;
--- /dev/null
+use crate::{
+ newtypes::LocalSiteId,
+ schema::tagline::dsl::*,
+ source::tagline::*,
+ utils::{get_conn, DbPool},
+};
+use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
+use diesel_async::{AsyncPgConnection, RunQueryDsl};
+
+impl Tagline {
+ pub async fn replace(
+ pool: &DbPool,
+ for_local_site_id: LocalSiteId,
+ list_content: Option<Vec<String>>,
+ ) -> Result<(), Error> {
+ if let Some(list) = list_content {
+ let conn = &mut get_conn(pool).await?;
+ conn
+ .build_transaction()
+ .run(|conn| {
+ Box::pin(async move {
+ Self::clear(conn).await?;
+
+ for item in list {
+ let form = TaglineForm {
+ local_site_id: for_local_site_id,
+ content: item,
+ updated: None,
+ };
+ insert_into(tagline)
+ .values(form)
+ .get_result::<Self>(conn)
+ .await?;
+ }
+ Ok(())
+ }) as _
+ })
+ .await
+ } else {
+ Ok(())
+ }
+ }
+
+ async fn clear(conn: &mut AsyncPgConnection) -> Result<usize, Error> {
+ diesel::delete(tagline).execute(conn).await
+ }
+ pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result<Vec<Self>, Error> {
+ use crate::schema::tagline::dsl::*;
+ let conn = &mut get_conn(pool).await?;
+ tagline
+ .filter(local_site_id.eq(for_local_site_id))
+ .get_results::<Self>(conn)
+ .await
+ }
+}
}
}
+table! {
+ tagline(id) {
+ id -> Int4,
+ local_site_id -> Int4,
+ content -> Text,
+ published -> Timestamp,
+ updated -> Nullable<Timestamp>,
+ }
+}
+
joinable!(person_block -> person (person_id));
joinable!(comment -> person (creator_id));
joinable!(federation_blocklist -> instance (instance_id));
joinable!(local_site -> site (site_id));
joinable!(local_site_rate_limit -> local_site (local_site_id));
+joinable!(tagline -> local_site (local_site_id));
allow_tables_to_appear_in_same_query!(
activity,
email_verification,
registration_application,
language,
+ tagline,
local_user_language,
site_language,
community_language,
pub mod registration_application;
pub mod secret;
pub mod site;
+pub mod tagline;
--- /dev/null
+use crate::newtypes::LocalSiteId;
+#[cfg(feature = "full")]
+use crate::schema::tagline;
+use serde::{Deserialize, Serialize};
+
+#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
+#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
+#[cfg_attr(feature = "full", diesel(table_name = tagline))]
+#[cfg_attr(
+ feature = "full",
+ diesel(belongs_to(crate::source::local_site::LocalSite))
+)]
+pub struct Tagline {
+ pub id: i32,
+ pub local_site_id: LocalSiteId,
+ pub content: String,
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+}
+
+#[derive(Clone, Default)]
+#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
+#[cfg_attr(feature = "full", diesel(table_name = tagline))]
+pub struct TaglineForm {
+ pub local_site_id: LocalSiteId,
+ pub content: String,
+ pub updated: Option<chrono::NaiveDateTime>,
+}
--- /dev/null
+drop table tagline;
\ No newline at end of file
--- /dev/null
+create table tagline (
+ id serial primary key,
+ local_site_id int references local_site on update cascade on delete cascade not null,
+ content text not null,
+ published timestamp without time zone default now() not null,
+ updated timestamp without time zone
+);
\ No newline at end of file