From b380b6115c77739892572e272952268e2292458b Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sun, 15 Aug 2021 20:34:30 -0500 Subject: [PATCH] Fix chat creation with non-contact users --- application/Server.cpp | 8 +++----- protocols/irc/IrcProtocol.cpp | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/application/Server.cpp b/application/Server.cpp index 0c92045..05a9c14 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -444,11 +444,9 @@ Server::ImMessage(BMessage* msg) } case IM_CREATE_CHAT: { - BString user_id = msg->FindString("user_id"); - if (user_id.IsEmpty() == false) { - User* user = ContactById(user_id, msg->FindInt64("instance")); - user->GetProtocolLooper()->PostMessage(msg); - } + ProtocolLooper* looper = _LooperFromMessage(msg); + if (looper != NULL) + looper->PostMessage(msg); break; } case IM_CHAT_CREATED: diff --git a/protocols/irc/IrcProtocol.cpp b/protocols/irc/IrcProtocol.cpp index 8801891..6bb7e6c 100644 --- a/protocols/irc/IrcProtocol.cpp +++ b/protocols/irc/IrcProtocol.cpp @@ -409,7 +409,6 @@ IrcProtocol::_ProcessCommand(BString command, BString sender, } else if (command == "PRIVMSG") { - BString chat_id = params.First(); BString user_id = _SenderIdent(sender); BString body = params.Last(); @@ -429,12 +428,17 @@ IrcProtocol::_ProcessCommand(BString command, BString sender, BString chat_id = params.First(); BMessage send(IM_MESSAGE); send.AddInt32("im_what", IM_MESSAGE_RECEIVED); - if (chat_id != "AUTH" && chat_id != "*") { + + if (_IsChannelName(chat_id) == false) + chat_id = _SenderNick(sender); + + if (chat_id != "AUTH" || chat_id != "*") send.AddString("chat_id", chat_id); - sender = ""; + + if (sender.IsEmpty() == false) { + send.AddString("user_id", _SenderIdent(sender)); + send.AddString("user_name", _SenderNick(sender)); } - if (sender.IsEmpty() == false) - send.AddString("user_id", sender); send.AddString("body", params.Last()); _SendMsg(&send); } @@ -567,8 +571,13 @@ BString IrcProtocol::_LineSender(BStringList words) { BString sender; - if (words.CountStrings() > 1) - sender = words.First().RemoveFirst(":"); + if (words.CountStrings() > 1) { + sender = words.First(); + if (sender.StartsWith(":") == true) + sender.RemoveFirst(":"); + else if (sender.StartsWith("*:") == true) + sender.RemoveFirst("*:"); + } return sender; }