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
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
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
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))
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'), })
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'])
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
def tag_uri(name): return util.tag_uri("flickr.com", name)
def tag_uri(name): return util.tag_uri("twitter.com", name)
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)
def tag_uri(name): return util.tag_uri('github.com', name)
def tag_uri(name): return util.tag_uri('twitter.com', name)
def tag_uri(name): return util.tag_uri('flickr.com', name)
def tag_uri(name): return util.tag_uri('plus.google.com', name)
def tag_uri(name): return util.tag_uri('instagram.com', name)
def tag_uri(name): return util.tag_uri('foo.com', name)
def tag_uri(name): return util.tag_uri("plus.google.com", name)
def tag_uri(name): return util.tag_uri('facebook.com', name)
def tag_uri(name): return util.tag_uri('meetup.com', name)
def tag_uri(name): return util.tag_uri("instagram.com", name)