From acd60f2b49bcc27386cdc94e7fdbd24b4ba44544 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Mon, 16 Oct 2023 23:20:01 +0900
Subject: [PATCH] Define StatusVisibility type for each SNS
---
megalodon/src/entities/preferences.ts | 4 +++-
megalodon/src/entities/status.ts | 4 +++-
megalodon/src/entities/status_params.ts | 4 +++-
megalodon/src/entity.ts | 1 +
megalodon/src/firefish.ts | 4 ++--
megalodon/src/firefish/api_client.ts | 11 ++++++-----
megalodon/src/firefish/entities/note.ts | 4 +++-
megalodon/src/firefish/entity.ts | 1 +
megalodon/src/friendica.ts | 4 ++--
megalodon/src/friendica/api_client.ts | 13 +++++++++++++
megalodon/src/friendica/entities/preferences.ts | 4 +++-
megalodon/src/friendica/entities/status.ts | 4 +++-
megalodon/src/friendica/entities/status_params.ts | 4 +++-
megalodon/src/friendica/entity.ts | 1 +
megalodon/src/mastodon.ts | 2 +-
megalodon/src/mastodon/entities/preferences.ts | 4 +++-
megalodon/src/mastodon/entities/status.ts | 4 +++-
megalodon/src/mastodon/entities/status_params.ts | 4 +++-
megalodon/src/megalodon.ts | 2 +-
megalodon/src/pleroma/entities/preferences.ts | 4 +++-
megalodon/src/pleroma/entities/status.ts | 4 +++-
megalodon/src/pleroma/entities/status_params.ts | 4 +++-
22 files changed, 67 insertions(+), 24 deletions(-)
diff --git a/megalodon/src/entities/preferences.ts b/megalodon/src/entities/preferences.ts
index e0646f6de..3777c9b21 100644
--- a/megalodon/src/entities/preferences.ts
+++ b/megalodon/src/entities/preferences.ts
@@ -1,5 +1,7 @@
+import { StatusVisibility } from './status'
+
export type Preferences = {
- 'posting:default:visibility': 'public' | 'unlisted' | 'private' | 'direct'
+ 'posting:default:visibility': StatusVisibility
'posting:default:sensitive': boolean
'posting:default:language': string | null
'reading:expand:media': 'default' | 'show_all' | 'hide_all'
diff --git a/megalodon/src/entities/status.ts b/megalodon/src/entities/status.ts
index 21797358d..f144a8772 100644
--- a/megalodon/src/entities/status.ts
+++ b/megalodon/src/entities/status.ts
@@ -27,7 +27,7 @@ export type Status = {
muted: boolean | null
sensitive: boolean
spoiler_text: string
- visibility: 'public' | 'unlisted' | 'private' | 'direct'
+ visibility: StatusVisibility
media_attachments: Array
mentions: Array
tags: Array
@@ -45,3 +45,5 @@ export type StatusTag = {
name: string
url: string
}
+
+export type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct'
diff --git a/megalodon/src/entities/status_params.ts b/megalodon/src/entities/status_params.ts
index 6a758ad8c..855640dba 100644
--- a/megalodon/src/entities/status_params.ts
+++ b/megalodon/src/entities/status_params.ts
@@ -1,10 +1,12 @@
+import { StatusVisibility } from './status'
+
export type StatusParams = {
text: string
in_reply_to_id: string | null
media_ids: Array | null
sensitive: boolean | null
spoiler_text: string | null
- visibility: 'public' | 'unlisted' | 'private' | 'direct' | null
+ visibility: StatusVisibility | null
scheduled_at: string | null
application_id: number | null
}
diff --git a/megalodon/src/entity.ts b/megalodon/src/entity.ts
index 024c4f3c4..dff6bd298 100644
--- a/megalodon/src/entity.ts
+++ b/megalodon/src/entity.ts
@@ -84,6 +84,7 @@ export namespace Entity {
export type Source = source.Source
export type Stats = stats.Stats
export type Status = status.Status
+ export type StatusVisibility = status.StatusVisibility
export type StatusTag = status.StatusTag
export type StatusParams = status_params.StatusParams
export type StatusSource = status_source.StatusSource
diff --git a/megalodon/src/firefish.ts b/megalodon/src/firefish.ts
index 460da05f5..383a0f267 100644
--- a/megalodon/src/firefish.ts
+++ b/megalodon/src/firefish.ts
@@ -960,7 +960,7 @@ export default class Firefish implements MegalodonInterface {
})
}
- private async getDefaultPostPrivacy(): Promise {
+ private async getDefaultPostPrivacy(): Promise {
return this.client
.post('/api/i/registry/get-unsecure', {
key: 'defaultNoteVisibility',
@@ -1036,7 +1036,7 @@ export default class Firefish implements MegalodonInterface {
in_reply_to_id?: string
sensitive?: boolean
spoiler_text?: string
- visibility?: 'public' | 'unlisted' | 'private' | 'direct'
+ visibility?: Entity.StatusVisibility
scheduled_at?: string
language?: string
quote_id?: string
diff --git a/megalodon/src/firefish/api_client.ts b/megalodon/src/firefish/api_client.ts
index 5c81dda76..9903a2e4c 100644
--- a/megalodon/src/firefish/api_client.ts
+++ b/megalodon/src/firefish/api_client.ts
@@ -28,6 +28,7 @@ namespace FirefishAPI {
export type Meta = FirefishEntity.Meta
export type Mute = FirefishEntity.Mute
export type Note = FirefishEntity.Note
+ export type NoteVisibility = FirefishEntity.NoteVisibility
export type Notification = FirefishEntity.Notification
export type Poll = FirefishEntity.Poll
export type Reaction = FirefishEntity.Reaction
@@ -157,7 +158,7 @@ namespace FirefishAPI {
export const userPreferences = (
u: FirefishAPI.Entity.UserDetailMe,
- v: 'public' | 'unlisted' | 'private' | 'direct'
+ v: MegalodonEntity.StatusVisibility
): MegalodonEntity.Preferences => {
return {
'reading:expand:media': 'default',
@@ -168,9 +169,7 @@ namespace FirefishAPI {
}
}
- export const visibility = (
- v: 'public' | 'home' | 'followers' | 'specified' | 'hidden'
- ): 'public' | 'unlisted' | 'private' | 'direct' => {
+ export const visibility = (v: FirefishAPI.Entity.NoteVisibility): MegalodonEntity.StatusVisibility => {
switch (v) {
case 'public':
return v
@@ -182,10 +181,12 @@ namespace FirefishAPI {
return 'direct'
case 'hidden':
return 'direct'
+ default:
+ return 'public'
}
}
- export const encodeVisibility = (v: 'public' | 'unlisted' | 'private' | 'direct'): 'public' | 'home' | 'followers' | 'specified' => {
+ export const encodeVisibility = (v: MegalodonEntity.StatusVisibility): FirefishAPI.Entity.NoteVisibility => {
switch (v) {
case 'public':
return v
diff --git a/megalodon/src/firefish/entities/note.ts b/megalodon/src/firefish/entities/note.ts
index 700279deb..854b45155 100644
--- a/megalodon/src/firefish/entities/note.ts
+++ b/megalodon/src/firefish/entities/note.ts
@@ -10,7 +10,7 @@ export type Note = {
user: User
text: string | null
cw?: string | null
- visibility: 'public' | 'home' | 'followers' | 'specified' | 'hidden'
+ visibility: NoteVisibility
renoteCount: number
repliesCount: number
reactions: { [key: string]: number }
@@ -27,3 +27,5 @@ export type Note = {
mentions?: Array
myReaction?: string | null
}
+
+export type NoteVisibility = 'public' | 'home' | 'followers' | 'specified' | 'hidden'
diff --git a/megalodon/src/firefish/entity.ts b/megalodon/src/firefish/entity.ts
index 6ea5cccd5..1422cbbf6 100644
--- a/megalodon/src/firefish/entity.ts
+++ b/megalodon/src/firefish/entity.ts
@@ -41,6 +41,7 @@ export namespace Entity {
export type Meta = meta.Meta
export type Mute = mute.Mute
export type Note = note.Note
+ export type NoteVisibility = note.NoteVisibility
export type Notification = notification.Notification
export type NotificationType = notification.NotificationType
export type Poll = poll.Poll
diff --git a/megalodon/src/friendica.ts b/megalodon/src/friendica.ts
index aa3c44548..9128da746 100644
--- a/megalodon/src/friendica.ts
+++ b/megalodon/src/friendica.ts
@@ -1255,7 +1255,7 @@ export default class Friendica implements MegalodonInterface {
in_reply_to_id?: string
sensitive?: boolean
spoiler_text?: string
- visibility?: 'public' | 'unlisted' | 'private' | 'direct'
+ visibility?: Entity.StatusVisibility
scheduled_at?: string
language?: string
quote_id?: string
@@ -1306,7 +1306,7 @@ export default class Friendica implements MegalodonInterface {
}
if (options.visibility) {
params = Object.assign(params, {
- visibility: options.visibility
+ visibility: FriendicaAPI.Converter.encodeVisibility(options.visibility)
})
}
if (options.scheduled_at) {
diff --git a/megalodon/src/friendica/api_client.ts b/megalodon/src/friendica/api_client.ts
index 1f27fd6d2..82f8c17bc 100644
--- a/megalodon/src/friendica/api_client.ts
+++ b/megalodon/src/friendica/api_client.ts
@@ -473,6 +473,7 @@ namespace FriendicaAPI {
export type Source = FriendicaEntity.Source
export type Stats = FriendicaEntity.Stats
export type Status = FriendicaEntity.Status
+ export type StatusVisibility = FriendicaEntity.StatusVisibility
export type StatusParams = FriendicaEntity.StatusParams
export type StatusSource = FriendicaEntity.StatusSource
export type Tag = FriendicaEntity.Tag
@@ -531,6 +532,18 @@ namespace FriendicaAPI {
}
}
+ export const encodeVisibility = (v: MegalodonEntity.StatusVisibility): FriendicaAPI.Entity.StatusVisibility => {
+ switch (v) {
+ case 'public':
+ return 'public'
+ case 'unlisted':
+ return 'unlisted'
+ case 'direct':
+ case 'private':
+ return 'private'
+ }
+ }
+
export const account = (a: Entity.Account): MegalodonEntity.Account => ({
id: a.id,
username: a.username,
diff --git a/megalodon/src/friendica/entities/preferences.ts b/megalodon/src/friendica/entities/preferences.ts
index e0646f6de..3777c9b21 100644
--- a/megalodon/src/friendica/entities/preferences.ts
+++ b/megalodon/src/friendica/entities/preferences.ts
@@ -1,5 +1,7 @@
+import { StatusVisibility } from './status'
+
export type Preferences = {
- 'posting:default:visibility': 'public' | 'unlisted' | 'private' | 'direct'
+ 'posting:default:visibility': StatusVisibility
'posting:default:sensitive': boolean
'posting:default:language': string | null
'reading:expand:media': 'default' | 'show_all' | 'hide_all'
diff --git a/megalodon/src/friendica/entities/status.ts b/megalodon/src/friendica/entities/status.ts
index 3b35c1af6..0d89b5efe 100644
--- a/megalodon/src/friendica/entities/status.ts
+++ b/megalodon/src/friendica/entities/status.ts
@@ -25,7 +25,7 @@ export type Status = {
muted: boolean | null
sensitive: boolean
spoiler_text: string
- visibility: 'public' | 'unlisted' | 'private' | 'direct'
+ visibility: StatusVisibility
media_attachments: Array
mentions: Array
tags: Array
@@ -44,3 +44,5 @@ export type StatusTag = {
name: string
url: string
}
+
+export type StatusVisibility = 'public' | 'unlisted' | 'private'
diff --git a/megalodon/src/friendica/entities/status_params.ts b/megalodon/src/friendica/entities/status_params.ts
index eecb3bb79..b0f572a67 100644
--- a/megalodon/src/friendica/entities/status_params.ts
+++ b/megalodon/src/friendica/entities/status_params.ts
@@ -1,10 +1,12 @@
+import { StatusVisibility } from './status'
+
export type StatusParams = {
text: string
in_reply_to_id: string | null
media_ids: Array | null
sensitive: boolean | null
spoiler_text: string | null
- visibility: 'public' | 'unlisted' | 'private' | null
+ visibility: StatusVisibility | null
scheduled_at: string | null
application_id: string
}
diff --git a/megalodon/src/friendica/entity.ts b/megalodon/src/friendica/entity.ts
index b2164281d..29b25a40b 100644
--- a/megalodon/src/friendica/entity.ts
+++ b/megalodon/src/friendica/entity.ts
@@ -68,6 +68,7 @@ export namespace Entity {
export type Source = source.Source
export type Stats = stats.Stats
export type Status = status.Status
+ export type StatusVisibility = status.StatusVisibility
export type StatusParams = status_params.StatusParams
export type StatusSource = status_source.StatusSource
export type Tag = tag.Tag
diff --git a/megalodon/src/mastodon.ts b/megalodon/src/mastodon.ts
index 98437c2fd..c60fa17b7 100644
--- a/megalodon/src/mastodon.ts
+++ b/megalodon/src/mastodon.ts
@@ -1519,7 +1519,7 @@ export default class Mastodon implements MegalodonInterface {
in_reply_to_id?: string
sensitive?: boolean
spoiler_text?: string
- visibility?: 'public' | 'unlisted' | 'private' | 'direct'
+ visibility?: Entity.StatusVisibility
scheduled_at?: string
language?: string
quote_id?: string
diff --git a/megalodon/src/mastodon/entities/preferences.ts b/megalodon/src/mastodon/entities/preferences.ts
index e0646f6de..3777c9b21 100644
--- a/megalodon/src/mastodon/entities/preferences.ts
+++ b/megalodon/src/mastodon/entities/preferences.ts
@@ -1,5 +1,7 @@
+import { StatusVisibility } from './status'
+
export type Preferences = {
- 'posting:default:visibility': 'public' | 'unlisted' | 'private' | 'direct'
+ 'posting:default:visibility': StatusVisibility
'posting:default:sensitive': boolean
'posting:default:language': string | null
'reading:expand:media': 'default' | 'show_all' | 'hide_all'
diff --git a/megalodon/src/mastodon/entities/status.ts b/megalodon/src/mastodon/entities/status.ts
index 24363a591..3c54667e4 100644
--- a/megalodon/src/mastodon/entities/status.ts
+++ b/megalodon/src/mastodon/entities/status.ts
@@ -25,7 +25,7 @@ export type Status = {
muted: boolean | null
sensitive: boolean
spoiler_text: string
- visibility: 'public' | 'unlisted' | 'private' | 'direct'
+ visibility: StatusVisibility
media_attachments: Array
mentions: Array
tags: Array
@@ -44,3 +44,5 @@ export type StatusTag = {
name: string
url: string
}
+
+export type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct'
diff --git a/megalodon/src/mastodon/entities/status_params.ts b/megalodon/src/mastodon/entities/status_params.ts
index 3f424bfef..0e32f6b11 100644
--- a/megalodon/src/mastodon/entities/status_params.ts
+++ b/megalodon/src/mastodon/entities/status_params.ts
@@ -1,10 +1,12 @@
+import { StatusVisibility } from './status'
+
export type StatusParams = {
text: string
in_reply_to_id: string | null
media_ids: Array | null
sensitive: boolean | null
spoiler_text: string | null
- visibility: 'public' | 'unlisted' | 'private' | 'direct' | null
+ visibility: StatusVisibility | null
scheduled_at: string | null
application_id: number
}
diff --git a/megalodon/src/megalodon.ts b/megalodon/src/megalodon.ts
index a399a5c74..aa592ffb5 100644
--- a/megalodon/src/megalodon.ts
+++ b/megalodon/src/megalodon.ts
@@ -671,7 +671,7 @@ export interface MegalodonInterface {
in_reply_to_id?: string
sensitive?: boolean
spoiler_text?: string
- visibility?: 'public' | 'unlisted' | 'private' | 'direct'
+ visibility?: Entity.StatusVisibility
scheduled_at?: string
language?: string
quote_id?: string
diff --git a/megalodon/src/pleroma/entities/preferences.ts b/megalodon/src/pleroma/entities/preferences.ts
index e0646f6de..3777c9b21 100644
--- a/megalodon/src/pleroma/entities/preferences.ts
+++ b/megalodon/src/pleroma/entities/preferences.ts
@@ -1,5 +1,7 @@
+import { StatusVisibility } from './status'
+
export type Preferences = {
- 'posting:default:visibility': 'public' | 'unlisted' | 'private' | 'direct'
+ 'posting:default:visibility': StatusVisibility
'posting:default:sensitive': boolean
'posting:default:language': string | null
'reading:expand:media': 'default' | 'show_all' | 'hide_all'
diff --git a/megalodon/src/pleroma/entities/status.ts b/megalodon/src/pleroma/entities/status.ts
index 75721e6dd..b3eaf38f5 100644
--- a/megalodon/src/pleroma/entities/status.ts
+++ b/megalodon/src/pleroma/entities/status.ts
@@ -26,7 +26,7 @@ export type Status = {
muted: boolean | null
sensitive: boolean
spoiler_text: string
- visibility: 'public' | 'unlisted' | 'private' | 'direct'
+ visibility: StatusVisibility
media_attachments: Array
mentions: Array
tags: Array
@@ -60,3 +60,5 @@ export type StatusTag = {
name: string
url: string
}
+
+export type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct'
diff --git a/megalodon/src/pleroma/entities/status_params.ts b/megalodon/src/pleroma/entities/status_params.ts
index af6579a99..f35886454 100644
--- a/megalodon/src/pleroma/entities/status_params.ts
+++ b/megalodon/src/pleroma/entities/status_params.ts
@@ -1,9 +1,11 @@
+import { StatusVisibility } from './status'
+
export type StatusParams = {
text: string
in_reply_to_id: string | null
media_ids?: Array | null
sensitive: boolean | null
spoiler_text: string | null
- visibility: 'public' | 'unlisted' | 'private' | 'direct' | null
+ visibility: StatusVisibility | null
scheduled_at: string | null
}