mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
xep-0107: code review
* Remarks in the Merge Request (ac_reset, help) * Defines in iq.c * Mood help and null check * Added additional information about tab key in CMD_DESC. * Added additional null check
This commit is contained in:
parent
e745b4af60
commit
2f3de0eb0d
@ -1460,6 +1460,7 @@ cmd_ac_reset(ProfWin* window)
|
|||||||
autocomplete_reset(executable_ac);
|
autocomplete_reset(executable_ac);
|
||||||
autocomplete_reset(intype_ac);
|
autocomplete_reset(intype_ac);
|
||||||
autocomplete_reset(mood_ac);
|
autocomplete_reset(mood_ac);
|
||||||
|
autocomplete_reset(mood_type_ac);
|
||||||
|
|
||||||
autocomplete_reset(script_ac);
|
autocomplete_reset(script_ac);
|
||||||
if (script_show_ac) {
|
if (script_show_ac) {
|
||||||
@ -4247,17 +4248,10 @@ _mood_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//jabber_conn_status_t conn_status = connection_get_status();
|
|
||||||
//if (conn_status == JABBER_CONNECTED) {
|
|
||||||
result = autocomplete_param_with_ac(input, "/mood set", mood_type_ac, FALSE, previous);
|
result = autocomplete_param_with_ac(input, "/mood set", mood_type_ac, FALSE, previous);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// result = autocomplete_param_with_func(input, "/mood get", roster_barejid_autocomplete, previous, NULL);
|
|
||||||
// if (result) {
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -2688,9 +2688,12 @@ static struct cmd_t command_defs[] = {
|
|||||||
CMD_SYN(
|
CMD_SYN(
|
||||||
"/mood set <mood> [\"Text\"]")
|
"/mood set <mood> [\"Text\"]")
|
||||||
CMD_DESC(
|
CMD_DESC(
|
||||||
"Set your mood")
|
"Set your mood. Use the tab key to switch through the available moods")
|
||||||
CMD_NOARGS
|
CMD_ARGS(
|
||||||
CMD_NOEXAMPLES
|
{ "set <mood>", "Your mood" },
|
||||||
|
{ "<text>", "Additional Text" })
|
||||||
|
CMD_EXAMPLES(
|
||||||
|
"/mood set happy \"I'm happy\"")
|
||||||
},
|
},
|
||||||
// NEXT-COMMAND (search helper)
|
// NEXT-COMMAND (search helper)
|
||||||
};
|
};
|
||||||
|
@ -9649,8 +9649,8 @@ cmd_register(ProfWin* window, const char* const command, gchar** args)
|
|||||||
gboolean
|
gboolean
|
||||||
cmd_mood(ProfWin* window, const char* const command, gchar** args)
|
cmd_mood(ProfWin* window, const char* const command, gchar** args)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (g_strcmp0(args[0], "set") == 0) {
|
if (g_strcmp0(args[0], "set") == 0) {
|
||||||
|
if(args[1]) {
|
||||||
cons_show("Your mood: %s", args[1]);
|
cons_show("Your mood: %s", args[1]);
|
||||||
if (args[2]) {
|
if (args[2]) {
|
||||||
publish_user_mood(args[1], args[2]);
|
publish_user_mood(args[1], args[2]);
|
||||||
@ -9658,5 +9658,6 @@ cmd_mood(ProfWin* window, const char* const command, gchar** args)
|
|||||||
publish_user_mood(args[1], args[1]);
|
publish_user_mood(args[1], args[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -2808,23 +2808,23 @@ publish_user_mood(const char* const mood, const char* const text)
|
|||||||
xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
|
xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
|
||||||
|
|
||||||
xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx);
|
xmpp_stanza_t* pubsub = xmpp_stanza_new(ctx);
|
||||||
xmpp_stanza_set_name(pubsub, "pubsub");
|
xmpp_stanza_set_name(pubsub, STANZA_NAME_PUBSUB);
|
||||||
xmpp_stanza_set_ns(pubsub, "http://jabber.org/protocol/pubsub");
|
xmpp_stanza_set_ns(pubsub, STANZA_NS_PUBSUB);
|
||||||
xmpp_stanza_add_child(iq, pubsub);
|
xmpp_stanza_add_child(iq, pubsub);
|
||||||
|
|
||||||
xmpp_stanza_t* publish = xmpp_stanza_new(ctx);
|
xmpp_stanza_t* publish = xmpp_stanza_new(ctx);
|
||||||
xmpp_stanza_set_name(publish, "publish");
|
xmpp_stanza_set_name(publish, STANZA_NAME_PUBLISH);
|
||||||
xmpp_stanza_set_attribute(publish, "node", "http://jabber.org/protocol/mood");
|
xmpp_stanza_set_attribute(publish, STANZA_ATTR_NODE, STANZA_NS_MOOD);
|
||||||
xmpp_stanza_add_child(pubsub, publish);
|
xmpp_stanza_add_child(pubsub, publish);
|
||||||
|
|
||||||
xmpp_stanza_t* item = xmpp_stanza_new(ctx);
|
xmpp_stanza_t* item = xmpp_stanza_new(ctx);
|
||||||
xmpp_stanza_set_name(item, "item");
|
xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
|
||||||
xmpp_stanza_set_attribute(item, "id", "current");
|
xmpp_stanza_set_attribute(item, "id", "current");
|
||||||
xmpp_stanza_add_child(publish, item);
|
xmpp_stanza_add_child(publish, item);
|
||||||
|
|
||||||
xmpp_stanza_t* mood_t = xmpp_stanza_new(ctx);
|
xmpp_stanza_t* mood_t = xmpp_stanza_new(ctx);
|
||||||
xmpp_stanza_set_name(mood_t, "mood");
|
xmpp_stanza_set_name(mood_t, STANZA_NAME_MOOD);
|
||||||
xmpp_stanza_set_ns(mood_t, "http://jabber.org/protocol/mood");
|
xmpp_stanza_set_ns(mood_t, STANZA_NS_MOOD);
|
||||||
xmpp_stanza_add_child(item, mood_t);
|
xmpp_stanza_add_child(item, mood_t);
|
||||||
|
|
||||||
xmpp_stanza_t* x = xmpp_stanza_new(ctx);
|
xmpp_stanza_t* x = xmpp_stanza_new(ctx);
|
||||||
@ -2832,7 +2832,7 @@ publish_user_mood(const char* const mood, const char* const text)
|
|||||||
xmpp_stanza_add_child(mood_t, x);
|
xmpp_stanza_add_child(mood_t, x);
|
||||||
|
|
||||||
xmpp_stanza_t* text_t = xmpp_stanza_new(ctx);
|
xmpp_stanza_t* text_t = xmpp_stanza_new(ctx);
|
||||||
xmpp_stanza_set_name(text_t, "text");
|
xmpp_stanza_set_name(text_t, STANZA_NAME_TEXT);
|
||||||
xmpp_stanza_add_child(mood_t, text_t);
|
xmpp_stanza_add_child(mood_t, text_t);
|
||||||
|
|
||||||
xmpp_stanza_t* t = xmpp_stanza_new(ctx);
|
xmpp_stanza_t* t = xmpp_stanza_new(ctx);
|
||||||
|
@ -286,24 +286,22 @@ session_get_account_name(void)
|
|||||||
return saved_account.name;
|
return saved_account.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _receive_mood(xmpp_stanza_t* const stanza, void* const userdata);
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_receive_mood(xmpp_stanza_t* const stanza, void* const userdata)
|
_receive_mood(xmpp_stanza_t* const stanza, void* const userdata)
|
||||||
{
|
{
|
||||||
const char* from = xmpp_stanza_get_from(stanza);
|
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");
|
xmpp_stanza_t* event = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_EVENT, STANZA_NS_PUBSUB_EVENT);
|
||||||
if (event) {
|
if (event) {
|
||||||
xmpp_stanza_t* items = xmpp_stanza_get_child_by_name(event, "items");
|
xmpp_stanza_t* items = xmpp_stanza_get_child_by_name(event, STANZA_NAME_ITEMS);
|
||||||
if (items) {
|
if (items) {
|
||||||
xmpp_stanza_t* item = xmpp_stanza_get_child_by_name(items, "item");
|
xmpp_stanza_t* item = xmpp_stanza_get_child_by_name(items, STANZA_NAME_ITEM);
|
||||||
if (item) {
|
if (item) {
|
||||||
xmpp_stanza_t* mood = xmpp_stanza_get_child_by_name_and_ns(item, "mood", "http://jabber.org/protocol/mood");
|
xmpp_stanza_t* mood = xmpp_stanza_get_child_by_name_and_ns(item, STANZA_NAME_MOOD, STANZA_NS_MOOD);
|
||||||
if (mood) {
|
if (mood) {
|
||||||
xmpp_stanza_t* c = xmpp_stanza_get_children(mood);
|
xmpp_stanza_t* c = xmpp_stanza_get_children(mood);
|
||||||
if (c) {
|
if (c) {
|
||||||
const char* m = xmpp_stanza_get_name(c);
|
const char* m = xmpp_stanza_get_name(c);
|
||||||
xmpp_stanza_t* t = xmpp_stanza_get_child_by_name(mood, "text");
|
xmpp_stanza_t* t = xmpp_stanza_get_child_by_name(mood, STANZA_NAME_TEXT);
|
||||||
if (t) {
|
if (t) {
|
||||||
const char* text = xmpp_stanza_get_text(t);
|
const char* text = xmpp_stanza_get_text(t);
|
||||||
cons_show("Mood from %s %s (%s)", from, m, text);
|
cons_show("Mood from %s %s (%s)", from, m, text);
|
||||||
@ -363,8 +361,8 @@ session_login_success(gboolean secured)
|
|||||||
reconnect_timer = NULL;
|
reconnect_timer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
message_pubsub_event_handler_add("http://jabber.org/protocol/mood", _receive_mood, NULL, NULL);
|
message_pubsub_event_handler_add(STANZA_NS_MOOD, _receive_mood, NULL, NULL);
|
||||||
caps_add_feature("http://jabber.org/protocol/mood+notify");
|
caps_add_feature(STANZA_NS_MOOD_NOTIFY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -117,6 +117,8 @@
|
|||||||
#define STANZA_NAME_USERNAME "username"
|
#define STANZA_NAME_USERNAME "username"
|
||||||
#define STANZA_NAME_PROPOSE "propose"
|
#define STANZA_NAME_PROPOSE "propose"
|
||||||
#define STANZA_NAME_REPORT "report"
|
#define STANZA_NAME_REPORT "report"
|
||||||
|
#define STANZA_NAME_EVENT "event"
|
||||||
|
#define STANZA_NAME_MOOD "mood"
|
||||||
|
|
||||||
// error conditions
|
// error conditions
|
||||||
#define STANZA_NAME_BAD_REQUEST "bad-request"
|
#define STANZA_NAME_BAD_REQUEST "bad-request"
|
||||||
@ -239,6 +241,8 @@
|
|||||||
#define STANZA_NS_JINGLE_MESSAGE "urn:xmpp:jingle-message:0"
|
#define STANZA_NS_JINGLE_MESSAGE "urn:xmpp:jingle-message:0"
|
||||||
#define STANZA_NS_JINGLE_RTP "urn:xmpp:jingle:apps:rtp:1"
|
#define STANZA_NS_JINGLE_RTP "urn:xmpp:jingle:apps:rtp:1"
|
||||||
#define STANZA_NS_REPORTING "urn:xmpp:reporting:1"
|
#define STANZA_NS_REPORTING "urn:xmpp:reporting:1"
|
||||||
|
#define STANZA_NS_MOOD "http://jabber.org/protocol/mood"
|
||||||
|
#define STANZA_NS_MOOD_NOTIFY "http://jabber.org/protocol/mood+notify"
|
||||||
|
|
||||||
#define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
|
#define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user