(irc) More reliable user-list population, IM_ROOM_GET_PARTICIPANTS
This commit is contained in:
parent
e8e78eeae4
commit
8d62ecca01
|
@ -161,9 +161,10 @@ IrcProtocol::Process(BMessage* msg)
|
||||||
_SendMsg(&created);
|
_SendMsg(&created);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// If it's not a known user, we need to get their ID/nick somehow
|
||||||
|
// … that is, through the WHO.
|
||||||
fWhoIm = user_id;
|
fWhoIm = user_id;
|
||||||
|
BString cmd("WHOIS ");
|
||||||
BString cmd("WHO ");
|
|
||||||
cmd << user_id << "\n";
|
cmd << user_id << "\n";
|
||||||
_SendIrc(cmd);
|
_SendIrc(cmd);
|
||||||
break;
|
break;
|
||||||
|
@ -212,6 +213,22 @@ IrcProtocol::Process(BMessage* msg)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case IM_GET_ROOM_PARTICIPANTS:
|
||||||
|
{
|
||||||
|
BString chat_id;
|
||||||
|
if (msg->FindString("chat_id", &chat_id) != B_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Rooms are populated with RPL_WHOREPLY, chats RPL_WHOISUSER
|
||||||
|
BString cmd;
|
||||||
|
if (_IsChannelName(chat_id) == true)
|
||||||
|
cmd = "WHO ";
|
||||||
|
else
|
||||||
|
cmd = "WHOIS ";
|
||||||
|
cmd << chat_id << "\n";
|
||||||
|
_SendIrc(cmd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case IM_ROOM_SEND_INVITE:
|
case IM_ROOM_SEND_INVITE:
|
||||||
{
|
{
|
||||||
BString chat_id = msg->FindString("chat_id");
|
BString chat_id = msg->FindString("chat_id");
|
||||||
|
@ -289,6 +306,8 @@ IrcProtocol::Connect()
|
||||||
status_t
|
status_t
|
||||||
IrcProtocol::Loop()
|
IrcProtocol::Loop()
|
||||||
{
|
{
|
||||||
|
fWhoIsRequested = false;
|
||||||
|
fWhoRequested = false;
|
||||||
while (fSocket != NULL && fSocket->IsConnected() == true)
|
while (fSocket != NULL && fSocket->IsConnected() == true)
|
||||||
_ProcessLine(_ReadUntilNewline(fSocket, &fRemainingBuf));
|
_ProcessLine(_ReadUntilNewline(fSocket, &fRemainingBuf));
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
@ -327,11 +346,50 @@ IrcProtocol::_ProcessNumeric(int32 numeric, BString sender, BStringList params,
|
||||||
{
|
{
|
||||||
if (params.CountStrings() == 2)
|
if (params.CountStrings() == 2)
|
||||||
fNick = params.First();
|
fNick = params.First();
|
||||||
BString cmd("WHO ");
|
BString cmd("WHOIS ");
|
||||||
cmd << fNick << "\n";
|
cmd << fNick << "\n";
|
||||||
_SendIrc(cmd);
|
_SendIrc(cmd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case RPL_WHOISUSER:
|
||||||
|
{
|
||||||
|
BString nick = params.StringAt(1);
|
||||||
|
BString user = params.StringAt(2);
|
||||||
|
BString host = params.StringAt(3);
|
||||||
|
BString ident = user;
|
||||||
|
ident << "@" << host;
|
||||||
|
|
||||||
|
fIdentNicks.RemoveItemFor(ident);
|
||||||
|
fIdentNicks.AddItem(ident, nick);
|
||||||
|
|
||||||
|
// Contains the own user's contact info― protocol ready!
|
||||||
|
if (fReady == false && nick == fNick) {
|
||||||
|
fUser = user.String();
|
||||||
|
_MakeReady(nick, ident);
|
||||||
|
}
|
||||||
|
// 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);
|
||||||
|
_SendMsg(&created);
|
||||||
|
}
|
||||||
|
// Used to populate a one-on-one chat's userlist… lol, I know.
|
||||||
|
else if (fWhoIsRequested == false && nick != fNick) {
|
||||||
|
BMessage user(IM_MESSAGE);
|
||||||
|
user.AddInt32("im_what", IM_ROOM_PARTICIPANTS);
|
||||||
|
user.AddString("chat_id", nick);
|
||||||
|
user.AddString("user_id", ident);
|
||||||
|
user.AddString("user_name", nick);
|
||||||
|
_SendMsg(&user);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case RPL_ENDOFWHOIS:
|
||||||
|
fWhoIsRequested = false;
|
||||||
|
break;
|
||||||
case RPL_WHOREPLY:
|
case RPL_WHOREPLY:
|
||||||
{
|
{
|
||||||
BString channel = params.StringAt(1);
|
BString channel = params.StringAt(1);
|
||||||
|
@ -341,32 +399,18 @@ IrcProtocol::_ProcessNumeric(int32 numeric, BString sender, BStringList params,
|
||||||
BString ident = user;
|
BString ident = user;
|
||||||
ident << "@" << host;
|
ident << "@" << host;
|
||||||
|
|
||||||
// Contains the user's contact info― protocol ready!
|
fIdentNicks.RemoveItemFor(ident);
|
||||||
if (fReady == false && nick == fNick) {
|
fIdentNicks.AddItem(ident, nick);
|
||||||
fUser = user.String();
|
|
||||||
_MakeReady(nick, ident);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used to populate a room's userlist
|
// Used to populate a room's userlist (one-by-one… :p)
|
||||||
if (fWhoRequested == false && channel != "*") {
|
if (fWhoRequested == false && _IsChannelName(channel)) {
|
||||||
BMessage user(IM_MESSAGE);
|
BMessage user(IM_MESSAGE);
|
||||||
user.AddInt32("im_what", IM_ROOM_PARTICIPANTS);
|
user.AddInt32("im_what", IM_ROOM_PARTICIPANTS);
|
||||||
user.AddString("chat_id", channel);
|
user.AddString("chat_id", channel);
|
||||||
user.AddString("user_id", ident);
|
user.AddString("user_id", ident);
|
||||||
user.AddString("user_name", nick);
|
user.AddString("user_name", 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:
|
||||||
|
@ -495,11 +539,6 @@ IrcProtocol::_ProcessCommand(BString command, BString sender,
|
||||||
joined.AddString("chat_id", chat_id);
|
joined.AddString("chat_id", chat_id);
|
||||||
if (_SenderIdent(sender) == fIdent) {
|
if (_SenderIdent(sender) == fIdent) {
|
||||||
joined.AddInt32("im_what", IM_ROOM_JOINED);
|
joined.AddInt32("im_what", IM_ROOM_JOINED);
|
||||||
// Populate the userlist
|
|
||||||
BString cmd("WHO ");
|
|
||||||
cmd << chat_id << "\n";
|
|
||||||
_SendIrc(cmd);
|
|
||||||
|
|
||||||
fChannels.Add(chat_id);
|
fChannels.Add(chat_id);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -114,6 +114,7 @@ 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;
|
||||||
|
bool fWhoIsRequested;
|
||||||
BString fWhoIm;
|
BString fWhoIm;
|
||||||
|
|
||||||
bool fWriteLocked;
|
bool fWriteLocked;
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
#define _RESPONSE_NUMERICS_H
|
#define _RESPONSE_NUMERICS_H
|
||||||
|
|
||||||
#define RPL_WELCOME 1
|
#define RPL_WELCOME 1
|
||||||
|
#define RPL_WHOISUSER 311
|
||||||
#define RPL_ENDOFWHO 315
|
#define RPL_ENDOFWHO 315
|
||||||
|
#define RPL_ENDOFWHOIS 318
|
||||||
#define RPL_TOPIC 332
|
#define RPL_TOPIC 332
|
||||||
#define RPL_WHOREPLY 352
|
#define RPL_WHOREPLY 352
|
||||||
#define RPL_NAMREPLY 353
|
#define RPL_NAMREPLY 353
|
||||||
|
|
Ŝarĝante…
Reference in New Issue