1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Merge branch 'master' into pgp

This commit is contained in:
James Booth 2015-04-21 22:08:00 +01:00
commit ebca38e224
3 changed files with 58 additions and 51 deletions

View File

@ -84,8 +84,6 @@ extern GHashTable *commands;
gboolean gboolean
cmd_execute_default(const char * inp) cmd_execute_default(const char * inp)
{ {
jabber_conn_status_t status = jabber_get_connection_status();
// handle escaped commands - treat as normal message // handle escaped commands - treat as normal message
if (g_str_has_prefix(inp, "//")) { if (g_str_has_prefix(inp, "//")) {
inp++; inp++;
@ -97,46 +95,40 @@ cmd_execute_default(const char * inp)
return TRUE; return TRUE;
} }
win_type_t win_type = ui_current_win_type(); // handle non commands in non chat windows
switch (win_type) ProfWin *current = wins_get_current();
if (current->type != WIN_CHAT && current->type != WIN_MUC && current->type != WIN_PRIVATE) {
cons_show("Unknown command: %s", inp);
return TRUE;
}
jabber_conn_status_t status = jabber_get_connection_status();
if (status != JABBER_CONNECTED) {
ui_current_print_line("You are not currently connected.");
return TRUE;
}
switch (current->type) {
case WIN_CHAT:
{ {
case WIN_MUC: ProfChatWin *chatwin = wins_get_current_chat();
if (status != JABBER_CONNECTED) { client_send_msg(chatwin->barejid, inp);
ui_current_print_line("You are not currently connected."); break;
} else { }
ProfMucWin *mucwin = wins_get_current_muc(); case WIN_PRIVATE:
message_send_groupchat(mucwin->roomjid, inp); {
} ProfPrivateWin *privatewin = wins_get_current_private();
break; client_send_priv_msg(privatewin->fulljid, inp);
break;
case WIN_CHAT: }
if (status != JABBER_CONNECTED) { case WIN_MUC:
ui_current_print_line("You are not currently connected."); {
} else { ProfMucWin *mucwin = wins_get_current_muc();
ProfWin *current = wins_get_current(); client_send_muc_msg(mucwin->roomjid, inp);
ProfChatWin *chatwin = (ProfChatWin*)current; break;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); }
client_msg_send(chatwin->barejid, inp); default:
} break;
break;
case WIN_PRIVATE:
if (status != JABBER_CONNECTED) {
ui_current_print_line("You are not currently connected.");
} else {
ProfPrivateWin *privatewin = wins_get_current_private();
message_send_private(privatewin->fulljid, inp);
ui_outgoing_private_msg(privatewin->fulljid, inp);
}
break;
case WIN_CONSOLE:
case WIN_XML:
cons_show("Unknown command: %s", inp);
break;
default:
break;
} }
return TRUE; return TRUE;
@ -1333,6 +1325,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
return TRUE; return TRUE;
} }
// send private message when in MUC room
if (win_type == WIN_MUC) { if (win_type == WIN_MUC) {
ProfMucWin *mucwin = wins_get_current_muc(); ProfMucWin *mucwin = wins_get_current_muc();
if (muc_roster_contains_nick(mucwin->roomjid, usr)) { if (muc_roster_contains_nick(mucwin->roomjid, usr)) {
@ -1340,9 +1333,8 @@ cmd_msg(gchar **args, struct cmd_help_t help)
g_string_append(full_jid, "/"); g_string_append(full_jid, "/");
g_string_append(full_jid, usr); g_string_append(full_jid, usr);
if (msg != NULL) { if (msg) {
message_send_private(full_jid->str, msg); client_send_priv_msg(full_jid->str, msg);
ui_outgoing_private_msg(full_jid->str, msg);
} else { } else {
ui_new_private_win(full_jid->str); ui_new_private_win(full_jid->str);
} }
@ -1355,6 +1347,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
return TRUE; return TRUE;
// send chat message
} else { } else {
char *barejid = roster_barejid_from_name(usr); char *barejid = roster_barejid_from_name(usr);
if (barejid == NULL) { if (barejid == NULL) {
@ -1362,7 +1355,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
} }
if (msg) { if (msg) {
client_msg_send(barejid, msg); client_send_msg(barejid, msg);
return TRUE; return TRUE;
} else { } else {
ui_new_chat_win(barejid); ui_new_chat_win(barejid);
@ -3170,20 +3163,19 @@ cmd_tiny(gchar **args, struct cmd_help_t help)
case WIN_CHAT: case WIN_CHAT:
{ {
ProfChatWin *chatwin = wins_get_current_chat(); ProfChatWin *chatwin = wins_get_current_chat();
client_msg_send(chatwin->barejid, tiny); client_send_msg(chatwin->barejid, tiny);
break; break;
} }
case WIN_PRIVATE: case WIN_PRIVATE:
{ {
ProfPrivateWin *privatewin = wins_get_current_private(); ProfPrivateWin *privatewin = wins_get_current_private();
message_send_private(privatewin->fulljid, tiny); client_send_priv_msg(privatewin->fulljid, tiny);
ui_outgoing_private_msg(privatewin->fulljid, tiny);
break; break;
} }
case WIN_MUC: case WIN_MUC:
{ {
ProfMucWin *mucwin = wins_get_current_muc(); ProfMucWin *mucwin = wins_get_current_muc();
message_send_groupchat(mucwin->roomjid, tiny); client_send_muc_msg(mucwin->roomjid, tiny);
break; break;
} }
default: default:

View File

@ -43,7 +43,7 @@
#endif #endif
void void
client_msg_send(const char * const barejid, const char * const msg) client_send_msg(const char * const barejid, const char * const msg)
{ {
char *id = NULL; char *id = NULL;
@ -83,4 +83,17 @@ client_msg_send(const char * const barejid, const char * const msg)
#endif #endif
free(id); free(id);
}
void
client_send_muc_msg(const char * const roomjid, const char * const msg)
{
message_send_groupchat(roomjid, msg);
}
void
client_send_priv_msg(const char * const fulljid, const char * const msg)
{
message_send_private(fulljid, msg);
ui_outgoing_private_msg(fulljid, msg);
} }

View File

@ -35,6 +35,8 @@
#ifndef CLIENT_EVENTS_H #ifndef CLIENT_EVENTS_H
#define CLIENT_EVENTS_H #define CLIENT_EVENTS_H
void client_msg_send(const char * const barejid, const char * const msg); void client_send_msg(const char * const barejid, const char * const msg);
void client_send_muc_msg(const char * const roomjid, const char * const msg);
void client_send_priv_msg(const char * const fulljid, const char * const msg);
#endif #endif