1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Replace stanza_create_message with libstrophe convenience functions

This commit is contained in:
James Booth 2016-08-20 18:51:19 +01:00
parent 24c3eff428
commit 45048e3ac8
3 changed files with 21 additions and 34 deletions

View File

@ -141,7 +141,8 @@ message_send_chat(const char *const barejid, const char *const msg, const char *
char *jid = chat_session_get_jid(barejid);
char *id = create_unique_id("msg");
xmpp_stanza_t *message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
xmpp_stanza_t *message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
xmpp_message_set_body(message, msg);
free(jid);
if (state) {
@ -179,7 +180,8 @@ message_send_chat_pgp(const char *const barejid, const char *const msg, gboolean
Jid *jidp = jid_create(jid);
char *encrypted = p_gpg_encrypt(jidp->barejid, msg, account->pgp_keyid);
if (encrypted) {
message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, "This message is encrypted.");
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
xmpp_message_set_body(message, "This message is encrypted.");
xmpp_stanza_t *x = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(x, STANZA_NAME_X);
xmpp_stanza_set_ns(x, STANZA_NS_ENCRYPTED);
@ -191,15 +193,18 @@ message_send_chat_pgp(const char *const barejid, const char *const msg, gboolean
xmpp_stanza_release(x);
free(encrypted);
} else {
message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
xmpp_message_set_body(message, msg);
}
jid_destroy(jidp);
} else {
message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
xmpp_message_set_body(message, msg);
}
account_free(account);
#else
message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
xmpp_message_set_body(message, msg);
#endif
free(jid);
@ -226,7 +231,9 @@ message_send_chat_otr(const char *const barejid, const char *const msg, gboolean
char *jid = chat_session_get_jid(barejid);
char *id = create_unique_id("msg");
xmpp_stanza_t *message = stanza_create_message(ctx, id, barejid, STANZA_TYPE_CHAT, msg);
xmpp_stanza_t *message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, barejid, id);
xmpp_message_set_body(message, msg);
free(jid);
if (state) {
@ -252,7 +259,10 @@ message_send_private(const char *const fulljid, const char *const msg, const cha
{
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("prv");
xmpp_stanza_t *message = stanza_create_message(ctx, id, fulljid, STANZA_TYPE_CHAT, msg);
xmpp_stanza_t *message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, fulljid, id);
xmpp_message_set_body(message, msg);
free(id);
if (oob_url) {
@ -268,7 +278,10 @@ message_send_groupchat(const char *const roomjid, const char *const msg, const c
{
xmpp_ctx_t * const ctx = connection_get_ctx();
char *id = create_unique_id("muc");
xmpp_stanza_t *message = stanza_create_message(ctx, id, roomjid, STANZA_TYPE_GROUPCHAT, msg);
xmpp_stanza_t *message = xmpp_message_new(ctx, STANZA_TYPE_GROUPCHAT, roomjid, id);
xmpp_message_set_body(message, msg);
free(id);
if (oob_url) {

View File

@ -442,29 +442,6 @@ stanza_attach_x_oob_url(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *cons
return stanza;
}
xmpp_stanza_t*
stanza_create_message(xmpp_ctx_t *ctx, char *id, const char *const recipient,
const char *const type, const char *const message)
{
xmpp_stanza_t *msg = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE);
xmpp_stanza_set_type(msg, type);
xmpp_stanza_set_to(msg, recipient);
xmpp_stanza_set_id(msg, id);
xmpp_stanza_t *body = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(body, STANZA_NAME_BODY);
xmpp_stanza_t *text = xmpp_stanza_new(ctx);
xmpp_stanza_set_text(text, message);
xmpp_stanza_add_child(body, text);
xmpp_stanza_release(text);
xmpp_stanza_add_child(msg, body);
xmpp_stanza_release(body);
return msg;
}
xmpp_stanza_t*
stanza_create_roster_remove_set(xmpp_ctx_t *ctx, const char *const barejid)
{

View File

@ -228,9 +228,6 @@ xmpp_stanza_t* stanza_attach_hints_no_store(xmpp_ctx_t *ctx, xmpp_stanza_t *stan
xmpp_stanza_t* stanza_attach_receipt_request(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza);
xmpp_stanza_t* stanza_attach_x_oob_url(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *const url);
xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx, char *id,
const char *const recipient, const char *const type, const char *const message);
xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t *const ctx,
const char *const full_room_jid, const char *const passwd);