mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Add xep-0107: User Mood support
Implementation of XEP 0107 - User Mood
This commit is contained in:
parent
9a9122c148
commit
23e886ed5e
@ -129,6 +129,7 @@ static char* _url_autocomplete(ProfWin* window, const char* const input, gboolea
|
|||||||
static char* _executable_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
static char* _executable_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||||
static char* _lastactivity_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
static char* _lastactivity_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||||
static char* _intype_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
static char* _intype_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||||
|
static char* _mood_autocomplete(ProfWin* window, const char* const input, gboolean previous);
|
||||||
|
|
||||||
static char* _script_autocomplete_func(const char* const prefix, gboolean previous, void* context);
|
static char* _script_autocomplete_func(const char* const prefix, gboolean previous, void* context);
|
||||||
|
|
||||||
@ -269,6 +270,8 @@ static Autocomplete avatar_ac;
|
|||||||
static Autocomplete url_ac;
|
static Autocomplete url_ac;
|
||||||
static Autocomplete executable_ac;
|
static Autocomplete executable_ac;
|
||||||
static Autocomplete intype_ac;
|
static Autocomplete intype_ac;
|
||||||
|
static Autocomplete mood_ac;
|
||||||
|
static Autocomplete mood_type_ac;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Initialization of auto completion for commands.
|
* \brief Initialization of auto completion for commands.
|
||||||
@ -1057,6 +1060,90 @@ cmd_ac_init(void)
|
|||||||
intype_ac = autocomplete_new();
|
intype_ac = autocomplete_new();
|
||||||
autocomplete_add(intype_ac, "console");
|
autocomplete_add(intype_ac, "console");
|
||||||
autocomplete_add(intype_ac, "titlebar");
|
autocomplete_add(intype_ac, "titlebar");
|
||||||
|
|
||||||
|
mood_ac = autocomplete_new();
|
||||||
|
autocomplete_add(mood_ac, "set");
|
||||||
|
mood_type_ac = autocomplete_new();
|
||||||
|
autocomplete_add(mood_type_ac, "afraid");
|
||||||
|
autocomplete_add(mood_type_ac, "amazed");
|
||||||
|
autocomplete_add(mood_type_ac, "angry");
|
||||||
|
autocomplete_add(mood_type_ac, "amorous");
|
||||||
|
autocomplete_add(mood_type_ac, "annoyed");
|
||||||
|
autocomplete_add(mood_type_ac, "anxious");
|
||||||
|
autocomplete_add(mood_type_ac, "aroused");
|
||||||
|
autocomplete_add(mood_type_ac, "ashamed");
|
||||||
|
autocomplete_add(mood_type_ac, "bored");
|
||||||
|
autocomplete_add(mood_type_ac, "brave");
|
||||||
|
autocomplete_add(mood_type_ac, "calm");
|
||||||
|
autocomplete_add(mood_type_ac, "cautious");
|
||||||
|
autocomplete_add(mood_type_ac, "cold");
|
||||||
|
autocomplete_add(mood_type_ac, "confident");
|
||||||
|
autocomplete_add(mood_type_ac, "confused");
|
||||||
|
autocomplete_add(mood_type_ac, "contemplative");
|
||||||
|
autocomplete_add(mood_type_ac, "contented");
|
||||||
|
autocomplete_add(mood_type_ac, "cranky");
|
||||||
|
autocomplete_add(mood_type_ac, "crazy");
|
||||||
|
autocomplete_add(mood_type_ac, "creative");
|
||||||
|
autocomplete_add(mood_type_ac, "curious");
|
||||||
|
autocomplete_add(mood_type_ac, "dejected");
|
||||||
|
autocomplete_add(mood_type_ac, "depressed");
|
||||||
|
autocomplete_add(mood_type_ac, "disappointed");
|
||||||
|
autocomplete_add(mood_type_ac, "disgusted");
|
||||||
|
autocomplete_add(mood_type_ac, "dismayed");
|
||||||
|
autocomplete_add(mood_type_ac, "distracted");
|
||||||
|
autocomplete_add(mood_type_ac, "embarrassed");
|
||||||
|
autocomplete_add(mood_type_ac, "envious");
|
||||||
|
autocomplete_add(mood_type_ac, "excited");
|
||||||
|
autocomplete_add(mood_type_ac, "flirtatious");
|
||||||
|
autocomplete_add(mood_type_ac, "frustrated");
|
||||||
|
autocomplete_add(mood_type_ac, "grumpy");
|
||||||
|
autocomplete_add(mood_type_ac, "guilty");
|
||||||
|
autocomplete_add(mood_type_ac, "happy");
|
||||||
|
autocomplete_add(mood_type_ac, "hopeful");
|
||||||
|
autocomplete_add(mood_type_ac, "hot");
|
||||||
|
autocomplete_add(mood_type_ac, "humbled");
|
||||||
|
autocomplete_add(mood_type_ac, "humiliated");
|
||||||
|
autocomplete_add(mood_type_ac, "hungry");
|
||||||
|
autocomplete_add(mood_type_ac, "hurt");
|
||||||
|
autocomplete_add(mood_type_ac, "impressed");
|
||||||
|
autocomplete_add(mood_type_ac, "in_awe");
|
||||||
|
autocomplete_add(mood_type_ac, "in_love");
|
||||||
|
autocomplete_add(mood_type_ac, "indignant");
|
||||||
|
autocomplete_add(mood_type_ac, "interested");
|
||||||
|
autocomplete_add(mood_type_ac, "intoxicated");
|
||||||
|
autocomplete_add(mood_type_ac, "invincible");
|
||||||
|
autocomplete_add(mood_type_ac, "jealous");
|
||||||
|
autocomplete_add(mood_type_ac, "lonely");
|
||||||
|
autocomplete_add(mood_type_ac, "lucky");
|
||||||
|
autocomplete_add(mood_type_ac, "mean");
|
||||||
|
autocomplete_add(mood_type_ac, "moody");
|
||||||
|
autocomplete_add(mood_type_ac, "nervous");
|
||||||
|
autocomplete_add(mood_type_ac, "neutral");
|
||||||
|
autocomplete_add(mood_type_ac, "offended");
|
||||||
|
autocomplete_add(mood_type_ac, "outraged");
|
||||||
|
autocomplete_add(mood_type_ac, "playful");
|
||||||
|
autocomplete_add(mood_type_ac, "proud");
|
||||||
|
autocomplete_add(mood_type_ac, "relaxed");
|
||||||
|
autocomplete_add(mood_type_ac, "relieved");
|
||||||
|
autocomplete_add(mood_type_ac, "remorseful");
|
||||||
|
autocomplete_add(mood_type_ac, "restless");
|
||||||
|
autocomplete_add(mood_type_ac, "sad");
|
||||||
|
autocomplete_add(mood_type_ac, "sarcastic");
|
||||||
|
autocomplete_add(mood_type_ac, "serious");
|
||||||
|
autocomplete_add(mood_type_ac, "shocked");
|
||||||
|
autocomplete_add(mood_type_ac, "shy");
|
||||||
|
autocomplete_add(mood_type_ac, "sick");
|
||||||
|
autocomplete_add(mood_type_ac, "sleepy");
|
||||||
|
autocomplete_add(mood_type_ac, "spontaneous");
|
||||||
|
autocomplete_add(mood_type_ac, "stressed");
|
||||||
|
autocomplete_add(mood_type_ac, "strong");
|
||||||
|
autocomplete_add(mood_type_ac, "surprised");
|
||||||
|
autocomplete_add(mood_type_ac, "thankful");
|
||||||
|
autocomplete_add(mood_type_ac, "thirsty");
|
||||||
|
autocomplete_add(mood_type_ac, "tired");
|
||||||
|
autocomplete_add(mood_type_ac, "undefined");
|
||||||
|
autocomplete_add(mood_type_ac, "weak");
|
||||||
|
autocomplete_add(mood_type_ac, "worried");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1372,6 +1459,7 @@ cmd_ac_reset(ProfWin* window)
|
|||||||
autocomplete_reset(url_ac);
|
autocomplete_reset(url_ac);
|
||||||
autocomplete_reset(executable_ac);
|
autocomplete_reset(executable_ac);
|
||||||
autocomplete_reset(intype_ac);
|
autocomplete_reset(intype_ac);
|
||||||
|
autocomplete_reset(mood_ac);
|
||||||
|
|
||||||
autocomplete_reset(script_ac);
|
autocomplete_reset(script_ac);
|
||||||
if (script_show_ac) {
|
if (script_show_ac) {
|
||||||
@ -1801,6 +1889,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ
|
|||||||
g_hash_table_insert(ac_funcs, "/executable", _executable_autocomplete);
|
g_hash_table_insert(ac_funcs, "/executable", _executable_autocomplete);
|
||||||
g_hash_table_insert(ac_funcs, "/lastactivity", _lastactivity_autocomplete);
|
g_hash_table_insert(ac_funcs, "/lastactivity", _lastactivity_autocomplete);
|
||||||
g_hash_table_insert(ac_funcs, "/intype", _intype_autocomplete);
|
g_hash_table_insert(ac_funcs, "/intype", _intype_autocomplete);
|
||||||
|
g_hash_table_insert(ac_funcs, "/mood", _mood_autocomplete);
|
||||||
|
|
||||||
int len = strlen(input);
|
int len = strlen(input);
|
||||||
char parsed[len + 1];
|
char parsed[len + 1];
|
||||||
@ -4147,3 +4236,28 @@ _intype_autocomplete(ProfWin* window, const char* const input, gboolean previous
|
|||||||
result = autocomplete_param_with_ac(input, "/intype", intype_ac, FALSE, previous);
|
result = autocomplete_param_with_ac(input, "/intype", intype_ac, FALSE, previous);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char*
|
||||||
|
_mood_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||||
|
{
|
||||||
|
char* result = NULL;
|
||||||
|
|
||||||
|
result = autocomplete_param_with_ac(input, "/mood", status_ac, TRUE, previous);
|
||||||
|
if (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);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// result = autocomplete_param_with_func(input, "/mood get", roster_barejid_autocomplete, previous, NULL);
|
||||||
|
// if (result) {
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -2679,6 +2679,19 @@ static struct cmd_t command_defs[] = {
|
|||||||
"/register someuser my.xmppserv.er port 5443 tls force")
|
"/register someuser my.xmppserv.er port 5443 tls force")
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{ "/mood",
|
||||||
|
parse_args, 2, 3, NULL,
|
||||||
|
CMD_NOSUBFUNCS
|
||||||
|
CMD_MAINFUNC(cmd_mood)
|
||||||
|
CMD_TAGS(
|
||||||
|
CMD_TAG_CHAT)
|
||||||
|
CMD_SYN(
|
||||||
|
"/mood set <mood> [\"Text\"]")
|
||||||
|
CMD_DESC(
|
||||||
|
"Set your mood")
|
||||||
|
CMD_NOARGS
|
||||||
|
CMD_NOEXAMPLES
|
||||||
|
},
|
||||||
// NEXT-COMMAND (search helper)
|
// NEXT-COMMAND (search helper)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9645,3 +9645,18 @@ cmd_register(ProfWin* window, const char* const command, gchar** args)
|
|||||||
log_info("we are leaving the registration process");
|
log_info("we are leaving the registration process");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
cmd_mood(ProfWin* window, const char* const command, gchar** args)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (g_strcmp0(args[0], "set") == 0) {
|
||||||
|
cons_show("Your mood: %s", args[1]);
|
||||||
|
if (args[2]) {
|
||||||
|
publish_user_mood(args[1], args[2]);
|
||||||
|
} else {
|
||||||
|
publish_user_mood(args[1], args[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
@ -249,5 +249,6 @@ gboolean cmd_editor(ProfWin* window, const char* const command, gchar** args);
|
|||||||
gboolean cmd_correct_editor(ProfWin* window, const char* const command, gchar** args);
|
gboolean cmd_correct_editor(ProfWin* window, const char* const command, gchar** args);
|
||||||
gboolean cmd_silence(ProfWin* window, const char* const command, gchar** args);
|
gboolean cmd_silence(ProfWin* window, const char* const command, gchar** args);
|
||||||
gboolean cmd_register(ProfWin* window, const char* const command, gchar** args);
|
gboolean cmd_register(ProfWin* window, const char* const command, gchar** args);
|
||||||
|
gboolean cmd_mood(ProfWin* window, const char* const command, gchar** args);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2798,3 +2798,55 @@ iq_muc_register_nick(const char* const roomjid)
|
|||||||
xmpp_stanza_release(iq);
|
xmpp_stanza_release(iq);
|
||||||
xmpp_stanza_release(query);
|
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) {
|
} else if (type && g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0) {
|
||||||
// XEP-0045: Multi-User Chat
|
// XEP-0045: Multi-User Chat
|
||||||
_handle_groupchat(stanza);
|
_handle_groupchat(stanza);
|
||||||
|
|
||||||
} else if (type && g_strcmp0(type, STANZA_TYPE_HEADLINE) == 0) {
|
} 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) {
|
} else if (type == NULL || g_strcmp0(type, STANZA_TYPE_CHAT) == 0 || g_strcmp0(type, STANZA_TYPE_NORMAL) == 0) {
|
||||||
// type: chat, normal (==NULL)
|
// 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) {
|
if (msg_stanza) {
|
||||||
_handle_chat(msg_stanza, FALSE, is_carbon, NULL, NULL);
|
_handle_chat(msg_stanza, FALSE, is_carbon, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
} else if (type && g_strcmp0(type, STANZA_TYPE_HEADLINE) == 0) {
|
||||||
|
_handle_headline(stanza);
|
||||||
} else {
|
} else {
|
||||||
// none of the allowed types
|
// none of the allowed types
|
||||||
char* text;
|
char* text;
|
||||||
|
@ -286,6 +286,38 @@ 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
|
||||||
|
_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
|
void
|
||||||
session_login_success(gboolean secured)
|
session_login_success(gboolean secured)
|
||||||
{
|
{
|
||||||
@ -330,6 +362,9 @@ session_login_success(gboolean secured)
|
|||||||
g_timer_destroy(reconnect_timer);
|
g_timer_destroy(reconnect_timer);
|
||||||
reconnect_timer = NULL;
|
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
|
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);
|
Autocomplete form_get_value_ac(DataForm* form, const char* const tag);
|
||||||
void form_reset_autocompleters(DataForm* form);
|
void form_reset_autocompleters(DataForm* form);
|
||||||
|
|
||||||
|
void publish_user_mood(const char* const mood, const char* const text);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user