(irc) Handling of QUIT

This commit is contained in:
Jaidyn Ann 2021-08-11 18:51:41 -05:00
parent ca704cb7b8
commit 3f754bd79d
2 changed files with 35 additions and 8 deletions

View File

@ -14,6 +14,7 @@
#include <libinterface/BitmapUtils.h> #include <libinterface/BitmapUtils.h>
#include <AppConstants.h>
#include <ChatProtocolMessages.h> #include <ChatProtocolMessages.h>
#include <Flags.h> #include <Flags.h>
@ -204,7 +205,7 @@ IrcProtocol::Process(BMessage* msg)
break; break;
} }
default: default:
std::cerr << "Unhandled message for IRC:\n"; std::cout << "Unhandled message for IRC:\n";
msg->PrintToStream(); msg->PrintToStream();
return B_ERROR; return B_ERROR;
} }
@ -419,6 +420,8 @@ IrcProtocol::_ProcessCommand(BString command, BString sender,
BString cmd("WHO "); BString cmd("WHO ");
cmd << chat_id << "\n"; cmd << chat_id << "\n";
_SendIrc(cmd); _SendIrc(cmd);
fChannels.Add(chat_id);
} }
else { else {
joined.AddInt32("im_what", IM_ROOM_PARTICIPANT_JOINED); joined.AddInt32("im_what", IM_ROOM_PARTICIPANT_JOINED);
@ -428,18 +431,19 @@ IrcProtocol::_ProcessCommand(BString command, BString sender,
} }
_SendMsg(&joined); _SendMsg(&joined);
} }
else if (command == "PART" || command == "QUIT") else if (command == "PART")
{ {
BString chat_id = params.First();
BString body = B_TRANSLATE("left: "); BString body = B_TRANSLATE("left: ");
if (command == "QUIT")
body = B_TRANSLATE("quit: ");
body << params.Last(); body << params.Last();
BMessage left(IM_MESSAGE); BMessage left(IM_MESSAGE);
left.AddString("chat_id",params.First()); left.AddString("chat_id", chat_id);
left.AddString("body", body); left.AddString("body", body);
if (_SenderIdent(sender) == fIdent) if (_SenderIdent(sender) == fIdent) {
left.AddInt32("im_what", IM_ROOM_LEFT); left.AddInt32("im_what", IM_ROOM_LEFT);
fChannels.Remove(chat_id);
}
else { else {
left.AddInt32("im_what", IM_ROOM_PARTICIPANT_LEFT); left.AddInt32("im_what", IM_ROOM_PARTICIPANT_LEFT);
left.AddString("user_id", _SenderIdent(sender)); left.AddString("user_id", _SenderIdent(sender));
@ -447,6 +451,26 @@ IrcProtocol::_ProcessCommand(BString command, BString sender,
} }
_SendMsg(&left); _SendMsg(&left);
} }
else if (command == "QUIT")
{
BString body = B_TRANSLATE("quit: ");
body << params.Last();
for (int i = 0; i < fChannels.CountStrings(); i++) {
BMessage left(IM_MESSAGE);
left.AddInt32("im_what", IM_ROOM_PARTICIPANT_LEFT);
left.AddString("user_id", _SenderIdent(sender));
left.AddString("user_name", _SenderNick(sender));
left.AddString("chat_id", fChannels.StringAt(i));
_SendMsg(&left);
}
BMessage status(IM_MESSAGE);
status.AddInt32("im_what", IM_USER_STATUS_SET);
status.AddString("user_id", _SenderIdent(sender));
status.AddInt32("status", STATUS_OFFLINE);
_SendMsg(&status);
}
else if (command == "INVITE") else if (command == "INVITE")
{ {
BMessage invite(IM_MESSAGE); BMessage invite(IM_MESSAGE);
@ -546,7 +570,7 @@ IrcProtocol::_SendMsg(BMessage* msg)
if (fReady == true) if (fReady == true)
fMessenger->SendMessage(msg); fMessenger->SendMessage(msg);
else { else {
std::cerr << "Tried sending message when not ready: \n"; std::cout << "Tried sending message when not ready: \n";
msg->PrintToStream(); msg->PrintToStream();
} }
} }
@ -624,7 +648,8 @@ IrcProtocol::_ReadUntilNewline(BDataIO* io, BString* extraBuffer)
while (!(strstr(buf, "\n"))) { while (!(strstr(buf, "\n"))) {
io->Read(buf, 1023); io->Read(buf, 1023);
std::cerr << buf << std::endl; std::cerr << buf << std::endl;
total << buf; if (DEBUG_ENABLED)
total << buf;
} }
BString currentLine = _TrimStringToNewline(&total); BString currentLine = _TrimStringToNewline(&total);

View File

@ -106,6 +106,8 @@ private:
StringMap fIdentNicks; // User ident → nick StringMap fIdentNicks; // User ident → nick
BStringList fChannels;
BPath fAddOnPath; BPath fAddOnPath;
BString fName; BString fName;
ChatProtocolMessengerInterface* fMessenger; ChatProtocolMessengerInterface* fMessenger;