mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Create chat session on send if none exists
This commit is contained in:
parent
d339004f55
commit
bee708c9d2
@ -52,6 +52,18 @@ chat_sessions_clear(void)
|
|||||||
g_hash_table_remove_all(sessions);
|
g_hash_table_remove_all(sessions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
chat_session_exists(const char * const recipient)
|
||||||
|
{
|
||||||
|
ChatSession session = g_hash_table_lookup(sessions, recipient);
|
||||||
|
|
||||||
|
if (session != NULL) {
|
||||||
|
return TRUE;
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
chat_session_start(const char * const recipient, gboolean recipient_supports)
|
chat_session_start(const char * const recipient, gboolean recipient_supports)
|
||||||
{
|
{
|
||||||
|
@ -31,6 +31,7 @@ void chat_sessions_init(void);
|
|||||||
void chat_sessions_clear(void);
|
void chat_sessions_clear(void);
|
||||||
void chat_session_start(const char * const recipient,
|
void chat_session_start(const char * const recipient,
|
||||||
gboolean recipient_supports);
|
gboolean recipient_supports);
|
||||||
|
gboolean chat_session_exists(const char * const recipient);
|
||||||
void chat_session_end(const char * const recipient);
|
void chat_session_end(const char * const recipient);
|
||||||
gboolean chat_session_recipient_supports(const char * const recipient);
|
gboolean chat_session_recipient_supports(const char * const recipient);
|
||||||
|
|
||||||
|
17
src/jabber.c
17
src/jabber.c
@ -137,16 +137,16 @@ jabber_process_events(void)
|
|||||||
void
|
void
|
||||||
jabber_send(const char * const msg, const char * const recipient)
|
jabber_send(const char * const msg, const char * const recipient)
|
||||||
{
|
{
|
||||||
|
if (!chat_session_exists(recipient)) {
|
||||||
|
chat_session_start(recipient, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
char *coded_msg = str_replace(msg, "&", "&");
|
char *coded_msg = str_replace(msg, "&", "&");
|
||||||
char *coded_msg2 = str_replace(coded_msg, "<", "<");
|
char *coded_msg2 = str_replace(coded_msg, "<", "<");
|
||||||
char *coded_msg3 = str_replace(coded_msg2, ">", ">");
|
char *coded_msg3 = str_replace(coded_msg2, ">", ">");
|
||||||
|
|
||||||
xmpp_stanza_t *reply, *body, *text, *active;
|
xmpp_stanza_t *reply, *body, *text, *active;
|
||||||
|
|
||||||
active = xmpp_stanza_new(jabber_conn.ctx);
|
|
||||||
xmpp_stanza_set_name(active, "active");
|
|
||||||
xmpp_stanza_set_ns(active, "http://jabber.org/protocol/chatstates");
|
|
||||||
|
|
||||||
reply = xmpp_stanza_new(jabber_conn.ctx);
|
reply = xmpp_stanza_new(jabber_conn.ctx);
|
||||||
xmpp_stanza_set_name(reply, "message");
|
xmpp_stanza_set_name(reply, "message");
|
||||||
xmpp_stanza_set_type(reply, "chat");
|
xmpp_stanza_set_type(reply, "chat");
|
||||||
@ -157,7 +157,14 @@ jabber_send(const char * const msg, const char * const recipient)
|
|||||||
|
|
||||||
text = xmpp_stanza_new(jabber_conn.ctx);
|
text = xmpp_stanza_new(jabber_conn.ctx);
|
||||||
xmpp_stanza_set_text(text, coded_msg3);
|
xmpp_stanza_set_text(text, coded_msg3);
|
||||||
xmpp_stanza_add_child(reply, active);
|
|
||||||
|
if (chat_session_recipient_supports(recipient)) {
|
||||||
|
active = xmpp_stanza_new(jabber_conn.ctx);
|
||||||
|
xmpp_stanza_set_name(active, "active");
|
||||||
|
xmpp_stanza_set_ns(active, "http://jabber.org/protocol/chatstates");
|
||||||
|
xmpp_stanza_add_child(reply, active);
|
||||||
|
}
|
||||||
|
|
||||||
xmpp_stanza_add_child(body, text);
|
xmpp_stanza_add_child(body, text);
|
||||||
xmpp_stanza_add_child(reply, body);
|
xmpp_stanza_add_child(reply, body);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user