add: channel mutes
This commit is contained in:
parent
02f3d08926
commit
884a89904e
17 changed files with 149 additions and 7 deletions
|
@ -293,3 +293,62 @@ pub async fn get_request(
|
|||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn mute_channel_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let mut user = match get_user_from_token!(jar, data, oauth::AppScope::UserManageChannelMutes) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if user.channel_mutes.contains(&id) {
|
||||
return Json(Error::MiscError("Channel already muted".to_string()).into());
|
||||
}
|
||||
|
||||
user.channel_mutes.push(id);
|
||||
match data
|
||||
.update_user_channel_mutes(user.id, user.channel_mutes)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Channel muted".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn unmute_channel_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let mut user = match get_user_from_token!(jar, data, oauth::AppScope::UserManageChannelMutes) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
let pos = match user.channel_mutes.iter().position(|x| *x == id) {
|
||||
Some(x) => x,
|
||||
None => return Json(Error::MiscError("Channel not muted".to_string()).into()),
|
||||
};
|
||||
|
||||
user.channel_mutes.remove(pos);
|
||||
match data
|
||||
.update_user_channel_mutes(user.id, user.channel_mutes)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Channel muted".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ use tetratto_core::model::{
|
|||
/// Expand a unicode emoji into its Gemoji shortcode.
|
||||
pub async fn get_emoji_shortcode(emoji: String) -> impl IntoResponse {
|
||||
match emoji.as_str() {
|
||||
// matches `CustomEmoji::replace`
|
||||
"💯" => "100".to_string(),
|
||||
"👍" => "thumbs_up".to_string(),
|
||||
"👎" => "thumbs_down".to_string(),
|
||||
_ => match emojis::get(&emoji) {
|
||||
|
|
|
@ -570,6 +570,14 @@ pub fn routes() -> Router {
|
|||
"/channels/{id}/kick",
|
||||
post(channels::channels::kick_member_request),
|
||||
)
|
||||
.route(
|
||||
"/channels/{id}/mute",
|
||||
post(channels::channels::mute_channel_request),
|
||||
)
|
||||
.route(
|
||||
"/channels/{id}/mute",
|
||||
delete(channels::channels::unmute_channel_request),
|
||||
)
|
||||
.route("/channels/{id}", get(channels::channels::get_request))
|
||||
.route(
|
||||
"/channels/community/{id}",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue