From d5a009f5471203f5643a5998dea02ba6433ddaaf Mon Sep 17 00:00:00 2001 From: Tony Olagbaiye Date: Wed, 30 Jun 2021 23:31:20 +0100 Subject: [PATCH] replies in pm at least --- Makefile | 2 +- connection.c | 15 ++++++++------- input.c | 17 ++++++++--------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 1f137d2..9a19fb7 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ xmpp.so: $(OBJS) test: xmpp.so env LD_PRELOAD=$(DEBUG) \ - weechat -a -P buflist -r '/plugin load ./xmpp.so' + weechat -a -P 'buflist,irc' -r '/plugin load ./xmpp.so' debug: xmpp.so gdb -ex "handle SIGPIPE nostop noprint pass" --args \ diff --git a/connection.c b/connection.c index 07e919b..8b0a787 100644 --- a/connection.c +++ b/connection.c @@ -72,8 +72,8 @@ int version_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) { struct t_account *account = (struct t_account *)userdata; - xmpp_stanza_t *body, *reply; - const char *type, *from, *from_jid; + xmpp_stanza_t *body, *reply, *to; + const char *type, *from, *from_bare; char *intext, *replytext; int quit = 0; @@ -84,15 +84,16 @@ int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) if (type != NULL && strcmp(type, "error") == 0) return 1; from = xmpp_stanza_get_from(stanza); - from_jid = xmpp_jid_bare(account->context, from); + from_bare = xmpp_jid_bare(account->context, from); + to = xmpp_stanza_get_to(stanza); intext = xmpp_stanza_get_text(body); - struct t_channel *channel = channel__search(account, from_jid); + struct t_channel *channel = channel__search(account, from_bare); if (!channel) - channel = channel__new(account, CHANNEL_TYPE_PM, from_jid, from_jid); + channel = channel__new(account, CHANNEL_TYPE_PM, from_bare, from_bare); - weechat_printf(channel->buffer, "%s: %s", from_jid, intext); + weechat_printf(channel->buffer, "<-(%s)- %s: %s", to, from, intext); reply = xmpp_stanza_reply(stanza); if (xmpp_stanza_get_type(reply) == NULL) @@ -107,7 +108,7 @@ int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata) xmpp_send(conn, reply); xmpp_stanza_release(reply); - weechat_printf(channel->buffer, "%s: %s", + weechat_printf(channel->buffer, "-> %s: %s", weechat_config_string(account->options[ACCOUNT_OPTION_JID]), replytext); free(replytext); diff --git a/input.c b/input.c index 6aebd91..d4ed0a9 100644 --- a/input.c +++ b/input.c @@ -10,7 +10,6 @@ #include "account.h" #include "channel.h" #include "buffer.h" -//#include "request.h" #include "message.h" #include "input.h" @@ -18,7 +17,7 @@ int input__data(struct t_gui_buffer *buffer, const char *text) { struct t_account *account = NULL; struct t_channel *channel = NULL; - struct t_request *request; + struct xmpp_stanza_t *message; buffer__get_account_and_channel(buffer, &account, &channel); @@ -35,13 +34,13 @@ int input__data(struct t_gui_buffer *buffer, const char *text) return WEECHAT_RC_OK; } - //TODO: SEND - //request = request_chat_postmessage(account, - // weechat_config_string( - // account->options[ACCOUNT_OPTION_TOKEN]), - // channel->id, text); - //if (request) - // account__register_request(account, request); + 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); } else {