about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-10-05 03:05:46 +0100
committerJames Booth <boothj5@gmail.com>2014-10-05 03:05:46 +0100
commit7584ddaa62033f876b78a4de8b32d8e1e90e0619 (patch)
tree4aec278429ca06f5b8a986cecf99badbc60b70a1 /src/xmpp
parent2026ab4b6ee7dca156b6b72d9889f2039279af27 (diff)
downloadprofani-tty-7584ddaa62033f876b78a4de8b32d8e1e90e0619.tar.gz
Added /room subject command
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/message.c18
-rw-r--r--src/xmpp/stanza.c23
-rw-r--r--src/xmpp/stanza.h1
-rw-r--r--src/xmpp/xmpp.h2
4 files changed, 40 insertions, 4 deletions
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
@@ -125,6 +125,17 @@ _message_send_groupchat(const char * const msg, const char * const recipient)
 }
 
 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)
 {
     xmpp_conn_t * const conn = connection_get_conn();
@@ -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
@@ -221,6 +221,29 @@ stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const recipient,
 }
 
 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,
     const char * const state)
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);