forked from forks/microblog.pub
Start displaying the acor that liked a particular note
This commit is contained in:
parent
a160a95e82
commit
8027a36359
4 changed files with 43 additions and 9 deletions
|
@ -246,9 +246,6 @@ class BaseActivity(object):
|
|||
raise ValueError('Invalid actor')
|
||||
return actor['id']
|
||||
|
||||
def reset_object_cache(self) -> None:
|
||||
self.__obj = None
|
||||
|
||||
def get_object(self) -> 'BaseActivity':
|
||||
if self.__obj:
|
||||
return self.__obj
|
||||
|
@ -264,9 +261,12 @@ class BaseActivity(object):
|
|||
|
||||
p = parse_activity(obj)
|
||||
|
||||
self.__obj: BaseActivity = p
|
||||
self.__obj: Optional[BaseActivity] = p
|
||||
return p
|
||||
|
||||
def reset_object_cache(self) -> None:
|
||||
self.__obj = None
|
||||
|
||||
def to_dict(self, embed: bool = False, embed_object_id_only: bool = False) -> ObjectType:
|
||||
data = dict(self._data)
|
||||
if embed:
|
||||
|
|
12
app.py
12
app.py
|
@ -464,7 +464,17 @@ def note_by_id(note_id):
|
|||
if data['meta'].get('deleted', False):
|
||||
abort(410)
|
||||
thread = _build_thread(data)
|
||||
return render_template('note.html', me=ME, thread=thread, note=data)
|
||||
|
||||
|
||||
likes = list(DB.inbox.find({
|
||||
'meta.undo': False,
|
||||
'type': ActivityType.LIKE.value,
|
||||
'$or': [{'activity.object.id': data['activity']['object']['id']},
|
||||
{'activity.object': data['activity']['object']['id']}],
|
||||
}))
|
||||
likes = [ACTOR_SERVICE.get(doc['activity']['actor']) for doc in likes]
|
||||
|
||||
return render_template('note.html', likes=likes, me=ME, thread=thread, note=data)
|
||||
|
||||
|
||||
@app.route('/nodeinfo')
|
||||
|
|
|
@ -16,6 +16,6 @@
|
|||
{% block content %}
|
||||
<div id="container">
|
||||
{% include "header.html" %}
|
||||
{{ utils.display_thread(thread) }}
|
||||
{{ utils.display_thread(thread, likes) }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
{% macro display_actor_inline(follower) -%}
|
||||
<a class="actor-box" href="{{follower.url}}" style="clear:both;">
|
||||
<span style="float:left;padding-right:15px;">
|
||||
{% if not follower.icon %}
|
||||
<img class="actor-icon" src="/static/nopic.png" style="width:50px">
|
||||
{% else %}
|
||||
<img class="actor-icon" src="{{ follower.icon.url }}" style="width:50px;">{% endif %}
|
||||
</span>
|
||||
<div>
|
||||
<div style="font-weight:bold">{{ follower.name or follower.preferredUsername }}</div>
|
||||
<small>@{{ follower.preferredUsername }}@{{ follower.url | domain }}</small>
|
||||
</div>
|
||||
</a>
|
||||
{%- endmacro %}
|
||||
|
||||
|
||||
{% macro display_actor(follower) -%}
|
||||
<a class="actor-box" href="{{follower.url}}">
|
||||
<div class="pure-g">
|
||||
|
@ -16,7 +32,7 @@
|
|||
</a>
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro display_note(item, perma=False, ui=False) -%}
|
||||
{% macro display_note(item, perma=False, ui=False, likes=[]) -%}
|
||||
{% set actor = item.activity.object.attributedTo | get_actor %}
|
||||
<div class="note h-entry" id="activity-{{ item['_id'].__str__() }}">
|
||||
|
||||
|
@ -111,12 +127,20 @@
|
|||
</div>
|
||||
|
||||
</div>
|
||||
{% if likes %}
|
||||
<div style="padding-bottom:40px;">
|
||||
<h4 style="font-weight:normal">Liked by</h4>{% for like in likes %}
|
||||
{{ display_actor_inline(like) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro display_thread(thread) -%}
|
||||
{% macro display_thread(thread, likes=[]) -%}
|
||||
{% for reply in thread %}
|
||||
{% if reply._requested %}
|
||||
{{ display_note(reply, perma=True, ui=False) }}
|
||||
{{ display_note(reply, perma=True, ui=False, likes=likes) }}
|
||||
{% else %}
|
||||
{{ display_note(reply, perma=False, ui=True) }}
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in a new issue