forked from chookspace/chookchat
yay initial commit
This commit is contained in:
40
server/src/post.cpp
Normal file
40
server/src/post.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "post.h"
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <maddy/parser.h>
|
||||
|
||||
Post::Post(const std::string& contentin, const std::string& user) : user(user), time(std::time(nullptr)) {
|
||||
// parse the post content markdown
|
||||
std::stringstream input(contentin);
|
||||
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>();
|
||||
content = parser->Parse(input);
|
||||
}
|
||||
|
||||
Post::Post(const std::string& contentin, uint64_t user) : userId(user), time(std::time(nullptr)) {
|
||||
// parse the post content markdown
|
||||
std::stringstream input(contentin);
|
||||
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>();
|
||||
content = parser->Parse(input);
|
||||
}
|
||||
|
||||
std::string Post::genHtml() const {
|
||||
std::stringstream ss;
|
||||
ss << "<hr>\n";
|
||||
|
||||
// do time
|
||||
char buf[256];
|
||||
struct tm ts;
|
||||
ts = *localtime(&time);
|
||||
strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", &ts);
|
||||
|
||||
ss << "<p><i>" << user << "</i> posted this at " << buf << "</p>\n";
|
||||
|
||||
ss << content;
|
||||
|
||||
ss << "<p>" << likes << " likes</p>";
|
||||
|
||||
return ss.str();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user