Merge pull request #568 from mouse-reeve/send-dms

Compose window for dms
This commit is contained in:
Mouse Reeve 2021-01-29 14:23:06 -08:00 committed by GitHub
commit 02c466e04a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 11 deletions

View file

@ -92,6 +92,12 @@ class ReplyForm(CustomForm):
'user', 'content', 'content_warning', 'sensitive', 'user', 'content', 'content_warning', 'sensitive',
'reply_parent', 'privacy'] 'reply_parent', 'privacy']
class StatusForm(CustomForm):
class Meta:
model = models.Status
fields = [
'user', 'content', 'content_warning', 'sensitive', 'privacy']
class EditUserForm(CustomForm): class EditUserForm(CustomForm):
class Meta: class Meta:

View file

@ -1,9 +1,16 @@
{% extends 'feed/feed_layout.html' %} {% extends 'feed/feed_layout.html' %}
{% block panel %} {% block panel %}
<div class="block"> <header class="block">
<h1 class="title">Direct Messages</h1> <h1 class="title">Direct Messages{% if partner %} with {% include 'snippets/username.html' with user=partner %}{% endif %}</h1>
{% if partner %}<p class="subtitle"><a href="/direct-messages"><span class="icon icon-arrow-left" aria-hidden="true"></span> All messages</a></p>{% endif %}
</header>
<div class="box">
{% include 'snippets/create_status_form.html' with type="direct" uuid=1 mentions=partner %}
</div>
<section class="block">
{% if not activities %} {% if not activities %}
<p>You have no messages right now.</p> <p>You have no messages right now.</p>
{% endif %} {% endif %}
@ -14,6 +21,6 @@
{% endfor %} {% endfor %}
{% include 'snippets/pagination.html' with page=activities path="direct-messages" %} {% include 'snippets/pagination.html' with page=activities path="direct-messages" %}
</div> </section>
{% endblock %} {% endblock %}

View file

@ -76,7 +76,7 @@
{% block panel %}{% endblock %} {% block panel %}{% endblock %}
{% if activities %} {% 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 %} {% endif %}
</div> </div>
</div> </div>

View file

@ -1,5 +1,5 @@
{% load bookwyrm_tags %} {% load bookwyrm_tags %}
<form class="is-flex-grow-1" name="{{ type }}" action="/post/{{ type }}" method="post" id="tab-{{ type }}-{{ book.id }}{{ reply_parent.id }}"> <form class="is-flex-grow-1" name="{{ type }}" action="/post/{% if type == 'direct' %}status{% else %}{{ type }}{% endif %}" method="post" id="tab-{{ type }}-{{ book.id }}{{ reply_parent.id }}">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="book" value="{{ book.id }}"> <input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="user" value="{{ request.user.id }}"> <input type="hidden" name="user" value="{{ request.user.id }}">
@ -11,7 +11,7 @@
</div> </div>
{% endif %} {% endif %}
<div class="control"> <div class="control">
{% if not type == 'reply' %} {% if type != 'reply' and type != 'direct' %}
<label class="label" for="id_{% if type == 'quotation' %}quote{% else %}content{% endif %}_{{ book.id }}_{{ type }}">{{ type|title }}:</label> <label class="label" for="id_{% if type == 'quotation' %}quote{% else %}content{% endif %}_{{ book.id }}_{{ type }}">{{ type|title }}:</label>
{% endif %} {% endif %}
@ -35,7 +35,7 @@
<textarea name="quote" class="textarea" id="id_quote_{{ book.id }}_{{ type }}" placeholder="{{ placeholder }}" required></textarea> <textarea name="quote" class="textarea" id="id_quote_{{ book.id }}_{{ type }}" placeholder="{{ placeholder }}" required></textarea>
{% else %} {% else %}
{% include 'snippets/content_warning_field.html' with parent_status=status %} {% include 'snippets/content_warning_field.html' with parent_status=status %}
<textarea name="content" class="textarea" id="id_content_{{ type }}-{{ book.id }}{{reply_parent.id}}" placeholder="{{ placeholder }}" {% if type == 'reply' %} aria-label="Reply"{% endif %} required>{% if reply_parent %}{{ reply_parent|mentions:request.user }}{% endif %}</textarea> <textarea name="content" class="textarea" id="id_content_{{ type }}-{{ book.id }}{{reply_parent.id}}" placeholder="{{ placeholder }}" {% if type == 'reply' %} aria-label="Reply"{% endif %} required>{% if reply_parent %}{{ reply_parent|mentions:request.user }}{% endif %}{% if mentions %}@{{ mentions|username }} {% endif %}</textarea>
{% endif %} {% endif %}
</div> </div>
{% if type == 'quotation' %} {% 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/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 %}
</div> </div>
<div class="control"> <div class="control">
{% include 'snippets/privacy_select.html' with current=reply_parent.privacy%} {% if type == 'direct' %}
<input type="hidden" name="privacy" value="direct">
<button type="button" class="button" aria-label="Privacy" disabled>Private</button>
{% else %}
{% include 'snippets/privacy_select.html' with current=reply_parent.privacy %}
{% endif %}
</div> </div>
</div> </div>
<div class="column is-narrow"> <div class="column is-narrow">

View file

@ -18,6 +18,9 @@
</form> </form>
</li> </li>
{% else %} {% else %}
<li role="menuitem">
<a href="/direct-messages/{{ status.user|username }}" class="button is-fullwidth is-small">Send direct message</a>
</li>
<li role="menuitem"> <li role="menuitem">
{% include 'snippets/block_button.html' with user=status.user class="is-fullwidth" %} {% include 'snippets/block_button.html' with user=status.user class="is-fullwidth" %}
</li> </li>

View file

@ -8,6 +8,9 @@
{% endblock %} {% endblock %}
{% block dropdown-list %} {% block dropdown-list %}
<li role="menuitem">
<a href="/direct-messages/{{ user|username }}" class="button is-fullwidth is-small">Send direct message</a>
</li>
<li role="menuitem"> <li role="menuitem">
{% include 'snippets/block_button.html' with user=user class="is-fullwidth" %} {% include 'snippets/block_button.html' with user=user class="is-fullwidth" %}
</li> </li>

View file

@ -42,7 +42,7 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% if not is_self %} {% if not is_self and request.user.is_authenticated %}
<div class="field has-addons"> <div class="field has-addons">
<div class="control"> <div class="control">
{% include 'snippets/follow_button.html' with user=user %} {% include 'snippets/follow_button.html' with user=user %}

View file

@ -62,6 +62,8 @@ urlpatterns = [
# feeds # feeds
re_path(r'^(?P<tab>home|local|federated)/?$', views.Feed.as_view()), re_path(r'^(?P<tab>home|local|federated)/?$', views.Feed.as_view()),
re_path(r'^direct-messages/?$', views.DirectMessage.as_view()), re_path(r'^direct-messages/?$', views.DirectMessage.as_view()),
re_path(r'^direct-messages/(?P<username>%s)?$' % regex.username,
views.DirectMessage.as_view()),
# search # search
re_path(r'^search/?$', views.Search.as_view()), re_path(r'^search/?$', views.Search.as_view()),

View file

@ -1,6 +1,7 @@
''' non-interactive pages ''' ''' non-interactive pages '''
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator from django.core.paginator import Paginator
from django.db.models import Q
from django.http import HttpResponseNotFound from django.http import HttpResponseNotFound
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.utils import timezone from django.utils import timezone
@ -44,6 +45,7 @@ class Feed(View):
'activities': paginated.page(page), 'activities': paginated.page(page),
'tab': tab, 'tab': tab,
'goal_form': forms.GoalForm(), 'goal_form': forms.GoalForm(),
'path': '/%s' % tab,
}} }}
return TemplateResponse(request, 'feed/feed.html', data) return TemplateResponse(request, 'feed/feed.html', data)
@ -51,20 +53,35 @@ class Feed(View):
@method_decorator(login_required, name='dispatch') @method_decorator(login_required, name='dispatch')
class DirectMessage(View): class DirectMessage(View):
''' dm view ''' ''' dm view '''
def get(self, request): def get(self, request, username=None):
''' like a feed but for dms only ''' ''' like a feed but for dms only '''
try: try:
page = int(request.GET.get('page', 1)) page = int(request.GET.get('page', 1))
except ValueError: except ValueError:
page = 1 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) paginated = Paginator(activities, PAGE_LENGTH)
activity_page = paginated.page(page) activity_page = paginated.page(page)
data = {**feed_page_data(request.user), **{ data = {**feed_page_data(request.user), **{
'title': 'Direct Messages', 'title': 'Direct Messages',
'user': request.user, 'user': request.user,
'partner': user,
'activities': activity_page, 'activities': activity_page,
'path': '/direct-messages',
}} }}
return TemplateResponse(request, 'feed/direct_messages.html', data) return TemplateResponse(request, 'feed/direct_messages.html', data)