mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-22 05:04:27 +00:00
Visibility tweaks
This commit is contained in:
parent
52bc600832
commit
5b1e776fa2
2 changed files with 33 additions and 29 deletions
53
app.py
53
app.py
|
@ -63,6 +63,7 @@ from core.meta import in_outbox
|
|||
from core.meta import is_public
|
||||
from core.meta import not_deleted
|
||||
from core.meta import not_undo
|
||||
from core.meta import pinned
|
||||
from core.shared import _build_thread
|
||||
from core.shared import _get_ip
|
||||
from core.shared import activitypubify
|
||||
|
@ -107,14 +108,12 @@ else:
|
|||
@app.context_processor
|
||||
def inject_config():
|
||||
q = {
|
||||
"type": "Create",
|
||||
"activity.object.inReplyTo": None,
|
||||
"meta.deleted": False,
|
||||
"meta.public": True,
|
||||
**in_outbox(),
|
||||
**by_type([ActivityType.CREATE, ActivityType.ANNOUNCE]),
|
||||
**not_deleted(),
|
||||
**by_visibility(ap.Visibility.PUBLIC),
|
||||
}
|
||||
notes_count = DB.activities.find(
|
||||
{"box": Box.OUTBOX.value, "$or": [q, {"type": "Announce", "meta.undo": False}]}
|
||||
).count()
|
||||
notes_count = DB.activities.count(q)
|
||||
# FIXME(tsileo): rename to all_count, and remove poll answers from it
|
||||
all_q = {
|
||||
"box": Box.OUTBOX.value,
|
||||
|
@ -348,30 +347,27 @@ def index():
|
|||
return activitypubify(**ME)
|
||||
|
||||
q = {
|
||||
"box": Box.OUTBOX.value,
|
||||
"type": {"$in": [ActivityType.CREATE.value, ActivityType.ANNOUNCE.value]},
|
||||
"activity.object.inReplyTo": None,
|
||||
"meta.deleted": False,
|
||||
"meta.undo": False,
|
||||
"meta.public": True,
|
||||
**in_outbox(),
|
||||
**by_type([ActivityType.CREATE, ActivityType.ANNOUNCE]),
|
||||
**not_deleted(),
|
||||
**by_visibility(ap.Visibility.PUBLIC),
|
||||
"$or": [{"meta.pinned": False}, {"meta.pinned": {"$exists": False}}],
|
||||
}
|
||||
|
||||
pinned = []
|
||||
apinned = []
|
||||
# Only fetch the pinned notes if we're on the first page
|
||||
if not request.args.get("older_than") and not request.args.get("newer_than"):
|
||||
q_pinned = {
|
||||
"box": Box.OUTBOX.value,
|
||||
"type": ActivityType.CREATE.value,
|
||||
"meta.deleted": False,
|
||||
"meta.undo": False,
|
||||
"meta.public": True,
|
||||
"meta.pinned": True,
|
||||
**in_outbox(),
|
||||
**by_type(ActivityType.CREATE),
|
||||
**not_deleted(),
|
||||
**pinned(),
|
||||
**by_visibility(ap.Visibility.PUBLIC),
|
||||
}
|
||||
pinned = list(DB.activities.find(q_pinned))
|
||||
apinned = list(DB.activities.find(q_pinned))
|
||||
|
||||
outbox_data, older_than, newer_than = paginated_query(
|
||||
DB.activities, q, limit=25 - len(pinned)
|
||||
DB.activities, q, limit=25 - len(apinned)
|
||||
)
|
||||
|
||||
return htmlify(
|
||||
|
@ -380,7 +376,7 @@ def index():
|
|||
outbox_data=outbox_data,
|
||||
older_than=older_than,
|
||||
newer_than=newer_than,
|
||||
pinned=pinned,
|
||||
pinned=apinned,
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -481,11 +477,10 @@ def outbox():
|
|||
_log_sig()
|
||||
# TODO(tsileo): returns the whole outbox if authenticated and look at OCAP support
|
||||
q = {
|
||||
"box": Box.OUTBOX.value,
|
||||
"meta.deleted": False,
|
||||
"meta.undo": False,
|
||||
"meta.public": True,
|
||||
"type": {"$in": [ActivityType.CREATE.value, ActivityType.ANNOUNCE.value]},
|
||||
**in_outbox(),
|
||||
**by_type([ActivityType.CREATE, ActivityType.ANNOUNCE]),
|
||||
**not_deleted(),
|
||||
**by_visibility(ap.Visibility.PUBLIC),
|
||||
}
|
||||
return activitypubify(
|
||||
**activitypub.build_ordered_collection(
|
||||
|
@ -497,7 +492,7 @@ def outbox():
|
|||
)
|
||||
)
|
||||
|
||||
# Handle POST request
|
||||
# Handle POST request aka C2S API
|
||||
try:
|
||||
_api_required()
|
||||
except BadSignature:
|
||||
|
|
|
@ -46,6 +46,7 @@ class MetaKey(Enum):
|
|||
OBJECT_ACTOR_HASH = "object_actor_hash"
|
||||
PUBLIC = "public"
|
||||
|
||||
PINNED = "pinned"
|
||||
HASHTAGS = "hashtags"
|
||||
MENTIONS = "mentions"
|
||||
|
||||
|
@ -100,6 +101,10 @@ def follow_request_accepted() -> _SubQuery:
|
|||
return flag(MetaKey.FOLLOW_STATUS, FollowStatus.ACCEPTED.value)
|
||||
|
||||
|
||||
def not_in_reply_to() -> _SubQuery:
|
||||
return {"activity.object.inReplyTo": None}
|
||||
|
||||
|
||||
def not_undo() -> _SubQuery:
|
||||
return flag(MetaKey.UNDO, False)
|
||||
|
||||
|
@ -108,6 +113,10 @@ def not_deleted() -> _SubQuery:
|
|||
return flag(MetaKey.DELETED, False)
|
||||
|
||||
|
||||
def pinned() -> _SubQuery:
|
||||
return flag(MetaKey.PINNED, True)
|
||||
|
||||
|
||||
def by_actor(actor: ap.BaseActivity) -> _SubQuery:
|
||||
return flag(MetaKey.ACTOR_ID, actor.id)
|
||||
|
||||
|
|
Loading…
Reference in a new issue