Ejemplo n.º 1
0
    def POST(self):
        params=web.input()
        cid=int(params.get('cid'))
        from_uid=int(params.get("from_uid",1))
        roleids=[int(one) for one in params.get('roleid',"0").split(',')]
        if not cid:
            return 'need cid'
        content=params.get('content')
        if not content:
            return 'need content'

        with dbconfig.Session() as session:
            query_params=UserCircle.cid==cid
            if len(roleids)>0 and 0 not in roleids:
                query_params=and_(query_params,UserCircle.roleid.in_(roleids))
            allUser=session.query(UserCircle).filter(query_params).all()
            alluid=[one.uid for one in allUser]
            newmsgs=[]
            for to_uid in alluid:
                newmsg=Message()
                newmsg.toid=to_uid
                newmsg.fromid=from_uid
                newmsg.content=content
                newmsg=session.merge(newmsg)
                newmsgs.append(newmsg)
            session.commit()
            msgids=[]
            for newmsg in newmsgs:
                msgids.append(newmsg.msgid)
                json_msg=DefJsonEncoder.encode(newmsg.toJson())
                pusher.rawPush(body=json_msg,headers={},
                                                    routing_key='sys.message_to_notify')

            return DefJsonEncoder.encode({'msgid':msgids})
Ejemplo n.º 2
0
def run(uid, content=None, lat=None, long=None):
    if content == None and (lat == None or long == None):
        return Res(errno=3, error="param error")
    with dbconfig.Session() as session:
        newmsg = Message()
        newmsg.toid = uid
        newmsg.fromid = BackEndEnvData.uid
        newmsg.content = content
        newmsg.lat = lat
        newmsg.long = long
        newmsg = session.merge(newmsg)
        session.commit()
        AddMessageTrans(newmsg.toJson())
        return Res({'msgid': newmsg.msgid})
Ejemplo n.º 3
0
    def POST(self):
        params=web.input(from_uid=1)
        from_uid=int(params.get('from_uid',1))
        to_uid=int(params.get('to_uid',0))
        if not to_uid:
            return 'need to_uid'
        content=params.get('content')
        if not content:
            return 'need content'

        with dbconfig.Session() as session:
            newmsg=Message()
            newmsg.toid=to_uid
            newmsg.fromid=from_uid
            newmsg.content=content
            newmsg=session.merge(newmsg)
            session.commit()

            json_msg=DefJsonEncoder.encode(newmsg.toJson())
            pusher.rawPush(body=json_msg,headers={},
                                                routing_key='sys.message_to_notify')
            return DefJsonEncoder.encode({'msgid':newmsg.msgid})
Ejemplo n.º 4
0
def run(uid,content=None,lat=None,long=None):
    if content==None and (lat==None or long==None):
        return Res(errno=3,error="param error")
    with dbconfig.Session() as session:
        newmsg=Message()
        newmsg.toid=uid
        newmsg.fromid=BackEndEnvData.uid
        newmsg.content=content
        newmsg.lat=lat
        newmsg.long=long
        newmsg=session.merge(newmsg)
        session.commit()
        AddMessageTrans(newmsg.toJson())
        return Res({'msgid':newmsg.msgid})