summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@jolla.com>2026-04-03 22:55:30 +0200
committerAndrew Branson <andrew.branson@jolla.com>2026-04-04 11:55:25 +0200
commita35c9fa159173388d88ef77e1d31f53488aad094 (patch)
treee4691b5bbf054ca13e35d98d9df653bf9cdc0054 /common
parent5f999f7a4712c4a4d1c89054b544064cfd4b769e (diff)
Generalize for all fediverse accounts
Diffstat (limited to 'common')
-rw-r--r--common/common.pri2
-rw-r--r--common/common.pro10
-rw-r--r--common/fediverseauthutils.h (renamed from common/mastodonauthutils.h)26
-rw-r--r--common/fediversepostsdatabase.cpp (renamed from common/mastodonpostsdatabase.cpp)107
-rw-r--r--common/fediversepostsdatabase.h (renamed from common/mastodonpostsdatabase.h)18
-rw-r--r--common/fediversetextutils.h (renamed from common/mastodontextutils.h)10
6 files changed, 95 insertions, 78 deletions
diff --git a/common/common.pri b/common/common.pri
index 7f593db..1e75506 100644
--- a/common/common.pri
+++ b/common/common.pri
@@ -5,4 +5,4 @@
INCLUDEPATH += $$PWD
DEPENDPATH += .
-LIBS += -L$$PWD -lmastodoncommon
+LIBS += -L$$PWD -lfediversecommon
diff --git a/common/common.pro b/common/common.pro
index c01e571..13aadb0 100644
--- a/common/common.pro
+++ b/common/common.pro
@@ -10,16 +10,16 @@ QT += sql
CONFIG += link_pkgconfig
PKGCONFIG += socialcache
-TARGET = mastodoncommon
+TARGET = fediversecommon
TARGET = $$qtLibraryTarget($$TARGET)
HEADERS += \
- $$PWD/mastodonauthutils.h \
- $$PWD/mastodontextutils.h \
- $$PWD/mastodonpostsdatabase.h
+ $$PWD/fediverseauthutils.h \
+ $$PWD/fediversetextutils.h \
+ $$PWD/fediversepostsdatabase.h
SOURCES += \
- $$PWD/mastodonpostsdatabase.cpp
+ $$PWD/fediversepostsdatabase.cpp
TARGETPATH = $$[QT_INSTALL_LIBS]
target.path = $$TARGETPATH
diff --git a/common/mastodonauthutils.h b/common/fediverseauthutils.h
index 3f1fc85..01f264a 100644
--- a/common/mastodonauthutils.h
+++ b/common/fediverseauthutils.h
@@ -16,8 +16,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef MASTODONAUTHUTILS_H
-#define MASTODONAUTHUTILS_H
+#ifndef FEDIVERSEAUTHUTILS_H
+#define FEDIVERSEAUTHUTILS_H
#include <QtCore/QVariantMap>
#include <QtCore/QUrl>
@@ -26,13 +26,23 @@
#include <SignOn/SessionData>
-namespace MastodonAuthUtils {
+namespace FediverseAuthUtils {
+
+inline QString defaultServerHost()
+{
+ return QStringLiteral("mastodon.social");
+}
+
+inline QString defaultApiHost()
+{
+ return QStringLiteral("https://") + defaultServerHost();
+}
inline QString normalizeApiHost(const QString &rawHost)
{
QString host = rawHost.trimmed();
if (host.isEmpty()) {
- host = QStringLiteral("https://mastodon.social");
+ host = defaultServerHost();
}
if (!host.startsWith(QLatin1String("https://"))
&& !host.startsWith(QLatin1String("http://"))) {
@@ -41,7 +51,7 @@ inline QString normalizeApiHost(const QString &rawHost)
QUrl url(host);
if (!url.isValid() || url.host().isEmpty()) {
- return QStringLiteral("https://mastodon.social");
+ return defaultApiHost();
}
QString normalized = QString::fromLatin1(url.toEncoded(QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment));
@@ -72,7 +82,7 @@ inline QString signOnHost(Accounts::Account *account)
configuredHost.chop(1);
}
if (configuredHost.isEmpty()) {
- configuredHost = QStringLiteral("mastodon.social");
+ configuredHost = defaultServerHost();
}
return configuredHost;
@@ -138,6 +148,6 @@ inline QVariantMap responseDataToMap(const SignOn::SessionData &responseData)
return data;
}
-} // namespace MastodonAuthUtils
+} // namespace FediverseAuthUtils
-#endif // MASTODONAUTHUTILS_H
+#endif // FEDIVERSEAUTHUTILS_H
diff --git a/common/mastodonpostsdatabase.cpp b/common/fediversepostsdatabase.cpp
index 7f82162..50bdf96 100644
--- a/common/mastodonpostsdatabase.cpp
+++ b/common/fediversepostsdatabase.cpp
@@ -16,9 +16,33 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "mastodonpostsdatabase.h"
+#include "fediversepostsdatabase.h"
-static const char *DB_NAME = "mastodon.db";
+namespace {
+
+QVariantMap postExtra(const SocialPost::ConstPtr &post)
+{
+ return post ? post->extra() : QVariantMap();
+}
+
+QString extraString(const SocialPost::ConstPtr &post, const char *key)
+{
+ return postExtra(post).value(QString::fromLatin1(key)).toString();
+}
+
+int extraInt(const SocialPost::ConstPtr &post, const char *key, int defaultValue = 0)
+{
+ return postExtra(post).value(QString::fromLatin1(key), defaultValue).toInt();
+}
+
+bool extraBool(const SocialPost::ConstPtr &post, const char *key, bool defaultValue = false)
+{
+ return postExtra(post).value(QString::fromLatin1(key), defaultValue).toBool();
+}
+
+}
+
+static const char *DB_NAME = "fediverse.db";
static const char *ACCOUNT_NAME_KEY = "account_name";
static const char *URL_KEY = "url";
static const char *BOOSTED_BY_KEY = "boosted_by";
@@ -28,17 +52,18 @@ static const char *REBLOGS_COUNT_KEY = "reblogs_count";
static const char *FAVOURITED_KEY = "favourited";
static const char *REBLOGGED_KEY = "reblogged";
static const char *INSTANCE_URL_KEY = "instance_url";
+static const char *INSTANCE_ICON_PATH_KEY = "instance_icon_path";
-MastodonPostsDatabase::MastodonPostsDatabase()
- : AbstractSocialPostCacheDatabase(QStringLiteral("mastodon"), QLatin1String(DB_NAME))
+FediversePostsDatabase::FediversePostsDatabase()
+ : AbstractSocialPostCacheDatabase(QStringLiteral("fediverse"), QLatin1String(DB_NAME))
{
}
-MastodonPostsDatabase::~MastodonPostsDatabase()
+FediversePostsDatabase::~FediversePostsDatabase()
{
}
-void MastodonPostsDatabase::addMastodonPost(
+void FediversePostsDatabase::addFediversePost(
const QString &identifier,
const QString &name,
const QString &accountName,
@@ -54,6 +79,7 @@ void MastodonPostsDatabase::addMastodonPost(
bool favourited,
bool reblogged,
const QString &instanceUrl,
+ const QString &instanceIconPath,
int account)
{
QVariantMap extra;
@@ -66,77 +92,56 @@ void MastodonPostsDatabase::addMastodonPost(
extra.insert(FAVOURITED_KEY, favourited);
extra.insert(REBLOGGED_KEY, reblogged);
extra.insert(INSTANCE_URL_KEY, instanceUrl);
+ extra.insert(INSTANCE_ICON_PATH_KEY, instanceIconPath);
addPost(identifier, name, body, timestamp, icon, images, extra, account);
}
-QString MastodonPostsDatabase::accountName(const SocialPost::ConstPtr &post)
+QString FediversePostsDatabase::accountName(const SocialPost::ConstPtr &post)
+{
+ return extraString(post, ACCOUNT_NAME_KEY);
+}
+
+QString FediversePostsDatabase::url(const SocialPost::ConstPtr &post)
{
- if (post.isNull()) {
- return QString();
- }
- return post->extra().value(ACCOUNT_NAME_KEY).toString();
+ return extraString(post, URL_KEY);
}
-QString MastodonPostsDatabase::url(const SocialPost::ConstPtr &post)
+QString FediversePostsDatabase::boostedBy(const SocialPost::ConstPtr &post)
{
- if (post.isNull()) {
- return QString();
- }
- return post->extra().value(URL_KEY).toString();
+ return extraString(post, BOOSTED_BY_KEY);
}
-QString MastodonPostsDatabase::boostedBy(const SocialPost::ConstPtr &post)
+int FediversePostsDatabase::repliesCount(const SocialPost::ConstPtr &post)
{
- if (post.isNull()) {
- return QString();
- }
- return post->extra().value(BOOSTED_BY_KEY).toString();
+ return extraInt(post, REPLIES_COUNT_KEY);
}
-int MastodonPostsDatabase::repliesCount(const SocialPost::ConstPtr &post)
+int FediversePostsDatabase::favouritesCount(const SocialPost::ConstPtr &post)
{
- if (post.isNull()) {
- return 0;
- }
- return post->extra().value(REPLIES_COUNT_KEY).toInt();
+ return extraInt(post, FAVOURITES_COUNT_KEY);
}
-int MastodonPostsDatabase::favouritesCount(const SocialPost::ConstPtr &post)
+int FediversePostsDatabase::reblogsCount(const SocialPost::ConstPtr &post)
{
- if (post.isNull()) {
- return 0;
- }
- return post->extra().value(FAVOURITES_COUNT_KEY).toInt();
+ return extraInt(post, REBLOGS_COUNT_KEY);
}
-int MastodonPostsDatabase::reblogsCount(const SocialPost::ConstPtr &post)
+bool FediversePostsDatabase::favourited(const SocialPost::ConstPtr &post)
{
- if (post.isNull()) {
- return 0;
- }
- return post->extra().value(REBLOGS_COUNT_KEY).toInt();
+ return extraBool(post, FAVOURITED_KEY);
}
-bool MastodonPostsDatabase::favourited(const SocialPost::ConstPtr &post)
+bool FediversePostsDatabase::reblogged(const SocialPost::ConstPtr &post)
{
- if (post.isNull()) {
- return false;
- }
- return post->extra().value(FAVOURITED_KEY).toBool();
+ return extraBool(post, REBLOGGED_KEY);
}
-bool MastodonPostsDatabase::reblogged(const SocialPost::ConstPtr &post)
+QString FediversePostsDatabase::instanceUrl(const SocialPost::ConstPtr &post)
{
- if (post.isNull()) {
- return false;
- }
- return post->extra().value(REBLOGGED_KEY).toBool();
+ return extraString(post, INSTANCE_URL_KEY);
}
-QString MastodonPostsDatabase::instanceUrl(const SocialPost::ConstPtr &post)
+QString FediversePostsDatabase::instanceIconPath(const SocialPost::ConstPtr &post)
{
- if (post.isNull()) {
- return QString();
- }
- return post->extra().value(INSTANCE_URL_KEY).toString();
+ return extraString(post, INSTANCE_ICON_PATH_KEY);
}
diff --git a/common/mastodonpostsdatabase.h b/common/fediversepostsdatabase.h
index 9736fa8..2c085e0 100644
--- a/common/mastodonpostsdatabase.h
+++ b/common/fediversepostsdatabase.h
@@ -16,19 +16,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef MASTODONPOSTSDATABASE_H
-#define MASTODONPOSTSDATABASE_H
+#ifndef FEDIVERSEPOSTSDATABASE_H
+#define FEDIVERSEPOSTSDATABASE_H
-#include <socialcache/abstractsocialpostcachedatabase.h>
+#include <abstractsocialpostcachedatabase.h>
-class MastodonPostsDatabase: public AbstractSocialPostCacheDatabase
+class FediversePostsDatabase: public AbstractSocialPostCacheDatabase
{
Q_OBJECT
public:
- MastodonPostsDatabase();
- ~MastodonPostsDatabase();
+ FediversePostsDatabase();
+ ~FediversePostsDatabase();
- void addMastodonPost(const QString &identifier, const QString &name,
+ void addFediversePost(const QString &identifier, const QString &name,
const QString &accountName, const QString &body,
const QDateTime &timestamp,
const QString &icon,
@@ -37,6 +37,7 @@ public:
int repliesCount, int favouritesCount, int reblogsCount,
bool favourited, bool reblogged,
const QString &instanceUrl,
+ const QString &instanceIconPath,
int account);
static QString accountName(const SocialPost::ConstPtr &post);
@@ -48,6 +49,7 @@ public:
static bool favourited(const SocialPost::ConstPtr &post);
static bool reblogged(const SocialPost::ConstPtr &post);
static QString instanceUrl(const SocialPost::ConstPtr &post);
+ static QString instanceIconPath(const SocialPost::ConstPtr &post);
};
-#endif // MASTODONPOSTSDATABASE_H
+#endif // FEDIVERSEPOSTSDATABASE_H
diff --git a/common/mastodontextutils.h b/common/fediversetextutils.h
index bde74c4..4fa7aed 100644
--- a/common/mastodontextutils.h
+++ b/common/fediversetextutils.h
@@ -16,14 +16,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef MASTODONTEXTUTILS_H
-#define MASTODONTEXTUTILS_H
+#ifndef FEDIVERSETEXTUTILS_H
+#define FEDIVERSETEXTUTILS_H
#include <QtCore/QDateTime>
#include <QtCore/QRegularExpression>
#include <QtCore/QString>
-namespace MastodonTextUtils {
+namespace FediverseTextUtils {
inline QString decodeHtmlEntities(QString text)
{
@@ -117,6 +117,6 @@ inline QDateTime parseTimestamp(const QString &timestampString)
return timestamp;
}
-} // namespace MastodonTextUtils
+} // namespace FediverseTextUtils
-#endif // MASTODONTEXTUTILS_H
+#endif // FEDIVERSETEXTUTILS_H