From 4dcb97eec19bcb5365fb355a81e299545b97ef75 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 7 Apr 2017 23:58:01 +0200 Subject: Make protocol more consistent --- command.c | 8 +++++--- webclient/client.html | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/command.c b/command.c index a691171..97f4fce 100644 --- a/command.c +++ b/command.c @@ -227,12 +227,14 @@ static bool cmd_send(struct conn_data *data,const char *tag,const char **args){ return false; } + i64 timestamp=make_timestamp(); db_create_message(roomid,data->userid,make_timestamp(),args[1]); bool closed=send_ok(data->fd,tag); char *pushbuf=NULL; char *username=db_get_username(data->userid); - i64 pushbuflen=asprintf(&pushbuf,"_push message %s %s %s\n",args[0],username,args[1]); + i64 pushbuflen=asprintf(&pushbuf,"_push message %s %s %" PRIi64 " %s\n", + args[0],username,timestamp,args[1]); assert(pushbuf); free(username); @@ -289,8 +291,8 @@ static bool cmd_history(struct conn_data *data,const char *tag,const char **args for(i64 i=ml.count-1;i>=0;i--){ char *username=db_get_username(ml.list[i].userid); - len=asprintf(&buf,"%s history_item %" PRIi64 " %s %" PRIi64 " %s\n", - tag,ml.count-1-i,username,ml.list[i].timestamp,ml.list[i].message); + len=asprintf(&buf,"%s history_message %" PRIi64 " %s %s %" PRIi64 " %s\n", + tag,ml.count-1-i,args[0],username,ml.list[i].timestamp,ml.list[i].message); assert(buf); closed=send_raw_text(data->fd,buf,len); free(buf); diff --git a/webclient/client.html b/webclient/client.html index 241ca90..f905569 100644 --- a/webclient/client.html +++ b/webclient/client.html @@ -95,8 +95,8 @@ function reconnect(){ var id=spl.word[0],type=spl.word[1]; if(id=="_push"){ if(type=="message"){ - var r=spl.word[2],u=spl.word[3]; - addRoomEntry(r,"message",[u,new Date().getTime(),spl.rest[4]]); + var r=spl.word[2],u=spl.word[3],t=new Date(+spl.word[4]/1000); + addRoomEntry(r,"message",[u,t,spl.rest[5]]); } else { alert("Unknown push message type '"+type+"'!"); } @@ -111,7 +111,7 @@ function reconnect(){ else if(type=="history"){ var count=+spl.word[2]; net_callbacks[id]=net_historyCollectionCallback.bind(this,id,[],count,fn); - } else if(type=="history_item")fn([spl.word[3],+spl.word[4]/1000,spl.rest[5]]); + } else if(type=="history_message")fn([spl.word[4],+spl.word[5]/1000,spl.rest[6]]); else alert("Unknown server response message type '"+type+"'!"); } else { alert("No callback for server message id '"+id+"'!"); -- cgit v1.2.3-54-g00ecf