diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 0e3ac9c1f..e92bc1802 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -92,6 +92,12 @@ class ReplyForm(CustomForm): 'user', 'content', 'content_warning', 'sensitive', 'reply_parent', 'privacy'] +class StatusForm(CustomForm): + class Meta: + model = models.Status + fields = [ + 'user', 'content', 'content_warning', 'sensitive', 'privacy'] + class EditUserForm(CustomForm): class Meta: diff --git a/bookwyrm/templates/feed/direct_messages.html b/bookwyrm/templates/feed/direct_messages.html index 44a0cded7..8c53cbeb1 100644 --- a/bookwyrm/templates/feed/direct_messages.html +++ b/bookwyrm/templates/feed/direct_messages.html @@ -1,9 +1,16 @@ {% extends 'feed/feed_layout.html' %} {% block panel %} -
-

Direct Messages

+
+

Direct Messages{% if partner %} with {% include 'snippets/username.html' with user=partner %}{% endif %}

+ {% if partner %}

All messages

{% endif %} +
+
+ {% include 'snippets/create_status_form.html' with type="direct" uuid=1 mentions=partner %} +
+ +
{% if not activities %}

You have no messages right now.

{% endif %} @@ -14,6 +21,6 @@ {% endfor %} {% include 'snippets/pagination.html' with page=activities path="direct-messages" %} -
+ {% endblock %} diff --git a/bookwyrm/templates/feed/feed_layout.html b/bookwyrm/templates/feed/feed_layout.html index 33123ca80..f0c7b0577 100644 --- a/bookwyrm/templates/feed/feed_layout.html +++ b/bookwyrm/templates/feed/feed_layout.html @@ -76,7 +76,7 @@ {% block panel %}{% endblock %} {% if activities %} - {% include 'snippets/pagination.html' with page=activities path='/'|add:tab anchor="#feed" %} + {% include 'snippets/pagination.html' with page=activities path=path anchor="#feed" %} {% endif %} diff --git a/bookwyrm/templates/snippets/create_status_form.html b/bookwyrm/templates/snippets/create_status_form.html index 0c2ebbee3..c6d7be3f2 100644 --- a/bookwyrm/templates/snippets/create_status_form.html +++ b/bookwyrm/templates/snippets/create_status_form.html @@ -1,5 +1,5 @@ {% load bookwyrm_tags %} -
+ {% csrf_token %} @@ -11,7 +11,7 @@ {% endif %}
- {% if not type == 'reply' %} + {% if type != 'reply' and type != 'direct' %} {% endif %} @@ -35,7 +35,7 @@ {% else %} {% include 'snippets/content_warning_field.html' with parent_status=status %} - + {% endif %}
{% if type == 'quotation' %} @@ -53,7 +53,12 @@ {% include 'snippets/toggle/toggle_button.html' with text="Include spoiler alert" icon="warning is-size-4" controls_text="spoilers" controls_uid=uuid focus="id_content_warning" checkbox="id_show_spoilers" class="toggle-button" pressed=status.content_warning %}
- {% include 'snippets/privacy_select.html' with current=reply_parent.privacy%} + {% if type == 'direct' %} + + + {% else %} + {% include 'snippets/privacy_select.html' with current=reply_parent.privacy %} + {% endif %}
diff --git a/bookwyrm/templates/snippets/status_options.html b/bookwyrm/templates/snippets/status_options.html index a6609cb30..3bf8251f6 100644 --- a/bookwyrm/templates/snippets/status_options.html +++ b/bookwyrm/templates/snippets/status_options.html @@ -18,6 +18,9 @@ {% else %} +
  • + Send direct message +
  • {% include 'snippets/block_button.html' with user=status.user class="is-fullwidth" %}
  • diff --git a/bookwyrm/templates/snippets/user_options.html b/bookwyrm/templates/snippets/user_options.html index ab68c2e3c..bc54ca1c7 100644 --- a/bookwyrm/templates/snippets/user_options.html +++ b/bookwyrm/templates/snippets/user_options.html @@ -8,6 +8,9 @@ {% endblock %} {% block dropdown-list %} +
  • + Send direct message +
  • {% include 'snippets/block_button.html' with user=user class="is-fullwidth" %}
  • diff --git a/bookwyrm/templates/user/user_layout.html b/bookwyrm/templates/user/user_layout.html index 3fcbf1e2f..1ab51ce32 100644 --- a/bookwyrm/templates/user/user_layout.html +++ b/bookwyrm/templates/user/user_layout.html @@ -42,7 +42,7 @@ {% endif %}
    - {% if not is_self %} + {% if not is_self and request.user.is_authenticated %}
    {% include 'snippets/follow_button.html' with user=user %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index d232747f9..6d759ac21 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -62,6 +62,8 @@ urlpatterns = [ # feeds re_path(r'^(?Phome|local|federated)/?$', views.Feed.as_view()), re_path(r'^direct-messages/?$', views.DirectMessage.as_view()), + re_path(r'^direct-messages/(?P%s)?$' % regex.username, + views.DirectMessage.as_view()), # search re_path(r'^search/?$', views.Search.as_view()), diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py index 931cf355c..0e550f0c8 100644 --- a/bookwyrm/views/feed.py +++ b/bookwyrm/views/feed.py @@ -1,6 +1,7 @@ ''' non-interactive pages ''' from django.contrib.auth.decorators import login_required from django.core.paginator import Paginator +from django.db.models import Q from django.http import HttpResponseNotFound from django.template.response import TemplateResponse from django.utils import timezone @@ -44,6 +45,7 @@ class Feed(View): 'activities': paginated.page(page), 'tab': tab, 'goal_form': forms.GoalForm(), + 'path': '/%s' % tab, }} return TemplateResponse(request, 'feed/feed.html', data) @@ -51,20 +53,35 @@ class Feed(View): @method_decorator(login_required, name='dispatch') class DirectMessage(View): ''' dm view ''' - def get(self, request): + def get(self, request, username=None): ''' like a feed but for dms only ''' try: page = int(request.GET.get('page', 1)) except ValueError: page = 1 - activities = get_activity_feed(request.user, 'direct') + queryset = models.Status.objects + + user = None + if username: + try: + user = get_user_from_username(username) + except models.User.DoesNotExist: + pass + if user: + queryset = queryset.filter(Q(user=user) | Q(mention_users=user)) + + activities = get_activity_feed( + request.user, 'direct', queryset=queryset) + paginated = Paginator(activities, PAGE_LENGTH) activity_page = paginated.page(page) data = {**feed_page_data(request.user), **{ 'title': 'Direct Messages', 'user': request.user, + 'partner': user, 'activities': activity_page, + 'path': '/direct-messages', }} return TemplateResponse(request, 'feed/direct_messages.html', data)