{% extends "notifications/_base.html" %}

{% block title %}
  Daily summary of activities in your communities
{% endblock %}

{% block body %}
  {% for digest in digests %}
    <h2>In the {{ digest.community.name }} community</h2>

    {%- if digest.new_members %}
      <h3>New members</h3>

      {%- for user in digest.new_members %}
        <p>
          <a href="{{ url_for("social.user", user_id=user.id, _external=True,
                              _scheme=config['PREFERRED_URL_SCHEME']) }}">{{ user }}</a>
        </p>
      {%- endfor %}
    {%- endif %}

    {%- if digest.new_documents %}
      <h3>New documents</h3>

      {%- for doc in digest.new_documents %}
        <p><a href="{{ url_for("documents.document_view",
                               community_id=digest.community.slug,
                               doc_id=doc.id, _external=True,
                               _scheme=config['PREFERRED_URL_SCHEME']) }}">{{ doc }}</a><br>
          <small>Posted by {{ doc.creator }}.</small>
        </p>
      {%- endfor %}
    {%- endif %}

    {%- if digest.updated_documents %}
      <h3>Updated documents</h3>

      {%- for doc in digest.updated_documents %}
        <p><a href="{{ url_for("documents.document_view",
                               community_id=digest.community.slug,
                               doc_id=doc.id, _external=True,
                               _scheme=config['PREFERRED_URL_SCHEME']) }}">{{ doc }}</a>.
        </p>
      {%- endfor %}
    {%- endif %}

    {%- if digest.new_conversations %}
      <h3>New conversations</h3>

      {%- for thread in digest.new_conversations %}
        <p><a href="{{ url_for("forum.thread",
                               community_id=digest.community.slug,
                               thread_id=thread.id, _external=True,
                               _scheme=config['PREFERRED_URL_SCHEME']) }}">{{ thread }}</a><br>
          <small>Posted by {{ thread.creator }}.</small>
        </p>
      {%- endfor %}
    {%- endif %}

    {%- if digest.updated_conversations %}
      <h3>New comments in conversations</h3>

      {%- for thread, info in digest.updated_conversations.items() %}
        <p><a href="{{ url_for(info['post'], _external=True,
                               _scheme=config['PREFERRED_URL_SCHEME'])}}">{{ thread }}</a><br>
          by {{ info['actors']|join(', ')}}
        </p>
      {%- endfor %}
    {%- endif %}

    {%- if digest.new_wiki_pages %}
      <h3>New wiki pages</h3>

      {%- for page in digest.new_wiki_pages %}
        <p><a href="{{ url_for('wiki.page',
                               community_id=digest.community.slug,
                               title=page.title, _external=True,
                               _scheme=config['PREFERRED_URL_SCHEME']) }}">{{ page }}</a>
          <br>
          <small>Posted by {{ page.creator }}.</small>
        </p>
      {%- endfor %}
    {%- endif %}

    {%- if digest.updated_wiki_pages %}
      <h3>Updated wiki pages</h3>

      {%- for page, actors in digest.updated_wiki_pages.items() %}
        <p><a href="{{ url_for('wiki.page',
                               community_id=digest.community.slug,
                               title=page.title, _external=True,
                               _scheme=config['PREFERRED_URL_SCHEME'])}}">{{ page }}</a><br>
        <small>by
          {% for actor, changes in actors.items() %}{{ actor }}
            {% if changes > 1 %}(x{{ changes }}){% endif %}
          {%- if not loop.last %}, {% endif %}
          {%- endfor %}.
        </small>

                  {{ actors }}

        </p>
      {%- endfor %}
    {%- endif %}
  {% endfor %}
{% endblock %}

{% block footer %}
  You receive this email because you are subscribed to communities notifications.
  <br>
  You can modify your notifications by going to the application's
  <a href="{{ url_for("preferences.index", _external=True, _scheme=config['PREFERRED_URL_SCHEME']) }}">Preferences</a>
   page.
  <br>
  You can unsubscribe by following
  <a href="{{ url_for("notifications.unsubscribe_sbe", token=token, _external=True, _scheme=config['PREFERRED_URL_SCHEME']) }}">this link</a>.
{% endblock %}
