Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define StatusVisibility type for each SNS #1984

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion megalodon/src/entities/preferences.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
4 changes: 3 additions & 1 deletion megalodon/src/entities/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Attachment>
mentions: Array<Mention>
tags: Array<StatusTag>
Expand All @@ -45,3 +45,5 @@ export type StatusTag = {
name: string
url: string
}

export type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct'
4 changes: 3 additions & 1 deletion megalodon/src/entities/status_params.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { StatusVisibility } from './status'

export type StatusParams = {
text: string
in_reply_to_id: string | null
media_ids: Array<string> | 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
}
1 change: 1 addition & 0 deletions megalodon/src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions megalodon/src/firefish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ export default class Firefish implements MegalodonInterface {
})
}

private async getDefaultPostPrivacy(): Promise<Entity.Preferences['posting:default:visibility']> {
private async getDefaultPostPrivacy(): Promise<Entity.StatusVisibility> {
return this.client
.post<string>('/api/i/registry/get-unsecure', {
key: 'defaultNoteVisibility',
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions megalodon/src/firefish/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion megalodon/src/firefish/entities/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -27,3 +27,5 @@ export type Note = {
mentions?: Array<string>
myReaction?: string | null
}

export type NoteVisibility = 'public' | 'home' | 'followers' | 'specified' | 'hidden'
1 change: 1 addition & 0 deletions megalodon/src/firefish/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions megalodon/src/friendica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions megalodon/src/friendica/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion megalodon/src/friendica/entities/preferences.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
4 changes: 3 additions & 1 deletion megalodon/src/friendica/entities/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Attachment>
mentions: Array<Mention>
tags: Array<StatusTag>
Expand All @@ -44,3 +44,5 @@ export type StatusTag = {
name: string
url: string
}

export type StatusVisibility = 'public' | 'unlisted' | 'private'
4 changes: 3 additions & 1 deletion megalodon/src/friendica/entities/status_params.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { StatusVisibility } from './status'

export type StatusParams = {
text: string
in_reply_to_id: string | null
media_ids: Array<string> | null
sensitive: boolean | null
spoiler_text: string | null
visibility: 'public' | 'unlisted' | 'private' | null
visibility: StatusVisibility | null
scheduled_at: string | null
application_id: string
}
1 change: 1 addition & 0 deletions megalodon/src/friendica/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion megalodon/src/mastodon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion megalodon/src/mastodon/entities/preferences.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
4 changes: 3 additions & 1 deletion megalodon/src/mastodon/entities/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Attachment>
mentions: Array<Mention>
tags: Array<StatusTag>
Expand All @@ -44,3 +44,5 @@ export type StatusTag = {
name: string
url: string
}

export type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct'
4 changes: 3 additions & 1 deletion megalodon/src/mastodon/entities/status_params.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { StatusVisibility } from './status'

export type StatusParams = {
text: string
in_reply_to_id: string | null
media_ids: Array<string> | null
sensitive: boolean | null
spoiler_text: string | null
visibility: 'public' | 'unlisted' | 'private' | 'direct' | null
visibility: StatusVisibility | null
scheduled_at: string | null
application_id: number
}
2 changes: 1 addition & 1 deletion megalodon/src/megalodon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion megalodon/src/pleroma/entities/preferences.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
4 changes: 3 additions & 1 deletion megalodon/src/pleroma/entities/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Attachment>
mentions: Array<Mention>
tags: Array<StatusTag>
Expand Down Expand Up @@ -60,3 +60,5 @@ export type StatusTag = {
name: string
url: string
}

export type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct'
4 changes: 3 additions & 1 deletion megalodon/src/pleroma/entities/status_params.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { StatusVisibility } from './status'

export type StatusParams = {
text: string
in_reply_to_id: string | null
media_ids?: Array<string> | null
sensitive: boolean | null
spoiler_text: string | null
visibility: 'public' | 'unlisted' | 'private' | 'direct' | null
visibility: StatusVisibility | null
scheduled_at: string | null
}
Loading