Пример #1
0
  def get_rsvps_from_event(event):
    """Returns RSVP objects for an event's *attending fields.

    Args:
      event: ActivityStreams event object

    Returns: sequence of ActivityStreams RSVP activity objects
    """
    id = event.get('id')
    if not id:
      return []
    parsed = util.parse_tag_uri(id)
    if not parsed:
      return []
    domain, event_id = parsed

    rsvps = []
    for verb, field in RSVP_TO_EVENT.items():
      for actor in event.get(field, []):
        rsvp = {'objectType': 'activity',
                'verb': verb,
                'actor': actor,
                }
        if event_id and 'id' in actor:
          _, actor_id = util.parse_tag_uri(actor['id'])
          rsvp['id'] = util.tag_uri(domain, '%s_rsvp_%s' % (event_id, actor_id))
        rsvps.append(rsvp)

    return rsvps
Пример #2
0
  def get_rsvps_from_event(event):
    """Returns RSVP objects for an event's *attending fields.

    Args:
      event: ActivityStreams event object

    Returns: sequence of ActivityStreams RSVP activity objects
    """
    id = event.get('id')
    if not id:
      return []
    parsed = util.parse_tag_uri(id)
    if not parsed:
      return []
    domain, event_id = parsed
    url = event.get('url')

    rsvps = []
    for verb, field in RSVP_TO_EVENT.items():
      for actor in event.get(field, []):
        rsvp = {'objectType': 'activity',
                'verb': verb,
                'actor': actor,
                'url': url,
                }
        if event_id and 'id' in actor:
          _, actor_id = util.parse_tag_uri(actor['id'])
          rsvp['id'] = util.tag_uri(domain, '%s_rsvp_%s' % (event_id, actor_id))
          if url:
            rsvp['url'] = '#'.join((url, actor_id))
        rsvps.append(rsvp)

    return rsvps
Пример #3
0
    def get_rsvps_from_event(event):
        """Returns RSVP objects for an event's *attending fields.

    Args:
      event: ActivityStreams event object

    Returns: sequence of ActivityStreams RSVP activity objects
    """
        id = event.get("id")
        if not id:
            return []
        parsed = util.parse_tag_uri(id)
        if not parsed:
            return []
        domain, event_id = parsed
        url = event.get("url")

        rsvps = []
        for verb, field in RSVP_TO_EVENT.items():
            for actor in event.get(field, []):
                rsvp = {"objectType": "activity", "verb": verb, "actor": actor, "url": url}
                if event_id and "id" in actor:
                    _, actor_id = util.parse_tag_uri(actor["id"])
                    rsvp["id"] = util.tag_uri(domain, "%s_rsvp_%s" % (event_id, actor_id))
                    if url:
                        rsvp["url"] = "#".join((url, actor_id))
                rsvps.append(rsvp)

        return rsvps
Пример #4
0
    def accept_follow(self, follow, follow_unwrapped):
        """Replies to an AP Follow request with an Accept request.

        Args:
          follow: dict, AP Follow activity
          follow_unwrapped: dict, same, except with redirect URLs unwrapped
        """
        logging.info('Replying to Follow with Accept')

        followee = follow.get('object')
        followee_unwrapped = follow_unwrapped.get('object')
        follower = follow.get('actor')
        if not followee or not followee_unwrapped or not follower:
            common.error(
                self,
                'Follow activity requires object and actor. Got: %s' % follow)

        inbox = follower.get('inbox')
        follower_id = follower.get('id')
        if not inbox or not follower_id:
            common.error(self, 'Follow actor requires id and inbox. Got: %s',
                         follower)

        # store Follower
        user_domain = util.domain_from_link(followee_unwrapped)
        Follower.get_or_create(user_domain,
                               follower_id,
                               last_follow=json.dumps(follow))

        # send AP Accept
        accept = {
            '@context':
            'https://www.w3.org/ns/activitystreams',
            'id':
            util.tag_uri(appengine_config.HOST,
                         'accept/%s/%s' % ((user_domain, follow.get('id')))),
            'type':
            'Accept',
            'actor':
            followee,
            'object': {
                'type': 'Follow',
                'actor': follower_id,
                'object': followee,
            }
        }
        resp = send(accept, inbox, user_domain)
        self.response.status_int = resp.status_code
        self.response.write(resp.text)

        # send webmention
        common.send_webmentions(self,
                                as2.to_as1(follow),
                                proxy=True,
                                protocol='activitypub',
                                source_as2=json.dumps(follow_unwrapped))
Пример #5
0
  def user_to_actor(self, account):
    """Converts a Mastodon account to an AS1 actor.

    Args:
      account: dict, Mastodon account

    Returns: dict, AS1 actor
    """
    domain = self.DOMAIN
    username = account.get('username')

    # parse acct. it's just username for local accounts but fully qualified
    # address for remote accounts, eg [email protected].
    acct = account.get('acct') or ''
    split = acct.split('@')
    if len(split) in (2, 3):
      acct_username, acct_domain = split[-2:]
      if acct_domain:
        domain = acct_domain
      if not username:
        username = acct[-2]
      elif acct_username and username != acct_username:
        raise ValueError('username %s and acct %s conflict!' % (username, acct))

    if not username:
      return {}

    url = account.get('url')
    # mastodon's 'Web site' fields are HTML links, so extract their URLs
    web_sites = sum((util.extract_links(f.get('value'))
                     for f in (account.get('fields') or [])), [])

    # account.created_at is string ISO8601 in Mastodon, int timestamp in Pixelfed
    published = account.get('created_at')
    if util.is_int(published) or util.is_float(published):
      published = util.maybe_timestamp_to_iso8601(published)

    return util.trim_nulls({
      'objectType': 'person',
      'id': util.tag_uri(domain, username),
      'numeric_id': account.get('id'),
      'username': username,
      'displayName': account.get('display_name') or acct or username,
      'url': url,
      'urls': [{'value': u} for u in [url] + web_sites],
      'image': {'url': account.get('avatar')},
      'published': published,
      'description': account.get('note'),
    })
Пример #6
0
  def test_search_links(self):
    self.m.domains = ['foo.com', 'bar']

    self.expect_requests_get(
      'https://foo.com' + API_SEARCH, params={
        'q': 'foo.com OR bar',
        'resolve': True,
        'offset': 0},
      response={'statuses': [STATUS]},
      headers={'Authorization': 'Bearer towkin'})
    self.mox.ReplayAll()

    got = self.m.search_for_links()
    self.assert_equals(1, len(got))
    # granary.test_mastodon's ACTIVITY has tag URIs without 2013, but we
    # generate them, so work around that in this comparison.
    self.assert_equals(util.tag_uri('foo.com', STATUS['id']), got[0]['id'])
Пример #7
0
  def get_rsvps_from_event(event):
    """Returns RSVP objects for an event's attending fields.

    Args:
      event: ActivityStreams event object

    Returns:
      sequence of ActivityStreams RSVP activity objects
    """
    id = event.get('id')
    if not id:
      return []
    parsed = util.parse_tag_uri(id)
    if not parsed:
      return []
    domain, event_id = parsed
    url = event.get('url')
    author = event.get('author')

    rsvps = []
    for verb, field in RSVP_VERB_TO_COLLECTION.items():
      for actor in event.get(field, []):
        rsvp = {'objectType': 'activity',
                'verb': verb,
                'object' if verb == 'invite' else 'actor': actor,
                'url': url,
                }

        if event_id and 'id' in actor:
          _, actor_id = util.parse_tag_uri(actor['id'])
          rsvp['id'] = util.tag_uri(domain, '%s_rsvp_%s' % (event_id, actor_id))
          if url:
            rsvp['url'] = '#'.join((url, actor_id))

        if verb == 'invite' and author:
          rsvp['actor'] = author

        rsvps.append(rsvp)

    return rsvps
Пример #8
0
def tag_uri(name):
    return util.tag_uri("flickr.com", name)
def tag_uri(name):
    return util.tag_uri("twitter.com", name)
Пример #10
0
 def tag_uri(self, name):
     """Returns a tag URI string for this source and the given string name."""
     return util.tag_uri(self.DOMAIN, name)
Пример #11
0
def tag_uri(name):
    return util.tag_uri('github.com', name)
def tag_uri(name):
  return util.tag_uri('twitter.com', name)
Пример #13
0
 def tag_uri(self, name):
   """Returns a tag URI string for this source and the given string name."""
   return util.tag_uri(self.DOMAIN, name)
Пример #14
0
def tag_uri(name):
  return util.tag_uri('flickr.com', name)
Пример #15
0
def tag_uri(name):
  return util.tag_uri('github.com', name)
Пример #16
0
def tag_uri(name):
  return util.tag_uri('plus.google.com', name)
Пример #17
0
def tag_uri(name):
    return util.tag_uri('flickr.com', name)
Пример #18
0
def tag_uri(name):
  return util.tag_uri('instagram.com', name)
Пример #19
0
def tag_uri(name):
  return util.tag_uri('foo.com', name)
Пример #20
0
def tag_uri(name):
    return util.tag_uri("plus.google.com", name)
def tag_uri(name):
  return util.tag_uri('facebook.com', name)
Пример #22
0
def tag_uri(name):
    return util.tag_uri('meetup.com', name)
def tag_uri(name):
  return util.tag_uri('instagram.com', name)
Пример #24
0
def tag_uri(name):
    return util.tag_uri("instagram.com", name)