mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Refactored chat session handling on sending message
This commit is contained in:
parent
42a5c431c7
commit
8326c8b3a2
@ -34,6 +34,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
@ -57,7 +58,7 @@ typedef enum {
|
||||
typedef struct chat_session_t {
|
||||
char *barejid;
|
||||
char *resource;
|
||||
gboolean supported;
|
||||
gboolean send_states;
|
||||
chat_state_t state;
|
||||
GTimer *active_timer;
|
||||
gboolean sent;
|
||||
@ -66,12 +67,12 @@ typedef struct chat_session_t {
|
||||
static GHashTable *sessions;
|
||||
|
||||
static ChatSession*
|
||||
_chat_session_new(const char * const barejid, const char * const resource, gboolean supported)
|
||||
_chat_session_new(const char * const barejid, const char * const resource, gboolean send_states)
|
||||
{
|
||||
ChatSession *new_session = malloc(sizeof(struct chat_session_t));
|
||||
new_session->barejid = strdup(barejid);
|
||||
new_session->resource = strdup(resource);
|
||||
new_session->supported = supported;
|
||||
new_session->send_states = send_states;
|
||||
new_session->state = CHAT_STATE_STARTED;
|
||||
new_session->active_timer = g_timer_new();
|
||||
new_session->sent = FALSE;
|
||||
@ -111,6 +112,7 @@ gboolean
|
||||
chat_session_exists(const char * const barejid)
|
||||
{
|
||||
ChatSession *session = g_hash_table_lookup(sessions, barejid);
|
||||
|
||||
return (session != NULL);
|
||||
}
|
||||
|
||||
@ -118,33 +120,22 @@ char*
|
||||
chat_session_get_resource(const char * const barejid)
|
||||
{
|
||||
ChatSession *session = g_hash_table_lookup(sessions, barejid);
|
||||
if (session) {
|
||||
return session->resource;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
assert(session != NULL);
|
||||
|
||||
return session->resource;
|
||||
}
|
||||
|
||||
gboolean
|
||||
chat_session_on_message_send(const char * const barejid)
|
||||
chat_session_send_states(const char * const barejid)
|
||||
{
|
||||
gboolean send_state = FALSE;
|
||||
ChatSession *session = g_hash_table_lookup(sessions, barejid);
|
||||
assert(session != NULL);
|
||||
|
||||
if (prefs_get_boolean(PREF_STATES)) {
|
||||
ChatSession *session = g_hash_table_lookup(sessions, barejid);
|
||||
if (session && session->supported) {
|
||||
session->state = CHAT_STATE_ACTIVE;
|
||||
g_timer_start(session->active_timer);
|
||||
session->sent = TRUE;
|
||||
send_state = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return send_state;
|
||||
return session->send_states;
|
||||
}
|
||||
|
||||
void
|
||||
chat_session_on_incoming_message(const char * const barejid, const char * const resource, gboolean supported)
|
||||
chat_session_on_incoming_message(const char * const barejid, const char * const resource, gboolean send_states)
|
||||
{
|
||||
ChatSession *session = g_hash_table_lookup(sessions, barejid);
|
||||
|
||||
@ -153,14 +144,14 @@ chat_session_on_incoming_message(const char * const barejid, const char * const
|
||||
if (g_strcmp0(session->resource, resource) != 0) {
|
||||
log_info("Replacing chat session %s/%s, with new session %s/%s", session->barejid, session->resource, barejid, resource);
|
||||
g_hash_table_remove(sessions, session);
|
||||
session = _chat_session_new(barejid, resource, supported);
|
||||
session = _chat_session_new(barejid, resource, send_states);
|
||||
g_hash_table_insert(sessions, strdup(barejid), session);
|
||||
} else {
|
||||
session->supported = supported;
|
||||
session->send_states = send_states;
|
||||
}
|
||||
} else {
|
||||
log_info("Starting chat session with %s/%s", barejid, resource);
|
||||
session = _chat_session_new(barejid, resource, supported);
|
||||
session = _chat_session_new(barejid, resource, send_states);
|
||||
g_hash_table_insert(sessions, strdup(barejid), session);
|
||||
}
|
||||
} else if (session) {
|
||||
@ -169,29 +160,34 @@ chat_session_on_incoming_message(const char * const barejid, const char * const
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
chat_session_on_message_send(const char * const barejid)
|
||||
{
|
||||
ChatSession *session = g_hash_table_lookup(sessions, barejid);
|
||||
assert(session != NULL);
|
||||
|
||||
session->state = CHAT_STATE_ACTIVE;
|
||||
g_timer_start(session->active_timer);
|
||||
session->sent = TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
chat_session_on_window_close(const char * const barejid)
|
||||
{
|
||||
if (prefs_get_boolean(PREF_STATES)) {
|
||||
ChatSession *session = g_hash_table_lookup(sessions, barejid);
|
||||
// send <gone/> chat state before closing
|
||||
if (session && session->supported) {
|
||||
session->state = CHAT_STATE_GONE;
|
||||
message_send_gone(barejid);
|
||||
session->sent = TRUE;
|
||||
g_hash_table_remove(sessions, barejid);
|
||||
}
|
||||
ChatSession *session = g_hash_table_lookup(sessions, barejid);
|
||||
assert(session != NULL);
|
||||
|
||||
if (prefs_get_boolean(PREF_STATES) && session->send_states) {
|
||||
message_send_gone(barejid);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
chat_session_on_cancel(const char * const jid)
|
||||
{
|
||||
if (prefs_get_boolean(PREF_STATES)) {
|
||||
ChatSession *session = g_hash_table_lookup(sessions, jid);
|
||||
if (session) {
|
||||
session->supported = FALSE;
|
||||
}
|
||||
ChatSession *session = g_hash_table_lookup(sessions, jid);
|
||||
if (session) {
|
||||
session->send_states = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +195,7 @@ void
|
||||
chat_session_on_activity(const char * const barejid)
|
||||
{
|
||||
ChatSession *session = g_hash_table_lookup(sessions, barejid);
|
||||
if (session && session->supported) {
|
||||
if (session) {
|
||||
if (session->state != CHAT_STATE_COMPOSING) {
|
||||
session->sent = FALSE;
|
||||
}
|
||||
@ -208,11 +204,15 @@ chat_session_on_activity(const char * const barejid)
|
||||
g_timer_start(session->active_timer);
|
||||
|
||||
if (!session->sent || session->state == CHAT_STATE_PAUSED) {
|
||||
Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource);
|
||||
message_send_composing(jidp->fulljid);
|
||||
if (prefs_get_boolean(PREF_STATES) && prefs_get_boolean(PREF_OUTTYPE) && session->send_states) {
|
||||
Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource);
|
||||
message_send_composing(jidp->fulljid);
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
session->sent = TRUE;
|
||||
jid_destroy(jidp);
|
||||
}
|
||||
} else if (prefs_get_boolean(PREF_STATES) && prefs_get_boolean(PREF_OUTTYPE)) {
|
||||
message_send_composing(barejid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,7 +220,7 @@ void
|
||||
chat_session_on_inactivity(const char * const barejid)
|
||||
{
|
||||
ChatSession *session = g_hash_table_lookup(sessions, barejid);
|
||||
if (session && session->supported) {
|
||||
if (session) {
|
||||
if (session->active_timer != NULL) {
|
||||
gdouble elapsed = g_timer_elapsed(session->active_timer, NULL);
|
||||
|
||||
@ -247,13 +247,19 @@ chat_session_on_inactivity(const char * const barejid)
|
||||
if (session->sent == FALSE) {
|
||||
Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource);
|
||||
if (session->state == CHAT_STATE_GONE) {
|
||||
message_send_gone(jidp->fulljid);
|
||||
if (prefs_get_boolean(PREF_STATES) && session->send_states) {
|
||||
message_send_gone(jidp->fulljid);
|
||||
}
|
||||
session->sent = TRUE;
|
||||
} else if (session->state == CHAT_STATE_INACTIVE) {
|
||||
message_send_inactive(jidp->fulljid);
|
||||
if (prefs_get_boolean(PREF_STATES) && session->send_states) {
|
||||
message_send_inactive(jidp->fulljid);
|
||||
}
|
||||
session->sent = TRUE;
|
||||
} else if (session->state == CHAT_STATE_PAUSED && prefs_get_boolean(PREF_OUTTYPE)) {
|
||||
message_send_paused(jidp->fulljid);
|
||||
if (prefs_get_boolean(PREF_STATES) && session->send_states) {
|
||||
message_send_paused(jidp->fulljid);
|
||||
}
|
||||
session->sent = TRUE;
|
||||
}
|
||||
jid_destroy(jidp);
|
||||
|
@ -42,11 +42,14 @@ void chat_sessions_clear(void);
|
||||
|
||||
gboolean chat_session_exists(const char * const barejid);
|
||||
char* chat_session_get_resource(const char * const barejid);
|
||||
gboolean chat_session_on_message_send(const char * const barejid);
|
||||
gboolean chat_session_send_states(const char * const barejid);
|
||||
|
||||
void chat_session_on_message_send(const char * const barejid);
|
||||
void chat_session_on_window_close(const char * const barejid);
|
||||
void chat_session_on_incoming_message(const char * const barejid, const char * const resource, gboolean supported);
|
||||
void chat_session_on_incoming_message(const char * const barejid, const char * const resource, gboolean send_states);
|
||||
void chat_session_on_cancel(const char * const jid);
|
||||
|
||||
void chat_session_on_activity(const char * const barejid);
|
||||
void chat_session_on_inactivity(const char * const recipient);
|
||||
void chat_session_on_inactivity(const char * const barejid);
|
||||
|
||||
#endif
|
||||
|
@ -1814,15 +1814,7 @@ cmd_execute_default(const char * inp)
|
||||
if (otr_is_secure(chatwin->barejid)) {
|
||||
char *encrypted = otr_encrypt_message(chatwin->barejid, inp);
|
||||
if (encrypted != NULL) {
|
||||
char *resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(chatwin->barejid)) {
|
||||
resource = chat_session_get_resource(chatwin->barejid);
|
||||
send_state = chat_session_on_message_send(chatwin->barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(chatwin->barejid, resource, encrypted, send_state);
|
||||
message_send_chat(chatwin->barejid, encrypted);
|
||||
otr_free_message(encrypted);
|
||||
if (prefs_get_boolean(PREF_CHLOG)) {
|
||||
const char *jid = jabber_get_fulljid();
|
||||
@ -1842,15 +1834,7 @@ cmd_execute_default(const char * inp)
|
||||
cons_show_error("Failed to send message.");
|
||||
}
|
||||
} else {
|
||||
char *resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(chatwin->barejid)) {
|
||||
resource = chat_session_get_resource(chatwin->barejid);
|
||||
send_state = chat_session_on_message_send(chatwin->barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(chatwin->barejid, resource, inp, send_state);
|
||||
message_send_chat(chatwin->barejid, inp);
|
||||
if (prefs_get_boolean(PREF_CHLOG)) {
|
||||
const char *jid = jabber_get_fulljid();
|
||||
Jid *jidp = jid_create(jid);
|
||||
@ -1861,15 +1845,7 @@ cmd_execute_default(const char * inp)
|
||||
ui_outgoing_chat_msg("me", chatwin->barejid, inp);
|
||||
}
|
||||
#else
|
||||
char *resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(chatwin->barejid)) {
|
||||
resource = chat_session_get_resource(chatwin->barejid);
|
||||
send_state = chat_session_on_message_send(chatwin->barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(chatwin->barejid, resource, inp, send_state);
|
||||
message_send_chat(chatwin->barejid, inp);
|
||||
if (prefs_get_boolean(PREF_CHLOG)) {
|
||||
const char *jid = jabber_get_fulljid();
|
||||
Jid *jidp = jid_create(jid);
|
||||
|
@ -1203,31 +1203,23 @@ cmd_msg(gchar **args, struct cmd_help_t help)
|
||||
barejid = usr;
|
||||
}
|
||||
|
||||
// if msg to current recipient, and resource specified, set resource
|
||||
char *resource = NULL;
|
||||
ProfWin *current = wins_get_current();
|
||||
if (current->type == WIN_CHAT) {
|
||||
ProfChatWin *chatwin = (ProfChatWin*)current;
|
||||
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||
if ((g_strcmp0(chatwin->barejid, barejid) == 0) && (chatwin->resource)) {
|
||||
resource = chatwin->resource;
|
||||
}
|
||||
}
|
||||
// TODO if msg to current recipient, and resource specified, set resource
|
||||
// char *resource = NULL;
|
||||
// ProfWin *current = wins_get_current();
|
||||
// if (current->type == WIN_CHAT) {
|
||||
// ProfChatWin *chatwin = (ProfChatWin*)current;
|
||||
// assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||
// if ((g_strcmp0(chatwin->barejid, barejid) == 0) && (chatwin->resource)) {
|
||||
// resource = chatwin->resource;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (msg != NULL) {
|
||||
#ifdef HAVE_LIBOTR
|
||||
if (otr_is_secure(barejid)) {
|
||||
char *encrypted = otr_encrypt_message(barejid, msg);
|
||||
if (encrypted != NULL) {
|
||||
resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(barejid)) {
|
||||
resource = chat_session_get_resource(barejid);
|
||||
send_state = chat_session_on_message_send(barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(barejid, resource, encrypted, send_state);
|
||||
message_send_chat(barejid, encrypted);
|
||||
otr_free_message(encrypted);
|
||||
ui_outgoing_chat_msg("me", barejid, msg);
|
||||
|
||||
@ -1256,27 +1248,11 @@ cmd_msg(gchar **args, struct cmd_help_t help)
|
||||
GString *otr_message = g_string_new(msg);
|
||||
g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE);
|
||||
g_string_append(otr_message, OTRL_MESSAGE_TAG_V2);
|
||||
resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(barejid)) {
|
||||
resource = chat_session_get_resource(barejid);
|
||||
send_state = chat_session_on_message_send(barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(barejid, resource, otr_message->str, send_state);
|
||||
message_send_chat(barejid, otr_message->str);
|
||||
|
||||
g_string_free(otr_message, TRUE);
|
||||
} else {
|
||||
resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(barejid)) {
|
||||
resource = chat_session_get_resource(barejid);
|
||||
send_state = chat_session_on_message_send(barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(barejid, resource, msg, send_state);
|
||||
message_send_chat(barejid, msg);
|
||||
}
|
||||
ui_outgoing_chat_msg("me", barejid, msg);
|
||||
|
||||
@ -1289,15 +1265,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
|
||||
}
|
||||
return TRUE;
|
||||
#else
|
||||
resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(barejid)) {
|
||||
resource = chat_session_get_resource(barejid);
|
||||
send_state = chat_session_on_message_send(barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(barejid, resource, msg, send_state);
|
||||
message_send_chat(barejid, msg);
|
||||
ui_outgoing_chat_msg("me", barejid, msg);
|
||||
|
||||
if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) {
|
||||
@ -3036,15 +3004,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help)
|
||||
if (otr_is_secure(chatwin->barejid)) {
|
||||
char *encrypted = otr_encrypt_message(chatwin->barejid, tiny);
|
||||
if (encrypted != NULL) {
|
||||
char *resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(chatwin->barejid)) {
|
||||
resource = chat_session_get_resource(chatwin->barejid);
|
||||
send_state = chat_session_on_message_send(chatwin->barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(chatwin->barejid, resource, encrypted, send_state);
|
||||
message_send_chat(chatwin->barejid, encrypted);
|
||||
otr_free_message(encrypted);
|
||||
if (prefs_get_boolean(PREF_CHLOG)) {
|
||||
const char *jid = jabber_get_fulljid();
|
||||
@ -3064,15 +3024,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help)
|
||||
cons_show_error("Failed to send message.");
|
||||
}
|
||||
} else {
|
||||
char *resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(chatwin->barejid)) {
|
||||
resource = chat_session_get_resource(chatwin->barejid);
|
||||
send_state = chat_session_on_message_send(chatwin->barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(chatwin->barejid, resource, tiny, send_state);
|
||||
message_send_chat(chatwin->barejid, tiny);
|
||||
if (prefs_get_boolean(PREF_CHLOG)) {
|
||||
const char *jid = jabber_get_fulljid();
|
||||
Jid *jidp = jid_create(jid);
|
||||
@ -3083,15 +3035,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help)
|
||||
ui_outgoing_chat_msg("me", chatwin->barejid, tiny);
|
||||
}
|
||||
#else
|
||||
char *resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(chatwin->barejid)) {
|
||||
resource = chat_session_get_resource(chatwin->barejid);
|
||||
send_state = chat_session_on_message_send(chatwin->barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(chatwin->barejid, resource, tiny, send_state);
|
||||
message_send_chat(chatwin->barejid, tiny);
|
||||
if (prefs_get_boolean(PREF_CHLOG)) {
|
||||
const char *jid = jabber_get_fulljid();
|
||||
Jid *jidp = jid_create(jid);
|
||||
@ -4008,15 +3952,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
|
||||
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
||||
} else if (!otr_is_secure(barejid)) {
|
||||
char *otr_query_message = otr_start_query();
|
||||
char *resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(barejid)) {
|
||||
resource = chat_session_get_resource(barejid);
|
||||
send_state = chat_session_on_message_send(barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(barejid, resource, otr_query_message, send_state);
|
||||
message_send_chat(barejid, otr_query_message);
|
||||
} else {
|
||||
ui_gone_secure(barejid, otr_is_trusted(barejid));
|
||||
}
|
||||
@ -4034,15 +3970,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
|
||||
} else {
|
||||
ProfChatWin *chatwin = ui_get_current_chat();
|
||||
char *otr_query_message = otr_start_query();
|
||||
char *resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(chatwin->barejid)) {
|
||||
resource = chat_session_get_resource(chatwin->barejid);
|
||||
send_state = chat_session_on_message_send(chatwin->barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(chatwin->barejid, resource, otr_query_message, send_state);
|
||||
message_send_chat(chatwin->barejid, otr_query_message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,15 +110,7 @@ static void
|
||||
cb_inject_message(void *opdata, const char *accountname,
|
||||
const char *protocol, const char *recipient, const char *message)
|
||||
{
|
||||
char *resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(recipient)) {
|
||||
resource = chat_session_get_resource(recipient);
|
||||
send_state = chat_session_on_message_send(recipient);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(recipient, resource, message, send_state);
|
||||
message_send_chat(recipient, message);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -318,15 +318,7 @@ handle_incoming_message(char *barejid, char *message)
|
||||
memmove(whitespace_base, whitespace_base+tag_length, tag_length);
|
||||
char *otr_query_message = otr_start_query();
|
||||
cons_show("OTR Whitespace pattern detected. Attempting to start OTR session...");
|
||||
char *resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(barejid)) {
|
||||
resource = chat_session_get_resource(barejid);
|
||||
send_state = chat_session_on_message_send(barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(barejid, resource, otr_query_message, send_state);
|
||||
message_send_chat(barejid, otr_query_message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -340,15 +332,7 @@ handle_incoming_message(char *barejid, char *message)
|
||||
if (policy == PROF_OTRPOLICY_ALWAYS && !was_decrypted && !whitespace_base) {
|
||||
char *otr_query_message = otr_start_query();
|
||||
cons_show("Attempting to start OTR session...");
|
||||
char *resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(barejid)) {
|
||||
resource = chat_session_get_resource(barejid);
|
||||
send_state = chat_session_on_message_send(barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
message_send_chat(barejid, resource, otr_query_message, send_state);
|
||||
message_send_chat(barejid, otr_query_message);
|
||||
}
|
||||
|
||||
ui_incoming_msg(barejid, newmessage, NULL);
|
||||
|
@ -705,7 +705,9 @@ ui_close_connected_win(int index)
|
||||
otr_end_session(chatwin->barejid);
|
||||
}
|
||||
#endif
|
||||
chat_session_on_window_close(chatwin->barejid);
|
||||
if (chat_session_exists(chatwin->barejid)) {
|
||||
chat_session_on_window_close(chatwin->barejid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1162,7 +1164,9 @@ ui_prune_wins(void)
|
||||
if (window->type == WIN_CHAT) {
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
ProfChatWin *chatwin = (ProfChatWin*)window;
|
||||
chat_session_on_window_close(chatwin->barejid);
|
||||
if (chat_session_exists(chatwin->barejid)) {
|
||||
chat_session_on_window_close(chatwin->barejid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,17 +151,11 @@ inp_get_char(char *input, int *size, int *result)
|
||||
in_command = TRUE;
|
||||
}
|
||||
|
||||
if (prefs_get_boolean(PREF_STATES)) {
|
||||
if (*result == ERR) {
|
||||
prof_handle_idle();
|
||||
}
|
||||
if (prefs_get_boolean(PREF_OUTTYPE)
|
||||
&& (*result != ERR)
|
||||
&& (*result != KEY_CODE_YES)
|
||||
&& !in_command
|
||||
&& _printable(ch)) {
|
||||
prof_handle_activity();
|
||||
}
|
||||
if (*result == ERR) {
|
||||
prof_handle_idle();
|
||||
}
|
||||
if ((*result != ERR) && (*result != KEY_CODE_YES) && !in_command && _printable(ch)) {
|
||||
prof_handle_activity();
|
||||
}
|
||||
|
||||
// if it wasn't an arrow key etc
|
||||
|
@ -80,19 +80,29 @@ message_add_handlers(void)
|
||||
}
|
||||
|
||||
void
|
||||
message_send_chat(const char * const barejid, const char * const resource, const char * const msg, gboolean send_state)
|
||||
message_send_chat(const char * const barejid, const char * const msg)
|
||||
{
|
||||
xmpp_stanza_t *message;
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
|
||||
char *resource = NULL;
|
||||
gboolean send_state = FALSE;
|
||||
if (chat_session_exists(barejid)) {
|
||||
chat_session_on_message_send(barejid);
|
||||
resource = chat_session_get_resource(barejid);
|
||||
send_state = chat_session_send_states(barejid);
|
||||
} else {
|
||||
send_state = TRUE;
|
||||
}
|
||||
|
||||
GString *jid = g_string_new(barejid);
|
||||
if (resource) {
|
||||
g_string_append(jid, "/");
|
||||
g_string_append(jid, resource);
|
||||
}
|
||||
|
||||
if (send_state) {
|
||||
if (prefs_get_boolean(PREF_STATES) && send_state) {
|
||||
message = stanza_create_message(ctx, jid->str, STANZA_TYPE_CHAT, msg, STANZA_NAME_ACTIVE);
|
||||
} else {
|
||||
message = stanza_create_message(ctx, jid->str, STANZA_TYPE_CHAT, msg, NULL);
|
||||
@ -149,22 +159,22 @@ message_send_invite(const char * const roomjid, const char * const contact,
|
||||
}
|
||||
|
||||
void
|
||||
message_send_composing(const char * const fulljid)
|
||||
message_send_composing(const char * const jid)
|
||||
{
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, fulljid, STANZA_NAME_COMPOSING);
|
||||
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, jid, STANZA_NAME_COMPOSING);
|
||||
|
||||
xmpp_send(conn, stanza);
|
||||
xmpp_stanza_release(stanza);
|
||||
}
|
||||
|
||||
void
|
||||
message_send_paused(const char * const fulljid)
|
||||
message_send_paused(const char * const jid)
|
||||
{
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, fulljid,
|
||||
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, jid,
|
||||
STANZA_NAME_PAUSED);
|
||||
|
||||
xmpp_send(conn, stanza);
|
||||
@ -172,11 +182,11 @@ message_send_paused(const char * const fulljid)
|
||||
}
|
||||
|
||||
void
|
||||
message_send_inactive(const char * const fulljid)
|
||||
message_send_inactive(const char * const jid)
|
||||
{
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, fulljid,
|
||||
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, jid,
|
||||
STANZA_NAME_INACTIVE);
|
||||
|
||||
xmpp_send(conn, stanza);
|
||||
@ -184,11 +194,11 @@ message_send_inactive(const char * const fulljid)
|
||||
}
|
||||
|
||||
void
|
||||
message_send_gone(const char * const fulljid)
|
||||
message_send_gone(const char * const jid)
|
||||
{
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, fulljid,
|
||||
xmpp_stanza_t *stanza = stanza_create_chat_state(ctx, jid,
|
||||
STANZA_NAME_GONE);
|
||||
|
||||
xmpp_send(conn, stanza);
|
||||
|
@ -145,16 +145,15 @@ char* jabber_get_account_name(void);
|
||||
GList * jabber_get_available_resources(void);
|
||||
|
||||
// message functions
|
||||
void message_send_chat(const char * const barejid, const char * const resource, const char * const msg,
|
||||
gboolean send_state);
|
||||
void message_send_chat(const char * const barejid, const char * const msg);
|
||||
void message_send_private(const char * const fulljid, const char * const msg);
|
||||
void message_send_groupchat(const char * const roomjid, const char * const msg);
|
||||
void message_send_groupchat_subject(const char * const roomjid, const char * const subject);
|
||||
|
||||
void message_send_inactive(const char * const fulljid);
|
||||
void message_send_composing(const char * const fulljid);
|
||||
void message_send_paused(const char * const fulljid);
|
||||
void message_send_gone(const char * const fulljid);
|
||||
void message_send_inactive(const char * const jid);
|
||||
void message_send_composing(const char * const jid);
|
||||
void message_send_paused(const char * const jid);
|
||||
void message_send_gone(const char * const jid);
|
||||
|
||||
void message_send_invite(const char * const room, const char * const contact,
|
||||
const char * const reason);
|
||||
|
@ -552,9 +552,7 @@ cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state)
|
||||
will_return(otr_start_query, query_message);
|
||||
|
||||
expect_string(message_send_chat, barejid, chatwin->barejid);
|
||||
expect_value(message_send_chat, resource, NULL);
|
||||
expect_string(message_send_chat, msg, query_message);
|
||||
expect_any(message_send_chat, send_state);
|
||||
|
||||
gboolean result = cmd_otr(args, *help);
|
||||
assert_true(result);
|
||||
|
@ -141,9 +141,10 @@ void handle_message_error_when_recipient_cancel_disables_chat_session(void **sta
|
||||
expect_any(ui_handle_recipient_not_found, err_msg);
|
||||
|
||||
handle_message_error(from, type, err_msg);
|
||||
gboolean chat_session_supported = chat_session_on_message_send(from);
|
||||
chat_session_on_message_send(from);
|
||||
gboolean send_states = chat_session_send_states(from);
|
||||
|
||||
assert_false(chat_session_supported);
|
||||
assert_false(send_states);
|
||||
chat_sessions_clear();
|
||||
}
|
||||
|
||||
|
@ -58,13 +58,10 @@ GList * jabber_get_available_resources(void)
|
||||
}
|
||||
|
||||
// message functions
|
||||
void message_send_chat(const char * const barejid, const char * const resource, const char * const msg,
|
||||
gboolean send_state)
|
||||
void message_send_chat(const char * const barejid, const char * const msg)
|
||||
{
|
||||
check_expected(barejid);
|
||||
check_expected(resource);
|
||||
check_expected(msg);
|
||||
check_expected(send_state);
|
||||
}
|
||||
|
||||
void message_send_private(const char * const fulljid, const char * const msg) {}
|
||||
@ -218,4 +215,4 @@ void roster_send_add_new(const char * const barejid, const char * const name)
|
||||
void roster_send_remove(const char * const barejid)
|
||||
{
|
||||
check_expected(barejid);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user