(irc) Sending/receiving invites

This commit is contained in:
Jaidyn Ann 2021-08-10 00:03:28 -05:00
parent adee8d6181
commit d0367db0bb
2 changed files with 44 additions and 0 deletions

View File

@ -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)
{

View File

@ -8,11 +8,18 @@
#include <String.h>
#include <StringList.h>
#include <libsupport/KeyMap.h>
#include <ChatProtocol.h>
typedef KeyMap<BString, BString> 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;