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

Merge branch 'master' into configure

This commit is contained in:
James Booth 2017-01-16 00:02:25 +00:00
commit b737f64026
16 changed files with 71 additions and 34 deletions

View File

@ -860,8 +860,7 @@ _account_set_presence_priority(char *account_name, char *presence, char *priorit
char *connected_account = session_get_account_name();
resource_presence_t last_presence = accounts_get_last_presence(connected_account);
if (presence_type == last_presence) {
char *message = connection_get_presence_msg();
cl_ev_presence_send(last_presence, message, 0);
cl_ev_presence_send(last_presence, 0);
}
}
cons_show("Updated %s priority for account %s: %s", presence, account_name, priority);
@ -5961,7 +5960,7 @@ cmd_priority(ProfWin *window, const char *const command, gchar **args)
if (res) {
accounts_set_priority_all(session_get_account_name(), intval);
resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0);
cl_ev_presence_send(last_presence, 0);
cons_show("Priority set to %d.", intval);
} else {
cons_show(err_msg);
@ -7198,7 +7197,8 @@ _update_presence(const resource_presence_t resource_presence,
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
} else {
cl_ev_presence_send(resource_presence, msg, 0);
connection_set_presence_msg(msg);
cl_ev_presence_send(resource_presence, 0);
ui_update_presence(resource_presence, msg, show);
}
}

View File

@ -96,9 +96,10 @@ cl_ev_disconnect(void)
}
void
cl_ev_presence_send(const resource_presence_t presence_type, const char *const msg, const int idle_secs)
cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs)
{
char *signed_status = NULL;
char *msg = connection_get_presence_msg();
#ifdef HAVE_LIBGPGME
char *account_name = session_get_account_name();
@ -109,7 +110,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const char *const m
account_free(account);
#endif
presence_send(presence_type, msg, idle_secs, signed_status);
presence_send(presence_type, idle_secs, signed_status);
free(signed_status);
}

View File

@ -42,7 +42,7 @@ jabber_conn_status_t cl_ev_connect_account(ProfAccount *account);
void cl_ev_disconnect(void);
void cl_ev_presence_send(const resource_presence_t presence_type, const char *const msg, const int idle_secs);
void cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs);
void cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oob_url);
void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, const char *const oob_url);

View File

@ -135,19 +135,23 @@ sv_ev_roster_received(void)
GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt);
int diff_secs = (diff_micros / 1000) / 1000;
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(conn_presence, NULL, diff_secs);
connection_set_presence_msg(NULL);
cl_ev_presence_send(conn_presence, diff_secs);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
connection_set_presence_msg(NULL);
cl_ev_presence_send(conn_presence, 0);
}
g_date_time_unref(lastdt);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
connection_set_presence_msg(NULL);
cl_ev_presence_send(conn_presence, 0);
}
free(last_activity_str);
g_date_time_unref(nowdt);
} else {
cl_ev_presence_send(conn_presence, NULL, 0);
connection_set_presence_msg(NULL);
cl_ev_presence_send(conn_presence, 0);
}
const char *fulljid = connection_get_fulljid();

View File

@ -493,7 +493,7 @@ api_disco_add_feature(char *plugin_name, char *feature)
// resend presence to update server's disco info data for this client
if (connection_get_status() == JABBER_CONNECTED) {
resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0);
cl_ev_presence_send(last_presence, 0);
}
}

View File

@ -214,8 +214,7 @@ plugins_unload(const char *const name)
if (connection_get_status() == JABBER_CONNECTED) {
char* account_name = session_get_account_name();
resource_presence_t last_presence = accounts_get_last_presence(account_name);
char *msg = connection_get_presence_msg();
cl_ev_presence_send(last_presence, msg, 0);
cl_ev_presence_send(last_presence, 0);
}
}
return TRUE;

View File

@ -125,7 +125,7 @@ caps_add_feature(char *feature)
// resend presence to update server's disco info data for this client
if (connection_get_status() == JABBER_CONNECTED) {
resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0);
cl_ev_presence_send(last_presence, 0);
}
}
@ -143,7 +143,7 @@ caps_remove_feature(char *feature)
// resend presence to update server's disco info data for this client
if (connection_get_status() == JABBER_CONNECTED) {
resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0);
cl_ev_presence_send(last_presence, 0);
}
}

View File

@ -46,7 +46,6 @@ jabber_conn_status_t connection_connect(const char *const fulljid, const char *c
void connection_disconnect(void);
void connection_set_disconnected(void);
void connection_set_presence_msg(const char *const message);
void connection_set_priority(const int priority);
void connection_set_priority(int priority);
void connection_set_disco_items(GSList *items);

View File

@ -191,21 +191,20 @@ presence_reset_sub_request_search(void)
}
void
presence_send(const resource_presence_t presence_type, const char *const msg, const int idle, char *signed_status)
presence_send(const resource_presence_t presence_type, const int idle, char *signed_status)
{
if (connection_get_status() != JABBER_CONNECTED) {
log_warning("Error setting presence, not connected.");
return;
}
char *msg = connection_get_presence_msg();
if (msg) {
log_debug("Updating presence: %s, \"%s\"", string_from_resource_presence(presence_type), msg);
} else {
log_debug("Updating presence: %s", string_from_resource_presence(presence_type));
}
connection_set_presence_msg(msg);
const int pri = accounts_get_priority_for_presence_type(session_get_account_name(), presence_type);
connection_set_priority(pri);

View File

@ -412,10 +412,11 @@ session_check_autoaway(void)
// send away presence with last activity
char *message = prefs_get_string(PREF_AUTOAWAY_MESSAGE);
connection_set_presence_msg(message);
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(RESOURCE_AWAY, message, idle_ms / 1000);
cl_ev_presence_send(RESOURCE_AWAY, idle_ms / 1000);
} else {
cl_ev_presence_send(RESOURCE_AWAY, message, 0);
cl_ev_presence_send(RESOURCE_AWAY, 0);
}
int pri = accounts_get_priority_for_presence_type(account, RESOURCE_AWAY);
@ -432,7 +433,8 @@ session_check_autoaway(void)
activity_state = ACTIVITY_ST_IDLE;
// send current presence with last activity
cl_ev_presence_send(curr_presence, curr_status, idle_ms / 1000);
connection_set_presence_msg(curr_status);
cl_ev_presence_send(curr_presence, idle_ms / 1000);
}
}
break;
@ -443,7 +445,8 @@ session_check_autoaway(void)
cons_show("No longer idle.");
// send current presence without last activity
cl_ev_presence_send(curr_presence, curr_status, 0);
connection_set_presence_msg(curr_status);
cl_ev_presence_send(curr_presence, 0);
}
break;
case ACTIVITY_ST_AWAY:
@ -452,10 +455,11 @@ session_check_autoaway(void)
// send extended away presence with last activity
char *message = prefs_get_string(PREF_AUTOXA_MESSAGE);
connection_set_presence_msg(message);
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
cl_ev_presence_send(RESOURCE_XA, message, idle_ms / 1000);
cl_ev_presence_send(RESOURCE_XA, idle_ms / 1000);
} else {
cl_ev_presence_send(RESOURCE_XA, message, 0);
cl_ev_presence_send(RESOURCE_XA, 0);
}
int pri = accounts_get_priority_for_presence_type(account, RESOURCE_XA);
@ -473,7 +477,8 @@ session_check_autoaway(void)
cons_show("No longer idle.");
// send saved presence without last activity
cl_ev_presence_send(saved_presence, saved_status, 0);
connection_set_presence_msg(saved_status);
cl_ev_presence_send(saved_presence, 0);
contact_presence_t contact_pres = contact_presence_from_resource_presence(saved_presence);
title_bar_set_presence(contact_pres);
}
@ -485,7 +490,8 @@ session_check_autoaway(void)
cons_show("No longer idle.");
// send saved presence without last activity
cl_ev_presence_send(saved_presence, saved_status, 0);
connection_set_presence_msg(saved_status);
cl_ev_presence_send(saved_presence, 0);
contact_presence_t contact_pres = contact_presence_from_resource_presence(saved_presence);
title_bar_set_presence(contact_pres);
}

View File

@ -120,6 +120,7 @@ char* session_get_account_name(void);
jabber_conn_status_t connection_get_status(void);
char *connection_get_presence_msg(void);
void connection_set_presence_msg(const char *const message);
const char* connection_get_fulljid(void);
char* connection_create_uuid(void);
void connection_free_uuid(char *uuid);
@ -153,7 +154,7 @@ char* presence_sub_request_find(const char *const search_str);
void presence_join_room(const char *const room, const char *const nick, const char *const passwd);
void presence_change_room_nick(const char *const room, const char *const nick);
void presence_leave_chat_room(const char *const room_jid);
void presence_send(resource_presence_t status, const char *const msg, int idle, char *signed_status);
void presence_send(resource_presence_t status, int idle, char *signed_status);
gboolean presence_sub_request_exists(const char *const bare_jid);
void iq_enable_carbons(void);

View File

@ -52,6 +52,7 @@ int main(int argc, char* argv[]) {
PROF_FUNC_TEST(presence_chat_with_message),
PROF_FUNC_TEST(presence_set_priority),
PROF_FUNC_TEST(presence_includes_priority),
PROF_FUNC_TEST(presence_keeps_status),
PROF_FUNC_TEST(presence_received),
PROF_FUNC_TEST(presence_missing_resource_defaults),

View File

@ -227,6 +227,33 @@ presence_includes_priority(void **state)
assert_true(prof_output_exact("Status set to chat (priority 25), \"Free to talk\"."));
}
void
presence_keeps_status(void **state)
{
prof_connect();
prof_input("/chat \"Free to talk\"");
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<show>chat</show>"
"<status>Free to talk</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
"</presence>"
));
assert_true(prof_output_exact("Status set to chat (priority 0), \"Free to talk\"."));
prof_input("/priority 25");
assert_true(stbbr_received(
"<presence id='prof_presence_5'>"
"<show>chat</show>"
"<status>Free to talk</status>"
"<priority>25</priority>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://www.profanity.im'/>"
"</presence>"
));
assert_true(prof_output_exact("Priority set to 25."));
}
void
presence_received(void **state)
{

View File

@ -10,5 +10,6 @@ void presence_chat(void **state);
void presence_chat_with_message(void **state);
void presence_set_priority(void **state);
void presence_includes_priority(void **state);
void presence_keeps_status(void **state);
void presence_received(void **state);
void presence_missing_resource_defaults(void **state);

View File

@ -806,17 +806,15 @@ void cmd_account_set_priority_updates_presence_when_account_connected_with_prese
expect_any(accounts_get_account, name);
will_return(accounts_get_account, account);
#endif
will_return(connection_get_presence_msg, "Free to chat");
expect_value(presence_send, status, RESOURCE_ONLINE);
expect_string(presence_send, msg, "Free to chat");
expect_value(presence_send, idle, 0);
expect_value(presence_send, signed_status, NULL);
expect_cons_show("Updated online priority for account a_account: 10");
expect_cons_show("");
gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args);
assert_true(result);
}

View File

@ -78,6 +78,8 @@ GList * session_get_available_resources(void)
return NULL;
}
void connection_set_presence_msg(const char *const message) {}
gboolean
connection_send_stanza(const char *const stanza)
{
@ -153,10 +155,9 @@ void presence_join_room(const char *const room, const char *const nick, const ch
void presence_change_room_nick(const char * const room, const char * const nick) {}
void presence_leave_chat_room(const char * const room_jid) {}
void presence_send(resource_presence_t status, const char * const msg, int idle, char *signed_status)
void presence_send(resource_presence_t status, int idle, char *signed_status)
{
check_expected(status);
check_expected(msg);
check_expected(idle);
check_expected(signed_status);
}