File: ChatMessageParser.h

package info (click to toggle)
swift-im 5.0~alpha2.145.g12d031cf8%2Bdfsg-4.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,256 kB
  • sloc: cpp: 134,640; python: 2,701; sh: 774; xml: 561; javascript: 69; makefile: 59
file content (44 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * Copyright (c) 2013-2017 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#pragma once

#include <memory>
#include <string>

#include <Swift/Controllers/Highlighting/HighlightConfiguration.h>
#include <Swift/Controllers/UIInterfaces/ChatWindow.h>

namespace Swift {

    /**
     * @brief The ChatMessageParser class takes an emoticon map, a \ref HighlightConfiguration, and a boolean that indicates if the message context is in a MUC or not.
     * The class handles parsing a message string and identifies emoticons, URLs, and various highlights.
     */
    class ChatMessageParser {
        public:
            enum class Mode { Chat, GroupChat };

        public:
            ChatMessageParser(const std::map<std::string, std::string>& emoticons, std::shared_ptr<HighlightConfiguration> highlightConfiguration, Mode mode = Mode::Chat);

            void setNick(const std::string& nick) { nick_ = nick; }
            std::string getNick() const { return nick_; }

            ChatWindow::ChatMessage parseMessageBody(const std::string& body, const std::string& sender = "", bool senderIsSelf = false);

        private:
            ChatWindow::ChatMessage emoticonHighlight(const ChatWindow::ChatMessage& parsedMessage);
            ChatWindow::ChatMessage splitHighlight(const ChatWindow::ChatMessage& parsedMessage);
            ChatWindow::ChatMessage fullMessageHighlight(const ChatWindow::ChatMessage& parsedMessage, const std::string& sender);

        private:
            std::map<std::string, std::string> emoticons_;
            std::shared_ptr<HighlightConfiguration> highlightConfiguration_;
            Mode mode_;
            std::string nick_;
    };
}