From 7584ddaa62033f876b78a4de8b32d8e1e90e0619 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 5 Oct 2014 03:05:46 +0100 Subject: Added /room subject command --- src/xmpp/message.c | 18 ++++++++++++++---- src/xmpp/stanza.c | 23 +++++++++++++++++++++++ src/xmpp/stanza.h | 1 + src/xmpp/xmpp.h | 2 ++ 4 files changed, 40 insertions(+), 4 deletions(-) (limited to 'src/xmpp') diff --git a/src/xmpp/message.c b/src/xmpp/message.c index f3940067..16a51829 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -124,6 +124,17 @@ _message_send_groupchat(const char * const msg, const char * const recipient) xmpp_stanza_release(message); } +static void +_message_send_groupchat_subject(const char * const room, const char * const subject) +{ + xmpp_conn_t * const conn = connection_get_conn(); + xmpp_ctx_t * const ctx = connection_get_ctx(); + xmpp_stanza_t *message = stanza_create_room_subject_message(ctx, room, subject); + + xmpp_send(conn, message); + xmpp_stanza_release(message); +} + static void _message_send_duck(const char * const query) { @@ -361,10 +372,8 @@ _groupchat_handler(xmpp_conn_t * const conn, xmpp_stanza_t *subject = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SUBJECT); if (subject != NULL) { message = xmpp_stanza_get_text(subject); - if (message != NULL) { - handle_room_subject(jid->barejid, message); - xmpp_free(ctx, message); - } + handle_room_subject(jid->barejid, jid->resourcepart, message); + xmpp_free(ctx, message); jid_destroy(jid); return 1; @@ -530,4 +539,5 @@ message_init_module(void) message_send_paused = _message_send_paused; message_send_inactive = _message_send_inactive; message_send_gone = _message_send_gone; + message_send_groupchat_subject = _message_send_groupchat_subject; } diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index e17ed86e..b1bb51d8 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -220,6 +220,29 @@ stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const recipient, return msg; } +xmpp_stanza_t * +stanza_create_room_subject_message(xmpp_ctx_t *ctx, const char * const room, const char * const subject) +{ + xmpp_stanza_t *msg = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE); + xmpp_stanza_set_type(msg, STANZA_TYPE_GROUPCHAT); + xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, room); + + xmpp_stanza_t *subject_st = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(subject_st, STANZA_NAME_SUBJECT); + if (subject) { + xmpp_stanza_t *subject_text = xmpp_stanza_new(ctx); + xmpp_stanza_set_text(subject_text, subject); + xmpp_stanza_add_child(subject_st, subject_text); + xmpp_stanza_release(subject_text); + } + + xmpp_stanza_add_child(msg, subject_st); + xmpp_stanza_release(subject_st); + + return msg; +} + xmpp_stanza_t * stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, const char * const type, const char * const message, diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index cf2dc482..d9f82929 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -209,6 +209,7 @@ xmpp_stanza_t* stanza_create_room_affiliation_list_iq(xmpp_ctx_t *ctx, const cha const char * const affiliation); xmpp_stanza_t* stanza_create_room_affiliation_set_iq(xmpp_ctx_t *ctx, const char * const room, const char * const jid, const char * const affiliation, const char * const reason); +xmpp_stanza_t* stanza_create_room_subject_message(xmpp_ctx_t *ctx, const char * const room, const char * const subject); int stanza_get_idle_time(xmpp_stanza_t * const stanza); char * stanza_get_caps_str(xmpp_stanza_t * const stanza); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 0695d903..37c916f4 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -156,6 +156,8 @@ GList * (*jabber_get_available_resources)(void); // message functions void (*message_send)(const char * const msg, const char * const recipient); void (*message_send_groupchat)(const char * const msg, const char * const recipient); +void (*message_send_groupchat_subject)(const char * const room, const char * const subject); + void (*message_send_inactive)(const char * const recipient); void (*message_send_composing)(const char * const recipient); void (*message_send_paused)(const char * const recipient); -- cgit 1.4.1-2-gfad0