aboutsummaryrefslogtreecommitdiff
path: root/weechat/tomsg.c
diff options
context:
space:
mode:
Diffstat (limited to 'weechat/tomsg.c')
-rw-r--r--weechat/tomsg.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/weechat/tomsg.c b/weechat/tomsg.c
index 6b5703c..7778645 100644
--- a/weechat/tomsg.c
+++ b/weechat/tomsg.c
@@ -17,7 +17,7 @@ WEECHAT_PLUGIN_LICENSE("MIT")
WEECHAT_PLUGIN_PRIORITY(1000)
-static const char *errpfx;
+static const char *errpfx,*netpfx;
struct roomdata{
@@ -98,12 +98,18 @@ static int room_close_cb(const void *room_vp,void *_d,struct t_gui_buffer *buffe
return WEECHAT_RC_OK;
}
+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 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);
struct conndata *conn=weechat_hashtable_get(conntable,&fd);
assert(conn);
- if(res.type==NET_MESSAGE){
+ if(res.type==NET_MESSAGE||res.type==NET_JOIN||res.type==NET_INVITE){
i64 roomi;
for(roomi=0;roomi<conn->nrooms;roomi++){
if(strcmp(conn->rooms[roomi]->name,res.room)==0){
@@ -121,9 +127,19 @@ static void push_net_callback(int fd,struct net_response res,void *payload){
room_input_cb,room,NULL,
room_close_cb,room,NULL);
}
- weechat_printf_date_tags(
- room->buffer,res.timestamp/1000000LL,NULL,
- "%s\t%s",res.username,res.message);
+
+ if(res.type==NET_MESSAGE){
+ weechat_printf_date_tags(
+ room->buffer,res.timestamp/1000000LL,NULL,
+ "%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);
+ } 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);
+ } else {
+ assert(false);
+ }
} else {
fprintf(debugf,"push_net_callback: unknown response type %d\n",res.type);
}
@@ -133,12 +149,6 @@ static void history_push_net_callback(int fd,struct net_response res,void *paylo
push_net_callback(fd,res,payload);
}
-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 roomlist_net_callback(int fd,struct net_response res,void *payload){
(void)payload;
fprintf(debugf,"roomlist_net_callback(fd=%d,res={.type=%d})\n",fd,res.type);
@@ -368,6 +378,7 @@ int weechat_plugin_init(struct t_weechat_plugin *plugin,int argc,char **argv){
fprintf(debugf,"------\n");
errpfx=weechat_prefix("error");
+ netpfx=weechat_prefix("network");
weechat_hook_command(
"tomsg",