diff options
Diffstat (limited to 'command.c')
-rw-r--r-- | command.c | 19 |
1 files changed, 9 insertions, 10 deletions
@@ -90,15 +90,6 @@ static bool send_list(int fd,const char *tag,i64 count,const char **list){ return send_raw_text(fd,"\n",1); } -static bool send_push(int fd,const char *head,const char *arg){ - char *buf=NULL; - i64 len=asprintf(&buf,"_push %s %s\n",head,arg); - assert(buf); - bool closed=send_raw_text(fd,buf,len); - free(buf); - return closed; -} - static bool cmd_register(struct conn_data *data,const char *tag,const char **args){ i64 userid=db_find_user(args[0]); @@ -239,6 +230,12 @@ static bool cmd_send(struct conn_data *data,const char *tag,const char **args){ 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]); + assert(pushbuf); + free(username); + struct db_user_list members=db_list_members(roomid); for(i64 i=0;i<members.count;i++){ i64 nfds; @@ -246,11 +243,13 @@ static bool cmd_send(struct conn_data *data,const char *tag,const char **args){ if(nfds<=0)continue; for(i64 j=0;j<nfds;j++){ if(fds[j]!=data->fd){ - send_push(fds[j],"message",args[1]); + send_raw_text(fds[j],pushbuf,pushbuflen); } } } + free(pushbuf); + return closed; } |