add: channel mutes
This commit is contained in:
parent
02f3d08926
commit
884a89904e
17 changed files with 149 additions and 7 deletions
|
@ -222,6 +222,8 @@ version = "1.0.0"
|
|||
"chats:action.add_someone" = "Add someone"
|
||||
"chats:action.kick_member" = "Kick member"
|
||||
"chats:action.mention_user" = "Mention user"
|
||||
"chats:action.mute" = "Mute"
|
||||
"chats:action.unmute" = "Unmute"
|
||||
|
||||
"stacks:link.stacks" = "Stacks"
|
||||
"stacks:label.my_stacks" = "My stacks"
|
||||
|
|
|
@ -210,6 +210,30 @@
|
|||
});
|
||||
};
|
||||
|
||||
globalThis.mute_channel = async (id, mute = true) => {
|
||||
await trigger(\"atto::debounce\", [\"channels::mute\"]);
|
||||
fetch(`/api/v1/channels/${id}/mute`, {
|
||||
method: mute ? \"POST\" : \"DELETE\",
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger(\"atto::toast\", [
|
||||
res.ok ? \"success\" : \"error\",
|
||||
res.message,
|
||||
]);
|
||||
|
||||
if (res.ok) {
|
||||
if (mute) {
|
||||
document.querySelector(`[ui_ident=channel\\\\.mute\\\\:${id}]`).classList.add(\"hidden\");
|
||||
document.querySelector(`[ui_ident=channel\\\\.unmute\\\\:${id}]`).classList.remove(\"hidden\");
|
||||
} else {
|
||||
document.querySelector(`[ui_ident=channel\\\\.mute\\\\:${id}]`).classList.remove(\"hidden\");
|
||||
document.querySelector(`[ui_ident=channel\\\\.unmute\\\\:${id}]`).classList.add(\"hidden\");
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
globalThis.update_channel_title = async (id) => {
|
||||
await trigger(\"atto::debounce\", [\"channels::update_title\"]);
|
||||
const title = await trigger(\"atto::prompt\", [\"New channel title:\"]);
|
||||
|
|
|
@ -31,6 +31,22 @@
|
|||
(text "{{ icon \"user-plus\" }}")
|
||||
(span
|
||||
(text "{{ text \"chats:action.add_someone\" }}")))
|
||||
; mute/unmute
|
||||
(button
|
||||
("class" "lowered small {% if channel.id in user.channel_mutes -%} hidden {%- endif %}")
|
||||
("ui_ident" "channel.mute:{{ channel.id }}")
|
||||
("onclick" "mute_channel('{{ channel.id }}')")
|
||||
(icon (text "bell-off"))
|
||||
(span
|
||||
(str (text "chats:action.mute"))))
|
||||
(button
|
||||
("class" "lowered small {% if not channel.id in user.channel_mutes -%} hidden {%- endif %}")
|
||||
("ui_ident" "channel.unmute:{{ channel.id }}")
|
||||
("onclick" "mute_channel('{{ channel.id }}', false)")
|
||||
(icon (text "bell-ring"))
|
||||
(span
|
||||
(str (text "chats:action.unmute"))))
|
||||
; ...
|
||||
(text "{%- endif %}")
|
||||
(button
|
||||
("class" "lowered small")
|
||||
|
|
|
@ -113,6 +113,12 @@
|
|||
("style" "color: var(--color-primary)")
|
||||
("class" "flex items-center")
|
||||
(text "{{ icon \"badge-check\" }}"))
|
||||
(text "{%- endif %} {% if user.permissions|has_staff_badge -%}")
|
||||
(span
|
||||
("title" "Staff")
|
||||
("style" "color: var(--color-primary);")
|
||||
("class" "flex items-center")
|
||||
(text "{{ icon \"shield-user\" }}"))
|
||||
(text "{%- endif %}"))
|
||||
(text "{%- endif %} {%- endmacro %} {% macro repost(repost, post, owner, secondary=false, community=false, show_community=true, can_manage_post=false) -%}")
|
||||
(div
|
||||
|
|
|
@ -689,7 +689,7 @@ media_theme_pref();
|
|||
});
|
||||
|
||||
self.define("hooks::check_message_reactions", async ({ $ }) => {
|
||||
const observer = $.offload_work_to_client_when_in_view(
|
||||
const observer = await $.offload_work_to_client_when_in_view(
|
||||
async (element) => {
|
||||
const reactions = await (
|
||||
await fetch(
|
||||
|
|
|
@ -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