-
-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/custom emoji and tagline views #4580
Merged
dessalines
merged 38 commits into
LemmyNet:main
from
fvanzee:feature/custom-emoji-and-tagline-views
Sep 19, 2024
Merged
Changes from 3 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
fd27523
Add custom_emoji list route
b4a8615
Add tagline list route
10a8f01
Apply linting
17e2834
Remove unecessary TaglineView
486c746
Add category filter for custom emoji
a1a7e2c
Add create tagline endpoint
ab93806
Add update tagline endpoint
e536d39
Add delete tagline endpoint
5358908
Format through lint.sh
2b1fdf1
Remove custom_emojis and taglines from site resource
f1b993f
Get random tagline on site requets
144c112
Impl Crud for Tagline
5342a22
Move tagline endpoints under /admin
bab417a
Impl Crud for CustomEmoji
ead5151
Remove delete from tagline and custom emoji impls
abdfc90
Check markdown for tagline
b2b8c43
Validate markdown on tagline
55be9a1
Merge branch 'main' into feature/custom-emoji-and-tagline-views
SleeplessOne1917 7759602
Make content fields non optional
6ffcc1f
Use process_markdown instead of process_markdown_opt
5cf15a4
Merge branch 'main' into feature/custom-emoji-and-tagline-views
SleeplessOne1917 7ce89fb
Consolidate Tagline error types
fvanzee 8c7b300
Remove unecessary clone
fvanzee 562c909
Updat misleading comments
fvanzee 6935acb
Remove local_site_id from tagline and custom_emoji
fvanzee 999e984
Update TaglineInserForm and TaglineUpdateForm
fvanzee 1f629cc
Add ignore_page_limits for custom emojis
fvanzee 4771085
Update custom_emoji_view
fvanzee 920adcc
Merge branch 'main' into feature/custom-emoji-and-tagline-views
fvanzee e96d0be
Merge remote-tracking branch 'origin/main' into custom_emoji_dess
dessalines 004b1b2
Removing pointless get_all fn.
dessalines e09e54e
remove tagline length checks
Nutomic 215ebf7
make fields of TaglineInsertForm and TaglineUpdateForm mandatory
Nutomic 2de4503
move emoji order statement
Nutomic 18a4cf9
add comment for GetSiteResponse.tagline
Nutomic e4e18fe
Merge remote-tracking branch 'origin/main' into custom_emoji_dess
dessalines 8076dd8
Adding a default_comment_sort_type column for local_site and local_us…
dessalines afe5ff6
Simplify tests using default (#5026)
Nutomic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use lemmy_db_views::structs::TaglineView; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_with::skip_serializing_none; | ||
#[cfg(feature = "full")] | ||
use ts_rs::TS; | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
#[cfg_attr(feature = "full", derive(TS))] | ||
#[cfg_attr(feature = "full", ts(export))] | ||
/// A response for custom emojis. | ||
fvanzee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub struct ListTaglinesResponse { | ||
pub taglines: Vec<TaglineView>, | ||
} | ||
|
||
#[skip_serializing_none] | ||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)] | ||
#[cfg_attr(feature = "full", derive(TS))] | ||
#[cfg_attr(feature = "full", ts(export))] | ||
/// Fetches a list of registration applications. | ||
fvanzee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pub struct ListTaglines { | ||
pub page: Option<i64>, | ||
pub limit: Option<i64>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use actix_web::web::{Data, Json, Query}; | ||
use lemmy_api_common::{ | ||
context::LemmyContext, | ||
custom_emoji::{ListCustomEmojis, ListCustomEmojisResponse}, | ||
}; | ||
use lemmy_db_views::structs::{CustomEmojiView, LocalUserView, SiteView}; | ||
use lemmy_utils::error::LemmyError; | ||
|
||
#[tracing::instrument(skip(context))] | ||
pub async fn list_custom_emojis( | ||
data: Query<ListCustomEmojis>, | ||
local_user_view: Option<LocalUserView>, | ||
context: Data<LemmyContext>, | ||
) -> Result<Json<ListCustomEmojisResponse>, LemmyError> { | ||
let local_site = SiteView::read_local(&mut context.pool()).await?; | ||
let custom_emojis = CustomEmojiView::list( | ||
&mut context.pool(), | ||
local_site.local_site.id, | ||
data.page, | ||
data.limit, | ||
) | ||
.await | ||
.map_err(|e| anyhow::anyhow!("Failed to construct custom emojis response: {e}"))?; | ||
fvanzee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Ok(Json(ListCustomEmojisResponse { custom_emojis })) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod create; | ||
pub mod delete; | ||
pub mod list; | ||
pub mod update; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ pub mod custom_emoji; | |
pub mod post; | ||
pub mod private_message; | ||
pub mod site; | ||
pub mod tagline; | ||
pub mod user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use actix_web::web::{Data, Json, Query}; | ||
use lemmy_api_common::{ | ||
context::LemmyContext, | ||
tagline::{ListTaglines, ListTaglinesResponse}, | ||
}; | ||
use lemmy_db_views::structs::{LocalUserView, SiteView, TaglineView}; | ||
use lemmy_utils::error::LemmyError; | ||
|
||
#[tracing::instrument(skip(context))] | ||
pub async fn list_taglines( | ||
data: Query<ListTaglines>, | ||
local_user_view: Option<LocalUserView>, | ||
context: Data<LemmyContext>, | ||
) -> Result<Json<ListTaglinesResponse>, LemmyError> { | ||
let local_site = SiteView::read_local(&mut context.pool()).await?; | ||
let taglines = TaglineView::list( | ||
&mut context.pool(), | ||
local_site.local_site.id, | ||
data.page, | ||
data.limit, | ||
) | ||
.await | ||
.map_err(|e| anyhow::anyhow!("Failed to construct taglines response: {e}"))?; | ||
fvanzee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Ok(Json(ListTaglinesResponse { taglines })) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod list; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ use lemmy_db_schema::{ | |
newtypes::{CustomEmojiId, LocalSiteId}, | ||
schema::{custom_emoji, custom_emoji_keyword}, | ||
source::{custom_emoji::CustomEmoji, custom_emoji_keyword::CustomEmojiKeyword}, | ||
utils::{get_conn, DbPool}, | ||
utils::{get_conn, limit_and_offset, DbPool}, | ||
}; | ||
use std::collections::HashMap; | ||
|
||
|
@@ -57,6 +57,33 @@ impl CustomEmojiView { | |
Ok(CustomEmojiView::from_tuple_to_vec(emojis)) | ||
} | ||
|
||
pub async fn list( | ||
pool: &mut DbPool<'_>, | ||
for_local_site_id: LocalSiteId, | ||
page: Option<i64>, | ||
limit: Option<i64>, | ||
) -> Result<Vec<Self>, Error> { | ||
let conn = &mut get_conn(pool).await?; | ||
let (limit, offset) = limit_and_offset(page, limit)?; | ||
let emojis = custom_emoji::table | ||
.filter(custom_emoji::local_site_id.eq(for_local_site_id)) | ||
.left_join( | ||
custom_emoji_keyword::table.on(custom_emoji_keyword::custom_emoji_id.eq(custom_emoji::id)), | ||
) | ||
.order(custom_emoji::category) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The category ordering should probably only happen if they supplied a category, just to be faster. So you could add then add |
||
.then_order_by(custom_emoji::id) | ||
.select(( | ||
custom_emoji::all_columns, | ||
custom_emoji_keyword::all_columns.nullable(), // (or all the columns if you want) | ||
)) | ||
.limit(limit) | ||
.offset(offset) | ||
.load::<CustomEmojiTuple>(conn) | ||
.await?; | ||
|
||
Ok(CustomEmojiView::from_tuple_to_vec(emojis)) | ||
} | ||
|
||
fn from_tuple_to_vec(items: Vec<CustomEmojiTuple>) -> Vec<Self> { | ||
let mut result = Vec::new(); | ||
let mut hash: HashMap<CustomEmojiId, Vec<CustomEmojiKeyword>> = HashMap::new(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::structs::TaglineView; | ||
use diesel::{result::Error, ExpressionMethods, QueryDsl}; | ||
use diesel_async::RunQueryDsl; | ||
use lemmy_db_schema::{ | ||
newtypes::LocalSiteId, | ||
schema::tagline, | ||
source::tagline::Tagline, | ||
utils::{get_conn, limit_and_offset, DbPool}, | ||
}; | ||
|
||
impl TaglineView { | ||
pub async fn list( | ||
pool: &mut DbPool<'_>, | ||
for_local_site_id: LocalSiteId, | ||
page: Option<i64>, | ||
limit: Option<i64>, | ||
) -> Result<Vec<Self>, Error> { | ||
let conn = &mut get_conn(pool).await?; | ||
let (limit, offset) = limit_and_offset(page, limit)?; | ||
let taglines = tagline::table | ||
.filter(tagline::local_site_id.eq(for_local_site_id)) | ||
.order(tagline::id) | ||
dessalines marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.select(tagline::all_columns) | ||
.limit(limit) | ||
.offset(offset) | ||
.load::<Tagline>(conn) | ||
.await?; | ||
|
||
let mut result = Vec::new(); | ||
for tagline in &taglines { | ||
result.push(TaglineView { | ||
tagline: tagline.clone(), | ||
}); | ||
} | ||
fvanzee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Ok(result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@makotech222 look into your emoji library, because these may need a search term, optional category, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a category search parameter. This column is also already indexed