mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Use handle in /msg command
This commit is contained in:
parent
ad6184c86b
commit
59a3a5fe9b
@ -1973,14 +1973,15 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
char *usr_jid = roster_jid_from_handle(usr);
|
||||||
if (msg != NULL) {
|
if (msg != NULL) {
|
||||||
message_send(msg, usr);
|
message_send(msg, usr_jid);
|
||||||
ui_outgoing_msg("me", usr, msg);
|
ui_outgoing_msg("me", usr_jid, msg);
|
||||||
|
|
||||||
if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) {
|
if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) {
|
||||||
const char *jid = jabber_get_jid();
|
const char *jid = jabber_get_jid();
|
||||||
Jid *jidp = jid_create(jid);
|
Jid *jidp = jid_create(jid);
|
||||||
chat_log_chat(jidp->barejid, usr, msg, PROF_OUT_LOG, NULL);
|
chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL);
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "profanity.h"
|
#include "profanity.h"
|
||||||
#include "xmpp/connection.h"
|
#include "xmpp/connection.h"
|
||||||
#include "xmpp/message.h"
|
#include "xmpp/message.h"
|
||||||
|
#include "xmpp/roster.h"
|
||||||
#include "xmpp/stanza.h"
|
#include "xmpp/stanza.h"
|
||||||
#include "xmpp/xmpp.h"
|
#include "xmpp/xmpp.h"
|
||||||
|
|
||||||
@ -59,21 +60,29 @@ message_add_handlers(void)
|
|||||||
void
|
void
|
||||||
message_send(const char * const msg, const char * const recipient)
|
message_send(const char * const msg, const char * const recipient)
|
||||||
{
|
{
|
||||||
|
const char * jid = NULL;
|
||||||
|
|
||||||
|
if (roster_jid_from_handle(recipient) != NULL) {
|
||||||
|
jid = roster_jid_from_handle(recipient);
|
||||||
|
} else {
|
||||||
|
jid = recipient;
|
||||||
|
}
|
||||||
|
|
||||||
xmpp_conn_t * const conn = connection_get_conn();
|
xmpp_conn_t * const conn = connection_get_conn();
|
||||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
if (prefs_get_boolean(PREF_STATES)) {
|
if (prefs_get_boolean(PREF_STATES)) {
|
||||||
if (!chat_session_exists(recipient)) {
|
if (!chat_session_exists(jid)) {
|
||||||
chat_session_start(recipient, TRUE);
|
chat_session_start(jid, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
xmpp_stanza_t *message;
|
xmpp_stanza_t *message;
|
||||||
if (prefs_get_boolean(PREF_STATES) && chat_session_get_recipient_supports(recipient)) {
|
if (prefs_get_boolean(PREF_STATES) && chat_session_get_recipient_supports(jid)) {
|
||||||
chat_session_set_active(recipient);
|
chat_session_set_active(jid);
|
||||||
message = stanza_create_message(ctx, recipient, STANZA_TYPE_CHAT,
|
message = stanza_create_message(ctx, jid, STANZA_TYPE_CHAT,
|
||||||
msg, STANZA_NAME_ACTIVE, NULL);
|
msg, STANZA_NAME_ACTIVE, NULL);
|
||||||
} else {
|
} else {
|
||||||
message = stanza_create_message(ctx, recipient, STANZA_TYPE_CHAT,
|
message = stanza_create_message(ctx, jid, STANZA_TYPE_CHAT,
|
||||||
msg, NULL, NULL);
|
msg, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ static int _roster_handle_result(xmpp_conn_t * const conn,
|
|||||||
static Autocomplete ac;
|
static Autocomplete ac;
|
||||||
static Autocomplete resource_ac;
|
static Autocomplete resource_ac;
|
||||||
static GHashTable *contacts;
|
static GHashTable *contacts;
|
||||||
|
static GHashTable *handle_to_jid;
|
||||||
|
|
||||||
static gboolean _key_equals(void *key1, void *key2);
|
static gboolean _key_equals(void *key1, void *key2);
|
||||||
static gboolean _datetimes_equal(GDateTime *dt1, GDateTime *dt2);
|
static gboolean _datetimes_equal(GDateTime *dt1, GDateTime *dt2);
|
||||||
@ -66,6 +67,12 @@ roster_request(void)
|
|||||||
xmpp_stanza_release(iq);
|
xmpp_stanza_release(iq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
roster_jid_from_handle(const char * const handle)
|
||||||
|
{
|
||||||
|
return g_hash_table_lookup(handle_to_jid, handle);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_roster_handle_set(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
_roster_handle_set(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
void * const userdata)
|
void * const userdata)
|
||||||
@ -82,7 +89,9 @@ _roster_handle_set(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME);
|
const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME);
|
||||||
const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION);
|
const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION);
|
||||||
if (g_strcmp0(sub, "remove") == 0) {
|
if (g_strcmp0(sub, "remove") == 0) {
|
||||||
roster_remove(jid);
|
autocomplete_remove(ac, name);
|
||||||
|
g_hash_table_remove(handle_to_jid, name);
|
||||||
|
g_hash_table_remove(contacts, jid);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +151,7 @@ roster_init(void)
|
|||||||
resource_ac = autocomplete_new();
|
resource_ac = autocomplete_new();
|
||||||
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
|
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
|
||||||
(GDestroyNotify)p_contact_free);
|
(GDestroyNotify)p_contact_free);
|
||||||
|
handle_to_jid = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -152,6 +162,8 @@ roster_clear(void)
|
|||||||
g_hash_table_destroy(contacts);
|
g_hash_table_destroy(contacts);
|
||||||
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
|
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free,
|
||||||
(GDestroyNotify)p_contact_free);
|
(GDestroyNotify)p_contact_free);
|
||||||
|
g_hash_table_destroy(handle_to_jid);
|
||||||
|
handle_to_jid = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -180,19 +192,19 @@ roster_add(const char * const barejid, const char * const name,
|
|||||||
contact = p_contact_new(barejid, name, subscription, offline_message,
|
contact = p_contact_new(barejid, name, subscription, offline_message,
|
||||||
pending_out);
|
pending_out);
|
||||||
g_hash_table_insert(contacts, strdup(barejid), contact);
|
g_hash_table_insert(contacts, strdup(barejid), contact);
|
||||||
|
if (name != NULL) {
|
||||||
|
autocomplete_add(ac, strdup(name));
|
||||||
|
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
||||||
|
} else {
|
||||||
autocomplete_add(ac, strdup(barejid));
|
autocomplete_add(ac, strdup(barejid));
|
||||||
|
g_hash_table_insert(handle_to_jid, strdup(barejid), strdup(barejid));
|
||||||
|
}
|
||||||
added = TRUE;
|
added = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return added;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
roster_remove(const char * const barejid)
|
|
||||||
{
|
|
||||||
g_hash_table_remove(contacts, barejid);
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
roster_update_presence(const char * const barejid, Resource *resource,
|
roster_update_presence(const char * const barejid, Resource *resource,
|
||||||
GDateTime *last_activity)
|
GDateTime *last_activity)
|
||||||
@ -243,6 +255,22 @@ roster_change_handle(const char * const barejid, const char * const handle)
|
|||||||
{
|
{
|
||||||
PContact contact = g_hash_table_lookup(contacts, barejid);
|
PContact contact = g_hash_table_lookup(contacts, barejid);
|
||||||
|
|
||||||
|
if (p_contact_name(contact) != NULL) {
|
||||||
|
autocomplete_remove(ac, p_contact_name(contact));
|
||||||
|
g_hash_table_remove(handle_to_jid, p_contact_name(contact));
|
||||||
|
} else {
|
||||||
|
autocomplete_remove(ac, barejid);
|
||||||
|
g_hash_table_remove(handle_to_jid, barejid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handle != NULL) {
|
||||||
|
autocomplete_add(ac, strdup(handle));
|
||||||
|
g_hash_table_insert(handle_to_jid, strdup(handle), strdup(barejid));
|
||||||
|
} else {
|
||||||
|
autocomplete_add(ac, strdup(barejid));
|
||||||
|
g_hash_table_insert(handle_to_jid, strdup(barejid), strdup(barejid));
|
||||||
|
}
|
||||||
|
|
||||||
if (contact != NULL) {
|
if (contact != NULL) {
|
||||||
p_contact_set_name(contact, handle);
|
p_contact_set_name(contact, handle);
|
||||||
}
|
}
|
||||||
@ -262,10 +290,29 @@ roster_update(const char * const barejid, const char * const name,
|
|||||||
|
|
||||||
if (contact == NULL) {
|
if (contact == NULL) {
|
||||||
contact = p_contact_new(barejid, name, subscription, NULL, pending_out);
|
contact = p_contact_new(barejid, name, subscription, NULL, pending_out);
|
||||||
|
autocomplete_add(ac, strdup(name));
|
||||||
|
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
||||||
g_hash_table_insert(contacts, strdup(barejid), contact);
|
g_hash_table_insert(contacts, strdup(barejid), contact);
|
||||||
} else {
|
} else {
|
||||||
p_contact_set_subscription(contact, subscription);
|
p_contact_set_subscription(contact, subscription);
|
||||||
p_contact_set_pending_out(contact, pending_out);
|
p_contact_set_pending_out(contact, pending_out);
|
||||||
|
|
||||||
|
if (p_contact_name(contact) == NULL) {
|
||||||
|
if (name != NULL) {
|
||||||
|
autocomplete_add(ac, strdup(name));
|
||||||
|
autocomplete_remove(ac, barejid);
|
||||||
|
g_hash_table_remove(handle_to_jid, barejid);
|
||||||
|
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (name != NULL) {
|
||||||
|
autocomplete_add(ac, strdup(name));
|
||||||
|
autocomplete_remove(ac, p_contact_name(contact));
|
||||||
|
g_hash_table_remove(handle_to_jid, p_contact_name(contact));
|
||||||
|
g_hash_table_insert(handle_to_jid, strdup(name), strdup(barejid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
p_contact_set_name(contact, name);
|
p_contact_set_name(contact, name);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
void roster_add_handlers(void);
|
void roster_add_handlers(void);
|
||||||
void roster_request(void);
|
void roster_request(void);
|
||||||
|
|
||||||
void roster_remove(const char * const barejid);
|
|
||||||
void roster_update(const char * const barejid, const char * const name,
|
void roster_update(const char * const barejid, const char * const name,
|
||||||
const char * const subscription, gboolean pending_out);
|
const char * const subscription, gboolean pending_out);
|
||||||
|
|
||||||
|
@ -141,5 +141,6 @@ gboolean roster_add(const char * const barejid, const char * const name,
|
|||||||
const char * const subscription, const char * const offline_message,
|
const char * const subscription, const char * const offline_message,
|
||||||
gboolean pending_out);
|
gboolean pending_out);
|
||||||
void roster_change_handle(const char * const barejid, const char * const handle);
|
void roster_change_handle(const char * const barejid, const char * const handle);
|
||||||
|
char * roster_jid_from_handle(const char * const handle);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user