handle /me

v1
Tony Olagbaiye 4 years ago
parent 60db9faf1b
commit b48a796e3d
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -83,6 +83,8 @@
* [ ] OMEMO presence * [ ] OMEMO presence
* [ ] OMEMO messages * [ ] OMEMO messages
* [ ] MUC PMs * [ ] MUC PMs
* [ ] Send typing notifications
* [ ] Recv typing notifications
** TODO [#B] Implement completion engine (milestone v0.3) ** TODO [#B] Implement completion engine (milestone v0.3)
** TODO [#D] Close all issues (milestone v1.0) ** TODO [#D] Close all issues (milestone v1.0)

@ -12,8 +12,8 @@
#include "buffer.h" #include "buffer.h"
void buffer__get_account_and_channel(struct t_gui_buffer *buffer, void buffer__get_account_and_channel(struct t_gui_buffer *buffer,
struct t_account **account, struct t_account **account,
struct t_channel **channel) struct t_channel **channel)
{ {
struct t_account *ptr_account; struct t_account *ptr_account;
struct t_channel *ptr_channel; struct t_channel *ptr_channel;
@ -21,7 +21,7 @@ void buffer__get_account_and_channel(struct t_gui_buffer *buffer,
if (!buffer) if (!buffer)
return; 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; for (ptr_account = accounts; ptr_account;
ptr_account = ptr_account->next_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 */ /* no account or channel found */
} }
char *buffer__typing_bar_cb(const void *pointer, char *buffer__typing_bar_cb(const void *pointer, void *data,
void *data, struct t_gui_bar_item *item,
struct t_gui_bar_item *item, struct t_gui_window *window,
struct t_gui_window *window, struct t_gui_buffer *buffer,
struct t_gui_buffer *buffer, struct t_hashtable *extra_info)
struct t_hashtable *extra_info)
{ {
struct t_channel_typing *ptr_typing; struct t_channel_typing *ptr_typing;
struct t_account *account; 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, int buffer__nickcmp_cb(const void *pointer, void *data,
struct t_gui_buffer *buffer, struct t_gui_buffer *buffer,
const char *nick1, const char *nick1,
const char *nick2) const char *nick2)
{ {
struct t_account *account; 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, 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_weechat_plugin *buffer_plugin = NULL;
struct t_account *ptr_account = NULL; struct t_account *ptr_account = NULL;

@ -6,22 +6,21 @@
#define _WEECHAT_XMPP_BUFFER_H_ #define _WEECHAT_XMPP_BUFFER_H_
void buffer__get_account_and_channel(struct t_gui_buffer *buffer, void buffer__get_account_and_channel(struct t_gui_buffer *buffer,
struct t_account **account, struct t_account **account,
struct t_channel **channel); struct t_channel **channel);
char *buffer__typing_bar_cb(const void *pointer, char *buffer__typing_bar_cb(const void *pointer, void *data,
void *data, struct t_gui_bar_item *item,
struct t_gui_bar_item *item, struct t_gui_window *window,
struct t_gui_window *window, struct t_gui_buffer *buffer,
struct t_gui_buffer *buffer, struct t_hashtable *extra_info);
struct t_hashtable *extra_info);
int buffer__nickcmp_cb(const void *pointer, void *data, int buffer__nickcmp_cb(const void *pointer, void *data,
struct t_gui_buffer *buffer, struct t_gui_buffer *buffer,
const char *nick1, const char *nick1,
const char *nick2); const char *nick2);
int buffer__close_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);
#endif /*WEECHAT_XMPP_BUFFER_H*/ #endif /*WEECHAT_XMPP_BUFFER_H*/

@ -115,7 +115,7 @@ struct t_gui_buffer *channel__create_buffer(struct t_account *account,
"localvar_channel"); "localvar_channel");
if (!short_name || 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); 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, 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);
} }

@ -117,4 +117,7 @@ struct t_channel_member *channel__add_member(struct t_account *account,
struct t_channel *channel, struct t_channel *channel,
const char *id); 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*/ #endif /*WEECHAT_XMPP_CHANNEL_H*/

@ -332,13 +332,12 @@ int command__me(const void *pointer, void *data,
char **argv, char **argv_eol) char **argv, char **argv_eol)
{ {
struct t_account *ptr_account = NULL; struct t_account *ptr_account = NULL;
struct t_xmpp_channel *ptr_channel = NULL; struct t_channel *ptr_channel = NULL;
//struct t_xmpp_request *request; struct xmpp_stanza_t *message;
char *text; char *text;
(void) pointer; (void) pointer;
(void) data; (void) data;
(void) buffer;
(void) argv; (void) argv;
buffer__get_account_and_channel(buffer, &ptr_account, &ptr_channel); 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) if (argc > 1)
{ {
text = argv_eol[1]; text = argv_eol[0];
//request = xmpp_request_chat_memessage(ptr_account, message = xmpp_message_new(ptr_account->context, "chat", ptr_channel->name, NULL);
// weechat_config_string( xmpp_message_set_body(message, text);
// ptr_account->options[XMPP_ACCOUNT_OPTION_TOKEN]), xmpp_send(ptr_account->connection, message);
// ptr_channel->id, text); xmpp_stanza_release(message);
//if (request) weechat_printf(ptr_channel->buffer, "* %s %s",
// xmpp_account_register_request(ptr_account, request); weechat_config_string(ptr_account->options[ACCOUNT_OPTION_JID]),
text);
} }
return WEECHAT_RC_OK; return WEECHAT_RC_OK;

@ -75,7 +75,6 @@ int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
xmpp_stanza_t *body, *reply, *to; xmpp_stanza_t *body, *reply, *to;
const char *type, *from, *from_bare; const char *type, *from, *from_bare;
char *intext, *replytext; char *intext, *replytext;
int quit = 0;
body = xmpp_stanza_get_child_by_name(stanza, "body"); body = xmpp_stanza_get_child_by_name(stanza, "body");
if (body == NULL) if (body == NULL)
@ -93,7 +92,12 @@ int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
if (!channel) if (!channel)
channel = channel__new(account, CHANNEL_TYPE_PM, from_bare, from_bare); 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); 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) { if (status == XMPP_CONN_CONNECT) {
xmpp_stanza_t *pres; 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, xmpp_handler_add(conn, version_handler, "jabber:iq:version", "iq", NULL,
account); account);
xmpp_handler_add(conn, message_handler, NULL, "message", 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_send(conn, pres);
xmpp_stanza_release(pres); xmpp_stanza_release(pres);
} else { } else {
weechat_printf(account->buffer, "DEBUG: disconnected"); //weechat_printf(account->buffer, "DEBUG: disconnected");
//xmpp_stop(account->context); //xmpp_stop(account->context);
} }
} }

@ -17,7 +17,6 @@ int input__data(struct t_gui_buffer *buffer, const char *text)
{ {
struct t_account *account = NULL; struct t_account *account = NULL;
struct t_channel *channel = NULL; struct t_channel *channel = NULL;
struct xmpp_stanza_t *message;
buffer__get_account_and_channel(buffer, &account, &channel); 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; return WEECHAT_RC_OK;
} }
message = xmpp_message_new(account->context, "chat", channel->id, NULL); channel__send_message(account, channel, channel->id, text);
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);
} }
else else
{ {

Loading…
Cancel
Save