(purple) Sending messages to chats

This commit is contained in:
Jaidyn Ann 2021-06-28 12:51:50 -05:00
parent 82cf946bc8
commit 06b1df8882
2 changed files with 60 additions and 0 deletions

View File

@ -152,7 +152,23 @@ PurpleApp::ImMessage(BMessage* msg)
purple_account_set_status(account, primId, true); purple_account_set_status(account, primId, true);
break; break;
} }
case IM_SEND_MESSAGE:
{
BString body;
if (msg->FindString("body", &body) != B_OK) return;
PurpleConversation* conv = _ConversationFromMessage(msg);
PurpleConvChat* chat = purple_conversation_get_chat_data(conv);
PurpleConvIm* im = purple_conversation_get_im_data(conv);
if (chat != NULL)
purple_conv_chat_send(chat, body.String());
else if (im != NULL)
purple_conv_im_send(im, body.String());
break;
}
default: default:
std::cout << "IM_MESSAGE unhandled by Purple:\n";
msg->PrintToStream(); msg->PrintToStream();
} }
} }
@ -410,6 +426,17 @@ PurpleApp::_AccountFromMessage(BMessage* msg)
} }
PurpleConversation*
PurpleApp::_ConversationFromMessage(BMessage* msg)
{
PurpleAccount* account = _AccountFromMessage(msg);
BString chat_id = msg->FindString("chat_id");
return purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY,
chat_id.String(), account);
}
static PurpleEventLoopUiOps _glib_eventloops = static PurpleEventLoopUiOps _glib_eventloops =
{ {
g_timeout_add, g_timeout_add,
@ -541,6 +568,34 @@ signal_received_chat_msg(PurpleAccount* account, char* sender, char* message,
} }
static void
signal_sent_chat_msg(PurpleAccount* account, const char* message, int conv_id)
{
PurpleConnection* gc = purple_account_get_connection(account);
PurpleConversation* conv = purple_find_chat(gc, conv_id);
BMessage sent(IM_MESSAGE);
sent.AddInt32("im_what", IM_MESSAGE_SENT);
sent.AddString("chat_id", purple_conversation_get_name(conv));
sent.AddString("user_id", purple_account_get_username(account));
sent.AddString("body", message);
((PurpleApp*)be_app)->SendMessage(account, sent);
}
static void
signal_sent_im_msg(PurpleAccount* account, const char* receiver,
const char* message)
{
BMessage sent(IM_MESSAGE);
sent.AddInt32("im_what", IM_MESSAGE_SENT);
sent.AddString("chat_id", receiver);
sent.AddString("user_id", purple_account_get_username(account));
sent.AddString("body", message);
((PurpleApp*)be_app)->SendMessage(account, sent);
}
PurpleStatusPrimitive PurpleStatusPrimitive
cardie_status_to_purple(UserStatus status) cardie_status_to_purple(UserStatus status)
{ {

View File

@ -87,6 +87,7 @@ private:
PurplePlugin* _PluginFromMessage(BMessage* msg); PurplePlugin* _PluginFromMessage(BMessage* msg);
PurpleAccount* _AccountFromMessage(BMessage* msg); PurpleAccount* _AccountFromMessage(BMessage* msg);
PurpleConversation* _ConversationFromMessage(BMessage* msg);
Accounts fAccounts; Accounts fAccounts;
AccountThreads fAccountThreads; AccountThreads fAccountThreads;
@ -115,6 +116,10 @@ private:
static void signal_received_chat_msg(PurpleAccount* account, static void signal_received_chat_msg(PurpleAccount* account,
char* sender, char* message, char* sender, char* message,
PurpleConversation* conv, PurpleMessageFlags flags); PurpleConversation* conv, PurpleMessageFlags flags);
static void signal_sent_chat_msg(PurpleAccount* account,
const char* message, int conv_id);
static void signal_sent_im_msg(PurpleAccount* account,
const char* receiver, const char* message);
// Util // Util
PurpleStatusPrimitive cardie_status_to_purple(UserStatus status); PurpleStatusPrimitive cardie_status_to_purple(UserStatus status);