(irc) Public room directory/list support

This commit is contained in:
Jaidyn Ann 2021-08-27 00:25:41 -05:00
parent 10b63e4138
commit 5dbbb3a8ad
3 changed files with 51 additions and 2 deletions

View File

@ -262,8 +262,8 @@ enum im_what_code {
/*! Quietly add user(s) to the chat →App
Shouldn't be sent automatically on joining a room.
Requires: String "chat_id", StringList "user_id"
Accepts: StringList "user_name" */
Requires: String "chat_id", Strings "user_id"
Accepts: Strings "user_name" */
IM_ROOM_PARTICIPANTS = 159,
/*! User has explicitly joined →App
@ -405,6 +405,28 @@ enum im_what_code {
IM_ROOM_PARTICIPANT_STOPPED_TYPING = 211,
/*
* Room directory messages
*/
/*! Request a list of rooms →Protocol */
IM_GET_ROOM_DIRECTORY = 230,
/*! Send a room in the directory →App
This can be used to send either a list of publically available rooms
or a list of "hidden"/"disabled" rooms, one-by-one.
A room listed thanks to this message might be joined through
IM_JOIN_ROOM. Since IM_JOIN_ROOM accepts slots from the template, you
must fill in IM_ROOM_DIRECTORY messages with any required custom slots
you use for room-joining the message you send will be actually be
copied and sent back verbatim (with im_what changed to IM_JOIN_ROOM)
to join.
Requires: Strings "chat_id"
Allows: String "chat_name", String "subject", int32 "user_count"*/
IM_ROOM_DIRECTORY = 231,
/*
* Misc. UI messages
*/

View File

@ -118,6 +118,8 @@ IrcProtocol::Process(BMessage* msg)
fWhoIsRequested = true;
else if (command.ICompare("WHO") == 0)
fWhoRequested = true;
else if (command.ICompare("LIST") == 0)
fListRequested = true;
_SendIrc(line);
break;
@ -352,6 +354,12 @@ IrcProtocol::Process(BMessage* msg)
_SendMsg(&info);
break;
}
case IM_GET_ROOM_DIRECTORY:
{
BString cmd("LIST");
_SendIrc(cmd);
break;
}
case IM_SET_ROOM_SUBJECT:
{
BString chat_id;
@ -441,6 +449,7 @@ IrcProtocol::Connect()
status_t
IrcProtocol::Loop()
{
fListRequested = false;
fWhoIsRequested = false;
fWhoRequested = false;
while (fSocket != NULL && fSocket->IsConnected() == true)
@ -597,6 +606,20 @@ IrcProtocol::_ProcessNumeric(int32 numeric, BString sender, BStringList params,
}
break;
}
case RPL_LIST:
{
BString chat_id = params.StringAt(1);
BString subject = params.Last();
int32 count = atoi(params.StringAt(2));
BMessage dir(IM_MESSAGE);
dir.AddInt32("im_what", IM_ROOM_DIRECTORY);
dir.AddString("chat_id", chat_id);
dir.AddString("subject", subject);
dir.AddInt32("user_count", count);
_SendMsg(&dir);
break;
}
case RPL_TOPIC:
{
BString chat_id = params.StringAt(1);
@ -613,6 +636,9 @@ IrcProtocol::_ProcessNumeric(int32 numeric, BString sender, BStringList params,
// Now, to determine if the line should be sent to system buffer
switch (numeric) {
case RPL_LISTEND:
fListRequested = false;
break;
case RPL_ENDOFWHO:
fWhoRequested = false;
break;

View File

@ -138,6 +138,7 @@ private:
// user might also use the /who command― if the user does, this is true
bool fWhoRequested;
bool fWhoIsRequested;
bool fListRequested;
BString fWhoIm;
bool fWriteLocked;