Skip to content

Commit

Permalink
Merge pull request #1694 from h3poteto/feat/scheduled
Browse files Browse the repository at this point in the history
Fix ScheduledStatus entity
  • Loading branch information
h3poteto authored Apr 26, 2023
2 parents 7bd0401 + a62f79e commit fef2cd3
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const rl: readline.ReadLine = readline.createInterface({
output: process.stdout
})

const BASE_URL: string = 'https://fedibird.com'
const BASE_URL: string = process.env.MASTODON_URL as string

const access_token: string = process.env.MASTODON_ACCESS_TOKEN as string

Expand All @@ -16,7 +16,7 @@ new Promise(resolve => {
rl.question('Toot: ', status => {
client
.postStatus(status)
.then((res: Response<Entity.Status|Entity.ScheduledStatus>) => {
.then((res: Response<Entity.Status | Entity.ScheduledStatus>) => {
console.log(res)
rl.close()
resolve(res)
Expand Down
34 changes: 34 additions & 0 deletions example/typescript/src/mastodon/post_status_with_schedule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as readline from 'readline'
import generator, { Entity, Response } from 'megalodon'

const rl: readline.ReadLine = readline.createInterface({
input: process.stdin,
output: process.stdout
})

const BASE_URL: string = process.env.MASTODON_URL as string

const access_token: string = process.env.MASTODON_ACCESS_TOKEN as string

const client = generator('mastodon', BASE_URL, access_token)

new Promise(resolve => {
rl.question('Toot: ', status => {
let now = new Date()
now.setMinutes(now.getMinutes() + 6)
client
.postStatus(status, {
scheduled_at: now.toISOString(),
visibility: 'private'
})
.then((res: Response<Entity.Status | Entity.ScheduledStatus>) => {
console.log(res)
rl.close()
resolve(res)
})
.catch(err => {
console.error(err)
rl.close()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const rl: readline.ReadLine = readline.createInterface({
output: process.stdout
})

const BASE_URL: string = 'https://pleroma.io'
const BASE_URL: string = process.env.PLEROMA_URL as string

const access_token: string = process.env.PLEROMA_ACCESS_TOKEN as string

Expand All @@ -16,7 +16,7 @@ new Promise(resolve => {
rl.question('Toot: ', status => {
client
.postStatus(status)
.then((res: Response<Entity.Status|Entity.ScheduledStatus>) => {
.then((res: Response<Entity.Status | Entity.ScheduledStatus>) => {
console.log(res)
rl.close()
resolve(res)
Expand Down
34 changes: 34 additions & 0 deletions example/typescript/src/pleroma/post_status_with_schedule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as readline from 'readline'
import generator, { Entity, Response } from 'megalodon'

const rl: readline.ReadLine = readline.createInterface({
input: process.stdin,
output: process.stdout
})

const BASE_URL: string = process.env.PLEROMA_URL as string

const access_token: string = process.env.PLEROMA_ACCESS_TOKEN as string

const client = generator('pleroma', BASE_URL, access_token)

new Promise(resolve => {
rl.question('Toot: ', status => {
let now = new Date()
now.setMinutes(now.getMinutes() + 6)
client
.postStatus(status, {
scheduled_at: now.toISOString(),
visibility: 'private'
})
.then((res: Response<Entity.Status | Entity.ScheduledStatus>) => {
console.log(res)
rl.close()
resolve(res)
})
.catch(err => {
console.error(err)
rl.close()
})
})
})
2 changes: 1 addition & 1 deletion megalodon/src/entities/scheduled_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace Entity {
id: string
scheduled_at: string
params: StatusParams
media_attachments: Array<Attachment>
media_attachments: Array<Attachment> | null
}
}
4 changes: 2 additions & 2 deletions megalodon/src/entities/status_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Entity {
media_ids: Array<string> | null
sensitive: boolean | null
spoiler_text: string | null
visibility: 'public' | 'unlisted' | 'private' | 'direct'
visibility: 'public' | 'unlisted' | 'private' | 'direct' | null
scheduled_at: string | null
application_id: string
application_id: number | null
}
}
22 changes: 20 additions & 2 deletions megalodon/src/friendica/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,14 @@ namespace FriendicaAPI {
statuses: Array.isArray(r.statuses) ? r.statuses.map(s => status(s)) : [],
hashtags: Array.isArray(r.hashtags) ? r.hashtags.map(h => tag(h)) : []
})
export const scheduled_status = (s: Entity.ScheduledStatus): MegalodonEntity.ScheduledStatus => s
export const scheduled_status = (s: Entity.ScheduledStatus): MegalodonEntity.ScheduledStatus => {
return {
id: s.id,
scheduled_at: s.scheduled_at,
params: status_params(s.params),
media_attachments: s.media_attachments ? s.media_attachments.map(a => attachment(a)) : null
}
}
export const source = (s: Entity.Source): MegalodonEntity.Source => s
export const stats = (s: Entity.Stats): MegalodonEntity.Stats => s
export const status = (s: Entity.Status): MegalodonEntity.Status => ({
Expand Down Expand Up @@ -658,7 +665,18 @@ namespace FriendicaAPI {
// Now quote is supported only fedibird.com.
quote: s.quote !== undefined && s.quote !== null
})
export const status_params = (s: Entity.StatusParams): MegalodonEntity.StatusParams => s
export const status_params = (s: Entity.StatusParams): MegalodonEntity.StatusParams => {
return {
text: s.text,
in_reply_to_id: s.in_reply_to_id,
media_ids: s.media_ids,
sensitive: s.sensitive,
spoiler_text: s.spoiler_text,
visibility: s.visibility,
scheduled_at: s.scheduled_at,
application_id: parseInt(s.application_id)
}
}
export const status_source = (s: Entity.StatusSource): MegalodonEntity.StatusSource => s
export const tag = (t: Entity.Tag): MegalodonEntity.Tag => t
export const token = (t: Entity.Token): MegalodonEntity.Token => t
Expand Down
2 changes: 1 addition & 1 deletion megalodon/src/friendica/entities/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ namespace FriendicaEntity {
moved: Account | null
fields: Array<Field>
bot: boolean
source: Source
source?: Source
}
}
2 changes: 1 addition & 1 deletion megalodon/src/friendica/entities/status_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace FriendicaEntity {
media_ids: Array<string> | null
sensitive: boolean | null
spoiler_text: string | null
visibility: 'public' | 'unlisted' | 'private' | 'direct'
visibility: 'public' | 'unlisted' | 'private' | null
scheduled_at: string | null
application_id: string
}
Expand Down
2 changes: 1 addition & 1 deletion megalodon/src/mastodon/entities/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ namespace MastodonEntity {
moved: Account | null
fields: Array<Field>
bot: boolean
source: Source
source?: Source
}
}
4 changes: 2 additions & 2 deletions megalodon/src/mastodon/entities/status_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace MastodonEntity {
media_ids: Array<string> | null
sensitive: boolean | null
spoiler_text: string | null
visibility: 'public' | 'unlisted' | 'private' | 'direct'
visibility: 'public' | 'unlisted' | 'private' | 'direct' | null
scheduled_at: string | null
application_id: string
application_id: number
}
}
17 changes: 14 additions & 3 deletions megalodon/src/pleroma/api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ namespace PleromaAPI {
export const scheduled_status = (s: Entity.ScheduledStatus): MegalodonEntity.ScheduledStatus => ({
id: s.id,
scheduled_at: s.scheduled_at,
params: s.params,
media_attachments: Array.isArray(s.media_attachments) ? s.media_attachments.map(m => attachment(m)) : []
params: status_params(s.params),
media_attachments: Array.isArray(s.media_attachments) ? s.media_attachments.map(m => attachment(m)) : null
})
export const source = (s: Entity.Source): MegalodonEntity.Source => s
export const stats = (s: Entity.Stats): MegalodonEntity.Stats => s
Expand Down Expand Up @@ -330,7 +330,18 @@ namespace PleromaAPI {
bookmarked: s.bookmarked ? s.bookmarked : false,
quote: s.reblog !== null && s.reblog.content !== s.content
})
export const status_params = (s: Entity.StatusParams): MegalodonEntity.StatusParams => s
export const status_params = (s: Entity.StatusParams): MegalodonEntity.StatusParams => {
return {
text: s.text,
in_reply_to_id: s.in_reply_to_id,
media_ids: Array.isArray(s.media_ids) ? s.media_ids : null,
sensitive: s.sensitive,
spoiler_text: s.spoiler_text,
visibility: s.visibility,
scheduled_at: s.scheduled_at,
application_id: null
}
}
export const status_source = (s: Entity.StatusSource): MegalodonEntity.StatusSource => s
export const tag = (t: Entity.Tag): MegalodonEntity.Tag => t
export const token = (t: Entity.Token): MegalodonEntity.Token => t
Expand Down
2 changes: 1 addition & 1 deletion megalodon/src/pleroma/entities/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ namespace PleromaEntity {
moved: Account | null
fields: Array<Field>
bot: boolean
source: Source
source?: Source
}
}
2 changes: 1 addition & 1 deletion megalodon/src/pleroma/entities/scheduled_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace PleromaEntity {
id: string
scheduled_at: string
params: StatusParams
media_attachments: Array<Attachment>
media_attachments: Array<Attachment> | null
}
}
5 changes: 2 additions & 3 deletions megalodon/src/pleroma/entities/status_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ namespace PleromaEntity {
export type StatusParams = {
text: string
in_reply_to_id: string | null
media_ids: Array<string> | null
media_ids?: Array<string> | null
sensitive: boolean | null
spoiler_text: string | null
visibility: 'public' | 'unlisted' | 'private' | 'direct'
visibility: 'public' | 'unlisted' | 'private' | 'direct' | null
scheduled_at: string | null
application_id: string
}
}

0 comments on commit fef2cd3

Please sign in to comment.