diff --git a/README.org b/README.org index 43336ac..4e9bd15 100644 --- a/README.org +++ b/README.org @@ -83,6 +83,8 @@ * [ ] OMEMO presence * [ ] OMEMO messages * [ ] MUC PMs + * [ ] Send typing notifications + * [ ] Recv typing notifications ** TODO [#B] Implement completion engine (milestone v0.3) ** TODO [#D] Close all issues (milestone v1.0) diff --git a/buffer.c b/buffer.c index 48232b3..6e974c9 100644 --- a/buffer.c +++ b/buffer.c @@ -12,8 +12,8 @@ #include "buffer.h" void buffer__get_account_and_channel(struct t_gui_buffer *buffer, - struct t_account **account, - struct t_channel **channel) + struct t_account **account, + struct t_channel **channel) { struct t_account *ptr_account; struct t_channel *ptr_channel; @@ -21,7 +21,7 @@ void buffer__get_account_and_channel(struct t_gui_buffer *buffer, if (!buffer) return; - /* look for a account or channel using this buffer */ + /* look for a account or channel using this buffer */ for (ptr_account = accounts; ptr_account; ptr_account = ptr_account->next_account) { @@ -49,12 +49,11 @@ void buffer__get_account_and_channel(struct t_gui_buffer *buffer, /* no account or channel found */ } -char *buffer__typing_bar_cb(const void *pointer, - void *data, - struct t_gui_bar_item *item, - struct t_gui_window *window, - struct t_gui_buffer *buffer, - struct t_hashtable *extra_info) +char *buffer__typing_bar_cb(const void *pointer, void *data, + struct t_gui_bar_item *item, + struct t_gui_window *window, + struct t_gui_buffer *buffer, + struct t_hashtable *extra_info) { struct t_channel_typing *ptr_typing; struct t_account *account; @@ -111,9 +110,9 @@ char *buffer__typing_bar_cb(const void *pointer, } int buffer__nickcmp_cb(const void *pointer, void *data, - struct t_gui_buffer *buffer, - const char *nick1, - const char *nick2) + struct t_gui_buffer *buffer, + const char *nick1, + const char *nick2) { struct t_account *account; @@ -135,7 +134,7 @@ int buffer__nickcmp_cb(const void *pointer, void *data, } int buffer__close_cb(const void *pointer, void *data, - struct t_gui_buffer *buffer) + struct t_gui_buffer *buffer) { struct t_weechat_plugin *buffer_plugin = NULL; struct t_account *ptr_account = NULL; diff --git a/buffer.h b/buffer.h index b126d9d..c07794c 100644 --- a/buffer.h +++ b/buffer.h @@ -6,22 +6,21 @@ #define _WEECHAT_XMPP_BUFFER_H_ void buffer__get_account_and_channel(struct t_gui_buffer *buffer, - struct t_account **account, - struct t_channel **channel); + struct t_account **account, + struct t_channel **channel); -char *buffer__typing_bar_cb(const void *pointer, - void *data, - struct t_gui_bar_item *item, - struct t_gui_window *window, - struct t_gui_buffer *buffer, - struct t_hashtable *extra_info); +char *buffer__typing_bar_cb(const void *pointer, void *data, + struct t_gui_bar_item *item, + struct t_gui_window *window, + struct t_gui_buffer *buffer, + struct t_hashtable *extra_info); int buffer__nickcmp_cb(const void *pointer, void *data, - struct t_gui_buffer *buffer, - const char *nick1, - const char *nick2); + struct t_gui_buffer *buffer, + const char *nick1, + const char *nick2); int buffer__close_cb(const void *pointer, void *data, - struct t_gui_buffer *buffer); + struct t_gui_buffer *buffer); #endif /*WEECHAT_XMPP_BUFFER_H*/ diff --git a/channel.c b/channel.c index c7da101..8b3fed8 100644 --- a/channel.c +++ b/channel.c @@ -115,7 +115,7 @@ struct t_gui_buffer *channel__create_buffer(struct t_account *account, "localvar_channel"); if (!short_name || - (localvar_channel && (strcmp(localvar_channel, short_name) == 0))) + (localvar_channel && (strcmp(localvar_channel, short_name) == 0))) { weechat_buffer_set (ptr_buffer, "short_name", name); } @@ -599,7 +599,13 @@ struct t_channel_member *channel__add_member(struct t_account *account, } void channel__send_message(struct t_account *account, struct t_channel *channel, - const char *to, const char *message) + const char *to, const char *body) { - + struct xmpp_stanza_t *message = xmpp_message_new(account->context, "chat", to, NULL); + xmpp_message_set_body(message, body); + xmpp_send(account->connection, message); + xmpp_stanza_release(message); + weechat_printf(channel->buffer, "%s: %s", + weechat_config_string(account->options[ACCOUNT_OPTION_JID]), + body); } diff --git a/channel.h b/channel.h index 3498c47..3145fa1 100644 --- a/channel.h +++ b/channel.h @@ -117,4 +117,7 @@ struct t_channel_member *channel__add_member(struct t_account *account, struct t_channel *channel, const char *id); +void channel__send_message(struct t_account *account, struct t_channel *channel, + const char *to, const char *body); + #endif /*WEECHAT_XMPP_CHANNEL_H*/ diff --git a/command.c b/command.c index 6ed8acd..25a75d7 100644 --- a/command.c +++ b/command.c @@ -332,13 +332,12 @@ int command__me(const void *pointer, void *data, char **argv, char **argv_eol) { struct t_account *ptr_account = NULL; - struct t_xmpp_channel *ptr_channel = NULL; - //struct t_xmpp_request *request; + struct t_channel *ptr_channel = NULL; + struct xmpp_stanza_t *message; char *text; (void) pointer; (void) data; - (void) buffer; (void) argv; buffer__get_account_and_channel(buffer, &ptr_account, &ptr_channel); @@ -365,14 +364,15 @@ int command__me(const void *pointer, void *data, if (argc > 1) { - text = argv_eol[1]; - - //request = xmpp_request_chat_memessage(ptr_account, - // weechat_config_string( - // ptr_account->options[XMPP_ACCOUNT_OPTION_TOKEN]), - // ptr_channel->id, text); - //if (request) - // xmpp_account_register_request(ptr_account, request); + text = argv_eol[0]; + + message = xmpp_message_new(ptr_account->context, "chat", ptr_channel->name, NULL); + xmpp_message_set_body(message, text); + xmpp_send(ptr_account->connection, message); + xmpp_stanza_release(message); + weechat_printf(ptr_channel->buffer, "* %s %s", + weechat_config_string(ptr_account->options[ACCOUNT_OPTION_JID]), + text); } return WEECHAT_RC_OK; diff --git a/connection.c b/connection.c index 39a3111..c8adde4 100644 --- a/connection.c +++ b/connection.c @@ -75,7 +75,6 @@ int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) xmpp_stanza_t *body, *reply, *to; const char *type, *from, *from_bare; char *intext, *replytext; - int quit = 0; body = xmpp_stanza_get_child_by_name(stanza, "body"); if (body == NULL) @@ -93,7 +92,12 @@ int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) if (!channel) channel = channel__new(account, CHANNEL_TYPE_PM, from_bare, from_bare); - weechat_printf(channel->buffer, "<-(%s)- %s: %s", to, from, intext); + if (strcmp(to, channel->id) == 0) + weechat_printf(channel->buffer, "%s [to %s]: %s", from, to, intext); + else if (strncmp(intext, "/me ", 4) == 0) + weechat_printf(channel->buffer, "* %s %s", from, intext+4); + else + weechat_printf(channel->buffer, "%s: %s", from, intext); xmpp_free(account->context, intext); @@ -111,7 +115,7 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status, if (status == XMPP_CONN_CONNECT) { xmpp_stanza_t *pres; - weechat_printf(account->buffer, "DEBUG: connected"); + //weechat_printf(account->buffer, "DEBUG: connected"); xmpp_handler_add(conn, version_handler, "jabber:iq:version", "iq", NULL, account); xmpp_handler_add(conn, message_handler, NULL, "message", NULL, account); @@ -121,7 +125,7 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status, xmpp_send(conn, pres); xmpp_stanza_release(pres); } else { - weechat_printf(account->buffer, "DEBUG: disconnected"); + //weechat_printf(account->buffer, "DEBUG: disconnected"); //xmpp_stop(account->context); } } diff --git a/input.c b/input.c index d4ed0a9..e454ede 100644 --- a/input.c +++ b/input.c @@ -17,7 +17,6 @@ int input__data(struct t_gui_buffer *buffer, const char *text) { struct t_account *account = NULL; struct t_channel *channel = NULL; - struct xmpp_stanza_t *message; buffer__get_account_and_channel(buffer, &account, &channel); @@ -34,13 +33,7 @@ int input__data(struct t_gui_buffer *buffer, const char *text) return WEECHAT_RC_OK; } - message = xmpp_message_new(account->context, "chat", channel->id, NULL); - xmpp_message_set_body(message, text); - xmpp_send(account->connection, message); - xmpp_stanza_release(message); - weechat_printf(channel->buffer, "-> %s: %s", - weechat_config_string(account->options[ACCOUNT_OPTION_JID]), - text); + channel__send_message(account, channel, channel->id, text); } else {