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