diff options
Diffstat (limited to 'command.c')
-rw-r--r-- | command.c | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -164,14 +164,31 @@ static struct cmd_retval cmd_list_members(struct conn_data *data,const char *tag static struct cmd_retval cmd_create_room(struct conn_data *data,const char *tag,const char **args){ (void)args; - if(data->userid==-1){ - net_send_error(data->fd,tag,"Not logged in"); + if (data->userid == -1) { + net_send_error(data->fd, tag, "Not logged in"); return RET_OK; } - userdata_mark_active(data->userid,data->fd,true); - struct db_name_id room=db_create_room(); - db_add_member(room.id,data->userid); - bool closed=net_send_name(data->fd,tag,room.name); + userdata_mark_active(data->userid, data->fd, true); + + struct db_name_id room = db_create_room(); + db_add_member(room.id, data->userid); + + char *username = db_get_username(data->userid); + char *invitebuf = NULL; + i64 invitebuflen = asprintf(&invitebuf, "_push invite %s %s\n", room.name, username); + free(username); + + i64 nfds; + const int *fds = userdata_online(data->userid, &nfds); + for (i64 j = 0; j < nfds; j++) { + if (fds[j] != data->fd) { + net_send_raw_text(fds[j], invitebuf, invitebuflen); + } + } + + free(invitebuf); + + bool closed = net_send_name(data->fd, tag, room.name); db_nullify_name_id(room); return RET_CLOSE(closed); } |