Forum: typing notices, smileys to emoji while typing, no emoji tray
"Holdfény gépel…" shows in threads and private conversations: the page says over the live connection (every few seconds while typing) that its member types, and the forum service passes it to those who may see that place, never back to the typer. The emoji tray is gone (phones have their emoji keyboard); character smileys turn into emoji as they are typed, from a longer list shared with the server (which also converts titles now; <3 is a red heart). Emoji show in colour: the forum's font stack names the systems' colour emoji fonts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
+38
-13
@@ -90,7 +90,7 @@ pub fn title(raw: &str) -> Result<String, ApiError> {
|
||||
if len > TITLE_MAX {
|
||||
return Err(ApiError::bad(format!("A cím legfeljebb {TITLE_MAX} karakter lehet.")));
|
||||
}
|
||||
Ok(title)
|
||||
Ok(smileys(&title))
|
||||
}
|
||||
|
||||
/// A post: control characters removed, at most one empty line in a row,
|
||||
@@ -180,21 +180,45 @@ fn clean_multiline(raw: &str, max_breaks: usize) -> String {
|
||||
out.trim().to_string()
|
||||
}
|
||||
|
||||
/// `:)`, `:D`, `;)`, `:(`, `:P` and `<3` standing alone become emoji, as on the
|
||||
/// old forums.
|
||||
/// The old forums' character smileys and their emoji. A smiley becomes the
|
||||
/// emoji only standing alone (between spaces), so links and the like stay as
|
||||
/// typed. The frontend converts the same list while typing
|
||||
/// (`src/lib/emoticons.ts`); this catches what it did not.
|
||||
pub const EMOTICONS: [(&str, &str); 27] = [
|
||||
(":)", "🙂"),
|
||||
(":-)", "🙂"),
|
||||
("(:", "🙂"),
|
||||
(":D", "😄"),
|
||||
(":-D", "😄"),
|
||||
("xD", "😆"),
|
||||
("XD", "😆"),
|
||||
(";)", "😉"),
|
||||
(";-)", "😉"),
|
||||
(":(", "🙁"),
|
||||
(":-(", "🙁"),
|
||||
(":'(", "😢"),
|
||||
(":P", "😛"),
|
||||
(":-P", "😛"),
|
||||
(":p", "😛"),
|
||||
(":O", "😮"),
|
||||
(":o", "😮"),
|
||||
(":-O", "😮"),
|
||||
(":*", "😘"),
|
||||
(":-*", "😘"),
|
||||
(":/", "😕"),
|
||||
(":|", "😐"),
|
||||
("B)", "😎"),
|
||||
("^^", "😊"),
|
||||
("^_^", "😊"),
|
||||
("<3", "❤️"),
|
||||
("</3", "💔"),
|
||||
];
|
||||
|
||||
fn smileys(text: &str) -> String {
|
||||
let mut out = String::with_capacity(text.len());
|
||||
let mut word = String::new();
|
||||
let flush = |word: &mut String, out: &mut String| {
|
||||
let emoji = match word.as_str() {
|
||||
":)" | ":-)" => Some("🙂"),
|
||||
":D" | ":-D" => Some("😄"),
|
||||
";)" | ";-)" => Some("😉"),
|
||||
":(" | ":-(" => Some("🙁"),
|
||||
":P" | ":-P" | ":p" => Some("😛"),
|
||||
"<3" => Some("🤍"),
|
||||
_ => None,
|
||||
};
|
||||
let emoji = EMOTICONS.iter().find(|(code, _)| code == word).map(|(_, e)| *e);
|
||||
out.push_str(emoji.unwrap_or(word));
|
||||
word.clear();
|
||||
};
|
||||
@@ -233,7 +257,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn bodies() {
|
||||
assert_eq!(body(" Szia :)\r\n\r\n\r\n\r\nMi újság? <3 ").unwrap(), "Szia 🙂\n\nMi újság? 🤍");
|
||||
assert_eq!(body(" Szia :)\r\n\r\n\r\n\r\nMi újság? <3 ").unwrap(), "Szia 🙂\n\nMi újság? ❤️");
|
||||
assert_eq!(body("Hiányzol :'( xD ^^").unwrap(), "Hiányzol 😢 😆 😊");
|
||||
assert_eq!(body("http://x.hu/:)").unwrap(), "http://x.hu/:)", "only smileys standing alone");
|
||||
assert!(body(" \n\t ").is_err());
|
||||
assert_eq!(body("a\u{0007}b").unwrap(), "ab");
|
||||
|
||||
Reference in New Issue
Block a user