From 4ddc26c6ca544117763d0c17081f5f26567215ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Tue, 12 Oct 2021 00:12:19 +0200 Subject: [PATCH] fixes in help cmd, make everything use markdown --- README.md | 1 + locales/en.json | 2 +- src/group_handler/handle_mention.rs | 20 +++----------------- src/store/group_config.rs | 21 +++++++++++++++------ 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 47196a9..915ff64 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ The locale file looks like this (excerpt): } ``` +- All messages can use markdown formatting. - Words in curly braces (`{}`) are substitution tokens. These must be preserved in all translations. - Pay attention to line endings and blank lines (`\n`). Some messages from the locale file are combined to form the final post, leaving out newlines can result in a mangled output. diff --git a/locales/en.json b/locales/en.json index 5ed832e..4280e63 100644 --- a/locales/en.json +++ b/locales/en.json @@ -11,7 +11,7 @@ "help_membership_member": "*You are a member.*", "help_membership_guest_closed": "*You are not a member, ask one of the admins to add you.*", "help_membership_guest_open": "*You are not a member, follow or use /join to join the group.*", - "help_admin_commands": "\n\n**Admin commands:**\n`/ping` - check the group works\n`/members - show group members / admins\n`/add user` - add a member (user@domain)\n`/remove user` - remove a member\n`/add #hashtag` - add a group hashtag\n`/remove #hashtag` - remove a group hashtag\n`/undo` - un-boost a replied-to post, delete an announcement\n`/ban x` - ban a user or server\n`/unban x` - lift a ban\n`/admin user` - grant admin rights\n`/deadmin user` - revoke admin rights\n`/closegroup` - make member-only\n`/opengroup` - make public-access\n`/announce x` - make a public announcement", + "help_admin_commands": "\n\n**Admin commands:**\n`/ping` - check the group works\n`/members` - show group members / admins\n`/add user` - add a member (user@domain)\n`/remove user` - remove a member\n`/add #hashtag` - add a group hashtag\n`/remove #hashtag` - remove a group hashtag\n`/undo` - un-boost a replied-to post, delete an announcement\n`/ban x` - ban a user or server\n`/unban x` - lift a ban\n`/admin user` - grant admin rights\n`/deadmin user` - revoke admin rights\n`/closegroup` - make member-only\n`/opengroup` - make public-access\n`/announce x` - make a public announcement", "help_basic_commands": "To share a post, @ the group user or use a group hashtag.\n\n**Supported commands:**\n`/boost`, `/b` - boost the replied-to post into the group\n`/ignore`, `/i` - make the group ignore the post\n`/tags` - show group hashtags\n`/join` - (re-)join the group\n`/leave` - leave the group\n`/optout` - forbid sharing of your posts", "help_member_commands": "\n`/admins` - show group admins\n`/undo` - un-boost your post (use in a reply)", "cmd_leave_ok": "You're no longer a group member. Unfollow the group user to stop receiving group messages.", diff --git a/src/group_handler/handle_mention.rs b/src/group_handler/handle_mention.rs index 218dae5..3bdba71 100644 --- a/src/group_handler/handle_mention.rs +++ b/src/group_handler/handle_mention.rs @@ -30,7 +30,6 @@ pub struct ProcessMention<'a> { replies: String, announcements: String, do_boost_prev_post: bool, - want_markdown: bool, } impl<'a> ProcessMention<'a> { @@ -134,7 +133,6 @@ impl<'a> ProcessMention<'a> { replies: String::new(), announcements: String::new(), do_boost_prev_post: false, - want_markdown: false, group_acct, status_acct, status, @@ -271,9 +269,7 @@ impl<'a> ProcessMention<'a> { let mut msg = std::mem::take(&mut self.replies); debug!("r={}", msg); - if self.want_markdown { - apply_trailing_hashtag_pleroma_bug_workaround(&mut msg); - } + apply_trailing_hashtag_pleroma_bug_workaround(&mut msg); let mention = crate::tr!(self, "mention_prefix", user = &self.status_acct); self.send_reply_multipart(mention, msg).await?; @@ -283,9 +279,7 @@ impl<'a> ProcessMention<'a> { let mut msg = std::mem::take(&mut self.announcements); debug!("a={}", msg); - if self.want_markdown { - apply_trailing_hashtag_pleroma_bug_workaround(&mut msg); - } + apply_trailing_hashtag_pleroma_bug_workaround(&mut msg); let msg = crate::tr!(self, "group_announcement", message = &msg); self.send_announcement_multipart(&msg).await?; @@ -301,11 +295,7 @@ impl<'a> ProcessMention<'a> { for p in parts { if let Ok(post) = StatusBuilder::new() .status(p) - .content_type(if self.want_markdown { - "text/markdown" - } else { - "text/plain" - }) + .content_type("text/markdown") .in_reply_to(&parent) .visibility(Visibility::Direct) .build() @@ -647,8 +637,6 @@ impl<'a> ProcessMention<'a> { } async fn cmd_help(&mut self) { - self.want_markdown = true; - let membership_line = if self.is_admin { crate::tr!(self, "help_membership_admin") } else if self.config.is_member(&self.status_acct) { @@ -677,7 +665,6 @@ impl<'a> ProcessMention<'a> { } async fn cmd_list_members(&mut self) { - self.want_markdown = true; if self.is_admin { self.add_reply(crate::tr!(self, "member_list_heading")); self.append_member_list_to_reply(); @@ -689,7 +676,6 @@ impl<'a> ProcessMention<'a> { async fn cmd_list_tags(&mut self) { self.add_reply(crate::tr!(self, "tag_list_heading")); - self.want_markdown = true; let mut tags = self.config.get_tags().collect::>(); tags.sort(); diff --git a/src/store/group_config.rs b/src/store/group_config.rs index 60dc934..5eddbea 100644 --- a/src/store/group_config.rs +++ b/src/store/group_config.rs @@ -583,6 +583,15 @@ mod tests { use crate::error::GroupError; use crate::store::group_config::{acct_to_server, GroupConfig}; + fn empty_group_config() -> GroupConfig { + GroupConfig { + config: Default::default(), + control: Default::default(), + state: Default::default(), + _group_tr: Default::default() + } + } + #[test] fn test_acct_to_server() { assert_eq!("pikachu.rocks", acct_to_server("raichu@pikachu.rocks")); @@ -592,7 +601,7 @@ mod tests { #[test] fn test_default_rules() { - let group = GroupConfig::default(); + let group = empty_group_config(); assert!(!group.is_member_only()); assert!(!group.is_member("piggo@piggo.space")); assert!(!group.is_admin("piggo@piggo.space")); @@ -601,7 +610,7 @@ mod tests { #[test] fn test_member_only() { - let mut group = GroupConfig::default(); + let mut group = empty_group_config(); assert!(group.can_write("piggo@piggo.space"), "rando can write in public group"); group.set_member_only(true); @@ -638,7 +647,7 @@ mod tests { #[test] fn test_banned_users() { // Banning single user - let mut group = GroupConfig::default(); + let mut group = empty_group_config(); group.ban_user("piggo@piggo.space", true).unwrap(); assert!(!group.can_write("piggo@piggo.space"), "banned user can't post"); group.ban_user("piggo@piggo.space", false).unwrap(); @@ -648,7 +657,7 @@ mod tests { #[test] fn test_banned_members() { // Banning single user - let mut group = GroupConfig::default(); + let mut group = empty_group_config(); group.set_member_only(true); group.set_member("piggo@piggo.space", true).unwrap(); @@ -669,7 +678,7 @@ mod tests { #[test] fn test_server_ban() { - let mut group = GroupConfig::default(); + let mut group = empty_group_config(); assert!(group.can_write("hitler@nazi.camp"), "randos can write"); group.ban_server("nazi.camp", true).unwrap(); @@ -689,7 +698,7 @@ mod tests { #[test] fn test_sanity() { - let mut group = GroupConfig::default(); + let mut group = empty_group_config(); group.set_admin("piggo@piggo.space", true).unwrap(); assert_eq!(