summaryrefslogtreecommitdiff
path: root/src/modules/m_ircv3_echomessage.cpp
diff options
context:
space:
mode:
authorlinuxdaemon <linuxdaemon@users.noreply.github.com>2019-06-24 11:10:17 -0500
committerPeter Powell <petpow@saberuk.com>2019-06-24 17:10:17 +0100
commit7ad534c1af4578a0d46742c4b6b00a5a33afb63f (patch)
treedacfcae9d65803a1aaa5941588b016f56be10e79 /src/modules/m_ircv3_echomessage.cpp
parent2ab383f707ec648ceeb29059ce4f54d4bbb056a4 (diff)
Replace large if/else blocks for target.type with switches (#1668).
Diffstat (limited to 'src/modules/m_ircv3_echomessage.cpp')
-rw-r--r--src/modules/m_ircv3_echomessage.cpp82
1 files changed, 47 insertions, 35 deletions
diff --git a/src/modules/m_ircv3_echomessage.cpp b/src/modules/m_ircv3_echomessage.cpp
index 3ec534e91..8f281da70 100644
--- a/src/modules/m_ircv3_echomessage.cpp
+++ b/src/modules/m_ircv3_echomessage.cpp
@@ -48,26 +48,32 @@ class ModuleIRCv3EchoMessage
const std::string& text = details.echo_original ? details.original_text : details.text;
const ClientProtocol::TagMap& tags = details.echo_original ? details.tags_in : details.tags_out;
- if (target.type == MessageTarget::TYPE_USER)
+ switch (target.type)
{
- User* destuser = target.Get<User>();
- ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, destuser, text, details.type);
- privmsg.AddTags(tags);
- localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
- }
- else if (target.type == MessageTarget::TYPE_CHANNEL)
- {
- Channel* chan = target.Get<Channel>();
- ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, chan, text, details.type, target.status);
- privmsg.AddTags(tags);
- localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
- }
- else
- {
- const std::string* servername = target.Get<std::string>();
- ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, *servername, text, details.type);
- privmsg.AddTags(tags);
- localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
+ case MessageTarget::TYPE_USER:
+ {
+ User* destuser = target.Get<User>();
+ ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, destuser, text, details.type);
+ privmsg.AddTags(tags);
+ localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
+ break;
+ }
+ case MessageTarget::TYPE_CHANNEL:
+ {
+ Channel* chan = target.Get<Channel>();
+ ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, chan, text, details.type, target.status);
+ privmsg.AddTags(tags);
+ localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
+ break;
+ }
+ case MessageTarget::TYPE_SERVER:
+ {
+ const std::string* servername = target.Get<std::string>();
+ ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, *servername, text, details.type);
+ privmsg.AddTags(tags);
+ localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
+ break;
+ }
}
}
@@ -80,23 +86,29 @@ class ModuleIRCv3EchoMessage
LocalUser* const localuser = static_cast<LocalUser*>(user);
const ClientProtocol::TagMap& tags = details.echo_original ? details.tags_in : details.tags_out;
- if (target.type == MessageTarget::TYPE_USER)
- {
- User* destuser = target.Get<User>();
- CTCTags::TagMessage message(user, destuser, tags);
- localuser->Send(tagmsgprov, message);
- }
- else if (target.type == MessageTarget::TYPE_CHANNEL)
- {
- Channel* chan = target.Get<Channel>();
- CTCTags::TagMessage message(user, chan, tags);
- localuser->Send(tagmsgprov, message);
- }
- else
+ switch (target.type)
{
- const std::string* servername = target.Get<std::string>();
- CTCTags::TagMessage message(user, servername->c_str(), tags);
- localuser->Send(tagmsgprov, message);
+ case MessageTarget::TYPE_USER:
+ {
+ User* destuser = target.Get<User>();
+ CTCTags::TagMessage message(user, destuser, tags);
+ localuser->Send(tagmsgprov, message);
+ break;
+ }
+ case MessageTarget::TYPE_CHANNEL:
+ {
+ Channel* chan = target.Get<Channel>();
+ CTCTags::TagMessage message(user, chan, tags);
+ localuser->Send(tagmsgprov, message);
+ break;
+ }
+ case MessageTarget::TYPE_SERVER:
+ {
+ const std::string* servername = target.Get<std::string>();
+ CTCTags::TagMessage message(user, servername->c_str(), tags);
+ localuser->Send(tagmsgprov, message);
+ break;
+ }
}
}