Commit 2ad5fe7f authored by kaniini's avatar kaniini

post: rework attachment type handling logic to use a lookup table as well

parent de5e56fb
......@@ -6,6 +6,12 @@
namespace Michabo {
static QMap<QString, Attachment::AttachmentType> str_to_att_type = {
{"image", Attachment::AttachmentType::Image},
{"gifv", Attachment::AttachmentType::GifV},
{"video", Attachment::AttachmentType::Video}
};
Attachment::Attachment(Post *parent, QJsonObject &obj)
: m_parent(parent),
m_reply(nullptr)
......@@ -21,12 +27,8 @@ Attachment::Attachment(Post *parent, QJsonObject &obj)
// determine type if we can
auto type = obj["type"].toString();
if (type == "image")
m_type = Image;
else if (type == "gifv")
m_type = GifV;
else if (type == "video")
m_type = Video;
if (str_to_att_type.contains (type))
m_type = str_to_att_type[type];
}
Attachment::~Attachment()
......
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