Only show public stuff on the homepage

This commit is contained in:
Thomas Sileo 2019-07-13 00:38:51 +02:00
parent 6ab59d2e41
commit 152bcf2b26
3 changed files with 8 additions and 7 deletions

11
app.py
View file

@ -86,8 +86,8 @@ from config import VERSION_DATE
from config import _drop_db from config import _drop_db
from poussetaches import PousseTaches from poussetaches import PousseTaches
from tasks import Tasks from tasks import Tasks
from utils import parse_datetime
from utils import opengraph from utils import opengraph
from utils import parse_datetime
from utils.key import get_secret_key from utils.key import get_secret_key
from utils.lookup import lookup from utils.lookup import lookup
from utils.media import Kind from utils.media import Kind
@ -143,13 +143,13 @@ def inject_config():
notes_count = DB.activities.find( notes_count = DB.activities.find(
{"box": Box.OUTBOX.value, "$or": [q, {"type": "Announce", "meta.undo": False}]} {"box": Box.OUTBOX.value, "$or": [q, {"type": "Announce", "meta.undo": False}]}
).count() ).count()
# FIXME(tsileo): rename to all_count, and remove poll answers from it
with_replies_count = DB.activities.find( with_replies_count = DB.activities.find(
{ {
"box": Box.OUTBOX.value, "box": Box.OUTBOX.value,
"type": {"$in": [ActivityType.CREATE.value, ActivityType.ANNOUNCE.value]}, "type": {"$in": [ActivityType.CREATE.value, ActivityType.ANNOUNCE.value]},
"meta.undo": False, "meta.undo": False,
"meta.deleted": False, "meta.deleted": False,
"meta.public": True,
} }
).count() ).count()
liked_count = DB.activities.count( liked_count = DB.activities.count(
@ -875,6 +875,7 @@ def index():
"activity.object.inReplyTo": None, "activity.object.inReplyTo": None,
"meta.deleted": False, "meta.deleted": False,
"meta.undo": False, "meta.undo": False,
"meta.public": True,
"$or": [{"meta.pinned": False}, {"meta.pinned": {"$exists": False}}], "$or": [{"meta.pinned": False}, {"meta.pinned": {"$exists": False}}],
} }
print(list(DB.activities.find(q))) print(list(DB.activities.find(q)))
@ -887,6 +888,7 @@ def index():
"type": ActivityType.CREATE.value, "type": ActivityType.CREATE.value,
"meta.deleted": False, "meta.deleted": False,
"meta.undo": False, "meta.undo": False,
"meta.public": True,
"meta.pinned": True, "meta.pinned": True,
} }
pinned = list(DB.activities.find(q_pinned)) pinned = list(DB.activities.find(q_pinned))
@ -906,14 +908,13 @@ def index():
return resp return resp
@app.route("/with_replies") @app.route("/all")
@login_required @login_required
def with_replies(): def all():
q = { q = {
"box": Box.OUTBOX.value, "box": Box.OUTBOX.value,
"type": {"$in": [ActivityType.CREATE.value, ActivityType.ANNOUNCE.value]}, "type": {"$in": [ActivityType.CREATE.value, ActivityType.ANNOUNCE.value]},
"meta.deleted": False, "meta.deleted": False,
"meta.public": True,
"meta.undo": False, "meta.undo": False,
} }
outbox_data, older_than, newer_than = paginated_query(DB.activities, q) outbox_data, older_than, newer_than = paginated_query(DB.activities, q)

View file

@ -2,8 +2,8 @@ import os
from datetime import datetime from datetime import datetime
from datetime import timezone from datetime import timezone
from utils import parse_datetime
from poussetaches import PousseTaches from poussetaches import PousseTaches
from utils import parse_datetime
p = PousseTaches( p = PousseTaches(
os.getenv("MICROBLOGPUB_POUSSETACHES_HOST", "http://localhost:7991"), os.getenv("MICROBLOGPUB_POUSSETACHES_HOST", "http://localhost:7991"),

View file

@ -18,7 +18,7 @@
<div class="menu"> <div class="menu">
<ul> <ul>
<li><a href="/" {% if request.path == "/" %}class="selected"{% endif %}>Notes <small class="badge">{{ notes_count }}</small></a></li> <li><a href="/" {% if request.path == "/" %}class="selected"{% endif %}>Notes <small class="badge">{{ notes_count }}</small></a></li>
{% if session.logged_in %}<li><a href="/with_replies" {% if request.path == "/with_replies" %}class="selected"{% endif %}>With replies <small class="badge">{{ with_replies_count }}</small></a></li> {% if session.logged_in %}<li><a href="/all" {% if request.path == url_for("all") %}class="selected"{% endif %}>All <small class="badge">{{ with_replies_count }}</small></a></li>
{% endif %} {% endif %}
<li><a href="/liked" {% if request.path == "/liked" %}class="selected"{% endif %}>Liked <small class="badge">{{ liked_count }}</small></a></li> <li><a href="/liked" {% if request.path == "/liked" %}class="selected"{% endif %}>Liked <small class="badge">{{ liked_count }}</small></a></li>
<li><a href="/followers"{% if request.path == "/followers" %} class="selected" {% endif %}>Followers <small class="badge">{{ followers_count }}</small></a></li> <li><a href="/followers"{% if request.path == "/followers" %} class="selected" {% endif %}>Followers <small class="badge">{{ followers_count }}</small></a></li>