1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-23 21:45:30 +00:00

Added xmpp_message.c

This commit is contained in:
James Booth 2013-01-29 00:21:04 +00:00
parent 0b7a0531d0
commit b269ac9702
5 changed files with 61 additions and 30 deletions

View File

@ -7,7 +7,7 @@ profanity_SOURCES = src/command.c src/contact.c src/command_history.c src/xmpp.h
src/history.c src/ui.h src/common.h src/ contact_list.h src/xmpp_conn.c \
src/main.c src/profanity.h src/history.h src/xmpp_presence.c \
src/tinyurl.c src/tinyurl.h src/chat_session.c \
src/chat_session.h src/muc.c \
src/chat_session.h src/muc.c src/xmpp_message.c \
src/muc.h src/xmpp_stanza.c src/command_parser.c \
src/theme.c src/theme.h src/window.c src/window.h \
src/files.c src/files.h src/accounts.c src/accounts.h \

View File

@ -909,7 +909,7 @@ cmd_execute_default(const char * const inp)
win_current_show("You are not currently connected.");
} else {
char *recipient = win_current_get_recipient();
jabber_send(inp, recipient);
message_send(inp, recipient);
if (win_current_is_chat() && prefs_get_chlog()) {
const char *jid = jabber_get_jid();
@ -1669,7 +1669,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
g_string_append(full_jid, usr);
if (msg != NULL) {
jabber_send(msg, full_jid->str);
message_send(msg, full_jid->str);
win_show_outgoing_msg("me", full_jid->str, msg);
} else {
win_new_chat_win(full_jid->str);
@ -1685,7 +1685,7 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
} else {
if (msg != NULL) {
jabber_send(msg, usr);
message_send(msg, usr);
win_show_outgoing_msg("me", usr, msg);
if (win_current_is_chat() && prefs_get_chlog()) {
@ -1882,7 +1882,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help)
if (tiny != NULL) {
if (win_current_is_chat()) {
char *recipient = win_current_get_recipient();
jabber_send(tiny, recipient);
message_send(tiny, recipient);
if (prefs_get_chlog()) {
const char *jid = jabber_get_jid();
@ -1893,7 +1893,7 @@ _cmd_tiny(gchar **args, struct cmd_help_t help)
free(recipient);
} else if (win_current_is_private()) {
char *recipient = win_current_get_recipient();
jabber_send(tiny, recipient);
message_send(tiny, recipient);
win_show_outgoing_msg("me", recipient, tiny);
free(recipient);
} else { // groupchat

View File

@ -146,7 +146,6 @@ jabber_conn_status_t jabber_connect_with_account(ProfAccount *account,
const char * const passwd);
void jabber_disconnect(void);
void jabber_process_events(void);
void jabber_send(const char * const msg, const char * const recipient);
void jabber_send_groupchat(const char * const msg, const char * const recipient);
void jabber_send_inactive(const char * const recipient);
void jabber_send_composing(const char * const recipient);
@ -168,6 +167,9 @@ void jabber_conn_set_priority(int priority);
void jabber_conn_set_status(const char * const message);
char* jabber_get_account_name(void);
// message functions
void message_send(const char * const msg, const char * const recipient);
// iq functions
void iq_add_handlers(void);

View File

@ -241,29 +241,6 @@ jabber_process_events(void)
}
void
jabber_send(const char * const msg, const char * const recipient)
{
if (prefs_get_states()) {
if (!chat_session_exists(recipient)) {
chat_session_start(recipient, TRUE);
}
}
xmpp_stanza_t *message;
if (prefs_get_states() && chat_session_get_recipient_supports(recipient)) {
chat_session_set_active(recipient);
message = stanza_create_message(jabber_conn.ctx, recipient, STANZA_TYPE_CHAT,
msg, STANZA_NAME_ACTIVE);
} else {
message = stanza_create_message(jabber_conn.ctx, recipient, STANZA_TYPE_CHAT,
msg, NULL);
}
xmpp_send(jabber_conn.conn, message);
xmpp_stanza_release(message);
}
void
jabber_send_groupchat(const char * const msg, const char * const recipient)
{

52
src/xmpp_message.c Normal file
View File

@ -0,0 +1,52 @@
/*
* xmpp_message.c
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <strophe.h>
#include "chat_session.h"
#include "preferences.h"
#include "xmpp.h"
void
message_send(const char * const msg, const char * const recipient)
{
xmpp_conn_t * const conn = jabber_get_conn();
xmpp_ctx_t * const ctx = jabber_get_ctx();
if (prefs_get_states()) {
if (!chat_session_exists(recipient)) {
chat_session_start(recipient, TRUE);
}
}
xmpp_stanza_t *message;
if (prefs_get_states() && chat_session_get_recipient_supports(recipient)) {
chat_session_set_active(recipient);
message = stanza_create_message(ctx, recipient, STANZA_TYPE_CHAT,
msg, STANZA_NAME_ACTIVE);
} else {
message = stanza_create_message(ctx, recipient, STANZA_TYPE_CHAT,
msg, NULL);
}
xmpp_send(conn, message);
xmpp_stanza_release(message);
}