-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support exclusive lists with GoToSocial 0.17 #817
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,14 @@ import { satisfies } from 'compare-versions'; | |
|
||
import features from '../data/features.json'; | ||
|
||
import { getCurrentInstance } from './store-utils'; | ||
import { getCurrentInstance, getCurrentNodeInfo } from './store-utils'; | ||
|
||
// Non-semver(?) UA string detection | ||
const containPixelfed = /pixelfed/i; | ||
const notContainPixelfed = /^(?!.*pixelfed).*$/i; | ||
const containPleroma = /pleroma/i; | ||
const containAkkoma = /akkoma/i; | ||
const containGTS = /gotosocial/i; | ||
const platformFeatures = { | ||
'@mastodon/lists': notContainPixelfed, | ||
'@mastodon/filters': notContainPixelfed, | ||
|
@@ -25,11 +26,19 @@ const platformFeatures = { | |
'@pleroma/local-visibility-post': containPleroma, | ||
'@akkoma/local-visibility-post': containAkkoma, | ||
}; | ||
|
||
const supportsCache = {}; | ||
|
||
function supports(feature) { | ||
try { | ||
const { version, domain } = getCurrentInstance(); | ||
let { version, domain } = getCurrentInstance(); | ||
let softwareName = getCurrentNodeInfo()?.software?.name || 'mastodon'; | ||
|
||
if (softwareName === 'hometown') { | ||
// Hometown is a Mastodon fork and inherits its features | ||
softwareName = 'mastodon'; | ||
} | ||
|
||
const key = `${domain}-${feature}`; | ||
if (supportsCache[key]) return supportsCache[key]; | ||
|
||
|
@@ -39,10 +48,17 @@ function supports(feature) { | |
|
||
const range = features[feature]; | ||
if (!range) return false; | ||
return (supportsCache[key] = satisfies(version, range, { | ||
includePrerelease: true, | ||
loose: true, | ||
})); | ||
|
||
// '@mastodon/blah' => 'mastodon' | ||
const featureSoftware = feature.match(/^@([a-z]+)\//)[1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be like I know my code above looks fancy (it's in other files too) so feel free to write it in a more understandable way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought I could rely on
So it seems like a call which did not match that pattern would likely be a bug. Do you want me to check for that here anyway? |
||
|
||
const doesSoftwareMatch = featureSoftware === softwareName.toLowerCase(); | ||
return (supportsCache[key] = | ||
doesSoftwareMatch && | ||
satisfies(version, range, { | ||
includePrerelease: true, | ||
loose: true, | ||
})); | ||
} catch (e) { | ||
return false; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering, how is this relevant to the current PR, which is meant for GTS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a future Hometown release includes the fix for nodeInfo,
softwareName
will be'hometown'
, so for features like'@mastodon/list-exclusive'
, without the above line of code, this comparison would be false ('mastodon' === 'hometown'
):