chat-message-p.h 6.19 KB
Newer Older
1 2
/*
 * chat-message-p.h
Ronan's avatar
Ronan committed
3
 * Copyright (C) 2010-2018 Belledonne Communications SARL
4
 *
Ghislain MARY's avatar
Ghislain MARY committed
5 6 7 8
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
9 10 11 12 13 14 15
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
Ghislain MARY's avatar
Ghislain MARY committed
16 17
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 19
 */

20 21
#ifndef _L_CHAT_MESSAGE_P_H_
#define _L_CHAT_MESSAGE_P_H_
22

23 24 25
#include <belle-sip/types.h>

#include "chat/chat-message/chat-message.h"
26 27
#include "chat/chat-room/chat-room-id.h"
#include "chat/modifier/file-transfer-chat-message-modifier.h"
28
#include "chat/notification/imdn.h"
29
#include "content/content-type.h"
30
#include "content/content.h"
31 32
#include "content/file-content.h"
#include "content/file-transfer-content.h"
33
#include "db/main-db-chat-message-key.h"
34
#include "event-log/conference/conference-chat-message-event.h"
35
#include "object/object-p.h"
36
#include "sal/sal.h"
37 38 39 40 41 42

// =============================================================================

LINPHONE_BEGIN_NAMESPACE

class ChatMessagePrivate : public ObjectPrivate {
Ronan's avatar
Ronan committed
43
	friend class CpimChatMessageModifier;
44
	friend class EncryptionChatMessageModifier;
Ronan's avatar
Ronan committed
45 46
	friend class MultipartChatMessageModifier;

Sylvain Berfini's avatar
Sylvain Berfini committed
47
public:
48 49 50 51 52
	enum Step {
		None = 1 << 0,
		FileUpload = 1 << 1,
		Multipart = 1 << 2,
		Encryption = 1 << 3,
53 54
		Cpim = 1 << 4,
		Started = 1 << 5,
55 56
	};

57 58
	void setApplyModifiers (bool value) { applyModifiers = value; }

59 60
	void setDirection (ChatMessage::Direction dir);

61 62
	void setParticipantState (const IdentityAddress &participantAddress, ChatMessage::State newState);
	void setState (ChatMessage::State newState, bool force = false);
63

64
	void setTime (time_t time);
65

66
	void setIsReadOnly (bool readOnly);
67

68 69
	void setImdnMessageId (const std::string &imdnMessageId);

70
	void forceFromAddress (const IdentityAddress &fromAddress) {
71 72 73
		this->fromAddress = fromAddress;
	}

74
	void forceToAddress (const IdentityAddress &toAddress) {
75 76 77
		this->toAddress = toAddress;
	}

78 79 80 81 82 83
	void markContentsAsNotLoaded () {
		contentsNotLoadedFromDatabase = true;
	}

	void loadContentsFromDatabase () const;

84 85 86 87 88 89 90 91 92 93
	std::list<Content* > &getContents () {
		loadContentsFromDatabase();
		return contents;
	}

	const std::list<Content* > &getContents () const {
		loadContentsFromDatabase();
		return contents;
	}

94 95
	belle_http_request_t *getHttpRequest () const;
	void setHttpRequest (belle_http_request_t *request);
96

97 98
	SalOp *getSalOp () const;
	void setSalOp (SalOp *op);
99

100 101
	SalCustomHeader *getSalCustomHeaders () const;
	void setSalCustomHeaders (SalCustomHeader *headers);
102

103 104 105
	void addSalCustomHeader (const std::string &name, const std::string &value);
	void removeSalCustomHeader (const std::string &name);
	std::string getSalCustomHeaderValue (const std::string &name);
106

107
	void loadFileTransferUrlFromBodyToContent ();
108
	std::string createFakeFileTransferFromUrl(const std::string &url);
109

110 111
	void setChatRoom (const std::shared_ptr<AbstractChatRoom> &chatRoom);

112 113
	void setEncryptionPrevented (bool value) { encryptionPrevented = value; }

114
	// -----------------------------------------------------------------------------
115
	// Deprecated methods only used for C wrapper, to be removed some day...
116
	// -----------------------------------------------------------------------------
117

118 119
	const ContentType &getContentType ();
	void setContentType (const ContentType &contentType);
120

121 122
	const std::string &getText ();
	void setText (const std::string &text);
123

Sylvain Berfini's avatar
Sylvain Berfini committed
124 125 126 127 128 129 130
	const std::string &getFileTransferFilepath () const;
	void setFileTransferFilepath (const std::string &path);

	const std::string &getAppdata () const;
	void setAppdata (const std::string &appData);

	const std::string &getExternalBodyUrl () const;
131
	void setExternalBodyUrl (const std::string &url);
132

133 134
	bool hasTextContent () const;
	const Content* getTextContent () const;
135

136 137
	bool hasFileTransferContent () const;
	const Content* getFileTransferContent () const;
Sylvain Berfini's avatar
Sylvain Berfini committed
138

139 140
	LinphoneContent *getFileTransferInformation () const;
	void setFileTransferInformation (const LinphoneContent *content);
141

142 143
	void addContent (Content &content);
	void removeContent (const Content &content);
144

145
	bool downloadFile ();
146

147
	void sendImdn (Imdn::Type imdnType, LinphoneReason reason);
148

149 150 151
	void notifyReceiving ();
	LinphoneReason receive ();
	void send ();
152

153 154
	void storeInDb ();
	void updateInDb ();
155

156
private:
157 158 159
	
	ChatMessagePrivate(const std::shared_ptr<AbstractChatRoom> &cr, ChatMessage::Direction dir);
	
160 161
	static bool validStateTransition (ChatMessage::State currentState, ChatMessage::State newState);

162
	// TODO: Clean attributes.
163
	time_t time = ::ms_time(0); // TODO: Change me in all files.
164
	std::string imdnId;
Ronan's avatar
Ronan committed
165
	std::string rttMessage;
166
	bool isSecured = false;
167
	mutable bool isReadOnly = false;
168
	Content internalContent;
169 170

	// TODO: to replace salCustomheaders
171
	std::unordered_map<std::string, std::string> customHeaders;
172

Ghislain MARY's avatar
Ghislain MARY committed
173 174 175
	mutable LinphoneErrorInfo * errorInfo = nullptr;
	SalOp *salOp = nullptr;
	SalCustomHeader *salCustomHeaders = nullptr;
176
	unsigned char currentSendStep = Step::None;
177
	unsigned char currentRecvStep = Step::None;
178
	bool applyModifiers = true;
179
	FileTransferChatMessageModifier fileTransferChatMessageModifier;
180

181
	// Cache for returned values, used for compatibility with previous C API
Sylvain Berfini's avatar
Sylvain Berfini committed
182
	std::string fileTransferFilePath;
183
	ContentType cContentType;
Ronan's avatar
Ronan committed
184
	std::string cText;
185

186 187 188
	// TODO: Remove my comment. VARIABLES OK.
	// Do not expose.

189 190 191 192
public:
	mutable MainDbChatMessageKey dbKey;

private:
193
	std::weak_ptr<AbstractChatRoom> chatRoom;
194
	ChatRoomId chatRoomId;
195 196
	IdentityAddress fromAddress;
	IdentityAddress toAddress;
197 198 199 200

	ChatMessage::State state = ChatMessage::State::Idle;
	ChatMessage::Direction direction = ChatMessage::Direction::Incoming;

201 202
	std::list<Content* > contents;

203
	bool encryptionPrevented = false;
204
	bool toBeStored = true;
205
	mutable bool contentsNotLoadedFromDatabase = false;
206 207 208 209 210
	L_DECLARE_PUBLIC(ChatMessage);
};

LINPHONE_END_NAMESPACE

211
#endif // ifndef _L_CHAT_MESSAGE_P_H_