From 2411b4fe79ab57563f0fdb282a46b82b5c40b2c3 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 19 Jan 2021 16:16:22 -0800 Subject: [PATCH 1/2] puts @'mentions directly in compose box --- bookwyrm/static/js/shared.js | 4 +++- bookwyrm/templates/snippets/create_status_form.html | 3 ++- bookwyrm/templatetags/bookwyrm_tags.py | 4 ++-- bookwyrm/views/status.py | 2 -- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js index e8ff9c46..a0c21bec 100644 --- a/bookwyrm/static/js/shared.js +++ b/bookwyrm/static/js/shared.js @@ -112,7 +112,9 @@ function toggleAction(e) { // set focus, if appropriate var focus = el.getAttribute('data-focus-target'); if (focus) { - document.getElementById(focus).focus(); + var focusEl = document.getElementById(focus); + focusEl.focus(); + setTimeout(function(){ focusEl.selectionStart = focusEl.selectionEnd = 10000; }, 0); } } diff --git a/bookwyrm/templates/snippets/create_status_form.html b/bookwyrm/templates/snippets/create_status_form.html index 3dfc19d9..0c2ebbee 100644 --- a/bookwyrm/templates/snippets/create_status_form.html +++ b/bookwyrm/templates/snippets/create_status_form.html @@ -1,3 +1,4 @@ +{% load bookwyrm_tags %}
{% csrf_token %} @@ -34,7 +35,7 @@ {% else %} {% include 'snippets/content_warning_field.html' with parent_status=status %} - + {% endif %} {% if type == 'quotation' %} diff --git a/bookwyrm/templatetags/bookwyrm_tags.py b/bookwyrm/templatetags/bookwyrm_tags.py index c58f5c47..08bbcafe 100644 --- a/bookwyrm/templatetags/bookwyrm_tags.py +++ b/bookwyrm/templatetags/bookwyrm_tags.py @@ -142,10 +142,10 @@ def get_markdown(content): @register.filter(name='mentions') def get_mentions(status, user): - ''' anyone tagged or replied to in this status ''' + ''' people to @ in a reply: the parent and all mentions ''' mentions = set([status.user] + list(status.mention_users.all())) return ' '.join( - '@' + get_user_identifier(m) for m in mentions if not m == user) + '@' + get_user_identifier(m) for m in mentions if not m == user) + ' ' @register.filter(name='status_preview_name') def get_status_preview_name(obj): diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py index a624c806..834cf583 100644 --- a/bookwyrm/views/status.py +++ b/bookwyrm/views/status.py @@ -86,8 +86,6 @@ class CreateStatus(View): # add reply parent to mentions and notify if status.reply_parent: status.mention_users.add(status.reply_parent.user) - for mention_user in status.reply_parent.mention_users.all(): - status.mention_users.add(mention_user) if status.reply_parent.user.local: create_notification( From 9f2ca73a58afc4778217cd599a2f681753a350ac Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 19 Jan 2021 16:48:06 -0800 Subject: [PATCH 2/2] Tests terminal space in mentions string --- bookwyrm/tests/test_templatetags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/tests/test_templatetags.py b/bookwyrm/tests/test_templatetags.py index 2cc61eab..d315144f 100644 --- a/bookwyrm/tests/test_templatetags.py +++ b/bookwyrm/tests/test_templatetags.py @@ -228,7 +228,7 @@ class TemplateTags(TestCase): status = models.Status.objects.create( content='hi', user=self.remote_user) result = bookwyrm_tags.get_mentions(status, self.user) - self.assertEqual(result, '@rat@example.com') + self.assertEqual(result, '@rat@example.com ') def test_get_status_preview_name(self):