upd: add MFM to HTML support and Mentions parsing to mastodon api (#33)

* upd: attempt to turn MFM to html on mastodon

* revert: recent change until better implementation later

* chore: remove unused packages

* Update docker.yml

* upd: add MFM to HTML for timelines and status view

* chore: lint

* upd: megalodon resolve urls

* upd: add spliting

* test: local user mention

* test: change local user url in mention

* upd: change check

* test: megalodon changes

* upd: edit resolving of local users

This is starting to drive me nuts

* upd: remove the @ symbol in query

* fix: make renderPerson return host instead of null for local

* upd: change url for local user

* upd: change limit

* upd: add url to output

* upd: add mastodon boolean

* test: test different format

* fix: test of different format

* test: change up resolving

* fix: forgot to provide url

* upd: change lookup function a bit

* test: substring

* test: regex

* upd: remove substr

* test: new regexs

* dirty test

* test: one last attempt for today

* upd: fix build error

* upd: take input from iceshrimp dev

* upd: parse remote statuses

* upd: fix pleroma users misformatted urls

* upd: add uri to normal user

* fix: forgot to push updated types

* fix: resolving broke

* fix: html not converting correctly

* fix: return default img if no banner

* upd: swap out img used for no header, set fallback avatar

* fix: html escaped & and ' symbols

* upd: fix ' converting into 39; and get profile fields

* upd: resolve fields on lookup

---------

Co-authored-by: Amelia Yukii <123300075+Insert5StarName@users.noreply.github.com>
This commit is contained in:
Marie 2023-10-01 01:58:06 +02:00 committed by GitHub
parent e5d9eb3082
commit 54578f6965
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 237 additions and 41 deletions

View file

@ -2122,6 +2122,40 @@ export default class Misskey implements MegalodonInterface {
): Promise<Response<Entity.Results>> {
switch (options.type) {
case 'accounts': {
if (q.startsWith("http://") || q.startsWith("https://")) {
return this.client
.post("/api/ap/show", { uri: q })
.then(async (res) => {
if (res.status != 200 || res.data.type != "User") {
res.status = 200;
res.statusText = "OK";
res.data = {
accounts: [],
statuses: [],
hashtags: [],
};
return res;
}
const account = await MisskeyAPI.Converter.userDetail(
res.data.object as MisskeyAPI.Entity.UserDetail,
this.baseUrl,
);
return {
...res,
data: {
accounts:
options?.max_id && options?.max_id >= account.id
? []
: [account],
statuses: [],
hashtags: [],
},
};
});
}
let params = {
query: q
}
@ -2151,7 +2185,7 @@ export default class Misskey implements MegalodonInterface {
});
}
try {
const match = q.match(/^@?(?<user>[a-zA-Z0-9_]+)(?:@(?<host>[a-zA-Z0-9-.]+\.[a-zA-Z0-9-]+)|)$/);
const match = params.query.match(/^@?(?<user>[a-zA-Z0-9_]+)(?:@(?<host>[a-zA-Z0-9-.]+\.[a-zA-Z0-9-]+)|)$/);
if (match) {
const lookupQuery = {
username: match.groups?.user,
@ -2195,6 +2229,38 @@ export default class Misskey implements MegalodonInterface {
}))
}
case 'statuses': {
if (q.startsWith("http://") || q.startsWith("https://")) {
return this.client
.post("/api/ap/show", { uri: q })
.then(async (res) => {
if (res.status != 200 || res.data.type != "Note") {
res.status = 200;
res.statusText = "OK";
res.data = {
accounts: [],
statuses: [],
hashtags: [],
};
return res;
}
const post = await MisskeyAPI.Converter.note(
res.data.object as MisskeyAPI.Entity.Note,
this.baseUrl
);
return {
...res,
data: {
accounts: [],
statuses:
options?.max_id && options.max_id >= post.id ? [] : [post],
hashtags: [],
},
};
});
}
let params = {
query: q
}

View file

@ -93,11 +93,11 @@ namespace MisskeyAPI {
following_count: u.followingCount ? u.followingCount : 0,
statuses_count: u.notesCount ? u.notesCount : 0,
note: u.description ? u.description : '',
url: acctUrl,
avatar: u.avatarUrl,
avatar_static: u.avatarUrl,
header: u.bannerUrl ? u.bannerUrl : '',
header_static: u.bannerUrl ? u.bannerUrl : '',
url: u.uri ?? acctUrl,
avatar: u.avatarUrl ? u.avatarUrl : 'https://dev.joinsharkey.org/static-assets/avatar.png',
avatar_static: u.avatarUrl ? u.avatarUrl : 'https://dev.joinsharkey.org/static-assets/avatar.png',
header: u.bannerUrl ? u.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png',
header_static: u.bannerUrl ? u.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png',
emojis: mapEmojis(u.emojis),
moved: null,
fields: [],
@ -128,11 +128,11 @@ namespace MisskeyAPI {
following_count: u.followingCount,
statuses_count: u.notesCount,
note: u.description ? u.description.replace(/\n|\\n/g, "<br>") : '',
url: acctUrl,
avatar: u.avatarUrl,
avatar_static: u.avatarUrl,
header: u.bannerUrl,
header_static: u.bannerUrl,
url: u.uri ?? acctUrl,
avatar: u.avatarUrl ? u.avatarUrl : 'https://dev.joinsharkey.org/static-assets/avatar.png',
avatar_static: u.avatarUrl ? u.avatarUrl : 'https://dev.joinsharkey.org/static-assets/avatar.png',
header: u.bannerUrl ? u.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png',
header_static: u.bannerUrl ? u.bannerUrl : 'https://dev.joinsharkey.org/static-assets/transparent.png',
emojis: mapEmojis(u.emojis),
moved: null,
fields: [],

View file

@ -12,6 +12,7 @@ namespace MisskeyEntity {
notesCount?: number
host: string | null
avatarUrl: string
uri?: string
bannerUrl?: string | null
avatarColor: string
emojis: Array<Emoji> | { [key: string]: string }

View file

@ -16,6 +16,7 @@ namespace MisskeyEntity {
emojis: Array<Emoji> | { [key: string]: string }
createdAt: string
bannerUrl: string
uri: string
bannerColor: string
isLocked: boolean
isSilenced: boolean