2020-01-30 16:55:01 +00:00
|
|
|
import escape from 'escape-html'
|
2020-07-03 19:45:49 +00:00
|
|
|
import parseLinkHeader from 'parse-link-header'
|
2020-04-25 04:04:39 +00:00
|
|
|
import { isStatusNotification } from '../notification_utils/notification_utils.js'
|
2021-01-05 08:09:08 +00:00
|
|
|
import punycode from 'punycode.js'
|
2020-01-30 16:55:01 +00:00
|
|
|
|
2020-11-17 13:25:38 +00:00
|
|
|
/** NOTICE! **
|
|
|
|
* Do not initialize UI-generated data here.
|
|
|
|
* It will override existing data.
|
|
|
|
*
|
|
|
|
* i.e. user.pinnedStatusIds was set to [] here
|
|
|
|
* UI code would update it with data but upon next user fetch
|
|
|
|
* it would be reverted back to []
|
|
|
|
*/
|
|
|
|
|
2019-01-14 12:30:14 +00:00
|
|
|
const qvitterStatusType = (status) => {
|
2019-01-13 19:07:55 +00:00
|
|
|
if (status.is_post_verb) {
|
|
|
|
return 'status'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status.retweeted_status) {
|
|
|
|
return 'retweet'
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((typeof status.uri === 'string' && status.uri.match(/(fave|objectType=Favourite)/)) ||
|
|
|
|
(typeof status.text === 'string' && status.text.match(/favorited/))) {
|
|
|
|
return 'favorite'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status.text.match(/deleted notice {{tag/) || status.qvitter_delete_notice) {
|
|
|
|
return 'deletion'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status.text.match(/started following/) || status.activity_type === 'follow') {
|
|
|
|
return 'follow'
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'unknown'
|
|
|
|
}
|
|
|
|
|
2019-01-14 12:30:14 +00:00
|
|
|
export const parseUser = (data) => {
|
|
|
|
const output = {}
|
|
|
|
const masto = data.hasOwnProperty('acct')
|
|
|
|
// case for users in "mentions" property for statuses in MastoAPI
|
|
|
|
const mastoShort = masto && !data.hasOwnProperty('avatar')
|
|
|
|
|
2019-01-17 16:23:14 +00:00
|
|
|
output.id = String(data.id)
|
2022-02-22 21:31:40 +00:00
|
|
|
output._original = data // used for server-side settings
|
2019-01-14 12:30:14 +00:00
|
|
|
|
|
|
|
if (masto) {
|
|
|
|
output.screen_name = data.acct
|
2019-05-23 03:47:20 +00:00
|
|
|
output.statusnet_profile_url = data.url
|
2019-01-14 12:30:14 +00:00
|
|
|
|
|
|
|
// There's nothing else to get
|
|
|
|
if (mastoShort) {
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
2021-06-07 15:39:51 +00:00
|
|
|
output.emoji = data.emojis
|
2021-11-16 16:49:01 +00:00
|
|
|
output.name = escape(data.display_name)
|
|
|
|
output.name_html = output.name
|
|
|
|
output.name_unescaped = data.display_name
|
2019-01-14 12:30:14 +00:00
|
|
|
|
2019-05-26 18:48:49 +00:00
|
|
|
output.description = data.note
|
2021-08-13 10:06:42 +00:00
|
|
|
// TODO cleanup this shit, output.description is overriden with source data
|
|
|
|
output.description_html = data.note
|
2019-01-14 12:30:14 +00:00
|
|
|
|
2019-11-19 14:15:41 +00:00
|
|
|
output.fields = data.fields
|
|
|
|
output.fields_html = data.fields.map(field => {
|
|
|
|
return {
|
2021-08-13 10:12:33 +00:00
|
|
|
name: escape(field.name),
|
|
|
|
value: field.value
|
2019-11-19 14:15:41 +00:00
|
|
|
}
|
|
|
|
})
|
2020-02-19 11:57:58 +00:00
|
|
|
output.fields_text = data.fields.map(field => {
|
|
|
|
return {
|
2020-06-17 15:26:06 +00:00
|
|
|
name: unescape(field.name.replace(/<[^>]*>/g, '')),
|
|
|
|
value: unescape(field.value.replace(/<[^>]*>/g, ''))
|
2020-02-19 11:57:58 +00:00
|
|
|
}
|
|
|
|
})
|
2019-11-19 14:15:41 +00:00
|
|
|
|
2019-01-14 12:30:14 +00:00
|
|
|
// Utilize avatar_static for gif avatars?
|
|
|
|
output.profile_image_url = data.avatar
|
|
|
|
output.profile_image_url_original = data.avatar
|
|
|
|
|
|
|
|
// Same, utilize header_static?
|
|
|
|
output.cover_photo = data.header
|
|
|
|
|
|
|
|
output.friends_count = data.following_count
|
|
|
|
|
|
|
|
output.bot = data.bot
|
|
|
|
|
2019-01-19 01:10:16 +00:00
|
|
|
if (data.pleroma) {
|
2019-03-11 21:08:14 +00:00
|
|
|
const relationship = data.pleroma.relationship
|
|
|
|
|
2019-06-16 17:17:59 +00:00
|
|
|
output.background_image = data.pleroma.background_image
|
2020-03-01 08:47:21 +00:00
|
|
|
output.favicon = data.pleroma.favicon
|
2019-06-16 17:17:59 +00:00
|
|
|
output.token = data.pleroma.chat_token
|
|
|
|
|
2020-04-21 20:27:51 +00:00
|
|
|
if (relationship) {
|
|
|
|
output.relationship = relationship
|
|
|
|
}
|
2019-02-18 14:49:32 +00:00
|
|
|
|
2020-02-03 19:26:32 +00:00
|
|
|
output.allow_following_move = data.pleroma.allow_following_move
|
|
|
|
|
2019-07-07 10:20:55 +00:00
|
|
|
output.hide_follows = data.pleroma.hide_follows
|
|
|
|
output.hide_followers = data.pleroma.hide_followers
|
2019-09-13 13:15:19 +00:00
|
|
|
output.hide_follows_count = data.pleroma.hide_follows_count
|
|
|
|
output.hide_followers_count = data.pleroma.hide_followers_count
|
2019-07-07 10:20:55 +00:00
|
|
|
|
2019-02-18 14:49:32 +00:00
|
|
|
output.rights = {
|
|
|
|
moderator: data.pleroma.is_moderator,
|
|
|
|
admin: data.pleroma.is_admin
|
|
|
|
}
|
2019-05-21 20:35:40 +00:00
|
|
|
// TODO: Clean up in UI? This is duplication from what BE does for qvitterapi
|
|
|
|
if (output.rights.admin) {
|
|
|
|
output.role = 'admin'
|
|
|
|
} else if (output.rights.moderator) {
|
|
|
|
output.role = 'moderator'
|
|
|
|
} else {
|
|
|
|
output.role = 'member'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.source) {
|
|
|
|
output.description = data.source.note
|
|
|
|
output.default_scope = data.source.privacy
|
2019-11-19 14:15:41 +00:00
|
|
|
output.fields = data.source.fields
|
2019-05-21 20:35:40 +00:00
|
|
|
if (data.source.pleroma) {
|
|
|
|
output.no_rich_text = data.source.pleroma.no_rich_text
|
|
|
|
output.show_role = data.source.pleroma.show_role
|
2019-09-26 22:31:28 +00:00
|
|
|
output.discoverable = data.source.pleroma.discoverable
|
2019-05-21 20:35:40 +00:00
|
|
|
}
|
2019-01-19 01:10:16 +00:00
|
|
|
}
|
2019-01-17 20:53:05 +00:00
|
|
|
|
2019-03-13 18:08:03 +00:00
|
|
|
// TODO: handle is_local
|
2019-03-13 19:43:48 +00:00
|
|
|
output.is_local = !output.screen_name.includes('@')
|
2019-01-14 12:30:14 +00:00
|
|
|
} else {
|
|
|
|
output.screen_name = data.screen_name
|
|
|
|
|
|
|
|
output.name = data.name
|
|
|
|
output.name_html = data.name_html
|
|
|
|
|
|
|
|
output.description = data.description
|
|
|
|
output.description_html = data.description_html
|
|
|
|
|
|
|
|
output.profile_image_url = data.profile_image_url
|
|
|
|
output.profile_image_url_original = data.profile_image_url_original
|
|
|
|
|
|
|
|
output.cover_photo = data.cover_photo
|
|
|
|
|
|
|
|
output.friends_count = data.friends_count
|
|
|
|
|
2019-03-11 21:03:55 +00:00
|
|
|
// output.bot = ??? missing
|
2019-01-14 12:30:14 +00:00
|
|
|
|
|
|
|
output.statusnet_profile_url = data.statusnet_profile_url
|
2019-01-17 20:53:05 +00:00
|
|
|
|
2019-01-14 12:30:14 +00:00
|
|
|
output.is_local = data.is_local
|
2019-02-04 14:03:35 +00:00
|
|
|
output.role = data.role
|
|
|
|
output.show_role = data.show_role
|
2019-01-17 19:11:51 +00:00
|
|
|
|
2019-02-18 14:49:32 +00:00
|
|
|
if (data.rights) {
|
|
|
|
output.rights = {
|
|
|
|
moderator: data.rights.delete_others_notice,
|
|
|
|
admin: data.rights.admin
|
|
|
|
}
|
|
|
|
}
|
2019-01-17 19:11:51 +00:00
|
|
|
output.no_rich_text = data.no_rich_text
|
|
|
|
output.default_scope = data.default_scope
|
2019-02-06 11:21:13 +00:00
|
|
|
output.hide_follows = data.hide_follows
|
2019-01-29 22:11:40 +00:00
|
|
|
output.hide_followers = data.hide_followers
|
2019-09-13 13:15:19 +00:00
|
|
|
output.hide_follows_count = data.hide_follows_count
|
|
|
|
output.hide_followers_count = data.hide_followers_count
|
2019-01-17 19:11:51 +00:00
|
|
|
output.background_image = data.background_image
|
2019-01-27 20:38:33 +00:00
|
|
|
// Websocket token
|
|
|
|
output.token = data.token
|
2020-04-21 20:27:51 +00:00
|
|
|
|
|
|
|
// Convert relationsip data to expected format
|
|
|
|
output.relationship = {
|
|
|
|
muting: data.muted,
|
|
|
|
blocking: data.statusnet_blocking,
|
|
|
|
followed_by: data.follows_you,
|
|
|
|
following: data.following
|
|
|
|
}
|
2019-01-13 19:07:55 +00:00
|
|
|
}
|
2019-01-14 12:30:14 +00:00
|
|
|
|
|
|
|
output.created_at = new Date(data.created_at)
|
|
|
|
output.locked = data.locked
|
|
|
|
output.followers_count = data.followers_count
|
|
|
|
output.statuses_count = data.statuses_count
|
2019-04-30 12:20:19 +00:00
|
|
|
|
2019-02-11 09:41:17 +00:00
|
|
|
if (data.pleroma) {
|
|
|
|
output.follow_request_count = data.pleroma.follow_request_count
|
2019-01-14 12:30:14 +00:00
|
|
|
|
2019-02-18 14:49:32 +00:00
|
|
|
output.tags = data.pleroma.tags
|
2021-01-19 16:01:55 +00:00
|
|
|
|
2021-01-18 21:54:12 +00:00
|
|
|
// deactivated was changed to is_active in Pleroma 2.3.0
|
2021-01-19 16:01:55 +00:00
|
|
|
// so check if is_active is present
|
2021-01-20 16:04:49 +00:00
|
|
|
output.deactivated = typeof data.pleroma.is_active !== 'undefined'
|
2021-01-19 16:01:55 +00:00
|
|
|
? !data.pleroma.is_active // new backend
|
|
|
|
: data.pleroma.deactivated // old backend
|
2019-02-18 14:49:32 +00:00
|
|
|
|
2019-05-25 07:01:02 +00:00
|
|
|
output.notification_settings = data.pleroma.notification_settings
|
2020-05-07 13:10:53 +00:00
|
|
|
output.unread_chat_count = data.pleroma.unread_chat_count
|
2019-02-18 14:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
output.tags = output.tags || []
|
2019-04-27 12:56:37 +00:00
|
|
|
output.rights = output.rights || {}
|
2019-05-25 07:01:02 +00:00
|
|
|
output.notification_settings = output.notification_settings || {}
|
2019-02-18 14:49:32 +00:00
|
|
|
|
2021-02-26 14:23:11 +00:00
|
|
|
// Convert punycode to unicode for UI
|
|
|
|
output.screen_name_ui = output.screen_name
|
2021-04-21 05:40:25 +00:00
|
|
|
if (output.screen_name && output.screen_name.includes('@')) {
|
2021-01-05 08:09:08 +00:00
|
|
|
const parts = output.screen_name.split('@')
|
|
|
|
let unicodeDomain = punycode.toUnicode(parts[1])
|
|
|
|
if (unicodeDomain !== parts[1]) {
|
|
|
|
// Add some identifier so users can potentially spot spoofing attempts:
|
|
|
|
// lain.com and xn--lin-6cd.com would appear identical otherwise.
|
|
|
|
unicodeDomain = '🌏' + unicodeDomain
|
2021-02-26 14:23:11 +00:00
|
|
|
output.screen_name_ui = [parts[0], unicodeDomain].join('@')
|
2021-01-05 08:09:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 12:30:14 +00:00
|
|
|
return output
|
2019-01-13 19:07:55 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 03:23:59 +00:00
|
|
|
export const parseAttachment = (data) => {
|
2019-01-21 13:28:36 +00:00
|
|
|
const output = {}
|
|
|
|
const masto = !data.hasOwnProperty('oembed')
|
|
|
|
|
|
|
|
if (masto) {
|
|
|
|
// Not exactly same...
|
2019-03-18 03:42:07 +00:00
|
|
|
output.mimetype = data.pleroma ? data.pleroma.mime_type : data.type
|
2019-01-21 13:28:36 +00:00
|
|
|
output.meta = data.meta // not present in BE yet
|
2019-03-25 16:19:33 +00:00
|
|
|
output.id = data.id
|
2019-01-21 13:28:36 +00:00
|
|
|
} else {
|
|
|
|
output.mimetype = data.mimetype
|
2019-03-11 21:03:55 +00:00
|
|
|
// output.meta = ??? missing
|
2019-01-13 19:07:55 +00:00
|
|
|
}
|
2019-01-21 13:28:36 +00:00
|
|
|
|
|
|
|
output.url = data.url
|
2020-08-19 12:54:00 +00:00
|
|
|
output.large_thumb_url = data.preview_url
|
2019-01-21 13:28:36 +00:00
|
|
|
output.description = data.description
|
|
|
|
|
|
|
|
return output
|
2019-01-13 19:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const parseStatus = (data) => {
|
|
|
|
const output = {}
|
2019-01-14 19:38:37 +00:00
|
|
|
const masto = data.hasOwnProperty('account')
|
|
|
|
|
2019-01-13 19:07:55 +00:00
|
|
|
if (masto) {
|
|
|
|
output.favorited = data.favourited
|
|
|
|
output.fave_num = data.favourites_count
|
|
|
|
|
|
|
|
output.repeated = data.reblogged
|
|
|
|
output.repeat_num = data.reblogs_count
|
|
|
|
|
2020-07-03 19:45:49 +00:00
|
|
|
output.bookmarked = data.bookmarked
|
|
|
|
|
2019-01-13 19:07:55 +00:00
|
|
|
output.type = data.reblog ? 'retweet' : 'status'
|
|
|
|
output.nsfw = data.sensitive
|
|
|
|
|
2021-06-07 00:14:48 +00:00
|
|
|
output.raw_html = data.content
|
|
|
|
output.emojis = data.emojis
|
2019-01-14 19:58:23 +00:00
|
|
|
|
2019-05-20 04:03:50 +00:00
|
|
|
output.tags = data.tags
|
|
|
|
|
2019-04-09 19:25:44 +00:00
|
|
|
if (data.pleroma) {
|
|
|
|
const { pleroma } = data
|
|
|
|
output.text = pleroma.content ? data.pleroma.content['text/plain'] : data.content
|
|
|
|
output.summary = pleroma.spoiler_text ? data.pleroma.spoiler_text['text/plain'] : data.spoiler_text
|
|
|
|
output.statusnet_conversation_id = data.pleroma.conversation_id
|
2019-04-10 12:02:14 +00:00
|
|
|
output.is_local = pleroma.local
|
2019-04-27 04:52:11 +00:00
|
|
|
output.in_reply_to_screen_name = data.pleroma.in_reply_to_account_acct
|
2019-09-14 02:59:24 +00:00
|
|
|
output.thread_muted = pleroma.thread_muted
|
2020-01-28 15:09:25 +00:00
|
|
|
output.emoji_reactions = pleroma.emoji_reactions
|
2020-06-30 12:04:16 +00:00
|
|
|
output.parent_visible = pleroma.parent_visible === undefined ? true : pleroma.parent_visible
|
2019-04-09 19:25:44 +00:00
|
|
|
} else {
|
|
|
|
output.text = data.content
|
|
|
|
output.summary = data.spoiler_text
|
|
|
|
}
|
2019-01-13 19:07:55 +00:00
|
|
|
|
|
|
|
output.in_reply_to_status_id = data.in_reply_to_id
|
2019-01-17 20:22:51 +00:00
|
|
|
output.in_reply_to_user_id = data.in_reply_to_account_id
|
2019-03-28 07:46:41 +00:00
|
|
|
output.replies_count = data.replies_count
|
2019-01-21 18:41:17 +00:00
|
|
|
|
2019-01-17 17:44:37 +00:00
|
|
|
if (output.type === 'retweet') {
|
|
|
|
output.retweeted_status = parseStatus(data.reblog)
|
|
|
|
}
|
2019-01-17 20:22:51 +00:00
|
|
|
|
2021-06-07 00:14:48 +00:00
|
|
|
output.summary_raw_html = escape(data.spoiler_text)
|
2019-01-17 20:44:31 +00:00
|
|
|
output.external_url = data.url
|
2019-06-18 20:28:31 +00:00
|
|
|
output.poll = data.poll
|
2020-06-14 11:16:08 +00:00
|
|
|
if (output.poll) {
|
2020-06-14 13:09:14 +00:00
|
|
|
output.poll.options = (output.poll.options || []).map(field => ({
|
|
|
|
...field,
|
2021-08-13 09:19:57 +00:00
|
|
|
title_html: escape(field.title)
|
2020-06-14 13:09:14 +00:00
|
|
|
}))
|
2020-06-14 11:16:08 +00:00
|
|
|
}
|
2019-04-04 16:47:25 +00:00
|
|
|
output.pinned = data.pinned
|
2019-07-07 20:02:09 +00:00
|
|
|
output.muted = data.muted
|
2019-01-13 19:07:55 +00:00
|
|
|
} else {
|
|
|
|
output.favorited = data.favorited
|
|
|
|
output.fave_num = data.fave_num
|
|
|
|
|
|
|
|
output.repeated = data.repeated
|
|
|
|
output.repeat_num = data.repeat_num
|
|
|
|
|
|
|
|
// catchall, temporary
|
|
|
|
// Object.assign(output, data)
|
|
|
|
|
|
|
|
output.type = qvitterStatusType(data)
|
|
|
|
|
|
|
|
if (data.nsfw === undefined) {
|
|
|
|
output.nsfw = isNsfw(data)
|
|
|
|
if (data.retweeted_status) {
|
|
|
|
output.nsfw = data.retweeted_status.nsfw
|
|
|
|
}
|
2019-01-15 15:39:24 +00:00
|
|
|
} else {
|
|
|
|
output.nsfw = data.nsfw
|
2019-01-13 19:07:55 +00:00
|
|
|
}
|
2019-01-15 15:39:24 +00:00
|
|
|
|
2021-06-12 16:54:03 +00:00
|
|
|
output.raw_html = data.statusnet_html
|
2019-01-13 19:07:55 +00:00
|
|
|
output.text = data.text
|
|
|
|
|
2019-01-17 20:22:51 +00:00
|
|
|
output.in_reply_to_status_id = data.in_reply_to_status_id
|
|
|
|
output.in_reply_to_user_id = data.in_reply_to_user_id
|
2019-01-21 18:41:17 +00:00
|
|
|
output.in_reply_to_screen_name = data.in_reply_to_screen_name
|
2019-01-14 19:58:23 +00:00
|
|
|
output.statusnet_conversation_id = data.statusnet_conversation_id
|
2019-01-17 17:44:37 +00:00
|
|
|
|
|
|
|
if (output.type === 'retweet') {
|
|
|
|
output.retweeted_status = parseStatus(data.retweeted_status)
|
|
|
|
}
|
2019-01-17 20:22:51 +00:00
|
|
|
|
|
|
|
output.summary = data.summary
|
2019-01-25 10:05:19 +00:00
|
|
|
output.summary_html = data.summary_html
|
2019-01-17 20:44:31 +00:00
|
|
|
output.external_url = data.external_url
|
|
|
|
output.is_local = data.is_local
|
2019-01-13 19:07:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-17 16:23:14 +00:00
|
|
|
output.id = String(data.id)
|
2019-01-13 19:07:55 +00:00
|
|
|
output.visibility = data.visibility
|
2019-01-27 12:56:07 +00:00
|
|
|
output.card = data.card
|
2019-01-13 19:07:55 +00:00
|
|
|
output.created_at = new Date(data.created_at)
|
|
|
|
|
2019-01-22 20:57:51 +00:00
|
|
|
// Converting to string, the right way.
|
|
|
|
output.in_reply_to_status_id = output.in_reply_to_status_id
|
|
|
|
? String(output.in_reply_to_status_id)
|
|
|
|
: null
|
|
|
|
output.in_reply_to_user_id = output.in_reply_to_user_id
|
|
|
|
? String(output.in_reply_to_user_id)
|
|
|
|
: null
|
|
|
|
|
2019-01-13 19:07:55 +00:00
|
|
|
output.user = parseUser(masto ? data.account : data.user)
|
|
|
|
|
2019-01-19 01:10:16 +00:00
|
|
|
output.attentions = ((masto ? data.mentions : data.attentions) || []).map(parseUser)
|
2019-01-13 19:07:55 +00:00
|
|
|
|
|
|
|
output.attachments = ((masto ? data.media_attachments : data.attachments) || [])
|
|
|
|
.map(parseAttachment)
|
|
|
|
|
|
|
|
const retweetedStatus = masto ? data.reblog : data.retweeted_status
|
|
|
|
if (retweetedStatus) {
|
|
|
|
output.retweeted_status = parseStatus(retweetedStatus)
|
|
|
|
}
|
|
|
|
|
2019-05-01 14:33:56 +00:00
|
|
|
output.favoritedBy = []
|
|
|
|
output.rebloggedBy = []
|
|
|
|
|
2019-01-13 19:07:55 +00:00
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
2019-01-14 19:38:37 +00:00
|
|
|
export const parseNotification = (data) => {
|
|
|
|
const mastoDict = {
|
|
|
|
'favourite': 'like',
|
|
|
|
'reblog': 'repeat'
|
|
|
|
}
|
|
|
|
const masto = !data.hasOwnProperty('ntype')
|
|
|
|
const output = {}
|
2020-04-23 11:27:27 +00:00
|
|
|
|
2019-01-14 19:38:37 +00:00
|
|
|
if (masto) {
|
|
|
|
output.type = mastoDict[data.type] || data.type
|
2019-03-18 16:30:34 +00:00
|
|
|
output.seen = data.pleroma.is_seen
|
2020-04-25 04:04:39 +00:00
|
|
|
output.status = isStatusNotification(output.type) ? parseStatus(data.status) : null
|
2019-03-31 18:50:34 +00:00
|
|
|
output.action = output.status // TODO: Refactor, this is unneeded
|
2019-12-10 14:54:28 +00:00
|
|
|
output.target = output.type !== 'move'
|
|
|
|
? null
|
|
|
|
: parseUser(data.target)
|
2019-01-14 19:38:37 +00:00
|
|
|
output.from_profile = parseUser(data.account)
|
2020-02-11 12:24:51 +00:00
|
|
|
output.emoji = data.emoji
|
2019-01-14 19:38:37 +00:00
|
|
|
} else {
|
|
|
|
const parsedNotice = parseStatus(data.notice)
|
|
|
|
output.type = data.ntype
|
2019-01-17 17:44:37 +00:00
|
|
|
output.seen = Boolean(data.is_seen)
|
2019-01-14 19:38:37 +00:00
|
|
|
output.status = output.type === 'like'
|
|
|
|
? parseStatus(data.notice.favorited_status)
|
|
|
|
: parsedNotice
|
|
|
|
output.action = parsedNotice
|
2020-05-07 13:10:53 +00:00
|
|
|
output.from_profile = output.type === 'pleroma:chat_mention' ? parseUser(data.account) : parseUser(data.from_profile)
|
2019-01-14 19:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
output.created_at = new Date(data.created_at)
|
2019-05-03 19:56:21 +00:00
|
|
|
output.id = parseInt(data.id)
|
2019-01-14 19:38:37 +00:00
|
|
|
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
2019-01-13 19:07:55 +00:00
|
|
|
const isNsfw = (status) => {
|
|
|
|
const nsfwRegex = /#nsfw/i
|
2019-03-22 17:15:11 +00:00
|
|
|
return (status.tags || []).includes('nsfw') || !!(status.text || '').match(nsfwRegex)
|
2019-01-13 19:07:55 +00:00
|
|
|
}
|
2020-07-03 19:45:49 +00:00
|
|
|
|
|
|
|
export const parseLinkHeaderPagination = (linkHeader, opts = {}) => {
|
|
|
|
const flakeId = opts.flakeId
|
|
|
|
const parsedLinkHeader = parseLinkHeader(linkHeader)
|
|
|
|
if (!parsedLinkHeader) return
|
|
|
|
const maxId = parsedLinkHeader.next.max_id
|
|
|
|
const minId = parsedLinkHeader.prev.min_id
|
|
|
|
|
|
|
|
return {
|
|
|
|
maxId: flakeId ? maxId : parseInt(maxId, 10),
|
|
|
|
minId: flakeId ? minId : parseInt(minId, 10)
|
|
|
|
}
|
|
|
|
}
|
2020-05-07 13:10:53 +00:00
|
|
|
|
|
|
|
export const parseChat = (chat) => {
|
|
|
|
const output = {}
|
|
|
|
output.id = chat.id
|
|
|
|
output.account = parseUser(chat.account)
|
|
|
|
output.unread = chat.unread
|
|
|
|
output.lastMessage = parseChatMessage(chat.last_message)
|
|
|
|
output.updated_at = new Date(chat.updated_at)
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
|
|
|
export const parseChatMessage = (message) => {
|
|
|
|
if (!message) { return }
|
|
|
|
if (message.isNormalized) { return message }
|
|
|
|
const output = message
|
|
|
|
output.id = message.id
|
|
|
|
output.created_at = new Date(message.created_at)
|
|
|
|
output.chat_id = message.chat_id
|
2021-06-07 16:50:26 +00:00
|
|
|
output.emojis = message.emojis
|
2021-06-12 16:54:03 +00:00
|
|
|
output.content = message.content
|
2020-05-07 13:10:53 +00:00
|
|
|
if (message.attachment) {
|
|
|
|
output.attachments = [parseAttachment(message.attachment)]
|
|
|
|
} else {
|
|
|
|
output.attachments = []
|
|
|
|
}
|
2020-10-29 10:33:06 +00:00
|
|
|
output.pending = !!message.pending
|
|
|
|
output.error = false
|
|
|
|
output.idempotency_key = message.idempotency_key
|
2020-05-07 13:10:53 +00:00
|
|
|
output.isNormalized = true
|
|
|
|
return output
|
|
|
|
}
|