Commit 59ff9d93 authored by kaniini's avatar kaniini

implement notification factory and event

parent 2bb23cf8
......@@ -626,6 +626,13 @@ QWebSocket *Account::streamingSocket(QString stream)
handleUpdate(doc, target_tl);
return;
}
else if (event == "notification")
{
QJsonDocument doc = QJsonDocument::fromJson(env.object()["payload"].toString().toLocal8Bit());
handleNotification(doc);
return;
}
qDebug() << socket << "UNHANDLED IN:" << env;
});
......@@ -650,6 +657,14 @@ void Account::handleUpdate(QJsonDocument doc, QString target)
emit fetchedTimeline(target, posts);
}
void Account::handleNotification(QJsonDocument doc)
{
auto obj = doc.object ();
std::shared_ptr<Notification> n = std::make_shared<Notification> (this, obj);
emit notification (n);
}
void Identity::fromSourceData(QJsonObject doc)
{
m_display_name = doc["display_name"].toString();
......
......@@ -137,6 +137,7 @@ signals:
void fetchedInstanceMetadata();
void invalidatedPost(Post *p);
void attachmentUploaded(std::shared_ptr<Post> p, std::shared_ptr<Attachment> att);
void notification(std::shared_ptr<Notification> n);
private:
QString m_name;
......@@ -156,7 +157,10 @@ private:
// OAuth authorization
QUrlQuery buildOAuthQuery();
void mutatePost(std::shared_ptr<Post> p, const QString verb, bool deliver_home = false);
// updates and notifications
void handleUpdate(QJsonDocument doc, QString target);
void handleNotification(QJsonDocument doc);
};
}
......
......@@ -207,4 +207,24 @@ void Post::updateAttachment(Attachment *a)
m_parent->updateAttachment(a);
}
static QMap<QString, Notification::Type> str_to_not_type = {
{"favorite", Notification::Type::Favorite},
{"follow", Notification::Type::Follow},
{"mention", Notification::Type::Mention},
{"reblog", Notification::Type::Repeat}
};
Notification::Notification(Account *parent, QJsonObject &obj)
: m_account(parent)
{
QJsonObject account = obj["account"].toObject ();
QJsonObject status = obj["status"].toObject ();
auto acct = account["acct"].toString ();
auto type = obj["type"].toString ();
m_post = std::make_shared<Post> (m_account, status);
m_identity = m_account->identityLookup (acct, account);
m_type = str_to_not_type[type];
}
}
......@@ -47,6 +47,26 @@ struct Attachment
void setDescription(QString desc);
};
struct Notification
{
Notification() = delete;
Notification(const Notification &) = delete;
Notification(Account *parent, QJsonObject &obj);
enum Type {
Mention,
Follow,
Repeat,
Favorite,
};
Account *m_account;
Type m_type;
std::shared_ptr<Post> m_post;
std::shared_ptr<Identity> m_identity;
};
struct Post
{
Post() = delete;
......
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