refs #935 Replace indent to br tag in misskey content
This commit is contained in:
parent
568d3d2e2c
commit
4e4383d520
|
@ -18,6 +18,7 @@ namespace Entity {
|
|||
in_reply_to_account_id: string | null
|
||||
reblog: Status | null
|
||||
content: string
|
||||
plain_content: string | null
|
||||
created_at: string
|
||||
emojis: Emoji[]
|
||||
replies_count: number
|
||||
|
|
|
@ -480,6 +480,7 @@ namespace MastodonAPI {
|
|||
in_reply_to_account_id: s.in_reply_to_account_id,
|
||||
reblog: s.reblog ? status(s.reblog) : s.quote ? status(s.quote) : null,
|
||||
content: s.content,
|
||||
plain_content: null,
|
||||
created_at: s.created_at,
|
||||
emojis: s.emojis.map(e => emoji(e)),
|
||||
replies_count: s.replies_count,
|
||||
|
|
|
@ -213,7 +213,17 @@ namespace MisskeyAPI {
|
|||
in_reply_to_id: n.replyId,
|
||||
in_reply_to_account_id: null,
|
||||
reblog: n.renote ? note(n.renote) : null,
|
||||
content: n.text ? n.text : '',
|
||||
content: n.text
|
||||
? n.text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/`/g, '`')
|
||||
.replace(/\r?\n/g, '<br>')
|
||||
: '',
|
||||
plain_content: n.text ? n.text : null,
|
||||
created_at: n.createdAt,
|
||||
emojis: n.emojis.map(e => emoji(e)),
|
||||
replies_count: n.repliesCount,
|
||||
|
|
|
@ -185,6 +185,7 @@ namespace PleromaAPI {
|
|||
in_reply_to_account_id: s.in_reply_to_account_id,
|
||||
reblog: s.reblog ? status(s.reblog) : null,
|
||||
content: s.content,
|
||||
plain_content: s.pleroma.context?.['text/plain'] ? s.pleroma.context['text/plain'] : null,
|
||||
created_at: s.created_at,
|
||||
emojis: s.emojis.map(e => emoji(e)),
|
||||
replies_count: s.replies_count,
|
||||
|
|
|
@ -36,6 +36,7 @@ const status: Entity.Status = {
|
|||
in_reply_to_account_id: null,
|
||||
reblog: null,
|
||||
content: 'hoge',
|
||||
plain_content: null,
|
||||
created_at: '2019-03-26T21:40:32',
|
||||
emojis: [],
|
||||
replies_count: 0,
|
||||
|
|
|
@ -4,6 +4,16 @@ import MisskeyEntity from '@/misskey/entity'
|
|||
import MegalodonNotificationType from '@/notification'
|
||||
import MisskeyNotificationType from '@/misskey/notification'
|
||||
|
||||
const user: MisskeyEntity.User = {
|
||||
id: '1',
|
||||
name: 'test_user',
|
||||
username: 'TestUser',
|
||||
host: 'misskey.io',
|
||||
avatarUrl: 'https://example.com/icon.png',
|
||||
avatarColor: '#000000',
|
||||
emojis: []
|
||||
}
|
||||
|
||||
describe('api_client', () => {
|
||||
describe('notification', () => {
|
||||
describe('encode', () => {
|
||||
|
@ -165,4 +175,57 @@ describe('api_client', () => {
|
|||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('status', () => {
|
||||
describe('plain content', () => {
|
||||
it('should be exported plain content and html content', () => {
|
||||
const plainContent = 'hoge\nfuga\nfuga'
|
||||
const content = 'hoge<br>fuga<br>fuga'
|
||||
const note: MisskeyEntity.Note = {
|
||||
id: '1',
|
||||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: '1',
|
||||
user: user,
|
||||
text: plainContent,
|
||||
cw: null,
|
||||
visibility: 'public',
|
||||
renoteCount: 0,
|
||||
repliesCount: 0,
|
||||
reactions: {},
|
||||
emojis: [],
|
||||
fileIds: [],
|
||||
files: [],
|
||||
replyId: null,
|
||||
renoteId: null
|
||||
}
|
||||
const megalodonStatus = MisskeyAPI.Converter.note(note)
|
||||
expect(megalodonStatus.plain_content).toEqual(plainContent)
|
||||
expect(megalodonStatus.content).toEqual(content)
|
||||
})
|
||||
it('html tags should be escaped', () => {
|
||||
const plainContent = '<p>hoge\nfuga\nfuga<p>'
|
||||
const content = '<p>hoge<br>fuga<br>fuga<p>'
|
||||
const note: MisskeyEntity.Note = {
|
||||
id: '1',
|
||||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: '1',
|
||||
user: user,
|
||||
text: plainContent,
|
||||
cw: null,
|
||||
visibility: 'public',
|
||||
renoteCount: 0,
|
||||
repliesCount: 0,
|
||||
reactions: {},
|
||||
emojis: [],
|
||||
fileIds: [],
|
||||
files: [],
|
||||
replyId: null,
|
||||
renoteId: null
|
||||
}
|
||||
const megalodonStatus = MisskeyAPI.Converter.note(note)
|
||||
expect(megalodonStatus.plain_content).toEqual(plainContent)
|
||||
expect(megalodonStatus.content).toEqual(content)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -32,6 +32,7 @@ const status: Entity.Status = {
|
|||
in_reply_to_account_id: null,
|
||||
reblog: null,
|
||||
content: 'hoge',
|
||||
plain_content: 'hoge',
|
||||
created_at: '2019-03-26T21:40:32',
|
||||
emojis: [],
|
||||
replies_count: 0,
|
||||
|
|
|
@ -4,6 +4,28 @@ import PleromaEntity from '@/pleroma/entity'
|
|||
import MegalodonNotificationType from '@/notification'
|
||||
import PleromaNotificationType from '@/pleroma/notification'
|
||||
|
||||
const account: PleromaEntity.Account = {
|
||||
id: '1',
|
||||
username: 'h3poteto',
|
||||
acct: 'h3poteto@pleroma.io',
|
||||
display_name: 'h3poteto',
|
||||
locked: false,
|
||||
created_at: '2019-03-26T21:30:32',
|
||||
followers_count: 10,
|
||||
following_count: 10,
|
||||
statuses_count: 100,
|
||||
note: 'engineer',
|
||||
url: 'https://pleroma.io',
|
||||
avatar: '',
|
||||
avatar_static: '',
|
||||
header: '',
|
||||
header_static: '',
|
||||
emojis: [],
|
||||
moved: null,
|
||||
fields: null,
|
||||
bot: false
|
||||
}
|
||||
|
||||
describe('api_client', () => {
|
||||
describe('notification', () => {
|
||||
describe('encode', () => {
|
||||
|
@ -81,4 +103,98 @@ describe('api_client', () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('status', () => {
|
||||
describe('plain content is included', () => {
|
||||
it('plain content in pleroma entity should be exported in plain_content column', () => {
|
||||
const plainContent = 'hoge\nfuga\nfuga'
|
||||
const content = '<p>hoge<br>fuga<br>fuga</p>'
|
||||
const pleromaStatus: PleromaEntity.Status = {
|
||||
id: '1',
|
||||
uri: 'https://pleroma.io/notice/1',
|
||||
url: 'https://pleroma.io/notice/1',
|
||||
account: account,
|
||||
in_reply_to_id: null,
|
||||
in_reply_to_account_id: null,
|
||||
reblog: null,
|
||||
content: content,
|
||||
created_at: '2019-03-26T21:40:32',
|
||||
emojis: [],
|
||||
replies_count: 0,
|
||||
reblogs_count: 0,
|
||||
favourites_count: 0,
|
||||
reblogged: null,
|
||||
favourited: null,
|
||||
muted: null,
|
||||
sensitive: false,
|
||||
spoiler_text: '',
|
||||
visibility: 'public',
|
||||
media_attachments: [],
|
||||
mentions: [],
|
||||
tags: [],
|
||||
card: null,
|
||||
poll: null,
|
||||
application: {
|
||||
name: 'Web'
|
||||
} as MastodonEntity.Application,
|
||||
language: null,
|
||||
pinned: null,
|
||||
bookmarked: false,
|
||||
pleroma: {
|
||||
context: {
|
||||
'text/plain': plainContent
|
||||
},
|
||||
local: false
|
||||
}
|
||||
}
|
||||
const megalodonStatus = PleromaAPI.Converter.status(pleromaStatus)
|
||||
expect(megalodonStatus.plain_content).toEqual(plainContent)
|
||||
expect(megalodonStatus.content).toEqual(content)
|
||||
})
|
||||
})
|
||||
|
||||
describe('plain content is not included', () => {
|
||||
it('plain_content should be null', () => {
|
||||
const content = '<p>hoge<br>fuga<br>fuga</p>'
|
||||
const pleromaStatus: PleromaEntity.Status = {
|
||||
id: '1',
|
||||
uri: 'https://pleroma.io/notice/1',
|
||||
url: 'https://pleroma.io/notice/1',
|
||||
account: account,
|
||||
in_reply_to_id: null,
|
||||
in_reply_to_account_id: null,
|
||||
reblog: null,
|
||||
content: content,
|
||||
created_at: '2019-03-26T21:40:32',
|
||||
emojis: [],
|
||||
replies_count: 0,
|
||||
reblogs_count: 0,
|
||||
favourites_count: 0,
|
||||
reblogged: null,
|
||||
favourited: null,
|
||||
muted: null,
|
||||
sensitive: false,
|
||||
spoiler_text: '',
|
||||
visibility: 'public',
|
||||
media_attachments: [],
|
||||
mentions: [],
|
||||
tags: [],
|
||||
card: null,
|
||||
poll: null,
|
||||
application: {
|
||||
name: 'Web'
|
||||
} as MastodonEntity.Application,
|
||||
language: null,
|
||||
pinned: null,
|
||||
bookmarked: false,
|
||||
pleroma: {
|
||||
local: false
|
||||
}
|
||||
}
|
||||
const megalodonStatus = PleromaAPI.Converter.status(pleromaStatus)
|
||||
expect(megalodonStatus.plain_content).toBeNull()
|
||||
expect(megalodonStatus.content).toEqual(content)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -31,6 +31,7 @@ const status: Entity.Status = {
|
|||
in_reply_to_account_id: null,
|
||||
reblog: null,
|
||||
content: 'hoge',
|
||||
plain_content: 'hoge',
|
||||
created_at: '2019-03-26T21:40:32',
|
||||
emojis: [],
|
||||
replies_count: 0,
|
||||
|
|
Loading…
Reference in a new issue