1 #include "providers/irc/IrcMessageBuilder.hpp"
2 
3 #include "Application.hpp"
4 #include "controllers/accounts/AccountController.hpp"
5 #include "controllers/ignores/IgnoreController.hpp"
6 #include "controllers/ignores/IgnorePhrase.hpp"
7 #include "messages/Message.hpp"
8 #include "providers/chatterino/ChatterinoBadges.hpp"
9 #include "singletons/Emotes.hpp"
10 #include "singletons/Resources.hpp"
11 #include "singletons/Settings.hpp"
12 #include "singletons/Theme.hpp"
13 #include "singletons/WindowManager.hpp"
14 #include "util/IrcHelpers.hpp"
15 #include "widgets/Window.hpp"
16 
17 namespace chatterino {
18 
IrcMessageBuilder(Channel * _channel,const Communi::IrcPrivateMessage * _ircMessage,const MessageParseArgs & _args)19 IrcMessageBuilder::IrcMessageBuilder(
20     Channel *_channel, const Communi::IrcPrivateMessage *_ircMessage,
21     const MessageParseArgs &_args)
22     : SharedMessageBuilder(_channel, _ircMessage, _args)
23 {
24 }
25 
IrcMessageBuilder(Channel * _channel,const Communi::IrcMessage * _ircMessage,const MessageParseArgs & _args,QString content,bool isAction)26 IrcMessageBuilder::IrcMessageBuilder(Channel *_channel,
27                                      const Communi::IrcMessage *_ircMessage,
28                                      const MessageParseArgs &_args,
29                                      QString content, bool isAction)
30     : SharedMessageBuilder(_channel, _ircMessage, _args, content, isAction)
31 {
32     assert(false);
33 }
34 
build()35 MessagePtr IrcMessageBuilder::build()
36 {
37     // PARSE
38     this->parse();
39 
40     // PUSH ELEMENTS
41     this->appendChannelName();
42 
43     this->emplace<TimestampElement>(
44         calculateMessageTimestamp(this->ircMessage));
45 
46     this->appendUsername();
47 
48     // words
49     this->addWords(this->originalMessage_.split(' '));
50 
51     this->message().messageText = this->originalMessage_;
52     this->message().searchText = this->message().localizedName + " " +
53                                  this->userName + ": " + this->originalMessage_;
54 
55     // highlights
56     this->parseHighlights();
57 
58     // highlighting incoming whispers if requested per setting
59     if (this->args.isReceivedWhisper && getSettings()->highlightInlineWhispers)
60     {
61         this->message().flags.set(MessageFlag::HighlightedWhisper, true);
62     }
63 
64     return this->release();
65 }
66 
addWords(const QStringList & words)67 void IrcMessageBuilder::addWords(const QStringList &words)
68 {
69     this->emplace<IrcTextElement>(words.join(' '), MessageElementFlag::Text);
70 }
71 
appendUsername()72 void IrcMessageBuilder::appendUsername()
73 {
74     QString username = this->userName;
75     this->message().loginName = username;
76     this->message().displayName = username;
77 
78     // The full string that will be rendered in the chat widget
79     QString usernameText = username;
80 
81     if (!this->action_)
82     {
83         usernameText += ":";
84     }
85 
86     this->emplace<TextElement>(usernameText, MessageElementFlag::Username,
87                                this->usernameColor_, FontStyle::ChatMediumBold)
88         ->setLink({Link::UserInfo, this->message().loginName});
89 }
90 
91 }  // namespace chatterino
92