Commit 1610aa41 authored by Ronan's avatar Ronan
Browse files

feat(Message): add a basic impl

parent 1b78b453
......@@ -15,3 +15,174 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unordered_map>
#include "db/events-db.h"
#include "object/object-p.h"
#include "message.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
using namespace std;
class MessagePrivate : public ObjectPrivate {
private:
weak_ptr<ChatRoom> chatRoom;
MessageDirection direction = MessageDirection::Incoming;
// LinphoneAddress *from;
// LinphoneAddress *to;
shared_ptr<ErrorInfo> errorInfo;
string contentType;
string text;
bool isSecured = false;
time_t time = 0;
string id;
string appData;
list<shared_ptr<Content> > contents;
unordered_map<string, string> customHeaders;
MessageState state = MessageState::Idle;
shared_ptr<EventsDb> eventsDb;
L_DECLARE_PUBLIC(Message);
};
// -----------------------------------------------------------------------------
Message::Message (MessagePrivate &p) : Object(p) {}
shared_ptr<ChatRoom> Message::getChatRoom () const {
L_D(const Message);
shared_ptr<ChatRoom> chatRoom = d->chatRoom.lock();
if (!chatRoom) {
// TODO.
}
return chatRoom;
}
MessageDirection Message::getDirection () const {
L_D(const Message);
return d->direction;
}
shared_ptr<const Address> Message::getFromAddress () const {
// TODO.
return nullptr;
}
shared_ptr<const Address> Message::getToAddress () const {
// TODO.
return nullptr;
}
shared_ptr<const Address> Message::getLocalAddress () const {
// TODO.
return nullptr;
}
shared_ptr<const Address> Message::getRemoteAddress () const {
// TODO.
return nullptr;
}
MessageState Message::getState () const {
L_D(const Message);
return d->state;
}
shared_ptr<const ErrorInfo> Message::getErrorInfo () const {
L_D(const Message);
return d->errorInfo;
}
string Message::getContentType () const {
L_D(const Message);
return d->contentType;
}
string Message::getText () const {
L_D(const Message);
return d->text;
}
void Message::setText (const string &text) {
L_D(Message);
d->text = text;
}
void Message::send () const {
// TODO.
}
bool Message::containsReadableText () const {
// TODO: Check content type.
return true;
}
bool Message::isSecured () const {
L_D(const Message);
return d->isSecured;
}
time_t Message::getTime () const {
L_D(const Message);
return d->time;
}
string Message::getId () const {
L_D(const Message);
return d->id;
}
string Message::getAppdata () const {
L_D(const Message);
return d->appData;
}
void Message::setAppdata (const string &appData) {
L_D(Message);
d->appData = appData;
}
list<const shared_ptr<const Content> > Message::getContents () const {
L_D(const Message);
list<const shared_ptr<const Content> > contents;
for (const auto &content : d->contents)
contents.push_back(content);
return contents;
}
void Message::addContent (const shared_ptr<Content> &content) {
L_D(Message);
d->contents.push_back(content);
}
void Message::removeContent (const shared_ptr<const Content> &content) {
L_D(Message);
d->contents.remove(const_pointer_cast<Content>(content));
}
string Message::getCustomHeaderValue (const string &headerName) const {
L_D(const Message);
try {
return d->customHeaders.at(headerName);
} catch (const exception &) {
// Key doesn't exist.
}
return "";
}
void Message::addCustomHeader (const string &headerName, const string &headerValue) {
L_D(Message);
d->customHeaders[headerName] = headerValue;
}
void Message::removeCustomHeader (const string &headerName) {
L_D(Message);
d->customHeaders.erase(headerName);
}
LINPHONE_END_NAMESPACE
......@@ -40,6 +40,8 @@ class LINPHONE_PUBLIC Message : public Object {
friend class ChatRoom;
public:
std::shared_ptr<ChatRoom> getChatRoom () const;
MessageDirection getDirection () const;
std::shared_ptr<const Address> getFromAddress () const;
......@@ -47,7 +49,7 @@ public:
std::shared_ptr<const Address> getLocalAddress () const;
std::shared_ptr<const Address> getRemoteAddress () const;
std::shared_ptr<ChatRoom> getChatRoom () const;
MessageState getState () const;
std::shared_ptr<const ErrorInfo> getErrorInfo () const;
......@@ -67,20 +69,19 @@ public:
std::string getId () const;
std::string getAppdata () const;
void setAppdata (const std::string &data);
void setAppdata (const std::string &appData);
std::list<const std::shared_ptr<Content> > getContents () const;
void addContent (std::shared_ptr<Content> &content);
void removeContent (std::shared_ptr<Content> &content);
std::list<const std::shared_ptr<const Content> > getContents () const;
void addContent (const std::shared_ptr<Content> &content);
void removeContent (const std::shared_ptr<const Content> &content);
std::string getCustomHeaderValue (const std::string &headerName);
std::string getCustomHeaderValue (const std::string &headerName) const;
void addCustomHeader (const std::string &headerName, const std::string &headerValue);
void removeCustomHeader (const std::string &headerName);
protected:
Message ();
private:
Message (MessagePrivate &p);
L_DECLARE_PRIVATE(Message);
L_DISABLE_COPY(Message);
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment