about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-03-28 22:51:41 +0000
committerJames Booth <boothj5@gmail.com>2015-03-28 22:51:41 +0000
commitfac2b2cf665e72f0f7fe66232952401274d51ee7 (patch)
tree0b6fc05e01b594ef106abfc6e5e51ec599b3f56b /src/xmpp
parentf1f047889eed360a0c91be4fcabd24199089c02a (diff)
downloadprofani-tty-fac2b2cf665e72f0f7fe66232952401274d51ee7.tar.gz
Added check members only room to send mediated invites
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/message.c11
-rw-r--r--src/xmpp/stanza.c40
-rw-r--r--src/xmpp/stanza.h2
3 files changed, 52 insertions, 1 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index e6927f76..1bb3bcdc 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -204,7 +204,16 @@ message_send_invite(const char * const roomjid, const char * const contact,
 {
     xmpp_conn_t * const conn = connection_get_conn();
     xmpp_ctx_t * const ctx = connection_get_ctx();
-    xmpp_stanza_t *stanza = stanza_create_invite(ctx, roomjid, contact, reason);
+    xmpp_stanza_t *stanza;
+
+    muc_member_type_t member_type = muc_member_type(roomjid);
+    if (member_type == MUC_MEMBER_TYPE_PUBLIC) {
+        log_debug("Sending direct invite to %s, for %s", contact, roomjid);
+        stanza = stanza_create_invite(ctx, roomjid, contact, reason);
+    } else {
+        log_debug("Sending mediated invite to %s, for %s", contact, roomjid);
+        stanza = stanza_create_mediated_invite(ctx, roomjid, contact, reason);
+    }
 
     xmpp_send(conn, stanza);
     xmpp_stanza_release(stanza);
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 0b291d2e..03567e31 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -441,6 +441,46 @@ stanza_create_invite(xmpp_ctx_t *ctx, const char * const room,
 }
 
 xmpp_stanza_t *
+stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char * const room,
+    const char * const contact, const char * const reason)
+{
+    xmpp_stanza_t *message, *x, *invite;
+
+    message = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(message, STANZA_NAME_MESSAGE);
+    xmpp_stanza_set_attribute(message, STANZA_ATTR_TO, room);
+    char *id = create_unique_id(NULL);
+    xmpp_stanza_set_id(message, id);
+    free(id);
+
+    x = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(x, STANZA_NAME_X);
+    xmpp_stanza_set_ns(x, STANZA_NS_MUC_USER);
+
+    invite = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(invite, STANZA_NAME_INVITE);
+    xmpp_stanza_set_attribute(invite, STANZA_ATTR_TO, contact);
+
+    if (reason != NULL) {
+        xmpp_stanza_t *reason_st = xmpp_stanza_new(ctx);
+        xmpp_stanza_set_name(reason_st, STANZA_NAME_REASON);
+        xmpp_stanza_t *reason_txt = xmpp_stanza_new(ctx);
+        xmpp_stanza_set_text(reason_txt, reason);
+        xmpp_stanza_add_child(reason_st, reason_txt);
+        xmpp_stanza_release(reason_txt);
+        xmpp_stanza_add_child(invite, reason_st);
+        xmpp_stanza_release(reason_st);
+    }
+
+    xmpp_stanza_add_child(x, invite);
+    xmpp_stanza_release(invite);
+    xmpp_stanza_add_child(message, x);
+    xmpp_stanza_release(x);
+
+    return message;
+}
+
+xmpp_stanza_t *
 stanza_create_room_join_presence(xmpp_ctx_t * const ctx,
     const char * const full_room_jid, const char * const passwd)
 {
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index 50f3dbd0..744bd7fb 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -215,6 +215,8 @@ xmpp_stanza_t* stanza_create_disco_info_iq(xmpp_ctx_t *ctx, const char * const i
 
 xmpp_stanza_t* stanza_create_invite(xmpp_ctx_t *ctx, const char * const room,
     const char * const contact, const char * const reason);
+xmpp_stanza_t* stanza_create_mediated_invite(xmpp_ctx_t *ctx, const char * const room,
+    const char * const contact, const char * const reason);
 
 gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza);