56 lines
2.2 KiB
Rust
56 lines
2.2 KiB
Rust
//! Stickers widget, used here for the emoji picker (reactions and insertion).
|
|
|
|
use serde_json::json;
|
|
|
|
use super::P;
|
|
use crate::{app::Ctx, db, utils};
|
|
|
|
pub fn build(_ctx: &Ctx) -> String {
|
|
String::new()
|
|
}
|
|
|
|
pub async fn call(ctx: &Ctx, func: &str, p: &P<'_>) -> bool {
|
|
match func {
|
|
"ajaxReaction" => {
|
|
let mid = p.i(0);
|
|
let mut suggested = vec![];
|
|
if let Some(mid) = mid {
|
|
let me = ctx.jid();
|
|
if let Ok(Some(m)) = db::message_by_mid(ctx.db(), &me, mid).await {
|
|
let reactions = db::reactions_for(ctx.db(), &[mid]).await.unwrap_or_default();
|
|
let mut emojis: Vec<String> = vec![];
|
|
// Emojis of the message body
|
|
let body = m.body.unwrap_or_default();
|
|
for e in body.split_whitespace().filter(|w| utils::is_single_emoji(w)) {
|
|
if !emojis.contains(&e.to_string()) {
|
|
emojis.push(e.to_string());
|
|
}
|
|
}
|
|
for r in reactions {
|
|
if !emojis.contains(&r.emoji) {
|
|
emojis.push(r.emoji);
|
|
}
|
|
}
|
|
for e in emojis {
|
|
let html = utils::replace_emojis(&e, &ctx.base_uri(), true);
|
|
if let Some((url, _)) = html.single {
|
|
suggested.push(json!({ "emoji": e, "url": url }));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
let html = ctx.render("Stickers/_stickers_emojis.html", json!({ "mid": mid, "suggested": suggested }));
|
|
super::drawer(ctx, "emojis", &html, true, true);
|
|
crate::rpc!(ctx, "Stickers.setEmojisEvent", mid);
|
|
}
|
|
"ajaxShow" => {
|
|
// Sticker packs are not supported: show the emojis instead
|
|
let html = ctx.render("Stickers/_stickers_emojis.html", json!({ "mid": null, "suggested": [] }));
|
|
super::drawer(ctx, "emojis", &html, true, true);
|
|
crate::rpc!(ctx, "Stickers.setEmojisEvent", serde_json::Value::Null);
|
|
}
|
|
_ => return false,
|
|
}
|
|
true
|
|
}
|