diff options
Diffstat (limited to 'eventsview-plugins')
3 files changed, 43 insertions, 5 deletions
diff --git a/eventsview-plugins/eventsview-plugin-mastodon/MastodonFeedItem.qml b/eventsview-plugins/eventsview-plugin-mastodon/MastodonFeedItem.qml index c96fb8a..9d86732 100644 --- a/eventsview-plugins/eventsview-plugin-mastodon/MastodonFeedItem.qml +++ b/eventsview-plugins/eventsview-plugin-mastodon/MastodonFeedItem.qml @@ -13,16 +13,17 @@ SocialMediaFeedItem { id: item property variant imageList - property int likeCount - property int commentCount - property int boostCount + property int likeCount: item.intValue("favouritesCount", "likeCount", "favoriteCount") + property int commentCount: item.intValue("repliesCount", "commentCount") + property int boostCount: item.intValue("reblogsCount", "boostCount", "repostsCount") property string _booster: item.stringValue("boostedBy", "rebloggedBy", "retweeter") property string _displayName: item.stringValue("name", "displayName", "display_name") property string _accountName: item.stringValue("accountName", "acct", "screenName", "username") property string _bodyText: item.stringValue("body", "content", "text") - timestamp: item.stringValue("timestamp", "createdAt", "created_at") + timestamp: model.timestamp + onRefreshTimeCountChanged: formattedTime = Format.formatDate(model.timestamp, Format.TimeElapsed) avatar.y: item._booster.length > 0 ? topMargin + boosterIcon.height + Theme.paddingSmall @@ -110,7 +111,7 @@ SocialMediaFeedItem { wrapMode: Text.Wrap color: item.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor font.pixelSize: Theme.fontSizeExtraSmall - text: item.formattedTime + text: item.metadataText() textFormat: Text.PlainText } @@ -140,4 +141,29 @@ SocialMediaFeedItem { } return "" } + + function intValue() { + for (var i = 0; i < arguments.length; ++i) { + var value = model[arguments[i]] + if (typeof value === "undefined" || value === null) { + continue + } + var number = Number(value) + if (!isNaN(number)) { + return Math.max(0, Math.floor(number)) + } + } + return 0 + } + + function metadataText() { + var parts = [] + parts.push("↩ " + item.commentCount) + parts.push("★ " + item.likeCount) + parts.push("↻ " + item.boostCount) + if (item.formattedTime.length > 0) { + parts.push(item.formattedTime) + } + return parts.join(" | ") + } } diff --git a/eventsview-plugins/eventsview-plugin-mastodon/mastodonpostsmodel.cpp b/eventsview-plugins/eventsview-plugin-mastodon/mastodonpostsmodel.cpp index 74d239e..4fe37d9 100644 --- a/eventsview-plugins/eventsview-plugin-mastodon/mastodonpostsmodel.cpp +++ b/eventsview-plugins/eventsview-plugin-mastodon/mastodonpostsmodel.cpp @@ -63,6 +63,9 @@ QHash<int, QByteArray> MastodonPostsModel::roleNames() const roleNames.insert(Link, "link"); roleNames.insert(BoostedBy, "boostedBy"); roleNames.insert(RebloggedBy, "rebloggedBy"); + roleNames.insert(RepliesCount, "repliesCount"); + roleNames.insert(FavouritesCount, "favouritesCount"); + roleNames.insert(ReblogsCount, "reblogsCount"); roleNames.insert(InstanceUrl, "instanceUrl"); roleNames.insert(Accounts, "accounts"); return roleNames; @@ -100,6 +103,9 @@ void MastodonPostsModel::postsChanged() const QString accountName = d->database.accountName(post); const QString postUrl = d->database.url(post); const QString boostedBy = d->database.boostedBy(post); + const int repliesCount = d->database.repliesCount(post); + const int favouritesCount = d->database.favouritesCount(post); + const int reblogsCount = d->database.reblogsCount(post); eventMap.insert(MastodonPostsModel::MastodonId, post->identifier()); eventMap.insert(MastodonPostsModel::Name, post->name()); @@ -112,6 +118,9 @@ void MastodonPostsModel::postsChanged() eventMap.insert(MastodonPostsModel::Link, postUrl); eventMap.insert(MastodonPostsModel::BoostedBy, boostedBy); eventMap.insert(MastodonPostsModel::RebloggedBy, boostedBy); + eventMap.insert(MastodonPostsModel::RepliesCount, repliesCount); + eventMap.insert(MastodonPostsModel::FavouritesCount, favouritesCount); + eventMap.insert(MastodonPostsModel::ReblogsCount, reblogsCount); eventMap.insert(MastodonPostsModel::InstanceUrl, d->database.instanceUrl(post)); QVariantList images; diff --git a/eventsview-plugins/eventsview-plugin-mastodon/mastodonpostsmodel.h b/eventsview-plugins/eventsview-plugin-mastodon/mastodonpostsmodel.h index 150438a..586d1a0 100644 --- a/eventsview-plugins/eventsview-plugin-mastodon/mastodonpostsmodel.h +++ b/eventsview-plugins/eventsview-plugin-mastodon/mastodonpostsmodel.h @@ -42,6 +42,9 @@ public: Link, BoostedBy, RebloggedBy, + RepliesCount, + FavouritesCount, + ReblogsCount, InstanceUrl, Accounts }; |
