From 183769d56c95b4628bdd815d3cffd5543a6f299a Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 9 Apr 2017 19:16:58 +0200 Subject: weechat: Add nicklist to buffers --- weechat/TODO.txt | 1 - weechat/tomsg.c | 64 +++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/weechat/TODO.txt b/weechat/TODO.txt index d00a028..08b4c3b 100644 --- a/weechat/TODO.txt +++ b/weechat/TODO.txt @@ -1,3 +1,2 @@ -- nicklist - nick in prompt - buffer_set(buffer, "notify", "2") on chats with 2 people diff --git a/weechat/tomsg.c b/weechat/tomsg.c index 7778645..83b8e17 100644 --- a/weechat/tomsg.c +++ b/weechat/tomsg.c @@ -23,6 +23,7 @@ static const char *errpfx,*netpfx; struct roomdata{ char *name; struct t_gui_buffer *buffer; + struct t_gui_nick_group *buffer_nickgroup; struct conndata *conn; // do not free }; @@ -98,12 +99,47 @@ static int room_close_cb(const void *room_vp,void *_d,struct t_gui_buffer *buffe return WEECHAT_RC_OK; } +static void create_room_buffer(struct roomdata *room){ + if(room->buffer!=NULL){ + weechat_buffer_close(room->buffer); + } + room->buffer= + weechat_buffer_new(room->name, room_input_cb,room,NULL, room_close_cb,room,NULL); + weechat_buffer_set(room->buffer,"nicklist","1"); + weechat_buffer_set(room->buffer,"nicklist_case_sensitive","1"); + weechat_buffer_set(room->buffer,"nicklist_display_groups","0"); + + room->buffer_nickgroup=NULL; +} + static void history_net_callback(int fd,struct net_response res,void *payload){ struct roomdata *room=(struct roomdata*)payload; assert(room); fprintf(debugf,"history_net_callback(fd=%d,res={.type=%d})\n",fd,res.type); } +static void members_net_callback(int fd,struct net_response res,void *payload){ + struct roomdata *room=(struct roomdata*)payload; + assert(room); + fprintf(debugf,"members_net_callback(fd=%d,res={.type=%d})\n",fd,res.type); + if(res.type!=NET_LIST){ + fprintf(debugf,"members_net_callback: res.type=%d\n",res.type); + return; + } + if(room->buffer_nickgroup!=NULL){ + weechat_nicklist_remove_all(room->buffer); + } + room->buffer_nickgroup= + weechat_nicklist_add_group(room->buffer,NULL,"members","weechat.color.nicklist_group",1); + for(int i=0;ibuffer,room->buffer_nickgroup, + res.items[i],"chat_nick", + "","chat_nick", + 1); + } +} + static void push_net_callback(int fd,struct net_response res,void *payload){ (void)payload; fprintf(debugf,"push_net_callback(fd=%d,res={.type=%d})\n",fd,res.type); @@ -122,10 +158,7 @@ static void push_net_callback(int fd,struct net_response res,void *payload){ } struct roomdata *room=conn->rooms[roomi]; if(room->buffer==NULL){ - room->buffer=weechat_buffer_new( - room->name, - room_input_cb,room,NULL, - room_close_cb,room,NULL); + create_room_buffer(room); } if(res.type==NET_MESSAGE){ @@ -134,6 +167,13 @@ static void push_net_callback(int fd,struct net_response res,void *payload){ "%s\t%s",res.username,res.message); } else if(res.type==NET_JOIN){ weechat_printf(room->buffer,"%sUser %s joined this room",netpfx,res.username); + if(room->buffer_nickgroup){ + weechat_nicklist_add_nick( + room->buffer,room->buffer_nickgroup, + res.username,"chat_nick", + "","chat_nick", + 1); + } } else if(res.type==NET_INVITE){ weechat_printf(room->buffer,"%sYou were invited into this room",netpfx); net_sendf(fd,history_net_callback,room,"history %s 10",room->name); @@ -146,6 +186,7 @@ static void push_net_callback(int fd,struct net_response res,void *payload){ } static void history_push_net_callback(int fd,struct net_response res,void *payload){ + fprintf(debugf,"history_ -> "); push_net_callback(fd,res,payload); } @@ -165,14 +206,13 @@ static void roomlist_net_callback(int fd,struct net_response res,void *payload){ } conn->nrooms=res.nitems; for(i64 i=0;irooms[i]=malloc(sizeof(struct roomdata)); - conn->rooms[i]->name=strdup(res.items[i]); - conn->rooms[i]->buffer=weechat_buffer_new( - conn->rooms[i]->name, - room_input_cb,conn->rooms[i],NULL, - room_close_cb,conn->rooms[i],NULL); - conn->rooms[i]->conn=conn; - net_sendf(fd,history_net_callback,conn->rooms[i],"history %s 10",conn->rooms[i]->name); + struct roomdata *room=conn->rooms[i]=malloc(sizeof(struct roomdata)); + room->name=strdup(res.items[i]); + room->conn=conn; + room->buffer=NULL; + create_room_buffer(room); + net_sendf(fd,history_net_callback,room,"history %s 10",room->name); + net_sendf(fd,members_net_callback,room,"list_members %s",room->name); } } else { fprintf(debugf,"roomlist_net_callback: res.type=%d\n",res.type); -- cgit v1.2.3-70-g09d2