Skip to content

Commit

Permalink
reduce msg_tip duplication
Browse files Browse the repository at this point in the history
Signed-off-by: xiehuc <[email protected]>
  • Loading branch information
xiehuc committed Dec 21, 2012
1 parent 002a3a4 commit ed007cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/liblwqq/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static int upload_offline_file_back(LwqqHttpRequest* req,void* data);
static int send_offfile_back(LwqqHttpRequest* req,void* data);
static void insert_recv_msg_with_order(LwqqRecvMsgList* list,LwqqMsg* msg);
static LwqqAsyncEvent* lwqq_msg_get_msg_tip(LwqqClient* lc,unsigned int counter);
static int get_msg_tip_back(LwqqHttpRequest* req);

/**
* Create a new LwqqRecvMsgList object
Expand Down Expand Up @@ -1887,10 +1888,24 @@ LwqqAsyncEvent* lwqq_msg_input_notify(LwqqClient* lc,const char* serv_id)
static LwqqAsyncEvent* lwqq_msg_get_msg_tip(LwqqClient* lc,unsigned int counter)
{
if(!lc) return NULL;
LwqqAsyncEvent* ev = lwqq_async_queue_find(&lc->ev_queue, lwqq_msg_get_msg_tip);
if(ev) return ev;
char url[512];
snprintf(url, sizeof(url), "https://web2.qq.com/web2/get_msg_tip?uin=&tp=1&id=0&retype=1&rc=%u&lv=3&t=%lu",counter,time(NULL));
lwqq_puts(url);
LwqqHttpRequest* req = lwqq_http_create_default_request(lc,url,NULL);
req->set_header(req,"Referer","https://web2.qq.com/");
return req->do_request_async(req,0,NULL,_C_(p_i,dump_response,req));
ev = req->do_request_async(req,0,NULL,_C_(p_i,get_msg_tip_back,req));
lwqq_async_queue_add(&lc->ev_queue,lwqq_msg_get_msg_tip,ev);
return ev;
}

static int get_msg_tip_back(LwqqHttpRequest* req)
{
LwqqClient* lc = req->lc;
lwqq_async_queue_rm(&lc->ev_queue,lwqq_msg_get_msg_tip);

lwqq_http_request_free(req);
return 0;
}

1 change: 1 addition & 0 deletions src/liblwqq/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ struct _LwqqClient {
struct LwqqRecvMsgList *msg_list;
long msg_id; /**< Used to send message */

LwqqAsyncQueue ev_queue;

LwqqBuddy* (*find_buddy_by_uin)(LwqqClient* lc,const char* uin);
LwqqBuddy* (*find_buddy_by_qqnumber)(LwqqClient* lc,const char* qqnumber);
Expand Down

0 comments on commit ed007cc

Please sign in to comment.