{% macro actor(activity) %}
  <span class="actor">
    {{ h.linked_user(activity.user_id, 0, 30) }}
  </span>
{% endmacro %}

{% macro dataset(activity) %}
  {% set dataset_type = activity.data.package.type or 'dataset' %}
  <span class="dataset">
    {{ h.link_to(activity.data.package.title if activity.data.package else _('unknown'),
      h.url_for(dataset_type ~ '.read', id=activity.object_id)) }}
    {# object_id because the object_name may be out of date) #}
  </span>
{% endmacro %}

{% macro organization(activity) %}
  {{ h.link_to(activity.data.group.title if activity.data.group else _('unknown'),
               h.url_for('organization.read', id=activity.object_id)) }}
               {# object_id because the object_name may be out of date) #}
{% endmacro %}

{% macro user(activity) %}
<span class="actor">
  {{ h.linked_user(activity.object_id, 0, 20) }}
</span>
{% endmacro %}

{% macro group(activity) %}
<span class="group">
  {{ h.link_to(activity.data.group.title if activity.data.group else _('unknown'),
               h.url_for('group.read', id=activity.object_id)) }}
               {# object_id because the object_name may be out of date) #}
</span>
{% endmacro %}

{# Displays an activity stream

activity_stream - the activity data. e.g. the output from package_activity_list
id - the id or current name of the object (e.g. package name, user id)
object_type - 'package', 'organization', 'group', 'user'

#}
{% block activity_stream %}
  <ul class="activity">
  {% set can_show_activity_detail = h.check_access('activity_list', {'id': id, 'include_data': True, 'object_type': object_type}) %}
  {% for activity in activity_stream %}
    {%- snippet "snippets/activities/{}.html".format(
      activity.activity_type.replace(' ', '_')
      ), "snippets/activities/fallback.html",
      activity=activity, can_show_activity_detail=can_show_activity_detail, ah={
        'actor': actor,
        'dataset': dataset,
        'organization': organization,
        'user': user,
        'group': group,
      }, id=id
    -%}
  {% endfor %}
  </ul>
{% endblock %}
