def receive(cls, xml, c_from, u_to): data = cls.as_dict(xml) if DiasporaPost.get_by_guid(data['guid']): return author = DiasporaContact.get_by_username(data['diaspora_handle'], True, False) assert (author) author = author.contact parent = DiasporaPost.get_by_guid(data['parent_guid']).post if not parent: raise TryLater() assert (parent.shared_with(c_from)) assert (parent.shared_with(u_to)) node = xml[0][0] if 'parent_author_signature' in data: assert (cls.valid_signature(parent.author, data['parent_author_signature'], node)) if not current_app.config.get('ALLOW_INSECURE_COMPAT', False): assert (cls.valid_signature(author, data['author_signature'], node)) else: assert (cls.valid_signature(author, data['author_signature'], node)) created = datetime.strptime(data['created_at'], '%Y-%m-%d %H:%M:%S %Z') p = Post(author=author, created_at=created, parent=parent) p.add_part(MimePart( type='text/x-markdown', body=data['text'].encode('utf-8'), ), order=0, inline=True) p.tags = cls.find_tags(data['text']) p.share_with([s.contact for s in p.root().shares]) p.thread_modified() p.diasp = DiasporaPost(guid=data['guid'], type='private') db.session.add(p) db.session.commit() if not (u_to) or (p.parent.author_id == u_to.contact.id): # If the parent has signed this then it must have already been # via the hub. if 'parent_author_signature' not in data: cls.forward(u_to, p, node)
def receive(cls, xml, c_from, u_to): data = cls.as_dict(xml) if DiasporaPost.get_by_guid(data['guid']): return author = DiasporaContact.get_by_username( data['diaspora_handle'], True, False ) assert(author) author = author.contact parent = DiasporaPost.get_by_guid(data['parent_guid']).post if not parent: raise TryLater() assert(parent.shared_with(c_from)) assert(parent.shared_with(u_to)) node = xml[0][0] if 'parent_author_signature' in data: assert(cls.valid_signature( parent.author, data['parent_author_signature'], node )) if not current_app.config.get('ALLOW_INSECURE_COMPAT', False): assert( cls.valid_signature(author, data['author_signature'], node) ) else: assert(cls.valid_signature(author, data['author_signature'], node)) created = datetime.strptime(data['created_at'], '%Y-%m-%d %H:%M:%S %Z') p = Post(author=author, created_at=created, parent=parent) p.add_part(MimePart( type='text/x-markdown', body=data['text'].encode('utf-8'), ), order=0, inline=True) p.tags = cls.find_tags(data['text']) p.share_with([s.contact for s in p.root().shares]) p.thread_modified() p.diasp = DiasporaPost(guid=data['guid'], type='private') db.session.add(p) db.session.commit() if not(u_to) or (p.parent.author_id == u_to.contact.id): # If the parent has signed this then it must have already been # via the hub. if 'parent_author_signature' not in data: cls.forward(u_to, p, node)
def receive(cls, xml, c_from, u_to): data = cls.as_dict(xml) if DiasporaPost.get_by_guid(data['guid']): return author = DiasporaContact.get_by_username( data['diaspora_handle'], True, False ) assert(author) author = author.contact parent = DiasporaPost.get_by_guid(data['parent_guid']).post assert(parent) assert(parent.shared_with(c_from)) assert(parent.shared_with(u_to)) node = xml[0][0] assert(cls.valid_signature(author, data['author_signature'], node)) if 'parent_author_signature' in data: assert(cls.valid_signature( parent.author, data['parent_author_signature'], node )) created = datetime.strptime(data['created_at'], '%Y-%m-%d %H:%M:%S %Z') p = Post(author=author, created_at=created) p.parent = parent p.add_part(MimePart( type='text/x-markdown', body=data['text'].encode('utf-8'), ), order=0, inline=True) p.tags = cls.find_tags(data['text']) p.share_with([s.contact for s in p.root().shares]) p.thread_modified() p.diasp = DiasporaPost(guid=data['guid'], type='private') db.session.add(p) db.session.commit() if not(u_to) or (p.parent.author_id == u_to.contact.id): cls.forward(u_to, p, node)
def receive(cls, xml, c_from, u_to): data = cls.as_dict(xml) if DiasporaPost.get_by_guid(data['guid']): return author = DiasporaContact.get_by_username(data['diaspora_handle'], True, False) assert (author) author = author.contact parent = DiasporaPost.get_by_guid(data['parent_guid']).post assert (parent) assert (parent.shared_with(c_from)) assert (parent.shared_with(u_to)) node = xml[0][0] assert (cls.valid_signature(author, data['author_signature'], node)) if 'parent_author_signature' in data: assert (cls.valid_signature(parent.author, data['parent_author_signature'], node)) created = datetime.strptime(data['created_at'], '%Y-%m-%d %H:%M:%S %Z') p = Post(author=author, created_at=created) p.parent = parent p.add_part(MimePart( type='text/x-markdown', body=data['text'].encode('utf-8'), ), order=0, inline=True) p.tags = cls.find_tags(data['text']) p.share_with([s.contact for s in p.root().shares]) p.thread_modified() p.diasp = DiasporaPost(guid=data['guid'], type='private') db.session.add(p) db.session.commit() if not (u_to) or (p.parent.author_id == u_to.contact.id): cls.forward(u_to, p, node)