summaryrefslogtreecommitdiff
path: root/packages/backend
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-01-31 11:14:21 -0500
committerHazelnoot <acomputerdog@gmail.com>2025-02-08 13:17:50 -0500
commitbd95e8a555e2fcb8b72ae4fbe496495af28fc8b3 (patch)
tree83ef8655ede379a8f68e03f0858b2aaad7d7c75c /packages/backend
parentadd `memo` and `isInstanceMuted` to UserRelation API entity (diff)
downloadsharkey-bd95e8a555e2fcb8b72ae4fbe496495af28fc8b3.tar.gz
sharkey-bd95e8a555e2fcb8b72ae4fbe496495af28fc8b3.tar.bz2
sharkey-bd95e8a555e2fcb8b72ae4fbe496495af28fc8b3.zip
fix relationship data for Mastodon API (resolves #714)
Diffstat (limited to 'packages/backend')
-rw-r--r--packages/backend/src/server/api/mastodon/converters.ts23
-rw-r--r--packages/backend/src/server/api/mastodon/endpoints/account.ts10
2 files changed, 26 insertions, 7 deletions
diff --git a/packages/backend/src/server/api/mastodon/converters.ts b/packages/backend/src/server/api/mastodon/converters.ts
index 3cb6ca61ce..4aea91b4f2 100644
--- a/packages/backend/src/server/api/mastodon/converters.ts
+++ b/packages/backend/src/server/api/mastodon/converters.ts
@@ -339,6 +339,7 @@ export function convertPoll(poll: Entity.Poll) {
return simpleConvert(poll);
}
+// noinspection JSUnusedGlobalSymbols
export function convertReaction(reaction: Entity.Reaction) {
if (reaction.accounts) {
reaction.accounts = reaction.accounts.map(convertAccount);
@@ -346,8 +347,25 @@ export function convertReaction(reaction: Entity.Reaction) {
return reaction;
}
-export function convertRelationship(relationship: Entity.Relationship) {
- return simpleConvert(relationship);
+// Megalodon sometimes returns broken / stubbed relationship data
+export function convertRelationship(relationship: Partial<Entity.Relationship> & { id: string }): MastodonEntity.Relationship {
+ return {
+ id: relationship.id,
+ following: relationship.following ?? false,
+ showing_reblogs: relationship.showing_reblogs ?? true,
+ notifying: relationship.notifying ?? true,
+ languages: [],
+ followed_by: relationship.followed_by ?? false,
+ blocking: relationship.blocking ?? false,
+ blocked_by: relationship.blocked_by ?? false,
+ muting: relationship.muting ?? false,
+ muting_notifications: relationship.muting_notifications ?? false,
+ requested: relationship.requested ?? false,
+ requested_by: relationship.requested_by ?? false,
+ domain_blocking: relationship.domain_blocking ?? false,
+ endorsed: relationship.endorsed ?? false,
+ note: relationship.note ?? '',
+ };
}
export function convertStatus(status: Entity.Status) {
@@ -361,6 +379,7 @@ export function convertStatus(status: Entity.Status) {
return status;
}
+// noinspection JSUnusedGlobalSymbols
export function convertStatusSource(status: Entity.StatusSource) {
return simpleConvert(status);
}
diff --git a/packages/backend/src/server/api/mastodon/endpoints/account.ts b/packages/backend/src/server/api/mastodon/endpoints/account.ts
index d24a62fb06..1481a48924 100644
--- a/packages/backend/src/server/api/mastodon/endpoints/account.ts
+++ b/packages/backend/src/server/api/mastodon/endpoints/account.ts
@@ -74,7 +74,7 @@ export class ApiAccountMastodon {
public async addFollow() {
if (!this.request.params.id) throw new Error('Missing required parameter "id"');
- const data = await this.client.followAccount( this.request.params.id );
+ const data = await this.client.followAccount(this.request.params.id);
const acct = convertRelationship(data.data);
acct.following = true;
return acct;
@@ -82,7 +82,7 @@ export class ApiAccountMastodon {
public async rmFollow() {
if (!this.request.params.id) throw new Error('Missing required parameter "id"');
- const data = await this.client.unfollowAccount( this.request.params.id );
+ const data = await this.client.unfollowAccount(this.request.params.id);
const acct = convertRelationship(data.data);
acct.following = false;
return acct;
@@ -90,13 +90,13 @@ export class ApiAccountMastodon {
public async addBlock() {
if (!this.request.params.id) throw new Error('Missing required parameter "id"');
- const data = await this.client.blockAccount( this.request.params.id );
+ const data = await this.client.blockAccount(this.request.params.id);
return convertRelationship(data.data);
}
public async rmBlock() {
if (!this.request.params.id) throw new Error('Missing required parameter "id"');
- const data = await this.client.unblockAccount( this.request.params.id );
+ const data = await this.client.unblockAccount(this.request.params.id);
return convertRelationship(data.data);
}
@@ -111,7 +111,7 @@ export class ApiAccountMastodon {
public async rmMute() {
if (!this.request.params.id) throw new Error('Missing required parameter "id"');
- const data = await this.client.unmuteAccount( this.request.params.id );
+ const data = await this.client.unmuteAccount(this.request.params.id);
return convertRelationship(data.data);
}