00001
00002
00003
00004
00005
00006
00007 #pragma once
00008
00009 #include <boost/optional.hpp>
00010 #include <boost/shared_ptr.hpp>
00011 #include <boost/smart_ptr/make_shared.hpp>
00012
00013 #include <string>
00014 #include <Swiften/Elements/Body.h>
00015 #include <Swiften/Elements/Subject.h>
00016 #include <Swiften/Elements/ErrorPayload.h>
00017 #include <Swiften/Elements/Stanza.h>
00018 #include <Swiften/Elements/Replace.h>
00019
00020 namespace Swift {
00021 class Message : public Stanza {
00022 public:
00023 typedef boost::shared_ptr<Message> ref;
00024
00025 enum Type { Normal, Chat, Error, Groupchat, Headline };
00026
00027 Message() : type_(Chat) { }
00028
00029 std::string getSubject() const {
00030 boost::shared_ptr<Subject> subject(getPayload<Subject>());
00031 if (subject) {
00032 return subject->getText();
00033 }
00034 return "";
00035 }
00036
00037 void setSubject(const std::string& subject) {
00038 updatePayload(boost::make_shared<Subject>(subject));
00039 }
00040
00041 bool hasSubject() {
00042 return getPayload<Subject>();
00043 }
00044
00045 std::string getBody() const {
00046 boost::shared_ptr<Body> body(getPayload<Body>());
00047 if (body) {
00048 return body->getText();
00049 }
00050 return "";
00051 }
00052
00053 void setBody(const std::string& body) {
00054 updatePayload(boost::make_shared<Body>(body));
00055 }
00056
00057 bool isError() {
00058 boost::shared_ptr<Swift::ErrorPayload> error(getPayload<Swift::ErrorPayload>());
00059 return getType() == Message::Error || error;
00060 }
00061
00062 Type getType() const { return type_; }
00063 void setType(Type type) { type_ = type; }
00064
00065 private:
00066 Type type_;
00067 };
00068 }