MCPcopy Create free account
hub / github.com/TimMcCool/scratchattach / target

Method target

scratchattach/site/activity.py:410–456  ·  view source on GitHub ↗

Returns the activity's target (depending on the activity, this is either a User, Project, Studio or Comment object). May also return None if the activity type is unknown.

(self)

Source from the content-addressed store, hash-verified

408 return None
409
410 def target(self):
411 """
412 Returns the activity's target (depending on the activity, this is either a User, Project, Studio or Comment object).
413 May also return None if the activity type is unknown.
414 """
415 if self.type is None:
416 return None
417
418 _type = self.type.value
419 if self.type in (
420 ActivityTypes.addprojecttostudio,
421 ActivityTypes.favoriteproject,
422 ActivityTypes.loveproject,
423 ActivityTypes.remixproject,
424 ActivityTypes.removeprojectfromstudio,
425 ActivityTypes.shareproject,
426 ): # target is a project
427 return self.target_project()
428
429 if self.type in (ActivityTypes.becomecurator, ActivityTypes.followstudio): # target is a studio
430 if ret := self.target_studio():
431 return ret
432 # NOTE: the "becomecurator" type is ambigous - if it is inside the studio activity tab, the target is the user who joined
433 return self.target_user()
434
435 if (
436 self.type
437 in (
438 ActivityTypes.followuser,
439 ActivityTypes.curatorinvite,
440 )
441 or self.recipient_username
442 ): # target is a user
443 # NOTE: the recipient_username field always indicates the target is a user
444 return self.target_user()
445
446 if self.type == ActivityTypes.addcomment: # target is a comment
447 if ret := self.target_comment():
448 return ret
449
450 raise ValueError(f"Either {self.comment_type} is an invalid comment type, or the linked target could not be found")
451
452 if _type == "forumpost":
453 # FIXME: why is the id here constant?!??
454 return forum.ForumTopic(id=603418, _session=self._session, title=self.title)
455
456 return None

Callers

nothing calls this directly

Calls 4

target_projectMethod · 0.95
target_studioMethod · 0.95
target_userMethod · 0.95
target_commentMethod · 0.95

Tested by

no test coverage detected