1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge pull request #1725 from profanity-im/feat/optional-mood

Make display of user mood optional
This commit is contained in:
Michael Vetter 2022-06-22 12:02:51 +02:00 committed by GitHub
commit 6147a1342d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 4 deletions

View File

@ -1079,6 +1079,8 @@ cmd_ac_init(void)
mood_ac = autocomplete_new(); mood_ac = autocomplete_new();
autocomplete_add(mood_ac, "set"); autocomplete_add(mood_ac, "set");
autocomplete_add(mood_ac, "clear"); autocomplete_add(mood_ac, "clear");
autocomplete_add(mood_ac, "on");
autocomplete_add(mood_ac, "off");
mood_type_ac = autocomplete_new(); mood_type_ac = autocomplete_new();
autocomplete_add(mood_type_ac, "afraid"); autocomplete_add(mood_type_ac, "afraid");
autocomplete_add(mood_type_ac, "amazed"); autocomplete_add(mood_type_ac, "amazed");

View File

@ -2714,17 +2714,19 @@ static struct cmd_t command_defs[] = {
}, },
{ "/mood", { "/mood",
parse_args, 1, 3, NULL, parse_args, 1, 3, &cons_mood_setting,
CMD_NOSUBFUNCS CMD_NOSUBFUNCS
CMD_MAINFUNC(cmd_mood) CMD_MAINFUNC(cmd_mood)
CMD_TAGS( CMD_TAGS(
CMD_TAG_CHAT) CMD_TAG_CHAT)
CMD_SYN( CMD_SYN(
"/mood on|off",
"/mood set <mood> [text]", "/mood set <mood> [text]",
"/mood clear") "/mood clear")
CMD_DESC( CMD_DESC(
"Set your mood (XEP-0107).") "Set your mood (XEP-0107).")
CMD_ARGS( CMD_ARGS(
{ "on|off", "Enable or disable displaying the mood of other users. On by default."},
{ "set <mood> [text]", "Set user mood to <mood> with an optional [text]. Use /mood set <tab> to toggle through predfined moods." }, { "set <mood> [text]", "Set user mood to <mood> with an optional [text]. Use /mood set <tab> to toggle through predfined moods." },
{ "clear", "Clear your user mood." }) { "clear", "Clear your user mood." })
CMD_EXAMPLES( CMD_EXAMPLES(

View File

@ -90,6 +90,7 @@
#include "xmpp/muc.h" #include "xmpp/muc.h"
#include "xmpp/chat_session.h" #include "xmpp/chat_session.h"
#include "xmpp/avatar.h" #include "xmpp/avatar.h"
#include "xmpp/stanza.h"
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
#include "otr/otr.h" #include "otr/otr.h"
@ -9769,7 +9770,13 @@ 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], "on") == 0) {
_cmd_set_boolean_preference(args[0], command, "User mood", PREF_MOOD);
caps_add_feature(STANZA_NS_MOOD_NOTIFY);
} else if (g_strcmp0(args[0], "off") == 0) {
_cmd_set_boolean_preference(args[0], command, "User mood", PREF_MOOD);
caps_remove_feature(STANZA_NS_MOOD_NOTIFY);
} else if (g_strcmp0(args[0], "set") == 0) {
if (args[1]) { if (args[1]) {
cons_show("Your mood: %s", args[1]); cons_show("Your mood: %s", args[1]);
if (args[2]) { if (args[2]) {
@ -9782,5 +9789,6 @@ cmd_mood(ProfWin* window, const char* const command, gchar** args)
cons_show("Clearing the user mood."); cons_show("Clearing the user mood.");
publish_user_mood(NULL, NULL); publish_user_mood(NULL, NULL);
} }
return TRUE; return TRUE;
} }

View File

@ -1819,6 +1819,7 @@ _get_group(preference_t pref)
case PREF_COMPOSE_EDITOR: case PREF_COMPOSE_EDITOR:
case PREF_OUTGOING_STAMP: case PREF_OUTGOING_STAMP:
case PREF_INCOMING_STAMP: case PREF_INCOMING_STAMP:
case PREF_MOOD:
return PREF_GROUP_UI; return PREF_GROUP_UI;
case PREF_STATES: case PREF_STATES:
case PREF_OUTTYPE: case PREF_OUTTYPE:
@ -2157,6 +2158,8 @@ _get_key(preference_t pref)
return "stamp.incoming"; return "stamp.incoming";
case PREF_OX_LOG: case PREF_OX_LOG:
return "log"; return "log";
case PREF_MOOD:
return "mood";
default: default:
return NULL; return NULL;
} }
@ -2208,6 +2211,7 @@ _get_default_boolean(preference_t pref)
case PREF_INTYPE: case PREF_INTYPE:
case PREF_INTYPE_CONSOLE: case PREF_INTYPE_CONSOLE:
case PREF_NOTIFY_MENTION_WHOLE_WORD: case PREF_NOTIFY_MENTION_WHOLE_WORD:
case PREF_MOOD:
return TRUE; return TRUE;
default: default:
return FALSE; return FALSE;

View File

@ -180,6 +180,7 @@ typedef enum {
PREF_INCOMING_STAMP, PREF_INCOMING_STAMP,
PREF_NOTIFY_ROOM_OFFLINE, PREF_NOTIFY_ROOM_OFFLINE,
PREF_OX_LOG, PREF_OX_LOG,
PREF_MOOD,
} preference_t; } preference_t;
typedef struct prof_alias_t typedef struct prof_alias_t

View File

@ -1733,6 +1733,7 @@ cons_show_ui_prefs(void)
cons_inpblock_setting(); cons_inpblock_setting();
cons_titlebar_setting(); cons_titlebar_setting();
cons_statusbar_setting(); cons_statusbar_setting();
cons_mood_setting();
cons_alert(NULL); cons_alert(NULL);
} }
@ -2947,3 +2948,13 @@ cons_remove_alert(ProfWin* window)
g_list_free_full(item, g_free); g_list_free_full(item, g_free);
free(win_name); free(win_name);
} }
void
cons_mood_setting(void)
{
if (prefs_get_boolean(PREF_MOOD)) {
cons_show("Display user mood (/mood) : ON");
} else {
cons_show("Display user mood (/mood) : OFF");
}
}

View File

@ -334,6 +334,7 @@ void cons_executable_setting(void);
void cons_slashguard_setting(void); void cons_slashguard_setting(void);
void cons_mam_setting(void); void cons_mam_setting(void);
void cons_silence_setting(void); void cons_silence_setting(void);
void cons_mood_setting(void);
void cons_show_contact_online(PContact contact, Resource* resource, GDateTime* last_activity); void cons_show_contact_online(PContact contact, Resource* resource, GDateTime* last_activity);
void cons_show_contact_offline(PContact contact, char* resource, char* status); void cons_show_contact_offline(PContact contact, char* resource, char* status);
void cons_theme_properties(void); void cons_theme_properties(void);

View File

@ -286,9 +286,13 @@ session_get_account_name(void)
return saved_account.name; return saved_account.name;
} }
static int static gboolean
_receive_mood(xmpp_stanza_t* const stanza, void* const userdata) _receive_mood(xmpp_stanza_t* const stanza, void* const userdata)
{ {
if (!prefs_get_boolean(PREF_MOOD)) {
return TRUE;
}
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, STANZA_NAME_EVENT, STANZA_NS_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) {
@ -362,7 +366,9 @@ session_login_success(gboolean secured)
} }
message_pubsub_event_handler_add(STANZA_NS_MOOD, _receive_mood, NULL, NULL); message_pubsub_event_handler_add(STANZA_NS_MOOD, _receive_mood, NULL, NULL);
caps_add_feature(STANZA_NS_MOOD_NOTIFY); if (prefs_get_boolean(PREF_MOOD)) {
caps_add_feature(STANZA_NS_MOOD_NOTIFY);
}
} }
void void

View File

@ -1149,6 +1149,11 @@ cons_silence_setting(void)
{ {
} }
void
cons_mood_setting(void)
{
}
void void
cons_show_bookmarks_ignore(gchar** list, gsize len) cons_show_bookmarks_ignore(gchar** list, gsize len)
{ {