1111from sqlalchemy import select
1212from sqlalchemy .orm import joinedload
1313
14- from app import activitypub as ap
14+ import activitypub .models
15+ from activitypub import activitypub as ap
1516from app import media
1617from app .config import BASE_URL
1718from app .config import USER_AGENT
2223from app .utils .datetime import now
2324
2425if typing .TYPE_CHECKING :
25- from app .models import Actor as ActorModel
26+ from activitypub .models import Actor as ActorModel
2627
2728
2829def _handle (raw_actor : ap .RawObject ) -> str :
@@ -216,7 +217,7 @@ async def save_actor(db_session: AsyncSession, ap_actor: ap.RawObject) -> "Actor
216217 if ap_type := ap_actor .get ("type" ) not in ap .ACTOR_TYPES :
217218 raise ValueError (f"Invalid type { ap_type } for actor { ap_actor } " )
218219
219- actor = models .Actor (
220+ actor = activitypub . models .Actor (
220221 ap_id = ap .get_id (ap_actor ["id" ]),
221222 ap_actor = ap_actor ,
222223 ap_type = ap .as_list (ap_actor ["type" ])[0 ],
@@ -239,8 +240,8 @@ async def fetch_actor(
239240
240241 existing_actor = (
241242 await db_session .scalars (
242- select (models .Actor ).where (
243- models .Actor .ap_id == actor_id ,
243+ select (activitypub . models .Actor ).where (
244+ activitypub . models .Actor .ap_id == actor_id ,
244245 )
245246 )
246247 ).one_or_none ()
@@ -273,8 +274,8 @@ async def fetch_actor(
273274 # (like Birdsite LIVE) , which mean we may already have it in DB
274275 existing_actor_by_url = (
275276 await db_session .scalars (
276- select (models .Actor ).where (
277- models .Actor .ap_id == ap .get_id (ap_actor ),
277+ select (activitypub . models .Actor ).where (
278+ activitypub . models .Actor .ap_id == ap .get_id (ap_actor ),
278279 )
279280 )
280281 ).one_or_none ()
@@ -298,8 +299,8 @@ async def list_actors(db_session: AsyncSession, limit: int = 100) -> list["Actor
298299 return (
299300 (
300301 await db_session .scalars (
301- select (models .Actor )
302- .where (models .Actor .is_deleted .is_ (False ))
302+ select (activitypub . models .Actor )
303+ .where (activitypub . models .Actor .is_deleted .is_ (False ))
303304 .limit (limit )
304305 )
305306 )
@@ -350,9 +351,9 @@ async def get_actors_metadata(
350351 follower .ap_actor_id : follower .inbox_object .ap_id
351352 for follower in (
352353 await db_session .scalars (
353- select (models .Follower )
354- .where (models .Follower .ap_actor_id .in_ (ap_actor_ids ))
355- .options (joinedload (models .Follower .inbox_object ))
354+ select (activitypub . models .Follower )
355+ .where (activitypub . models .Follower .ap_actor_id .in_ (ap_actor_ids ))
356+ .options (joinedload (activitypub . models .Follower .inbox_object ))
356357 )
357358 )
358359 .unique ()
@@ -361,37 +362,37 @@ async def get_actors_metadata(
361362 following = {
362363 following .ap_actor_id
363364 for following in await db_session .execute (
364- select (models .Following .ap_actor_id ).where (
365- models .Following .ap_actor_id .in_ (ap_actor_ids )
365+ select (activitypub . models .Following .ap_actor_id ).where (
366+ activitypub . models .Following .ap_actor_id .in_ (ap_actor_ids )
366367 )
367368 )
368369 }
369370 sent_follow_requests = {
370371 follow_req .ap_object ["object" ]: follow_req .ap_id
371372 for follow_req in await db_session .execute (
372- select (models .OutboxObject .ap_object , models .OutboxObject .ap_id ).where (
373- models .OutboxObject .ap_type == "Follow" ,
374- models .OutboxObject .undone_by_outbox_object_id .is_ (None ),
375- models .OutboxObject .activity_object_ap_id .in_ (ap_actor_ids ),
373+ select (activitypub . models .OutboxObject .ap_object , activitypub . models .OutboxObject .ap_id ).where (
374+ activitypub . models .OutboxObject .ap_type == "Follow" ,
375+ activitypub . models .OutboxObject .undone_by_outbox_object_id .is_ (None ),
376+ activitypub . models .OutboxObject .activity_object_ap_id .in_ (ap_actor_ids ),
376377 )
377378 )
378379 }
379380 rejected_follow_requests = {
380381 reject .activity_object_ap_id
381382 for reject in await db_session .execute (
382- select (models .InboxObject .activity_object_ap_id ).where (
383- models .InboxObject .ap_type == "Reject" ,
384- models .InboxObject .ap_actor_id .in_ (ap_actor_ids ),
383+ select (activitypub . models .InboxObject .activity_object_ap_id ).where (
384+ activitypub . models .InboxObject .ap_type == "Reject" ,
385+ activitypub . models .InboxObject .ap_actor_id .in_ (ap_actor_ids ),
385386 )
386387 )
387388 }
388389 blocks = {
389390 block .ap_actor_id
390391 for block in await db_session .execute (
391- select (models .InboxObject .ap_actor_id ).where (
392- models .InboxObject .ap_type == "Block" ,
393- models .InboxObject .undone_by_inbox_object_id .is_ (None ),
394- models .InboxObject .ap_actor_id .in_ (ap_actor_ids ),
392+ select (activitypub . models .InboxObject .ap_actor_id ).where (
393+ activitypub . models .InboxObject .ap_type == "Block" ,
394+ activitypub . models .InboxObject .undone_by_inbox_object_id .is_ (None ),
395+ activitypub . models .InboxObject .ap_actor_id .in_ (ap_actor_ids ),
395396 )
396397 )
397398 }
0 commit comments