forked from mirrors/linphone-iphone
Moved from shared_ptr<Content> to Content in ChatMessage
This commit is contained in:
parent
5eca36e071
commit
54de6bb650
7 changed files with 55 additions and 58 deletions
|
|
@ -117,8 +117,8 @@ private:
|
|||
std::string rttMessage = "";
|
||||
bool isSecured = false;
|
||||
bool isReadOnly = false;
|
||||
std::list<std::shared_ptr<Content> > contents;
|
||||
std::shared_ptr<Content> internalContent;
|
||||
std::list<Content > contents;
|
||||
Content internalContent;
|
||||
std::unordered_map<std::string, std::string> customHeaders;
|
||||
std::shared_ptr<EventsDb> eventsDb;
|
||||
mutable LinphoneErrorInfo * errorInfo = NULL;
|
||||
|
|
|
|||
|
|
@ -140,41 +140,35 @@ string ChatMessagePrivate::getSalCustomHeaderValue(const string& name) {
|
|||
// -----------------------------------------------------------------------------
|
||||
|
||||
const string& ChatMessagePrivate::getContentType() {
|
||||
if (internalContent) {
|
||||
cContentType = internalContent->getContentType().asString();
|
||||
if (!internalContent.isEmpty()) {
|
||||
cContentType = internalContent.getContentType().asString();
|
||||
} else {
|
||||
if (contents.size() > 0) {
|
||||
shared_ptr<Content> content = contents.front();
|
||||
cContentType = content->getContentType().asString();
|
||||
Content content = contents.front();
|
||||
cContentType = content.getContentType().asString();
|
||||
}
|
||||
}
|
||||
return cContentType;
|
||||
}
|
||||
|
||||
void ChatMessagePrivate::setContentType(const string& contentType) {
|
||||
if (!internalContent) {
|
||||
internalContent = make_shared<Content>();
|
||||
}
|
||||
internalContent->setContentType(contentType);
|
||||
internalContent.setContentType(contentType);
|
||||
}
|
||||
|
||||
const string& ChatMessagePrivate::getText() {
|
||||
if (internalContent) {
|
||||
cText = internalContent->getBodyAsString();
|
||||
if (!internalContent.isEmpty()) {
|
||||
cText = internalContent.getBodyAsString();
|
||||
} else {
|
||||
if (contents.size() > 0) {
|
||||
shared_ptr<Content> content = contents.front();
|
||||
cText = content->getBodyAsString();
|
||||
Content content = contents.front();
|
||||
cText = content.getBodyAsString();
|
||||
}
|
||||
}
|
||||
return cText;
|
||||
}
|
||||
|
||||
void ChatMessagePrivate::setText(const string& text) {
|
||||
if (!internalContent) {
|
||||
internalContent = make_shared<Content>();
|
||||
}
|
||||
internalContent->setBody(text);
|
||||
internalContent.setBody(text);
|
||||
}
|
||||
|
||||
LinphoneContent * ChatMessagePrivate::getFileTransferInformation() const {
|
||||
|
|
@ -1297,26 +1291,23 @@ bool ChatMessage::isReadOnly () const {
|
|||
return d->isReadOnly;
|
||||
}
|
||||
|
||||
list<shared_ptr<const Content> > ChatMessage::getContents () const {
|
||||
const list<Content >& ChatMessage::getContents () const {
|
||||
L_D();
|
||||
list<shared_ptr<const Content> > contents;
|
||||
for (const auto &content : d->contents)
|
||||
contents.push_back(content);
|
||||
return contents;
|
||||
return d->contents;
|
||||
}
|
||||
|
||||
void ChatMessage::addContent (const shared_ptr<Content> &content) {
|
||||
void ChatMessage::addContent (const Content &content) {
|
||||
L_D();
|
||||
if (d->isReadOnly) return;
|
||||
|
||||
d->contents.push_back(content);
|
||||
}
|
||||
|
||||
void ChatMessage::removeContent (const shared_ptr<const Content> &content) {
|
||||
void ChatMessage::removeContent (const Content& content) {
|
||||
L_D();
|
||||
if (d->isReadOnly) return;
|
||||
|
||||
d->contents.remove(const_pointer_cast<Content>(content));
|
||||
d->contents.remove(content);
|
||||
}
|
||||
|
||||
string ChatMessage::getCustomHeaderValue (const string &headerName) const {
|
||||
|
|
|
|||
|
|
@ -133,9 +133,9 @@ public:
|
|||
|
||||
bool isReadOnly() const;
|
||||
|
||||
std::list<std::shared_ptr<const Content> > getContents() const;
|
||||
void addContent(const std::shared_ptr<Content> &content);
|
||||
void removeContent(const std::shared_ptr<const Content> &content);
|
||||
const std::list<Content>& getContents() const;
|
||||
void addContent(const Content& content);
|
||||
void removeContent(const Content& content);
|
||||
|
||||
std::string getCustomHeaderValue(const std::string &headerName) const;
|
||||
void addCustomHeader(const std::string &headerName, const std::string &headerValue);
|
||||
|
|
|
|||
|
|
@ -120,9 +120,9 @@ void ChatRoomPrivate::sendImdn (const string &payload, LinphoneReason reason) {
|
|||
msg->setFromAddress(identity);
|
||||
msg->setToAddress(peerAddress.asString());
|
||||
|
||||
shared_ptr<Content> content = make_shared<Content>();
|
||||
content->setContentType("message/imdn+xml");
|
||||
content->setBody(payload);
|
||||
Content content;
|
||||
content.setContentType("message/imdn+xml");
|
||||
content.setBody(payload);
|
||||
msg->addContent(content);
|
||||
|
||||
/* Do not try to encrypt the notification when it is reporting an error (maybe it should be bypassed only for some reasons). */
|
||||
|
|
@ -212,9 +212,9 @@ void ChatRoomPrivate::sendIsComposingNotification () {
|
|||
msg->setFromAddress(identity);
|
||||
msg->setToAddress(peerAddress.asString());
|
||||
|
||||
shared_ptr<Content> content = make_shared<Content>();
|
||||
content->setContentType("application/im-iscomposing+xml");
|
||||
content->setBody(payload);
|
||||
Content content;
|
||||
content.setContentType("application/im-iscomposing+xml");
|
||||
content.setBody(payload);
|
||||
msg->addContent(content);
|
||||
|
||||
LinphoneImEncryptionEngine *imee = linphone_core_get_im_encryption_engine(core);
|
||||
|
|
@ -269,14 +269,14 @@ int ChatRoomPrivate::createChatMessageFromDb (int argc, char **argv, char **colN
|
|||
if (!message) {
|
||||
message = q->createMessage();
|
||||
|
||||
shared_ptr<Content> content = make_shared<Content>();
|
||||
Content content;
|
||||
message->addContent(content);
|
||||
|
||||
if (argv[4]) {
|
||||
content->setBody(argv[4]);
|
||||
content.setBody(argv[4]);
|
||||
}
|
||||
if (argv[13]) {
|
||||
content->setContentType(argv[13]);
|
||||
content.setContentType(argv[13]);
|
||||
}
|
||||
|
||||
Address peer(peerAddress.asString());
|
||||
|
|
@ -399,9 +399,9 @@ LinphoneReason ChatRoomPrivate::messageReceived (SalOp *op, const SalMessage *sa
|
|||
|
||||
msg = q->createMessage();
|
||||
|
||||
shared_ptr<Content> content = make_shared<Content>();
|
||||
content->setContentType(salMsg->content_type);
|
||||
content->setBody(salMsg->text ? salMsg->text : "");
|
||||
Content content;
|
||||
content.setContentType(salMsg->content_type);
|
||||
content.setBody(salMsg->text ? salMsg->text : "");
|
||||
msg->addContent(content);
|
||||
|
||||
msg->setToAddress(op->get_to() ? op->get_to() : linphone_core_get_identity(core));
|
||||
|
|
@ -565,9 +565,9 @@ shared_ptr<ChatMessage> ChatRoom::createMessage (const string &message) {
|
|||
L_D();
|
||||
shared_ptr<ChatMessage> chatMessage = createMessage();
|
||||
|
||||
shared_ptr<Content> content = make_shared<Content>();
|
||||
content->setContentType("text/plain");
|
||||
content->setBody(message);
|
||||
Content content;
|
||||
content.setContentType("text/plain");
|
||||
content.setBody(message);
|
||||
chatMessage->addContent(content);
|
||||
|
||||
chatMessage->setToAddress(d->peerAddress);
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ int CpimChatMessageModifier::encode (ChatMessagePrivate *messagePrivate) {
|
|||
cpimContentTypeHeader.setValue("Message/CPIM");
|
||||
message.addCpimHeader(cpimContentTypeHeader);
|
||||
|
||||
shared_ptr<Content> content;
|
||||
if (messagePrivate->internalContent) {
|
||||
Content content;
|
||||
if (!messagePrivate->internalContent.isEmpty()) {
|
||||
// Another ChatMessageModifier was called before this one, we apply our changes on the private content
|
||||
content = messagePrivate->internalContent;
|
||||
} else {
|
||||
|
|
@ -48,8 +48,8 @@ int CpimChatMessageModifier::encode (ChatMessagePrivate *messagePrivate) {
|
|||
content = messagePrivate->contents.front();
|
||||
}
|
||||
|
||||
string contentType = content->getContentType().asString();
|
||||
const vector<char> body = content->getBody();
|
||||
string contentType = content.getContentType().asString();
|
||||
const vector<char> body = content.getBody();
|
||||
string contentBody(body.begin(), body.end());
|
||||
|
||||
Cpim::GenericHeader contentTypeHeader;
|
||||
|
|
@ -62,33 +62,33 @@ int CpimChatMessageModifier::encode (ChatMessagePrivate *messagePrivate) {
|
|||
if (!message.isValid()) {
|
||||
//TODO
|
||||
} else {
|
||||
shared_ptr<Content> newContent = make_shared<Content>();
|
||||
Content newContent;
|
||||
ContentType newContentType("Message/CPIM");
|
||||
newContent->setContentType(newContentType);
|
||||
newContent->setBody(message.asString());
|
||||
newContent.setContentType(newContentType);
|
||||
newContent.setBody(message.asString());
|
||||
messagePrivate->internalContent = newContent;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CpimChatMessageModifier::decode (ChatMessagePrivate *messagePrivate) {
|
||||
shared_ptr<Content> content;
|
||||
if (messagePrivate->internalContent) {
|
||||
Content content;
|
||||
if (!messagePrivate->internalContent.isEmpty()) {
|
||||
content = messagePrivate->internalContent;
|
||||
} else {
|
||||
content = messagePrivate->contents.front();
|
||||
}
|
||||
|
||||
ContentType contentType = content->getContentType();
|
||||
ContentType contentType = content.getContentType();
|
||||
if (contentType.asString() == "Message/CPIM") {
|
||||
const vector<char> body = content->getBody();
|
||||
const vector<char> body = content.getBody();
|
||||
string contentBody(body.begin(), body.end());
|
||||
shared_ptr<const Cpim::Message> message = Cpim::Message::createFromString(contentBody);
|
||||
if (message && message->isValid()) {
|
||||
shared_ptr<Content> newContent = make_shared<Content>();
|
||||
Content newContent;
|
||||
ContentType newContentType(message->getContentHeaders()->front()->getValue());
|
||||
newContent->setContentType(newContentType);
|
||||
newContent->setBody(message->getContent());
|
||||
newContent.setContentType(newContentType);
|
||||
newContent.setBody(message->getContent());
|
||||
} else {
|
||||
//TODO
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,6 +67,11 @@ Content &Content::operator= (Content &&src) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
bool Content::operator==(const Content& content) {
|
||||
// return true if the two are equal, and false otherwise.
|
||||
return true;
|
||||
}
|
||||
|
||||
const ContentType &Content::getContentType () const {
|
||||
L_D();
|
||||
return d->contentType;
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ public:
|
|||
|
||||
Content &operator= (const Content &src);
|
||||
Content &operator= (Content &&src);
|
||||
bool operator==(const Content& content);
|
||||
|
||||
const ContentType &getContentType () const;
|
||||
void setContentType (const ContentType &contentType);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue