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

Add preference/commands for carbons message

This commit is contained in:
Olivier LE MOAL 2015-02-03 15:27:56 +01:00
parent e3feacddd6
commit 2a12a4d93b
12 changed files with 85 additions and 6 deletions

View File

@ -858,6 +858,16 @@ static struct cmd_t command_defs[] =
"shared : Share logs between all instances, accepts 'on' or 'off', defaults to 'on'.", "shared : Share logs between all instances, accepts 'on' or 'off', defaults to 'on'.",
NULL } } }, NULL } } },
{ "/carbons",
cmd_carbons, parse_args, 1, 1, &cons_carbons_setting,
{ "/carbons on|off", "Message carbons.",
{ "/carbons on|off",
"---------------",
"Enable or disable message carbons.",
"",
"Example : /carbons on",
NULL } } },
{ "/reconnect", { "/reconnect",
cmd_reconnect, parse_args, 1, 1, &cons_reconnect_setting, cmd_reconnect, parse_args, 1, 1, &cons_reconnect_setting,
{ "/reconnect seconds", "Set reconnect interval.", { "/reconnect seconds", "Set reconnect interval.",

View File

@ -3882,6 +3882,22 @@ cmd_history(gchar **args, struct cmd_help_t help)
return result; return result;
} }
gboolean
cmd_carbons(gchar **args, struct cmd_help_t help)
{
gboolean result = _cmd_set_boolean_preference(args[0], help,
"Carbons message", PREF_CARBONS);
// enable carbons
if (strcmp(args[0], "on") == 0) {
iq_enable_carbons();
}
else if (strcmp(args[0], "off") == 0){
iq_disable_carbons();
}
return result;
}
gboolean gboolean
cmd_away(gchar **args, struct cmd_help_t help) cmd_away(gchar **args, struct cmd_help_t help)
{ {

View File

@ -85,6 +85,7 @@ gboolean cmd_grlog(gchar **args, struct cmd_help_t help);
gboolean cmd_group(gchar **args, struct cmd_help_t help); gboolean cmd_group(gchar **args, struct cmd_help_t help);
gboolean cmd_help(gchar **args, struct cmd_help_t help); gboolean cmd_help(gchar **args, struct cmd_help_t help);
gboolean cmd_history(gchar **args, struct cmd_help_t help); gboolean cmd_history(gchar **args, struct cmd_help_t help);
gboolean cmd_carbons(gchar **args, struct cmd_help_t help);
gboolean cmd_info(gchar **args, struct cmd_help_t help); gboolean cmd_info(gchar **args, struct cmd_help_t help);
gboolean cmd_intype(gchar **args, struct cmd_help_t help); gboolean cmd_intype(gchar **args, struct cmd_help_t help);
gboolean cmd_invite(gchar **args, struct cmd_help_t help); gboolean cmd_invite(gchar **args, struct cmd_help_t help);

View File

@ -558,6 +558,7 @@ _get_group(preference_t pref)
return PREF_GROUP_PRESENCE; return PREF_GROUP_PRESENCE;
case PREF_CONNECT_ACCOUNT: case PREF_CONNECT_ACCOUNT:
case PREF_DEFAULT_ACCOUNT: case PREF_DEFAULT_ACCOUNT:
case PREF_CARBONS:
return PREF_GROUP_CONNECTION; return PREF_GROUP_CONNECTION;
case PREF_OTR_WARN: case PREF_OTR_WARN:
case PREF_OTR_LOG: case PREF_OTR_LOG:
@ -593,6 +594,8 @@ _get_key(preference_t pref)
return "intype"; return "intype";
case PREF_HISTORY: case PREF_HISTORY:
return "history"; return "history";
case PREF_CARBONS:
return "carbons";
case PREF_MOUSE: case PREF_MOUSE:
return "mouse"; return "mouse";
case PREF_OCCUPANTS: case PREF_OCCUPANTS:

View File

@ -59,6 +59,7 @@ typedef enum {
PREF_FLASH, PREF_FLASH,
PREF_INTYPE, PREF_INTYPE,
PREF_HISTORY, PREF_HISTORY,
PREF_CARBONS,
PREF_MOUSE, PREF_MOUSE,
PREF_OCCUPANTS, PREF_OCCUPANTS,
PREF_OCCUPANTS_SIZE, PREF_OCCUPANTS_SIZE,

View File

@ -1167,6 +1167,15 @@ cons_history_setting(void)
cons_show("Chat history (/history) : OFF"); cons_show("Chat history (/history) : OFF");
} }
void
cons_carbons_setting(void)
{
if (prefs_get_boolean(PREF_CARBONS))
cons_show("Message carbons (/carbons) : ON");
else
cons_show("Message carbons (/carbons) : OFF");
}
void void
cons_show_chat_prefs(void) cons_show_chat_prefs(void)
{ {

View File

@ -308,6 +308,7 @@ void cons_outtype_setting(void);
void cons_intype_setting(void); void cons_intype_setting(void);
void cons_gone_setting(void); void cons_gone_setting(void);
void cons_history_setting(void); void cons_history_setting(void);
void cons_carbons_setting(void);
void cons_log_setting(void); void cons_log_setting(void);
void cons_chlog_setting(void); void cons_chlog_setting(void);
void cons_grlog_setting(void); void cons_grlog_setting(void);

View File

@ -463,10 +463,14 @@ _connection_handler(xmpp_conn_t * const conn,
message_add_handlers(); message_add_handlers();
presence_add_handlers(); presence_add_handlers();
iq_add_handlers(); iq_add_handlers();
iq_enable_carbons();
roster_request(); roster_request();
bookmark_request(); bookmark_request();
if (prefs_get_boolean(PREF_CARBONS)){
iq_enable_carbons();
}
jabber_conn.conn_status = JABBER_CONNECTED; jabber_conn.conn_status = JABBER_CONNECTED;
if (prefs_get_reconnect() != 0) { if (prefs_get_reconnect() != 0) {

View File

@ -162,6 +162,16 @@ iq_enable_carbons()
xmpp_stanza_release(iq); xmpp_stanza_release(iq);
} }
void
iq_disable_carbons()
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_disable_carbons(ctx);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
void void
iq_disco_info_request(gchar *jid) iq_disco_info_request(gchar *jid)
{ {

View File

@ -206,12 +206,32 @@ stanza_enable_carbons(xmpp_ctx_t *ctx){
xmpp_stanza_set_name(iq, STANZA_NAME_IQ); xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
xmpp_stanza_set_type(iq, STANZA_TYPE_SET); xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
xmpp_stanza_set_id(iq, id); xmpp_stanza_set_id(iq, id);
free(id);
xmpp_stanza_t *carbon_enable = xmpp_stanza_new(ctx); xmpp_stanza_t *carbons_enable = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(carbon_enable, STANZA_NAME_ENABLE); xmpp_stanza_set_name(carbons_enable, STANZA_NAME_ENABLE);
xmpp_stanza_set_ns(carbon_enable, STANZA_NS_CARBONS); xmpp_stanza_set_ns(carbons_enable, STANZA_NS_CARBONS);
xmpp_stanza_add_child(iq, carbon_enable); xmpp_stanza_add_child(iq, carbons_enable);
return iq;
}
xmpp_stanza_t *
stanza_disable_carbons(xmpp_ctx_t *ctx){
xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
char *id = create_unique_id(NULL);
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
xmpp_stanza_set_id(iq, id);
free(id);
xmpp_stanza_t *carbons_disable = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(carbons_disable, STANZA_NAME_DISABLE);
xmpp_stanza_set_ns(carbons_disable, STANZA_NS_CARBONS);
xmpp_stanza_add_child(iq, carbons_disable);
return iq; return iq;
} }

View File

@ -78,6 +78,7 @@
#define STANZA_NAME_DESTROY "destroy" #define STANZA_NAME_DESTROY "destroy"
#define STANZA_NAME_ACTOR "actor" #define STANZA_NAME_ACTOR "actor"
#define STANZA_NAME_ENABLE "enable" #define STANZA_NAME_ENABLE "enable"
#define STANZA_NAME_DISABLE "disable"
// error conditions // error conditions
#define STANZA_NAME_BAD_REQUEST "bad-request" #define STANZA_NAME_BAD_REQUEST "bad-request"
@ -183,6 +184,8 @@ xmpp_stanza_t* stanza_create_bookmarks_storage_request(xmpp_ctx_t *ctx);
xmpp_stanza_t * stanza_enable_carbons(xmpp_ctx_t *ctx); xmpp_stanza_t * stanza_enable_carbons(xmpp_ctx_t *ctx);
xmpp_stanza_t * stanza_disable_carbons(xmpp_ctx_t *ctx);
xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx, xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx,
const char * const fulljid, const char * const state); const char * const fulljid, const char * const state);

View File

@ -173,6 +173,7 @@ gboolean presence_sub_request_exists(const char * const bare_jid);
// iq functions // iq functions
void iq_enable_carbons(); void iq_enable_carbons();
void iq_disable_carbons();
void iq_send_software_version(const char * const fulljid); void iq_send_software_version(const char * const fulljid);
void iq_room_list_request(gchar *conferencejid); void iq_room_list_request(gchar *conferencejid);
void iq_disco_info_request(gchar *jid); void iq_disco_info_request(gchar *jid);