diff --git a/protocols/irc/IrcProtocol.cpp b/protocols/irc/IrcProtocol.cpp index 20c20d2..fa5bb3e 100644 --- a/protocols/irc/IrcProtocol.cpp +++ b/protocols/irc/IrcProtocol.cpp @@ -137,6 +137,7 @@ IrcProtocol::Process(BMessage* msg) } break; } + case IM_ROOM_INVITE_ACCEPT: case IM_JOIN_ROOM: { BString chat_id; @@ -170,6 +171,17 @@ IrcProtocol::Process(BMessage* msg) } break; } + case IM_ROOM_SEND_INVITE: + { + BString chat_id = msg->FindString("chat_id"); + BString user_id = msg->FindString("user_id"); + if (chat_id.IsEmpty() == false || user_id.IsEmpty() == false) { + BString cmd("INVITE "); + cmd << _IdentNick(user_id) << " " << chat_id << "\n"; + _SendIrc(cmd); + } + break; + } default: std::cerr << "Unhandled message for IRC:\n"; msg->PrintToStream(); @@ -271,6 +283,7 @@ IrcProtocol::_ProcessNumeric(int32 numeric, BString sender, BStringList params) user.AddString("chat_id", channel); user.AddString("user_id", ident); user.AddString("user_name", nick); + fIdentNicks.AddItem(ident, nick); _SendMsg(&user); } break; @@ -394,6 +407,7 @@ IrcProtocol::_ProcessCommand(BString command, BString sender, joined.AddInt32("im_what", IM_ROOM_PARTICIPANT_JOINED); joined.AddString("user_id", _SenderIdent(sender)); joined.AddString("user_name", _SenderNick(sender)); + fIdentNicks.AddItem(_SenderIdent(sender), _SenderNick(sender)); } _SendMsg(&joined); } @@ -416,6 +430,14 @@ IrcProtocol::_ProcessCommand(BString command, BString sender, } _SendMsg(&left); } + else if (command == "INVITE") + { + BMessage invite(IM_MESSAGE); + invite.AddInt32("im_what", IM_ROOM_INVITE_RECEIVED); + invite.AddString("chat_id", params.Last()); + invite.AddString("user_id", _SenderIdent(sender)); + _SendMsg(&invite); + } } @@ -501,6 +523,17 @@ IrcProtocol::_SenderIdent(BString sender) } +BString +IrcProtocol::_IdentNick(BString ident) +{ + bool found = false; + BString nick = fIdentNicks.ValueFor(ident, &found); + if (found == true) + return nick; + return ident; +} + + BString IrcProtocol::_ReadUntilNewline(BDataIO* io, BString* extraBuffer) { diff --git a/protocols/irc/IrcProtocol.h b/protocols/irc/IrcProtocol.h index 6d9a0c7..4b7f64f 100644 --- a/protocols/irc/IrcProtocol.h +++ b/protocols/irc/IrcProtocol.h @@ -8,11 +8,18 @@ #include #include +#include + #include + +typedef KeyMap StringMap; + + class BSocket; class BDataIO; + class IrcProtocol : public ChatProtocol { public: IrcProtocol(); @@ -65,6 +72,8 @@ private: BString _SenderNick(BString sender); BString _SenderIdent(BString sender); + BString _IdentNick(BString ident); + // Read a data stream until newline found; if data found past // newline, append to given buffer for later use BString _ReadUntilNewline(BDataIO* data, BString* extraBuffer); @@ -88,6 +97,8 @@ private: // user might also use the /who command― if the user does, this is true bool fWhoRequested; + StringMap fIdentNicks; // User ident → nick + BPath fAddOnPath; BString fName; ChatProtocolMessengerInterface* fMessenger;