mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	digest emails: use a template filter to format new users, streams, etc.
(imported from commit e61a3dd6753db82da1b30c50e5bbf6273f302645)
This commit is contained in:
		@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					{% load app_filters %}
 | 
				
			||||||
{% comment %}
 | 
					{% comment %}
 | 
				
			||||||
Mail sent to a user who hasn't logged in for 24 hours.
 | 
					Mail sent to a user who hasn't logged in for 24 hours.
 | 
				
			||||||
{% endcomment %}
 | 
					{% endcomment %}
 | 
				
			||||||
@@ -31,7 +32,7 @@ been gone:
 | 
				
			|||||||
{% endif %}
 | 
					{% endif %}
 | 
				
			||||||
{% for message_block in sender_block.content %}{{ message_block.plain }}
 | 
					{% for message_block in sender_block.content %}{{ message_block.plain }}
 | 
				
			||||||
{% endfor %}{% endfor %}
 | 
					{% endfor %}{% endfor %}
 | 
				
			||||||
{% if convo.count > 0 %}+ {{ convo.count }} more message{{ convo.count|pluralize }} by {{ convo.participants_string }}.{% endif %}
 | 
					{% if convo.count > 0 %}+ {{ convo.count }} more message{{ convo.count|pluralize }} by {{ convo.participants|display_list:4 }}.{% endif %}
 | 
				
			||||||
{% endfor %}{% endfor %}
 | 
					{% endfor %}{% endfor %}
 | 
				
			||||||
Catch up on the rest of these conversations: https://zulip.com.{% endif %}
 | 
					Catch up on the rest of these conversations: https://zulip.com.{% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -40,11 +41,11 @@ Catch up on the rest of these conversations: https://zulip.com.{% endif %}
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
{% if new_streams.plain %}{% if new_stream_count > 1 %}A new stream was{% else %}Some new streams were{% endif %} created:
 | 
					{% if new_streams.plain %}{% if new_stream_count > 1 %}A new stream was{% else %}Some new streams were{% endif %} created:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {{ new_streams.plain }}.
 | 
					    {{ new_streams.plain|display_list:4 }}.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Visit your Streams page to subscribe: https://zulip.com/#subscriptions.{% endif %}
 | 
					Visit your Streams page to subscribe: https://zulip.com/#subscriptions.{% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{% if new_users %}{% if new_streams.plain or unread_pms or hot_conversations %}And finally, please{% else %}Please{% endif %} welcome {{ new_users }} to Zulip!{% endif %}
 | 
					{% if new_users %}{% if new_streams.plain or unread_pms or hot_conversations %}And finally, please{% else %}Please{% endif %} welcome {{ new_users|display_list:4 }} to Zulip!{% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Click here to log in to Zulip and catch up: https://zulip.com.
 | 
					Click here to log in to Zulip and catch up: https://zulip.com.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					{% load app_filters %}
 | 
				
			||||||
{% comment %}
 | 
					{% comment %}
 | 
				
			||||||
Mail sent to a user who hasn't logged in for 24 hours.
 | 
					Mail sent to a user who hasn't logged in for 24 hours.
 | 
				
			||||||
{% endcomment %}
 | 
					{% endcomment %}
 | 
				
			||||||
@@ -55,7 +56,7 @@ Here are some of the hot conversations that have happened while you've been gone
 | 
				
			|||||||
            {% endfor %}
 | 
					            {% endfor %}
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        {% if convo.count > 0 %}<p>+ {{ convo.count }} more message{{ convo.count|pluralize }} by {{ convo.participants_string }}.</p>{% endif %}
 | 
					        {% if convo.count > 0 %}<p>+ {{ convo.count }} more message{{ convo.count|pluralize }} by {{ convo.participants|display_list:4 }}.</p>{% endif %}
 | 
				
			||||||
    {% endfor %}
 | 
					    {% endfor %}
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
{% endfor %}
 | 
					{% endfor %}
 | 
				
			||||||
@@ -77,13 +78,13 @@ Here are some of the hot conversations that have happened while you've been gone
 | 
				
			|||||||
{% if new_streams.html %}
 | 
					{% if new_streams.html %}
 | 
				
			||||||
<p>{% if new_stream_count > 1 %}A new stream was{% else %}Some new streams were{% endif %} created:</p>
 | 
					<p>{% if new_stream_count > 1 %}A new stream was{% else %}Some new streams were{% endif %} created:</p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<p>{{ new_streams.html|safe }}.</p>
 | 
					<p>{{ new_streams.html|display_list:4|safe }}.</p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<p>Click on {% if new_stream_count > 1 %}a{% else %}the{% endif %} name to check out some of the traffic, or visit your <a href="https://zulip.com/#subscriptions">Streams page</a> to subscribe.</p>
 | 
					<p>Click on {% if new_stream_count > 1 %}a{% else %}the{% endif %} name to check out some of the traffic, or visit your <a href="https://zulip.com/#subscriptions">Streams page</a> to subscribe.</p>
 | 
				
			||||||
{% endif %}
 | 
					{% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{% if new_users %}
 | 
					{% if new_users %}
 | 
				
			||||||
<p>{% if new_streams.html or unread_pms or hot_conversations %}And finally, please{% else %}Please{% endif %} welcome {{ new_users }} to Zulip!</p>
 | 
					<p>{% if new_streams.html or unread_pms or hot_conversations %}And finally, please{% else %}Please{% endif %} welcome {{ new_users|display_list:4 }} to Zulip!</p>
 | 
				
			||||||
{% endif %}
 | 
					{% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<br />
 | 
					<br />
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -62,24 +62,7 @@ def gather_hot_conversations(user_profile, stream_messages):
 | 
				
			|||||||
                message__recipient__type_id=stream_id,
 | 
					                message__recipient__type_id=stream_id,
 | 
				
			||||||
                message__subject=subject)[:2]]
 | 
					                message__subject=subject)[:2]]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Show up to 4 participants names.
 | 
					        teaser_data = {"participants": users,
 | 
				
			||||||
        participant_limit = 4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if len(users) == 1:
 | 
					 | 
				
			||||||
            # One participant.
 | 
					 | 
				
			||||||
            participants_string = "%s" % (users[0],)
 | 
					 | 
				
			||||||
        elif len(users) <= participant_limit:
 | 
					 | 
				
			||||||
            # A few participants, show all of them.
 | 
					 | 
				
			||||||
            participants_string = ", ".join(
 | 
					 | 
				
			||||||
                "%s" % (user,) for user in users[:-1])
 | 
					 | 
				
			||||||
            participants_string += " and %s" % (users[-1],)
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            # More than 4 participants, only mention a few.
 | 
					 | 
				
			||||||
            participants_string = ", ".join(
 | 
					 | 
				
			||||||
                "%s" % (user,) for user in users[:participant_limit])
 | 
					 | 
				
			||||||
            participants_string += and_n_others(users, participant_limit)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        teaser_data = {"participants_string": participants_string,
 | 
					 | 
				
			||||||
                       "count": count - len(first_few_messages),
 | 
					                       "count": count - len(first_few_messages),
 | 
				
			||||||
                       "first_few_messages": build_message_list(
 | 
					                       "first_few_messages": build_message_list(
 | 
				
			||||||
                user_profile, first_few_messages)}
 | 
					                user_profile, first_few_messages)}
 | 
				
			||||||
@@ -93,66 +76,24 @@ def gather_new_users(user_profile, threshold):
 | 
				
			|||||||
    new_users = list(UserProfile.objects.filter(
 | 
					    new_users = list(UserProfile.objects.filter(
 | 
				
			||||||
            realm=user_profile.realm, date_joined__gt=threshold,
 | 
					            realm=user_profile.realm, date_joined__gt=threshold,
 | 
				
			||||||
            is_bot=False))
 | 
					            is_bot=False))
 | 
				
			||||||
 | 
					    user_names = [user.full_name for user in new_users]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Show up to 4 new users.
 | 
					    return len(user_names), user_names
 | 
				
			||||||
    user_limit = 4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if not new_users:
 | 
					 | 
				
			||||||
        # No new users.
 | 
					 | 
				
			||||||
        new_users_string = None
 | 
					 | 
				
			||||||
    elif len(new_users) == 1:
 | 
					 | 
				
			||||||
        # One new user.
 | 
					 | 
				
			||||||
        new_users_string = "%s" % (new_users[0].full_name,)
 | 
					 | 
				
			||||||
    elif len(new_users) <= user_limit:
 | 
					 | 
				
			||||||
        # A few new users, show all of them.
 | 
					 | 
				
			||||||
        new_users_string = ", ".join(
 | 
					 | 
				
			||||||
            "%s" % (user.full_name,) for user in new_users[:-1])
 | 
					 | 
				
			||||||
        new_users_string += " and %s" % (new_users[-1].full_name,)
 | 
					 | 
				
			||||||
    else:
 | 
					 | 
				
			||||||
        # More than 4 new users, only mention a few.
 | 
					 | 
				
			||||||
        new_users_string = ", ".join(
 | 
					 | 
				
			||||||
            "%s" % (user.full_name,) for user in new_users[:user_limit])
 | 
					 | 
				
			||||||
        new_users_string += and_n_others(new_users, user_limit)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return len(new_users), new_users_string
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
def gather_new_streams(user_profile, threshold):
 | 
					def gather_new_streams(user_profile, threshold):
 | 
				
			||||||
    new_streams = list(Stream.objects.filter(
 | 
					    new_streams = list(Stream.objects.filter(
 | 
				
			||||||
            realm=user_profile.realm, date_created__gt=threshold))
 | 
					            realm=user_profile.realm, date_created__gt=threshold))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    base_url = "https://zulip.com/#narrow/stream/"
 | 
					    base_url = "https://zulip.com/#narrow/stream/"
 | 
				
			||||||
    stream_links = []
 | 
					
 | 
				
			||||||
 | 
					    streams_html = []
 | 
				
			||||||
 | 
					    streams_plain = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for stream in new_streams:
 | 
					    for stream in new_streams:
 | 
				
			||||||
        narrow_url = base_url + hashchange_encode(stream.name)
 | 
					        narrow_url = base_url + hashchange_encode(stream.name)
 | 
				
			||||||
        stream_link = "<a href='%s'>%s</a>" % (narrow_url, stream.name)
 | 
					        stream_link = "<a href='%s'>%s</a>" % (narrow_url, stream.name)
 | 
				
			||||||
        stream_links.append(stream_link)
 | 
					        streams_html.append(stream_link)
 | 
				
			||||||
 | 
					        streams_plain.append(stream.name)
 | 
				
			||||||
    # Show up to 4 new streams.
 | 
					 | 
				
			||||||
    stream_limit = 4
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if not stream_links:
 | 
					 | 
				
			||||||
        # No new stream.
 | 
					 | 
				
			||||||
        streams_html = streams_plain = None
 | 
					 | 
				
			||||||
    elif len(stream_links) == 1:
 | 
					 | 
				
			||||||
        # One new stream.
 | 
					 | 
				
			||||||
        streams_html = "%s" % (stream_links[0],)
 | 
					 | 
				
			||||||
        streams_plain = stream.name
 | 
					 | 
				
			||||||
    elif len(stream_links) <= stream_limit:
 | 
					 | 
				
			||||||
        # A few new streams, show all of them.
 | 
					 | 
				
			||||||
        streams_html = ", ".join(
 | 
					 | 
				
			||||||
            "%s" % (stream_link,) for stream_link in stream_links[:-1])
 | 
					 | 
				
			||||||
        streams_html += " and %s." % (stream_links[-1],)
 | 
					 | 
				
			||||||
        streams_plain = ", ".join(
 | 
					 | 
				
			||||||
            "%s" % (stream.name,) for stream in new_streams[:-1])
 | 
					 | 
				
			||||||
        streams_plain += " and %s." % (new_streams[-1].name,)
 | 
					 | 
				
			||||||
    else:
 | 
					 | 
				
			||||||
        # More than 4 new users, only mention a few.
 | 
					 | 
				
			||||||
        streams_html = ", ".join(
 | 
					 | 
				
			||||||
            "%s" % (stream_link,) for stream_link in stream_links[:stream_limit])
 | 
					 | 
				
			||||||
        streams_html += and_n_others(stream_links, stream_limit)
 | 
					 | 
				
			||||||
        streams_plain = ", ".join(
 | 
					 | 
				
			||||||
            "%s" % (stream.name,) for stream in new_streams[:stream_limit])
 | 
					 | 
				
			||||||
        streams_plain += and_n_others(new_streams, stream_limit)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return len(new_streams), {"html": streams_html, "plain": streams_plain}
 | 
					    return len(new_streams), {"html": streams_html, "plain": streams_plain}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user