def run(gid,after_postid): params={'gid':gid} params['postid__gt']=after_postid posts=GroupPost.objects(**params).order_by("-postid").limit(100) allpost=[] for one in posts: allpost.append(one.toJson()) return Res({"posts":allpost})
def run(gid,before_postid=None,count=20): query=dict(gid=gid) if before_postid: query['postid__lt']=before_postid posts=[] for one in GroupPost.objects(**query).order_by("-postid").limit(count): posts.append(one.toJson()) return Res({"posts":posts})
def run(postid,content): newpost=GroupPost.objects(postid=postid).first() newreply=ReplyRecord() newreply.uid=BackEndEnvData.uid newreply.content=content newpost.replys.append(newreply) newpost.save() json_msg=DefJsonEncoder.encode({'reply':newreply.toJson(),"gid":newpost.gid,'postid':newpost.postid}) BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2, routing_key="group.change",headers={"type":"group.newreply"}, compression='gzip') return Res({"post":newreply.toJson()})
def run(postid): post=GroupPost.objects(postid=postid).first() if post is None: return Res(errno=3,error="post not exists") for one in post.likes: if one.uid==BackEndEnvData.uid: return Res({'like':one.toJson()}) newlike=LikeRecord() newlike.uid=BackEndEnvData.uid post.likes.append(newlike) post.save() json_msg=DefJsonEncoder.encode({"like":newlike.toJson(),"postid":post.postid,"gid":post.gid}) BackEndEnvData.queue_producer.publish(body=json_msg, headers={"uid":post.uid,"type":"group.post.newlike"}, delivery_mode=2, routing_key='sys.push_to_user', compression='gzip') return Res({'like':newlike.toJson()})
def run(gid,content=None,pictures=[],video=None,videolen=None,voice=None,voicelen=None, lat=None,lng=None): if not content and not pictures and not video and not voice: return Res(errno=2,error="not conent is not allow") newpost=GroupPost() newpost.gid=gid newpost.uid=BackEndEnvData.uid if content: newpost.content=content if pictures: newpost.pictures=pictures if video: newpost.video=video newpost.voicelen=videolen if voice: newpost.voice=voice newpost.voicelen=voicelen if lat is not None and lng is not None: newpost.position=[lng,lat] newpost.save() json_msg=DefJsonEncoder.encode(newpost.toJson()) BackEndEnvData.queue_producer.publish(body=json_msg,delivery_mode=2, routing_key="group.change",headers={"type":"group.newpost"}, compression='gzip') return Res({'postid':newpost.postid})