1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Merge branch 'master' into osx-functional

This commit is contained in:
James Booth 2015-10-14 22:10:10 +01:00
commit b6f91ae284
10 changed files with 81 additions and 21 deletions

View File

@ -703,13 +703,16 @@ static struct cmd_t command_defs[] =
CMD_TAGS( CMD_TAGS(
CMD_TAG_PRESENCE) CMD_TAG_PRESENCE)
CMD_SYN( CMD_SYN(
"/lastactivity on|off",
"/lastactivity [<jid>]") "/lastactivity [<jid>]")
CMD_DESC( CMD_DESC(
"Send a last activity query to the supplied JID, omitting the JID will send the query to your server.") "Enable/disable sending last activity, and send last activity requests.")
CMD_ARGS( CMD_ARGS(
{ "<jid>", "The JID of the entity to which the query will be sent." }) { "on|off", "Enable or disable sending of last activity." },
{ "<jid>", "The JID of the entity to query, omitting the JID will query your server." })
CMD_EXAMPLES( CMD_EXAMPLES(
"/lastactivity", "/lastactivity",
"/lastactivity off",
"/lastactivity alice@securechat.org", "/lastactivity alice@securechat.org",
"/lastactivity alice@securechat.org/laptop", "/lastactivity alice@securechat.org/laptop",
"/lastactivity someserver.com") "/lastactivity someserver.com")
@ -2564,7 +2567,7 @@ _cmd_complete_parameters(ProfWin *window, const char * const input)
// autocomplete boolean settings // autocomplete boolean settings
gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype",
"/flash", "/splash", "/chlog", "/grlog", "/history", "/vercheck", "/flash", "/splash", "/chlog", "/grlog", "/history", "/vercheck",
"/privileges", "/presence", "/wrap", "/winstidy", "/carbons", "/encwarn" }; "/privileges", "/presence", "/wrap", "/winstidy", "/carbons", "/encwarn", "/lastactivity" };
for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) {
result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice); result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice);

View File

@ -3279,11 +3279,16 @@ cmd_lastactivity(ProfWin *window, const char * const command, gchar **args)
g_string_free(jid, TRUE); g_string_free(jid, TRUE);
jid_destroy(jidp); jid_destroy(jidp);
return TRUE;
} else if ((g_strcmp0(args[0], "on") == 0) || (g_strcmp0(args[0], "off") == 0)) {
return _cmd_set_boolean_preference(args[0], command, "Last activity responses", PREF_LASTACTIVITY);
} else { } else {
iq_last_activity_request(args[0]); iq_last_activity_request(args[0]);
return TRUE;
} }
return TRUE;
} }
gboolean gboolean

View File

@ -627,6 +627,7 @@ _get_group(preference_t pref)
case PREF_AUTOAWAY_MODE: case PREF_AUTOAWAY_MODE:
case PREF_AUTOAWAY_MESSAGE: case PREF_AUTOAWAY_MESSAGE:
case PREF_AUTOXA_MESSAGE: case PREF_AUTOXA_MESSAGE:
case PREF_LASTACTIVITY:
return PREF_GROUP_PRESENCE; return PREF_GROUP_PRESENCE;
case PREF_CONNECT_ACCOUNT: case PREF_CONNECT_ACCOUNT:
case PREF_DEFAULT_ACCOUNT: case PREF_DEFAULT_ACCOUNT:
@ -784,6 +785,8 @@ _get_key(preference_t pref)
return "certpath"; return "certpath";
case PREF_TLS_SHOW: case PREF_TLS_SHOW:
return "tls.show"; return "tls.show";
case PREF_LASTACTIVITY:
return "lastactivity";
default: default:
return NULL; return NULL;
} }
@ -821,6 +824,7 @@ _get_default_boolean(preference_t pref)
case PREF_ROSTER_RESOURCE: case PREF_ROSTER_RESOURCE:
case PREF_ROSTER_EMPTY: case PREF_ROSTER_EMPTY:
case PREF_TLS_SHOW: case PREF_TLS_SHOW:
case PREF_LASTACTIVITY:
return TRUE; return TRUE;
default: default:
return FALSE; return FALSE;

View File

@ -113,6 +113,7 @@ typedef enum {
PREF_PGP_LOG, PREF_PGP_LOG,
PREF_CERT_PATH, PREF_CERT_PATH,
PREF_TLS_SHOW, PREF_TLS_SHOW,
PREF_LASTACTIVITY,
} preference_t; } preference_t;
typedef struct prof_alias_t { typedef struct prof_alias_t {

View File

@ -212,7 +212,11 @@ _check_autoaway()
// send away presence with last activity // send away presence with last activity
char *message = prefs_get_string(PREF_AUTOAWAY_MESSAGE); char *message = prefs_get_string(PREF_AUTOAWAY_MESSAGE);
cl_ev_presence_send(RESOURCE_AWAY, message, idle_ms / 1000); if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(RESOURCE_AWAY, message, idle_ms / 1000);
} else {
cl_ev_presence_send(RESOURCE_AWAY, message, 0);
}
int pri = accounts_get_priority_for_presence_type(account, RESOURCE_AWAY); int pri = accounts_get_priority_for_presence_type(account, RESOURCE_AWAY);
if (message) { if (message) {
@ -248,7 +252,11 @@ _check_autoaway()
// send extended away presence with last activity // send extended away presence with last activity
char *message = prefs_get_string(PREF_AUTOXA_MESSAGE); char *message = prefs_get_string(PREF_AUTOXA_MESSAGE);
cl_ev_presence_send(RESOURCE_XA, message, idle_ms / 1000); if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(RESOURCE_XA, message, idle_ms / 1000);
} else {
cl_ev_presence_send(RESOURCE_XA, message, 0);
}
int pri = accounts_get_priority_for_presence_type(account, RESOURCE_XA); int pri = accounts_get_priority_for_presence_type(account, RESOURCE_XA);
if (message) { if (message) {

View File

@ -1459,6 +1459,12 @@ cons_show_presence_prefs(void)
cons_show(""); cons_show("");
cons_autoaway_setting(); cons_autoaway_setting();
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cons_show("Send last activity (/lastactivity) : ON");
} else {
cons_show("Send last activity (/lastactivity) : OFF");
}
cons_alert(); cons_alert();
} }

View File

@ -1094,7 +1094,11 @@ _last_activity_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanz
xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_ctx_t *ctx = connection_get_ctx();
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
if (from) { if (!from) {
return 1;
}
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
int idls_secs = ui_get_idle_time() / 1000; int idls_secs = ui_get_idle_time() / 1000;
char str[50]; char str[50];
sprintf(str, "%d", idls_secs); sprintf(str, "%d", idls_secs);
@ -1111,10 +1115,34 @@ _last_activity_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanz
xmpp_stanza_set_attribute(query, "seconds", str); xmpp_stanza_set_attribute(query, "seconds", str);
xmpp_stanza_add_child(response, query); xmpp_stanza_add_child(response, query);
xmpp_stanza_release(query);
xmpp_send(conn, response);
xmpp_stanza_release(response);
} else {
xmpp_stanza_t *response = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(response, STANZA_NAME_IQ);
xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza));
xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from);
xmpp_stanza_set_type(response, STANZA_TYPE_ERROR);
xmpp_stanza_t *error = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(error, STANZA_NAME_ERROR);
xmpp_stanza_set_type(error, "cancel");
xmpp_stanza_t *service_unavailable = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(service_unavailable, "service-unavailable");
xmpp_stanza_set_ns(service_unavailable, "urn:ietf:params:xml:ns:xmpp-stanzas");
xmpp_stanza_add_child(error, service_unavailable);
xmpp_stanza_release(service_unavailable);
xmpp_stanza_add_child(response, error);
xmpp_stanza_release(error);
xmpp_send(conn, response); xmpp_send(conn, response);
xmpp_stanza_release(query);
xmpp_stanza_release(response); xmpp_stanza_release(response);
} }

View File

@ -243,7 +243,9 @@ presence_send(const resource_presence_t presence_type, const char * const msg, c
} }
stanza_attach_priority(ctx, presence, pri); stanza_attach_priority(ctx, presence, pri);
stanza_attach_last_activity(ctx, presence, idle); if (idle > 0) {
stanza_attach_last_activity(ctx, presence, idle);
}
stanza_attach_caps(ctx, presence); stanza_attach_caps(ctx, presence);
xmpp_send(conn, presence); xmpp_send(conn, presence);
_send_room_presence(conn, presence); _send_room_presence(conn, presence);

View File

@ -53,6 +53,7 @@
#include "event/server_events.h" #include "event/server_events.h"
#include "event/client_events.h" #include "event/client_events.h"
#include "tools/autocomplete.h" #include "tools/autocomplete.h"
#include "config/preferences.h"
#include "xmpp/connection.h" #include "xmpp/connection.h"
#include "xmpp/roster.h" #include "xmpp/roster.h"
#include "roster_list.h" #include "roster_list.h"
@ -355,7 +356,11 @@ _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, v
GDateTime *lastdt = g_date_time_new_from_timeval_utc(&lasttv); GDateTime *lastdt = g_date_time_new_from_timeval_utc(&lasttv);
GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt); GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt);
int diff_secs = (diff_micros / 1000) / 1000; int diff_secs = (diff_micros / 1000) / 1000;
cl_ev_presence_send(conn_presence, NULL, diff_secs); if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(conn_presence, NULL, diff_secs);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
}
g_date_time_unref(lastdt); g_date_time_unref(lastdt);
} else { } else {
cl_ev_presence_send(conn_presence, NULL, 0); cl_ev_presence_send(conn_presence, NULL, 0);

View File

@ -1662,16 +1662,14 @@ void
stanza_attach_last_activity(xmpp_ctx_t * const ctx, stanza_attach_last_activity(xmpp_ctx_t * const ctx,
xmpp_stanza_t * const presence, const int idle) xmpp_stanza_t * const presence, const int idle)
{ {
if (idle > 0) { xmpp_stanza_t *query = xmpp_stanza_new(ctx);
xmpp_stanza_t *query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
xmpp_stanza_set_name(query, STANZA_NAME_QUERY); xmpp_stanza_set_ns(query, STANZA_NS_LASTACTIVITY);
xmpp_stanza_set_ns(query, STANZA_NS_LASTACTIVITY); char idle_str[10];
char idle_str[10]; snprintf(idle_str, sizeof(idle_str), "%d", idle);
snprintf(idle_str, sizeof(idle_str), "%d", idle); xmpp_stanza_set_attribute(query, STANZA_ATTR_SECONDS, idle_str);
xmpp_stanza_set_attribute(query, STANZA_ATTR_SECONDS, idle_str); xmpp_stanza_add_child(presence, query);
xmpp_stanza_add_child(presence, query); xmpp_stanza_release(query);
xmpp_stanza_release(query);
}
} }
void void