Fix #1762, add a link to see the mastodon account directly on your home server if the contributor has a mastodon set

This commit is contained in:
Pieter Vander Vennet 2024-01-21 02:54:49 +01:00
parent 256e294fc0
commit 25dafe747c
3 changed files with 30 additions and 4 deletions

View file

@ -723,7 +723,8 @@
"fediverse": { "fediverse": {
"description": "A fediverse handle, often @username@server.tld", "description": "A fediverse handle, often @username@server.tld",
"feedback": "A fediverse handle consists of @username@server.tld or is a link to a profile", "feedback": "A fediverse handle consists of @username@server.tld or is a link to a profile",
"invalidHost": "{host} is not a valid hostname" "invalidHost": "{host} is not a valid hostname",
"onYourServer": "See and follow on your server"
}, },
"float": { "float": {
"description": "a number", "description": "a number",

View file

@ -3,7 +3,7 @@ import { Translation } from "../../i18n/Translation"
import Translations from "../../i18n/Translations" import Translations from "../../i18n/Translations"
export default class FediverseValidator extends Validator { export default class FediverseValidator extends Validator {
public static readonly usernameAtServer: RegExp = /^@?(\w+)@((\w|\.)+)$/ public static readonly usernameAtServer: RegExp = /^@?(\w+)@((\w|-|\.)+)$/
constructor() { constructor() {
super( super(

View file

@ -88,6 +88,7 @@ import MaprouletteSetStatus from "./MapRoulette/MaprouletteSetStatus.svelte"
import DirectionIndicator from "./Base/DirectionIndicator.svelte" import DirectionIndicator from "./Base/DirectionIndicator.svelte"
import Img from "./Base/Img" import Img from "./Base/Img"
import Qr from "../Utils/Qr" import Qr from "../Utils/Qr"
import { log } from "node:util"
class NearbyImageVis implements SpecialVisualization { class NearbyImageVis implements SpecialVisualization {
// Class must be in SpecialVisualisations due to weird cyclical import that breaks the tests // Class must be in SpecialVisualisations due to weird cyclical import that breaks the tests
@ -1387,11 +1388,35 @@ export default class SpecialVisualizations {
const [_, username, host] = fediAccount.match( const [_, username, host] = fediAccount.match(
FediverseValidator.usernameAtServer FediverseValidator.usernameAtServer
) )
return new SvelteUIElement(Link, {
const normalLink = new SvelteUIElement(Link, {
text: fediAccount, text: fediAccount,
url: "https://" + host + "/@" + username, href: "https://" + host + "/@" + username,
newTab: true, newTab: true,
}) })
const loggedInContributorMastodon =
state.userRelatedState?.preferencesAsTags?.data?.[
"_mastodon_link"
]
console.log(
"LoggedinContributorMastodon",
loggedInContributorMastodon
)
if (!loggedInContributorMastodon) {
return normalLink
}
const homeUrl = new URL(loggedInContributorMastodon)
const homeHost = homeUrl.protocol + "//" + homeUrl.hostname
return new Combine([
normalLink,
new SvelteUIElement(Link, {
href: homeHost + "/" + fediAccount,
text: Translations.t.validation.fediverse.onYourServer,
newTab: true,
}).SetClass("button"),
])
}) })
) )
}, },