{% macro actor(activity) %}
  <span>
    {{ 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">
    <a href="{{ h.url_for(dataset_type ~ '.read', id=activity.object_id ) }}">
      {{ activity.data.package.title if activity.data.package else _("unknown") }}
    </a>
  </span>
{% endmacro %}

{% macro organization(activity) %}
  {% set group_type = group_type or (activity.data.group.type if (activity.data.group and activity.data.group.type) else 'organization') %}
  <a href="{{ h.url_for(group_type ~ '.read', id=activity.object_id) }}">
    {{ activity.data.group.title if activity.data.group else _('unknown') }}
  </a>
{% endmacro %}

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

{% macro group(activity) %}
<span class="group">
  <a href="{{ h.url_for('group.read', id=activity.object_id) }}">
    {{ activity.data.group.title if activity.data.group else _('unknown') }}
  </a>
</span>
{% endmacro %}

{# Renders the actual stream of activities

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 {% if not activity_stream %}activity-empty{% endif %}">
  {% 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
    -%}
  {% else %}
      {{ _("No activity found for this type") }}
  {% endfor %}
  </ul>
{% endblock %}
