add: channel mutes

This commit is contained in:
trisua 2025-07-18 20:04:26 -04:00
parent 02f3d08926
commit 884a89904e
17 changed files with 149 additions and 7 deletions

View file

@ -120,6 +120,7 @@ impl DataManager {
browser_session: get!(x->26(String)),
seller_data: serde_json::from_str(&get!(x->27(String)).to_string()).unwrap(),
ban_reason: get!(x->28(String)),
channel_mutes: serde_json::from_str(&get!(x->29(String)).to_string()).unwrap(),
}
}
@ -276,7 +277,7 @@ impl DataManager {
let res = execute!(
&conn,
"INSERT INTO users VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29)",
"INSERT INTO users VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30)",
params![
&(data.id as i64),
&(data.created as i64),
@ -306,7 +307,8 @@ impl DataManager {
&if data.was_purchased { 1_i32 } else { 0_i32 },
&data.browser_session,
&serde_json::to_string(&data.seller_data).unwrap(),
&data.ban_reason
&data.ban_reason,
&serde_json::to_string(&data.channel_mutes).unwrap(),
]
);
@ -1004,6 +1006,7 @@ impl DataManager {
auto_method!(update_user_browser_session(&str)@get_user_by_id -> "UPDATE users SET browser_session = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_user);
auto_method!(update_user_seller_data(StripeSellerData)@get_user_by_id -> "UPDATE users SET seller_data = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
auto_method!(update_user_ban_reason(&str)@get_user_by_id -> "UPDATE users SET ban_reason = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_user);
auto_method!(update_user_channel_mutes(Vec<usize>)@get_user_by_id -> "UPDATE users SET channel_mutes = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
auto_method!(get_user_by_stripe_id(&str)@get_user_from_row -> "SELECT * FROM users WHERE stripe_id = $1" --name="user" --returns=User);
auto_method!(update_user_stripe_id(&str)@get_user_by_id -> "UPDATE users SET stripe_id = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_user);

View file

@ -44,6 +44,7 @@ impl DataManager {
execute!(&conn, common::CREATE_TABLE_SERVICES).unwrap();
execute!(&conn, common::CREATE_TABLE_PRODUCTS).unwrap();
execute!(&conn, common::CREATE_TABLE_APP_DATA).unwrap();
execute!(&conn, common::VERSION_MIGRATIONS).unwrap();
self.0
.1

View file

@ -1,3 +1,4 @@
pub const VERSION_MIGRATIONS: &str = include_str!("./sql/version_migrations.sql");
pub const CREATE_TABLE_USERS: &str = include_str!("./sql/create_users.sql");
pub const CREATE_TABLE_COMMUNITIES: &str = include_str!("./sql/create_communities.sql");
pub const CREATE_TABLE_POSTS: &str = include_str!("./sql/create_posts.sql");

View file

@ -27,5 +27,6 @@ CREATE TABLE IF NOT EXISTS users (
was_purchased INT NOT NULL,
browser_session TEXT NOT NULL,
seller_data TEXT NOT NULL,
ban_reason TEXT NOT NULL
ban_reason TEXT NOT NULL,
channel_mutes TEXT NOT NULL
)

View file

@ -0,0 +1,3 @@
-- users channel_mutes
ALTER TABLE users
ADD COLUMN IF NOT EXISTS channel_mutes TEXT DEFAULT '[]';

View file

@ -190,6 +190,11 @@ impl DataManager {
continue;
}
let user = self.get_user_by_id(member).await?;
if user.channel_mutes.contains(&channel.id) {
continue;
}
let mut notif = Notification::new(
"You've received a new message!".to_string(),
format!(

View file

@ -86,6 +86,9 @@ pub struct User {
/// The reason the user was banned.
#[serde(default)]
pub ban_reason: String,
/// IDs of channels the user has muted.
#[serde(default)]
pub channel_mutes: Vec<usize>,
}
pub type UserConnections =
@ -387,6 +390,7 @@ impl User {
browser_session: String::new(),
seller_data: StripeSellerData::default(),
ban_reason: String::new(),
channel_mutes: Vec::new(),
}
}

View file

@ -144,6 +144,8 @@ pub enum AppScope {
UserManageServices,
/// Manage the user's products.
UserManageProducts,
/// Manage the user's channel mutes.
UserManageChannelMutes,
/// Edit posts created by the user.
UserEditPosts,
/// Edit drafts created by the user.

View file

@ -131,9 +131,14 @@ impl CustomEmoji {
if emoji.1 == 0 {
out = out.replace(
&emoji.0,
match emojis::get_by_shortcode(&emoji.2) {
Some(e) => e.as_str(),
None => &emoji.0,
match emoji.2.as_str() {
"100" => "💯",
"thumbs_up" => "👍",
"thumbs_down" => "👎",
_ => match emojis::get_by_shortcode(&emoji.2) {
Some(e) => e.as_str(),
None => &emoji.0,
},
},
);
} else {