1 /*
2     Copyright © 2019 by The qTox Project Contributors
3 
4     This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6     qTox is libre software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10 
11     qTox is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with qTox.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef CHAT_LOG_ITEM_H
21 #define CHAT_LOG_ITEM_H
22 
23 #include "src/core/toxfile.h"
24 #include "src/core/toxpk.h"
25 #include "src/model/message.h"
26 #include "src/persistence/history.h"
27 
28 #include <memory>
29 
30 struct ChatLogMessage
31 {
32     MessageState state;
33     Message message;
34 };
35 
36 struct ChatLogFile
37 {
38     QDateTime timestamp;
39     ToxFile file;
40 };
41 
42 class ChatLogItem
43 {
44 private:
45     using ContentPtr = std::unique_ptr<void, void (*)(void*)>;
46 
47 public:
48     enum class ContentType
49     {
50         message,
51         fileTransfer,
52     };
53 
54     ChatLogItem(ToxPk sender, ChatLogFile file);
55     ChatLogItem(ToxPk sender, ChatLogMessage message);
56     const ToxPk& getSender() const;
57     ContentType getContentType() const;
58     ChatLogFile& getContentAsFile();
59     const ChatLogFile& getContentAsFile() const;
60     ChatLogMessage& getContentAsMessage();
61     const ChatLogMessage& getContentAsMessage() const;
62     QDateTime getTimestamp() const;
63     void setDisplayName(QString name);
64     const QString& getDisplayName() const;
65 
66 private:
67     ChatLogItem(ToxPk sender, ContentType contentType, ContentPtr content);
68 
69     ToxPk sender;
70     QString displayName;
71     ContentType contentType;
72 
73     ContentPtr content;
74 };
75 
76 #endif /*CHAT_LOG_ITEM_H*/
77