fix: emoji shortcodes
This commit is contained in:
parent
570a290954
commit
24cf61c783
7 changed files with 39 additions and 17 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -3711,6 +3711,7 @@ dependencies = [
|
||||||
"axum-extra",
|
"axum-extra",
|
||||||
"cf-turnstile",
|
"cf-turnstile",
|
||||||
"contrasted",
|
"contrasted",
|
||||||
|
"emojis",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"image",
|
"image",
|
||||||
"mime_guess",
|
"mime_guess",
|
||||||
|
|
|
@ -47,3 +47,4 @@ async-stripe = { version = "0.41.0", features = [
|
||||||
"billing",
|
"billing",
|
||||||
"runtime-tokio-hyper",
|
"runtime-tokio-hyper",
|
||||||
] }
|
] }
|
||||||
|
emojis = "0.6.4"
|
||||||
|
|
|
@ -1146,28 +1146,25 @@ secondary=false) -%}
|
||||||
<script>
|
<script>
|
||||||
document
|
document
|
||||||
.querySelector("emoji-picker")
|
.querySelector("emoji-picker")
|
||||||
.addEventListener("emoji-click", (event) => {
|
.addEventListener("emoji-click", async (event) => {
|
||||||
function gemoji() {
|
if (event.detail.skinTone > 0) {
|
||||||
const use_first_shortcode = [
|
document.getElementById(
|
||||||
"grinning squinting face",
|
window.EMOJI_PICKER_TEXT_ID,
|
||||||
"smiling_face_with_heart_eyes",
|
).value += event.detail.unicode;
|
||||||
];
|
|
||||||
|
|
||||||
if (
|
document.getElementById("emoji_dialog").close();
|
||||||
use_first_shortcode.includes(
|
return;
|
||||||
event.detail.emoji.annotation,
|
|
||||||
) ||
|
|
||||||
!event.detail.emoji.shortcodes[1]
|
|
||||||
) {
|
|
||||||
return event.detail.emoji.shortcodes[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return event.detail.emoji.shortcodes[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById(
|
document.getElementById(
|
||||||
window.EMOJI_PICKER_TEXT_ID,
|
window.EMOJI_PICKER_TEXT_ID,
|
||||||
).value += ` :${gemoji()}:`;
|
).value += ` :${await (
|
||||||
|
await fetch("/api/v1/lookup_emoji", {
|
||||||
|
method: "POST",
|
||||||
|
body: event.detail.unicode,
|
||||||
|
})
|
||||||
|
).text()}:`;
|
||||||
|
|
||||||
document.getElementById("emoji_dialog").close();
|
document.getElementById("emoji_dialog").close();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
12
crates/app/src/routes/api/v1/communities/emojis.rs
Normal file
12
crates/app/src/routes/api/v1/communities/emojis.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
use axum::response::IntoResponse;
|
||||||
|
|
||||||
|
/// Expand a unicode emoji into its Gemoji shortcode.
|
||||||
|
pub async fn get_emoji_shortcode(emoji: String) -> impl IntoResponse {
|
||||||
|
match emojis::get(&emoji) {
|
||||||
|
Some(e) => match e.shortcode() {
|
||||||
|
Some(s) => s.to_string(),
|
||||||
|
None => e.name().replace(" ", "-"),
|
||||||
|
},
|
||||||
|
None => String::new(),
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
pub mod communities;
|
pub mod communities;
|
||||||
|
pub mod emojis;
|
||||||
pub mod images;
|
pub mod images;
|
||||||
pub mod posts;
|
pub mod posts;
|
||||||
pub mod questions;
|
pub mod questions;
|
||||||
|
|
|
@ -311,6 +311,11 @@ pub fn routes() -> Router {
|
||||||
)
|
)
|
||||||
.route("/messages", post(channels::messages::create_request))
|
.route("/messages", post(channels::messages::create_request))
|
||||||
.route("/messages/{id}", delete(channels::messages::delete_request))
|
.route("/messages/{id}", delete(channels::messages::delete_request))
|
||||||
|
// emojis
|
||||||
|
.route(
|
||||||
|
"/lookup_emoji",
|
||||||
|
post(communities::emojis::get_emoji_shortcode),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
|
@ -105,6 +105,11 @@ impl DataManager {
|
||||||
pub async fn create_emoji(&self, data: CustomEmoji) -> Result<()> {
|
pub async fn create_emoji(&self, data: CustomEmoji) -> Result<()> {
|
||||||
let user = self.get_user_by_id(data.owner).await?;
|
let user = self.get_user_by_id(data.owner).await?;
|
||||||
|
|
||||||
|
// check if we can create animated emojis
|
||||||
|
if !user.permissions.check(FinePermission::SUPPORTER) && data.is_animated {
|
||||||
|
return Err(Error::RequiresSupporter);
|
||||||
|
}
|
||||||
|
|
||||||
// check user permission in community
|
// check user permission in community
|
||||||
if data.community != 0 {
|
if data.community != 0 {
|
||||||
let membership = self
|
let membership = self
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue