From 047e1828901b5b08cd538a7b11c0de2149606797 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 16 Mar 2017 21:06:11 +0100 Subject: Basic message sending TODO: broadcast to all online fd's of a user? TODO: close users that aren't reachable in a broadcast? --- db.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'db.c') diff --git a/db.c b/db.c index fa7603c..828c081 100644 --- a/db.c +++ b/db.c @@ -85,6 +85,37 @@ bool db_is_member(i64 roomid,i64 userid){ return success; } +struct db_user_list db_get_members(i64 roomid){ + sqlite3_stmt *stmt; + SQLITE(prepare_v2,database, + "select U.id, U.name " + "from Users as U, Members as M " + "where M.room = ? and M.user = U.id" + ,-1,&stmt,NULL); + SQLITE(bind_int64,stmt,1,roomid); + + struct db_user_list ul; + i64 cap=4; + ul.count=0; + ul.list=malloc(cap,struct db_name_id); + + int ret; + while((ret=sqlite3_step(stmt))==SQLITE_ROW){ + if(ul.count==cap){ + cap*=2; + ul.list=realloc(ul.list,cap,struct db_name_id); + } + ul.list[ul.count].id=sqlite3_column_int64(stmt,0); + ul.list[ul.count].name=strdup((const char*)sqlite3_column_text(stmt,1)); + ul.count++; + } + + if(ret!=SQLITE_DONE)die_sqlite("sqlite3_step"); + SQLITE(finalize,stmt); + + return ul; +} + i64 db_find_room(const char *name){ sqlite3_stmt *stmt; SQLITE(prepare_v2,database,"select id from Rooms where name = ?",-1,&stmt,NULL); -- cgit v1.2.3-70-g09d2