Ejemplo n.º 1
0
def message_sent_from_business(request):
    print '*'  * 40
    print request
    body = request.GET.get('body')
    coll_id = request.GET.get('coll_id')
    coll = ChatCollections.objects.get(id=coll_id)
    coll.unread = 0
    coll.from_user = False
    coll.save()
    a = ChatMessaged()
    a.coll_id = int(coll_id)
    a.body = body
    a.direction = False
    a.save()
    return HttpResponse(True)
Ejemplo n.º 2
0
def message_sent_from_user(request):
    try:
        user_id = request.GET.get('user_id')
        business_id = request.GET.get('business_id') 
        body = request.GET.get('body')
        #user_name = request.GET.get('user_name')
        #business_via_name = request.GET.get('via_name')
        #business_xmpp_handle = request.GET.get('business_handle')
        #body = request.POST.get('body')
        #if '@' in user_name:
        #    user_name = user_name.split('@')[0]
        #if '@' not in business_xmpp_handle:
        #    business_xmpp_handle = '%@@%@' % (business_xmpp_handle, kXMPP_SERVER)
        #user = User2.objects.get(user_name = user_name)
        #if business_xmpp_handle == kDEFAULT_AGENT_HANDLE:
        #    business = Business.objects.get(via_name = business_via_name)
        #else:
        #    business = Business.objects.get(xmpp_handle = business_xmpp_handle)
        coll = ChatCollections.objects.filter(business_id = business_id).filter(user_id = user_id).all()
        if len(coll) == 0:
            coll = ChatCollections()
            coll.business_id = business_id
            coll.user_id = user_id
            coll.unread = 0
        else:
            coll = coll[0]
        coll.from_user = True
        coll.unread += 1
        coll.save()
        a = ChatMessaged()
        a.coll_id = coll.id
        a.body = body
        a.direction = True
        a.save()
        resp = {'success' : True}
        return HttpResponse(json.dumps(resp), mimetype="application/json")
    except Exception, e:
        print 'EXCEPTION IN LOGGIN MESSAGE FROM USER: ', e