Add xep-0107: User Mood support
Implementation of XEP 0107 - User Mood
This commit is contained in:
committed by
Michael Vetter
parent
9a9122c148
commit
23e886ed5e
@@ -2798,3 +2798,55 @@ iq_muc_register_nick(const char* const roomjid)
|
||||
xmpp_stanza_release(iq);
|
||||
xmpp_stanza_release(query);
|
||||
}
|
||||
|
||||
void
|
||||
publish_user_mood(const char* const mood, const char* const text)
|
||||
{
|
||||
xmpp_ctx_t* const ctx = connection_get_ctx();
|
||||
char* id = connection_create_stanza_id();
|
||||
|
||||
xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
|
||||
|
||||
xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(pubsub, "pubsub");
|
||||
xmpp_stanza_set_ns(pubsub, "http://jabber.org/protocol/pubsub");
|
||||
xmpp_stanza_add_child(iq, pubsub);
|
||||
|
||||
xmpp_stanza_t* publish = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(publish, "publish");
|
||||
xmpp_stanza_set_attribute(publish, "node", "http://jabber.org/protocol/mood");
|
||||
xmpp_stanza_add_child(pubsub, publish);
|
||||
|
||||
xmpp_stanza_t* item = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(item, "item");
|
||||
xmpp_stanza_set_attribute(item, "id", "current");
|
||||
xmpp_stanza_add_child(publish, item);
|
||||
|
||||
xmpp_stanza_t* mood_t = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(mood_t, "mood");
|
||||
xmpp_stanza_set_ns(mood_t, "http://jabber.org/protocol/mood");
|
||||
xmpp_stanza_add_child(item, mood_t);
|
||||
|
||||
xmpp_stanza_t* x = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(x, mood);
|
||||
xmpp_stanza_add_child(mood_t, x);
|
||||
|
||||
xmpp_stanza_t* text_t = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(text_t, "text");
|
||||
xmpp_stanza_add_child(mood_t, text_t);
|
||||
|
||||
xmpp_stanza_t* t = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(t, text);
|
||||
xmpp_stanza_add_child(text_t, t);
|
||||
|
||||
iq_send_stanza(iq);
|
||||
|
||||
xmpp_stanza_release(iq);
|
||||
xmpp_stanza_release(pubsub);
|
||||
xmpp_stanza_release(publish);
|
||||
xmpp_stanza_release(item);
|
||||
xmpp_stanza_release(mood_t);
|
||||
xmpp_stanza_release(x);
|
||||
xmpp_stanza_release(text_t);
|
||||
xmpp_stanza_release(t);
|
||||
}
|
||||
|
||||
@@ -161,8 +161,13 @@ _message_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* con
|
||||
} else if (type && g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0) {
|
||||
// XEP-0045: Multi-User Chat
|
||||
_handle_groupchat(stanza);
|
||||
|
||||
} else if (type && g_strcmp0(type, STANZA_TYPE_HEADLINE) == 0) {
|
||||
_handle_headline(stanza);
|
||||
xmpp_stanza_t* event = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_PUBSUB_EVENT);
|
||||
if (event) {
|
||||
_handle_pubsub(stanza, event);
|
||||
return 1;
|
||||
}
|
||||
} else if (type == NULL || g_strcmp0(type, STANZA_TYPE_CHAT) == 0 || g_strcmp0(type, STANZA_TYPE_NORMAL) == 0) {
|
||||
// type: chat, normal (==NULL)
|
||||
|
||||
@@ -247,6 +252,8 @@ _message_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* con
|
||||
if (msg_stanza) {
|
||||
_handle_chat(msg_stanza, FALSE, is_carbon, NULL, NULL);
|
||||
}
|
||||
} else if (type && g_strcmp0(type, STANZA_TYPE_HEADLINE) == 0) {
|
||||
_handle_headline(stanza);
|
||||
} else {
|
||||
// none of the allowed types
|
||||
char* text;
|
||||
|
||||
@@ -286,6 +286,38 @@ session_get_account_name(void)
|
||||
return saved_account.name;
|
||||
}
|
||||
|
||||
static int _receive_mood(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
|
||||
static int
|
||||
_receive_mood(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
{
|
||||
const char* from = xmpp_stanza_get_from(stanza);
|
||||
xmpp_stanza_t* event = xmpp_stanza_get_child_by_name_and_ns(stanza, "event", "http://jabber.org/protocol/pubsub#event");
|
||||
if (event) {
|
||||
xmpp_stanza_t* items = xmpp_stanza_get_child_by_name(event, "items");
|
||||
if (items) {
|
||||
xmpp_stanza_t* item = xmpp_stanza_get_child_by_name(items, "item");
|
||||
if (item) {
|
||||
xmpp_stanza_t* mood = xmpp_stanza_get_child_by_name_and_ns(item, "mood", "http://jabber.org/protocol/mood");
|
||||
if (mood) {
|
||||
xmpp_stanza_t* c = xmpp_stanza_get_children(mood);
|
||||
if (c) {
|
||||
const char* m = xmpp_stanza_get_name(c);
|
||||
xmpp_stanza_t* t = xmpp_stanza_get_child_by_name(mood, "text");
|
||||
if (t) {
|
||||
const char* text = xmpp_stanza_get_text(t);
|
||||
cons_show("Mood from %s %s (%s)", from, m, text);
|
||||
} else {
|
||||
cons_show("Mood from %s %s", from, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
session_login_success(gboolean secured)
|
||||
{
|
||||
@@ -330,6 +362,9 @@ session_login_success(gboolean secured)
|
||||
g_timer_destroy(reconnect_timer);
|
||||
reconnect_timer = NULL;
|
||||
}
|
||||
|
||||
message_pubsub_event_handler_add("http://jabber.org/protocol/mood", _receive_mood, NULL, NULL);
|
||||
caps_add_feature("http://jabber.org/protocol/mood+notify");
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -307,4 +307,6 @@ FormField* form_get_field_by_tag(DataForm* form, const char* const tag);
|
||||
Autocomplete form_get_value_ac(DataForm* form, const char* const tag);
|
||||
void form_reset_autocompleters(DataForm* form);
|
||||
|
||||
void publish_user_mood(const char* const mood, const char* const text);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user