def _send_to_remotes(self, contacts): """ Arrange to send this post to contacts on the remote node. """ from pyaspora.diaspora.models import DiasporaPost contacts = [c for c in contacts if not c.user] if contacts: DiasporaPost.get_for_post(self).send_to(contacts)
def _send_to_remotes(self, contacts, reshare_of): """ Arrange to send this post to contacts on the remote node. """ from pyaspora.diaspora.models import DiasporaPost db.session.commit() # write out shares contacts = [c for c in contacts if not c.user] if contacts: # Only public posts can be reshared by Diaspora if reshare_of and self.author_made_public() and \ reshare_of.author_made_public(): DiasporaPost.get_for_post(self).reshare(contacts, reshare_of) else: DiasporaPost.get_for_post(self).send_to(contacts)
def generate(cls, u_from, c_to, post, reshare): req = etree.Element('reshare') diasp = DiasporaPost.get_for_post(post) r_diasp = DiasporaPost.get_for_post(reshare) cls.struct_to_xml(req, [ {'root_diaspora_id': reshare.author.diasp.username}, {'root_guid': r_diasp.guid}, {'guid': diasp.guid}, {'diaspora_handle': post.author.diasp.username}, {'public': 'true'}, {'created_at': cls.format_dt(reshare.created_at)} ]) return req
def _send_to_remotes(self, contacts, reshare_of): """ Arrange to send this post to contacts on the remote node. """ from pyaspora.diaspora.models import DiasporaPost db.session.commit() # write out shares contacts = [c for c in contacts if not c.user] if contacts: # Only public posts can be reshared by Diaspora if reshare_of and self.author_made_public() and \ reshare_of.author_made_public(): DiasporaPost.get_for_post(self).reshare(contacts, reshare_of) else: DiasporaPost.get_for_post(self).send_to(contacts)
def json_feed(guid): """ Look up the User identified by GUID and return the User's public feed as Diaspora-style JSON. """ contact = DiasporaContact.get_by_guid(guid) if not(contact and contact.contact.user): abort(404, 'No such contact', force_status=True) feed_query = Post.Queries.public_wall_for_contact(contact.contact) feed = db.session.query(Post).join(Share).filter(feed_query). \ order_by(desc(Post.thread_modified_at)). \ group_by(Post.id).limit(99) ret = [] for post in feed: text = DiasporaPost.get_for_post(post, commit=False).as_text() rep = { "author": { "diaspora_id": contact.username, "name": contact.contact.realname, "guid": contact.guid, }, "created_at": post.created_at.isoformat(), "text": text, "public": True, "post_type": "StatusMessage", "guid": post.diasp.guid, "interacted_at": post.root().thread_modified_at.isoformat(), "provider_display_name": None, } ret.append(rep) return jsonify(response)
def generate(cls, u_from, c_to, post, text): req = etree.Element("conversation") diasp = DiasporaPost.get_for_post(post) cls.struct_to_xml(req, [ {'guid': diasp.guid}, {'subject': '(no subject)'}, {'created_at': cls.format_dt(post.created_at)} ]) msg = etree.SubElement(req, "message") cls.struct_to_xml(msg, [ {'guid': diasp.guid + '-1'}, {'parent_guid': diasp.guid}, {'text': text}, {'created_at': cls.format_dt(post.created_at)}, {'diaspora_handle': u_from.contact.diasp.username}, {'conversation_guid': diasp.guid} ]) etree.SubElement(msg, "parent_author_signature").text = \ cls.generate_signature(u_from, msg) etree.SubElement(msg, "author_signature").text = \ cls.generate_signature(u_from, msg) cls.struct_to_xml(req, [ {'diaspora_handle': u_from.contact.diasp.username}, {'participant_handles': ';'.join( s.contact.diasp.username for s in post.shares if s.contact.diasp )} ]) return req
def json_feed(guid): """ Look up the User identified by GUID and return the User's public feed as Diaspora-style JSON. """ contact = DiasporaContact.get_by_guid(guid) if not (contact and contact.contact.user): abort(404, 'No such contact', force_status=True) feed_query = Post.Queries.public_wall_for_contact(contact.contact) feed = db.session.query(Post).join(Share).filter(feed_query). \ order_by(desc(Post.thread_modified_at)). \ group_by(Post.id).limit(99) ret = [] for post in feed: text = DiasporaPost.get_for_post(post, commit=False).as_text() rep = { "author": { "diaspora_id": contact.username, "name": contact.contact.realname, "guid": contact.guid, }, "created_at": post.created_at.isoformat(), "text": text, "public": True, "post_type": "StatusMessage", "guid": post.diasp.guid, "interacted_at": post.root().thread_modified_at.isoformat(), "provider_display_name": None, } ret.append(rep) return jsonify(response)
def generate(cls, u_from, c_to, post, text): req = etree.Element('comment') diasp = DiasporaPost.get_for_post(post) p_diasp = DiasporaPost.get_for_post(post.root()) cls.struct_to_xml(req, [ {'guid': diasp.guid}, {'parent_guid': p_diasp.guid}, {'text': text}, {'diaspora_handle': post.author.diasp.username} ]) etree.SubElement(req, "author_signature").text = \ cls.generate_signature(u_from, req) if p_diasp.post.author.id == u_from.id: etree.SubElement(req, "parent_author_signature").text = \ cls.generate_signature(u_from, req) return req
def generate(cls, u_from, c_to, post, text): diasp = DiasporaPost.get_for_post(post) req = etree.Element("status_message") cls.struct_to_xml(req, [ {'raw_message': text}, {'guid': diasp.guid}, {'diaspora_handle': u_from.contact.diasp.username}, {'public': 'false' if c_to else 'true'}, {'created_at': cls.format_dt(post.created_at)} ]) return req
def generate(cls, u_from, c_to, post, text): req = etree.Element('comment') diasp = DiasporaPost.get_for_post(post) p_diasp = DiasporaPost.get_for_post(post.root()) cls.struct_to_xml(req, [{ 'guid': diasp.guid }, { 'parent_guid': p_diasp.guid }, { 'text': text }, { 'diaspora_handle': post.author.diasp.username }]) etree.SubElement(req, "author_signature").text = \ cls.generate_signature(u_from, req) if p_diasp.post.author.id == u_from.id: etree.SubElement(req, "parent_author_signature").text = \ cls.generate_signature(u_from, req) return req
def generate(cls, u_from, c_to, post, reshare): req = etree.Element('reshare') diasp = DiasporaPost.get_for_post(post) r_diasp = DiasporaPost.get_for_post(reshare) cls.struct_to_xml(req, [{ 'root_diaspora_id': reshare.author.diasp.username }, { 'root_guid': r_diasp.guid }, { 'guid': diasp.guid }, { 'diaspora_handle': post.author.diasp.username }, { 'public': 'true' }, { 'created_at': cls.format_dt(reshare.created_at) }]) return req
def generate(cls, u_from, c_to, post, text): diasp = DiasporaPost.get_for_post(post) req = etree.Element("status_message") cls.struct_to_xml(req, [{ 'raw_message': text }, { 'guid': diasp.guid }, { 'diaspora_handle': u_from.contact.diasp.username }, { 'public': 'false' if c_to else 'true' }, { 'created_at': cls.format_dt(post.created_at) }]) return req
def generate(cls, u_from, c_to, post, text): req = etree.Element("conversation") diasp = DiasporaPost.get_for_post(post) cls.struct_to_xml(req, [{ 'guid': diasp.guid }, { 'subject': '(no subject)' }, { 'created_at': cls.format_dt(post.created_at) }]) msg = etree.SubElement(req, "message") cls.struct_to_xml(msg, [{ 'guid': diasp.guid + '-1' }, { 'parent_guid': diasp.guid }, { 'text': text }, { 'created_at': cls.format_dt(post.created_at) }, { 'diaspora_handle': u_from.contact.diasp.username }, { 'conversation_guid': diasp.guid }]) etree.SubElement(msg, "parent_author_signature").text = \ cls.generate_signature(u_from, msg) etree.SubElement(msg, "author_signature").text = \ cls.generate_signature(u_from, msg) cls.struct_to_xml(req, [{ 'diaspora_handle': u_from.contact.diasp.username }, { 'participant_handles': ';'.join(s.contact.diasp.username for s in post.shares if s.contact.diasp) }]) return req