summaryrefslogtreecommitdiff
path: root/eventsview-plugins/eventsview-plugin-mastodon/mastodon-delegate.qml
diff options
context:
space:
mode:
Diffstat (limited to 'eventsview-plugins/eventsview-plugin-mastodon/mastodon-delegate.qml')
-rw-r--r--eventsview-plugins/eventsview-plugin-mastodon/mastodon-delegate.qml214
1 files changed, 0 insertions, 214 deletions
diff --git a/eventsview-plugins/eventsview-plugin-mastodon/mastodon-delegate.qml b/eventsview-plugins/eventsview-plugin-mastodon/mastodon-delegate.qml
deleted file mode 100644
index fac0b89..0000000
--- a/eventsview-plugins/eventsview-plugin-mastodon/mastodon-delegate.qml
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2013 - 2026 Jolla Ltd.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-import QtQuick 2.0
-import Sailfish.Silica 1.0
-import org.nemomobile.socialcache 1.0
-import com.jolla.eventsview.mastodon 1.0
-import QtQml.Models 2.1
-import "shared"
-
-SocialMediaAccountDelegate {
- id: delegateItem
-
- //: Mastodon posts
- //% "Posts"
- headerText: qsTrId("lipstick-jolla-home-la-mastodon_posts")
- headerIcon: "image://theme/icon-l-mastodon"
- showRemainingCount: false
-
- services: ["Posts"]
- socialNetwork: 9
- dataType: SocialSync.Posts
- providerName: "mastodon"
-
- MastodonPostActions {
- id: mastodonPostActions
- }
-
- model: MastodonPostsModel {
- onCountChanged: {
- if (count > 0) {
- if (!updateTimer.running) {
- shortUpdateTimer.start()
- }
- } else {
- shortUpdateTimer.stop()
- }
- }
- }
-
- delegate: MastodonFeedItem {
- downloader: delegateItem.downloader
- imageList: delegateItem.variantRole(model, ["images", "mediaAttachments", "media"])
- avatarSource: delegateItem.convertUrl(delegateItem.stringRole(model, ["icon", "avatar", "avatarUrl"]))
- fallbackAvatarSource: delegateItem.stringRole(model, ["icon", "avatar", "avatarUrl"])
- resolvedStatusUrl: delegateItem.authorizeInteractionUrl(model)
- postId: delegateItem.stringRole(model, ["mastodonId", "statusId", "id", "twitterId"])
- postActions: mastodonPostActions
- accountId: delegateItem.firstAccountId(model)
-
- onTriggered: Qt.openUrlExternally(resolvedStatusUrl)
-
- Component.onCompleted: {
- refreshTimeCount = Qt.binding(function() { return delegateItem.refreshTimeCount })
- connectedToNetwork = Qt.binding(function() { return delegateItem.connectedToNetwork })
- eventsColumnMaxWidth = Qt.binding(function() { return delegateItem.eventsColumnMaxWidth })
- }
- }
- //% "Show more in Mastodon"
- expandedLabel: qsTrId("lipstick-jolla-home-la-show-more-in-mastodon")
-
- onHeaderClicked: Qt.openUrlExternally("https://mastodon.social/explore")
- onExpandedClicked: Qt.openUrlExternally("https://mastodon.social/explore")
-
- onViewVisibleChanged: {
- if (viewVisible) {
- delegateItem.resetHasSyncableAccounts()
- delegateItem.model.refresh()
- if (delegateItem.hasSyncableAccounts && !updateTimer.running) {
- shortUpdateTimer.start()
- }
- } else {
- shortUpdateTimer.stop()
- }
- }
-
- onConnectedToNetworkChanged: {
- if (viewVisible) {
- if (!updateTimer.running) {
- shortUpdateTimer.start()
- }
- }
- }
-
- // The Mastodon feed is updated 3 seconds after the feed view becomes visible,
- // unless it has been updated during last 60 seconds. After that it will be updated
- // periodically in every 60 seconds as long as the feed view is visible.
-
- Timer {
- id: shortUpdateTimer
-
- interval: 3000
- onTriggered: {
- delegateItem.sync()
- updateTimer.start()
- }
- }
-
- Timer {
- id: updateTimer
-
- interval: 60000
- repeat: true
- onTriggered: {
- if (delegateItem.viewVisible) {
- delegateItem.sync()
- } else {
- stop()
- }
- }
- }
-
- function variantRole(modelData, roleNames) {
- for (var i = 0; i < roleNames.length; ++i) {
- var value = modelData[roleNames[i]]
- if (typeof value !== "undefined" && value !== null) {
- return value
- }
- }
- return undefined
- }
-
- function stringRole(modelData, roleNames) {
- for (var i = 0; i < roleNames.length; ++i) {
- var value = modelData[roleNames[i]]
- if (typeof value === "undefined" || value === null) {
- continue
- }
- value = String(value)
- if (value.length > 0) {
- return value
- }
- }
- return ""
- }
-
- function statusUrl(modelData) {
- var directUrl = stringRole(modelData, ["url", "link", "uri"])
- if (directUrl.length > 0) {
- return directUrl
- }
-
- var instanceUrl = stringRole(modelData, ["instanceUrl", "serverUrl", "baseUrl"])
- if (instanceUrl.length === 0) {
- instanceUrl = "https://mastodon.social"
- }
- while (instanceUrl.length > 0 && instanceUrl.charAt(instanceUrl.length - 1) === "/") {
- instanceUrl = instanceUrl.slice(0, instanceUrl.length - 1)
- }
-
- var accountName = stringRole(modelData, ["accountName", "acct", "screenName", "username"])
- var statusId = stringRole(modelData, ["mastodonId", "statusId", "id", "twitterId"])
- if (accountName.length > 0 && statusId.length > 0) {
- while (accountName.length > 0 && accountName.charAt(0) === "@") {
- accountName = accountName.substring(1)
- }
- return instanceUrl + "/@" + accountName + "/" + statusId
- }
-
- return instanceUrl + "/explore"
- }
-
- function authorizeInteractionUrl(modelData) {
- var targetUrl = statusUrl(modelData)
- if (targetUrl.length === 0) {
- return targetUrl
- }
-
- var instanceUrl = stringRole(modelData, ["instanceUrl", "serverUrl", "baseUrl"])
- if (instanceUrl.length === 0) {
- return targetUrl
- }
- while (instanceUrl.length > 0 && instanceUrl.charAt(instanceUrl.length - 1) === "/") {
- instanceUrl = instanceUrl.slice(0, instanceUrl.length - 1)
- }
-
- // Links on the user's own instance should open directly.
- var sameServer = /^([a-z][a-z0-9+.-]*):\/\/([^\/?#]+)/i
- var targetMatch = targetUrl.match(sameServer)
- var instanceMatch = instanceUrl.match(sameServer)
- if (targetMatch && instanceMatch
- && targetMatch.length > 2
- && instanceMatch.length > 2
- && targetMatch[1].toLowerCase() === instanceMatch[1].toLowerCase()
- && targetMatch[2].toLowerCase() === instanceMatch[2].toLowerCase()) {
- return targetUrl
- }
-
- return instanceUrl + "/authorize_interaction?uri=" + encodeURIComponent(targetUrl)
- }
-
- function convertUrl(source) {
- if (source.indexOf("_normal.") !== -1) {
- return source.replace("_normal.", "_bigger.")
- } else if (source.indexOf("_mini.") !== -1) {
- return source.replace("_mini.", "_bigger.")
- }
- return source
- }
-
- function firstAccountId(modelData) {
- var accounts = modelData.accounts
- if (accounts && accounts.length > 0) {
- var accountId = Number(accounts[0])
- if (!isNaN(accountId)) {
- return accountId
- }
- }
- return -1
- }
-}