(irc) Support creating one-on-one chats/PMs

This commit is contained in:
Jaidyn Ann 2021-08-15 20:44:34 -05:00
parent b380b6115c
commit e8e78eeae4
2 changed files with 38 additions and 2 deletions

View File

@ -146,8 +146,32 @@ IrcProtocol::Process(BMessage* msg)
} }
break; break;
} }
case IM_ROOM_INVITE_ACCEPT: case IM_CREATE_CHAT:
{
BString user_id;
if (msg->FindString("user_id", &user_id) != B_OK)
break;
BString user_name = _IdentNick(user_id);
if (user_name != user_id) {
BMessage created(IM_MESSAGE);
created.AddInt32("im_what", IM_CHAT_CREATED);
created.AddString("chat_id", user_name);
created.AddString("user_id", user_id);
_SendMsg(&created);
break;
}
fWhoIm = user_id;
BString cmd("WHO ");
cmd << user_id << "\n";
_SendIrc(cmd);
break;
}
case IM_JOIN_ROOM: case IM_JOIN_ROOM:
case IM_CREATE_ROOM:
case IM_ROOM_INVITE_ACCEPT:
{ {
BString chat_id; BString chat_id;
if (msg->FindString("chat_id", &chat_id) == B_OK) { if (msg->FindString("chat_id", &chat_id) == B_OK) {
@ -333,6 +357,16 @@ IrcProtocol::_ProcessNumeric(int32 numeric, BString sender, BStringList params,
fIdentNicks.AddItem(ident, nick); fIdentNicks.AddItem(ident, nick);
_SendMsg(&user); _SendMsg(&user);
} }
// Here, used in the creation of a one-on-one chat
else if (fWhoIm == user || fWhoIm == nick) {
fWhoIm = "";
BMessage created(IM_MESSAGE);
created.AddInt32("im_what", IM_CHAT_CREATED);
created.AddString("chat_id", nick);
created.AddString("user_id", ident);
fIdentNicks.AddItem(ident, nick);
_SendMsg(&created);
}
break; break;
} }
case RPL_ENDOFWHO: case RPL_ENDOFWHO:
@ -617,7 +651,7 @@ IrcProtocol::_SendMsg(BMessage* msg)
msg->AddString("protocol", Signature()); msg->AddString("protocol", Signature());
if (fReady == true) if (fReady == true)
fMessenger->SendMessage(msg); fMessenger->SendMessage(msg);
else { else if (DEBUG_ENABLED == true) {
std::cout << "Tried sending message when not ready: \n"; std::cout << "Tried sending message when not ready: \n";
msg->PrintToStream(); msg->PrintToStream();
} }

View File

@ -114,6 +114,8 @@ private:
// WHOREPLY is requested by the add-on to populate the user-list, but the // WHOREPLY is requested by the add-on to populate the user-list, but the
// user might also use the /who command― if the user does, this is true // user might also use the /who command― if the user does, this is true
bool fWhoRequested; bool fWhoRequested;
BString fWhoIm;
bool fWriteLocked; bool fWriteLocked;
StringMap fIdentNicks; // User ident → nick StringMap fIdentNicks; // User ident → nick