Search by user name and ID for chat commands
This commit is contained in:
parent
03c9cdb249
commit
f1464cb01c
|
@ -109,24 +109,26 @@ ChatCommand::_ProcessArgs(BString args, BMessage* msg, BString* errorMsg,
|
|||
{
|
||||
case CMD_ROOM_PARTICIPANT:
|
||||
{
|
||||
if (chat->UserById(arg) == NULL) {
|
||||
User* user = _FindUser(arg, chat->Users());
|
||||
if (user == NULL) {
|
||||
errorMsg->SetTo(B_TRANSLATE("%user% isn't a member of this "
|
||||
"room."));
|
||||
errorMsg->ReplaceAll("%user%", arg);
|
||||
return false;
|
||||
}
|
||||
msg->AddString("user_id", arg);
|
||||
msg->AddString("user_id", user->GetId());
|
||||
break;
|
||||
}
|
||||
case CMD_KNOWN_USER:
|
||||
{
|
||||
if (chat->GetProtocolLooper()->UserById(arg) == NULL) {
|
||||
User* user = _FindUser(arg, chat->GetProtocolLooper()->Users());
|
||||
if (user == NULL) {
|
||||
errorMsg->SetTo(B_TRANSLATE("You aren't contacts with and "
|
||||
"have no chats in common with %user%. Shame."));
|
||||
errorMsg->ReplaceAll("%user%", arg);
|
||||
return false;
|
||||
}
|
||||
msg->AddString("user_id", arg);
|
||||
msg->AddString("user_id", user->GetId());
|
||||
break;
|
||||
}
|
||||
case CMD_ANY_USER:
|
||||
|
@ -146,6 +148,24 @@ ChatCommand::_ProcessArgs(BString args, BMessage* msg, BString* errorMsg,
|
|||
}
|
||||
|
||||
|
||||
User*
|
||||
ChatCommand::_FindUser(BString idOrName, UserMap users)
|
||||
{
|
||||
if (idOrName.IsEmpty() == true)
|
||||
return NULL;
|
||||
|
||||
bool idFound = false;
|
||||
User* user = users.ValueFor(idOrName, &idFound);
|
||||
if (idFound == false)
|
||||
for (int i = 0; i < users.CountItems(); i++) {
|
||||
User* check = users.ValueAt(i);
|
||||
if (check != NULL && check->GetName() == idOrName)
|
||||
return check;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ChatCommand::_Send(BMessage* msg, Conversation* chat)
|
||||
{
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
#include <libsupport/List.h>
|
||||
|
||||
class Conversation;
|
||||
class User;
|
||||
|
||||
typedef KeyMap<BString, User*> UserMap;
|
||||
|
||||
|
||||
enum cmd_arg_type
|
||||
|
@ -46,6 +49,8 @@ private:
|
|||
bool _ProcessArgs(BString args, BMessage* msg, BString* errorMsg,
|
||||
Conversation* chat);
|
||||
|
||||
User* _FindUser(BString idOrName, UserMap users);
|
||||
|
||||
bool _Send(BMessage* msg, Conversation* chat);
|
||||
|
||||
BString fName;
|
||||
|
|
Ŝarĝante…
Reference in New Issue