diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index eea37459..eab3c596 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -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);
}
}
diff --git a/src/event/client_events.c b/src/event/client_events.c
index dcd49b94..d2dc29c6 100644
--- a/src/event/client_events.c
+++ b/src/event/client_events.c
@@ -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);
}
diff --git a/src/event/client_events.h b/src/event/client_events.h
index 876a0d54..b46a0a13 100644
--- a/src/event/client_events.h
+++ b/src/event/client_events.h
@@ -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);
diff --git a/src/event/server_events.c b/src/event/server_events.c
index a434bf47..56971e6a 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -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();
diff --git a/src/plugins/api.c b/src/plugins/api.c
index a4a1f998..8ebb0bb8 100644
--- a/src/plugins/api.c
+++ b/src/plugins/api.c
@@ -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);
}
}
diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c
index a4846b20..054cb8e1 100644
--- a/src/plugins/plugins.c
+++ b/src/plugins/plugins.c
@@ -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;
diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c
index e09270cb..7571ad0c 100644
--- a/src/xmpp/capabilities.c
+++ b/src/xmpp/capabilities.c
@@ -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);
}
}
diff --git a/src/xmpp/connection.h b/src/xmpp/connection.h
index b691e90d..7bedb94a 100644
--- a/src/xmpp/connection.h
+++ b/src/xmpp/connection.h
@@ -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);
diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c
index 4c686b7d..2a844ac6 100644
--- a/src/xmpp/presence.c
+++ b/src/xmpp/presence.c
@@ -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);
diff --git a/src/xmpp/session.c b/src/xmpp/session.c
index 032ca77a..ea6a8a7f 100644
--- a/src/xmpp/session.c
+++ b/src/xmpp/session.c
@@ -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);
}
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 7302b279..c70fd4dd 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -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);
diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c
index ef9f0e39..1e01071d 100644
--- a/tests/functionaltests/functionaltests.c
+++ b/tests/functionaltests/functionaltests.c
@@ -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),
diff --git a/tests/functionaltests/test_presence.c b/tests/functionaltests/test_presence.c
index 97cf168c..bf0171a7 100644
--- a/tests/functionaltests/test_presence.c
+++ b/tests/functionaltests/test_presence.c
@@ -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(
+ ""
+ "chat"
+ "Free to talk"
+ ""
+ ""
+ ));
+ assert_true(prof_output_exact("Status set to chat (priority 0), \"Free to talk\"."));
+
+ prof_input("/priority 25");
+ assert_true(stbbr_received(
+ ""
+ "chat"
+ "Free to talk"
+ "25"
+ ""
+ ""
+ ));
+ assert_true(prof_output_exact("Priority set to 25."));
+}
+
void
presence_received(void **state)
{
diff --git a/tests/functionaltests/test_presence.h b/tests/functionaltests/test_presence.h
index 7df362bf..107fa794 100644
--- a/tests/functionaltests/test_presence.h
+++ b/tests/functionaltests/test_presence.h
@@ -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);
diff --git a/tests/unittests/test_cmd_account.c b/tests/unittests/test_cmd_account.c
index 0b723bde..9e7ae197 100644
--- a/tests/unittests/test_cmd_account.c
+++ b/tests/unittests/test_cmd_account.c
@@ -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);
}
diff --git a/tests/unittests/xmpp/stub_xmpp.c b/tests/unittests/xmpp/stub_xmpp.c
index e4ef7ea1..38f7428e 100644
--- a/tests/unittests/xmpp/stub_xmpp.c
+++ b/tests/unittests/xmpp/stub_xmpp.c
@@ -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);
}