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

Added resource override for chat sessions

This commit is contained in:
James Booth 2015-01-10 21:07:40 +00:00
parent 7256e49396
commit 965e82b350
4 changed files with 19 additions and 20 deletions

View File

@ -46,7 +46,8 @@
static GHashTable *sessions;
static void
_chat_session_new(const char * const barejid, const char * const resource, gboolean send_states)
_chat_session_new(const char * const barejid, const char * const resource,
gboolean resource_override, gboolean send_states)
{
assert(barejid != NULL);
assert(resource != NULL);
@ -54,9 +55,10 @@ _chat_session_new(const char * const barejid, const char * const resource, gbool
ChatSession *new_session = malloc(sizeof(struct chat_session_t));
new_session->barejid = strdup(barejid);
new_session->resource = strdup(resource);
new_session->resource_override = resource_override;
new_session->send_states = send_states;
g_hash_table_insert(sessions, strdup(barejid), new_session);
g_hash_table_replace(sessions, strdup(barejid), new_session);
}
static void
@ -83,6 +85,12 @@ chat_sessions_clear(void)
g_hash_table_remove_all(sessions);
}
void
chat_session_resource_override(const char * const barejid, const char * const resource)
{
_chat_session_new(barejid, resource, TRUE, FALSE);
}
ChatSession*
chat_session_get(const char * const barejid)
{
@ -100,15 +108,14 @@ chat_session_on_recipient_activity(const char * const barejid, const char * cons
// session exists with resource, do nothing
if (g_strcmp0(session->resource, resource) == 0) {
return;
// session exists with differet resource, replace
} else {
g_hash_table_remove(sessions, barejid);
_chat_session_new(barejid, resource, FALSE);
// session exists with differet resource and no override, replace
} else if (!session->resource_override) {
_chat_session_new(barejid, resource, FALSE, FALSE);
}
// no session, create one
} else {
_chat_session_new(barejid, resource, FALSE);
_chat_session_new(barejid, resource, FALSE, FALSE);
}
}

View File

@ -40,12 +40,15 @@
typedef struct chat_session_t {
char *barejid;
char *resource;
gboolean resource_override;
gboolean send_states;
} ChatSession;
void chat_sessions_init(void);
void chat_sessions_clear(void);
void chat_session_resource_override(const char * const barejid, const char * const resource);
ChatSession* chat_session_get(const char * const barejid);
void chat_session_on_recipient_activity(const char * const barejid, const char * const resourcepart);
void chat_session_remove(const char * const barejid);

View File

@ -1203,17 +1203,6 @@ cmd_msg(gchar **args, struct cmd_help_t help)
barejid = usr;
}
// 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)) {
@ -1635,10 +1624,12 @@ cmd_resource(gchar **args, struct cmd_help_t help)
}
chatwin->resource_override = strdup(resource);
chat_session_resource_override(chatwin->barejid, resource);
return TRUE;
} else if (g_strcmp0(cmd, "off") == 0) {
FREE_SET_NULL(chatwin->resource_override);
chat_session_remove(chatwin->barejid);
return TRUE;
} else {
cons_show("Usage: %s", help.usage);

View File

@ -931,8 +931,6 @@ ui_gone_secure(const char * const barejid, gboolean trusted)
chatwin = (ProfChatWin*)window;
}
FREE_SET_NULL(chatwin->resource_override);
chatwin->is_otr = TRUE;
chatwin->is_trusted = trusted;
if (trusted) {