Skip to content

Commit 137e80f

Browse files
authored
Merge pull request #2299 from h3poteto/iss-2294
refs #2294 Improve quote architecture for other fediverse
2 parents 55761c5 + c42583a commit 137e80f

File tree

22 files changed

+195
-23
lines changed

22 files changed

+195
-23
lines changed

megalodon/src/entities/quote.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Status } from './status.js'
2+
3+
export type ShallowQuote = {
4+
state: QuoteState
5+
quoted_status_id: string | null
6+
}
7+
8+
export type QuoteState =
9+
| 'pending'
10+
| 'accepted'
11+
| 'rejected'
12+
| 'revoked'
13+
| 'deleted'
14+
| 'unauthorized'
15+
| 'blocked_account'
16+
| 'blocked_domain'
17+
| 'muted_account'
18+
19+
export type Quote = {
20+
state: QuoteState
21+
quoted_status: Status | null
22+
}
23+
24+
export type QuotedStatus = ShallowQuote | Quote
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type QuoteApproval = {
2+
automatic: Array<string>
3+
manual: Array<string>
4+
current_user: string
5+
}

megalodon/src/entities/status.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { Mention } from './mention.js'
66
import { Reaction } from './reaction.js'
77
import { Card } from './card.js'
88
import { Poll } from './poll.js'
9+
import { QuotedStatus } from './quote.js'
10+
import { QuoteApproval } from './quote_approval.js'
911

1012
export type Status = {
1113
id: string
@@ -38,7 +40,8 @@ export type Status = {
3840
language: string | null
3941
pinned: boolean | null
4042
emoji_reactions: Array<Reaction>
41-
quote: boolean
43+
quote: QuotedStatus | null
44+
quote_approval: QuoteApproval
4245
bookmarked: boolean
4346
}
4447

megalodon/src/entity.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import * as status_source from './entities/status_source.js'
3636
import * as tag from './entities/tag.js'
3737
import * as token from './entities/token.js'
3838
import * as urls from './entities/urls.js'
39+
import * as quote from './entities/quote.js'
3940

4041
export namespace Entity {
4142
export type Account = account.Account
@@ -91,6 +92,10 @@ export namespace Entity {
9192
export type Tag = tag.Tag
9293
export type Token = token.Token
9394
export type URLs = urls.URLs
95+
export type Quote = quote.Quote
96+
export type ShallowQuote = quote.ShallowQuote
97+
export type QuotedStatus = quote.QuotedStatus
98+
export type QuoteState = quote.QuoteState
9499
}
95100

96101
export default Entity

megalodon/src/firefish/api_client.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,23 @@ namespace FirefishAPI {
325325
// Use emojis list to provide URLs for emoji reactions.
326326
emoji_reactions: mapReactions(n.emojis ? n.emojis : [], n.reactions, n.myReaction),
327327
bookmarked: false,
328-
quote: n.renote !== undefined && n.text !== null
328+
quote: quote(n),
329+
quote_approval: {
330+
automatic: ['unsupported_policy'],
331+
manual: [],
332+
current_user: 'automatic'
333+
}
334+
}
335+
}
336+
337+
export const quote = (n: Entity.Note): MegalodonEntity.QuotedStatus | null => {
338+
if (n.renote !== undefined && n.text !== null) {
339+
return {
340+
state: 'accepted',
341+
quoted_status: note(n.renote)
342+
}
343+
} else {
344+
return null
329345
}
330346
}
331347

megalodon/src/friendica/api_client.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ namespace FriendicaAPI {
689689
account: account(s.account),
690690
in_reply_to_id: s.in_reply_to_id,
691691
in_reply_to_account_id: s.in_reply_to_account_id,
692-
reblog: s.reblog ? status(s.reblog) : s.quote ? status(s.quote) : null,
692+
reblog: s.reblog ? status(s.reblog) : null,
693693
content: s.content,
694694
plain_content: null,
695695
created_at: s.created_at,
@@ -714,7 +714,12 @@ namespace FriendicaAPI {
714714
pinned: s.pinned,
715715
emoji_reactions: [],
716716
bookmarked: s.bookmarked ? s.bookmarked : false,
717-
quote: false
717+
quote: null,
718+
quote_approval: {
719+
automatic: ['unsupported_policy'],
720+
manual: [],
721+
current_user: 'automatic'
722+
}
718723
})
719724
export const status_params = (s: Entity.StatusParams): MegalodonEntity.StatusParams => {
720725
return {

megalodon/src/friendica/entities/status.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ export type Status = {
3535
language: string | null
3636
pinned: boolean | null
3737
bookmarked?: boolean
38-
// These parameters are unique parameters in fedibird.com for quote.
39-
quote_id?: string
40-
quote?: Status | null
4138
}
4239

4340
export type StatusTag = {

megalodon/src/gotosocial/api_client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,12 @@ namespace GotosocialAPI {
683683
pinned: s.pinned,
684684
emoji_reactions: [],
685685
bookmarked: s.bookmarked ? s.bookmarked : false,
686-
quote: false
686+
quote: null,
687+
quote_approval: {
688+
automatic: ['unsupported_policy'],
689+
manual: [],
690+
current_user: 'automatic'
691+
}
687692
})
688693
export const status_params = (s: Entity.StatusParams): MegalodonEntity.StatusParams => s
689694
export const tag = (t: Entity.Tag): MegalodonEntity.Tag => ({

megalodon/src/mastodon/api_client.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ namespace MastodonAPI {
421421
export type Tag = MastodonEntity.Tag
422422
export type Token = MastodonEntity.Token
423423
export type URLs = MastodonEntity.URLs
424+
export type ShallowQuote = MastodonEntity.ShallowQuote
425+
export type QuotedStatus = MastodonEntity.QuotedStatus
426+
export type Quote = MastodonEntity.Quote
427+
export type QuoteApproval = MastodonEntity.QuoteApproval
424428
}
425429

426430
export namespace Converter {
@@ -594,7 +598,7 @@ namespace MastodonAPI {
594598
account: account(s.account),
595599
in_reply_to_id: s.in_reply_to_id,
596600
in_reply_to_account_id: s.in_reply_to_account_id,
597-
reblog: s.reblog ? status(s.reblog) : s.quote ? status(s.quote) : null,
601+
reblog: s.reblog ? status(s.reblog) : null,
598602
content: s.content,
599603
plain_content: null,
600604
created_at: s.created_at,
@@ -619,14 +623,27 @@ namespace MastodonAPI {
619623
pinned: s.pinned,
620624
emoji_reactions: [],
621625
bookmarked: s.bookmarked ? s.bookmarked : false,
622-
// Now quote is supported only fedibird.com.
623-
quote: s.quote !== undefined && s.quote !== null
626+
quote: s.quote ? quote(s.quote) : null,
627+
quote_approval: s.quote_approval
624628
})
625629
export const status_params = (s: Entity.StatusParams): MegalodonEntity.StatusParams => s
626630
export const status_source = (s: Entity.StatusSource): MegalodonEntity.StatusSource => s
627631
export const tag = (t: Entity.Tag): MegalodonEntity.Tag => t
628632
export const token = (t: Entity.Token): MegalodonEntity.Token => t
629633
export const urls = (u: Entity.URLs): MegalodonEntity.URLs => u
634+
export const quote = (q: Entity.QuotedStatus): MegalodonEntity.QuotedStatus => {
635+
if ('quoted_status' in q) {
636+
return {
637+
state: q.state,
638+
quoted_status: q.quoted_status ? status(q.quoted_status) : null
639+
}
640+
} else {
641+
return {
642+
state: q.state,
643+
quoted_status_id: q.quoted_status_id
644+
}
645+
}
646+
}
630647
}
631648
}
632649
export default MastodonAPI
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Status } from './status.js'
2+
3+
export type ShallowQuote = {
4+
state: QuoteState
5+
quoted_status_id: string | null
6+
}
7+
8+
export type QuoteState =
9+
| 'pending'
10+
| 'accepted'
11+
| 'rejected'
12+
| 'revoked'
13+
| 'deleted'
14+
| 'unauthorized'
15+
| 'blocked_account'
16+
| 'blocked_domain'
17+
| 'muted_account'
18+
19+
export type Quote = {
20+
state: QuoteState
21+
quoted_status: Status | null
22+
}
23+
24+
export type QuotedStatus = ShallowQuote | Quote

0 commit comments

Comments
 (0)