Skip to content
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

Fix links looking like lemmy links being used as one #1048

Merged
merged 18 commits into from
Jul 20, 2023

Conversation

MV-GH
Copy link
Collaborator

@MV-GH MV-GH commented Jul 16, 2023

  • Updates instance list
  • Use a set instead of array for instance list (for O(1) search)
  • Fixes lemmy thinking /c/ or /u/ as lemmy instances. Now it does a check if the host is not in LEMMY_INSTANCES, which then gets cached, for links formatted as lemmy instances it directly assumes they are lemmy instances
  • Fixes instance/c/community@otherinstance not being displayed correctly in community (basically just errors)

studio64_w1TfQLJKuE

basically what would happen is:
at openLink receives
-> https://lemmy.one/c/technology@beehaw.org
Transformed and navigated to
-> lemmy.one/c/technology@beehaw.org
-> instance/c/community@otherinstance
by logic in navhost turned into
-> community@otherinstance@instance
due to {instance}/c/{name} -> {name}@{instance}
studio64_w1TfQLJKuE

Shows the fix, this would previously show only errors

rC5OPRqCT1.mp4

Fully Fixes #1020
This link was previously thought as a community by Jerboa, (and crashed before my other fix)

8ge8yVQqGC.mp4

@@ -24,6 +24,8 @@ const val DEFAULT_INSTANCE = "lemmy.ml"
const val MINIMUM_API_VERSION: String = "0.18"
val REDACTED_QUERY_PARAMS = setOf("auth")
val REDACTED_BODY_FIELDS = setOf("jwt", "password")
val TEMP_RECOGNISED_AS_LEMMY_INSTANCES = mutableSetOf<String>()
val TEMP_NOT_RECOGNISED_AS_LEMMY_INSTANCES = mutableSetOf<String>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are these getting filled? Should you just use the hardcoded DEFAULT_INSTANCES ?

Globals should probably go inside the singleton if you really need them, but I don't see why you do, because DEFAULT_INSTANCES already exists.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are getting filled from checkIfLemmyInstance, it caches the hosts. Not sure where I should put them. Which singleton do you mean? I don't want to update DEFAULT_INSTANCES for several reasons, first its not mutable, so updating would incur a much higher cost. And making it mutable would make it unstable for composable use. Secondly I would still need a temp_not_recongized list to cache the hosts not recognized as lemmy instance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine I spose. The API's companion object is a singleton, and you could use it to store these temp lists, but that's up to you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it and checkIfLemmyInstance to the singleton

Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work, I'll let @twizmwazin look over before a merge.

@@ -24,6 +24,8 @@ const val DEFAULT_INSTANCE = "lemmy.ml"
const val MINIMUM_API_VERSION: String = "0.18"
val REDACTED_QUERY_PARAMS = setOf("auth")
val REDACTED_BODY_FIELDS = setOf("jwt", "password")
val TEMP_RECOGNISED_AS_LEMMY_INSTANCES = mutableSetOf<String>()
val TEMP_NOT_RECOGNISED_AS_LEMMY_INSTANCES = mutableSetOf<String>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine I spose. The API's companion object is a singleton, and you could use it to store these temp lists, but that's up to you.

@dessalines dessalines merged commit e1fce30 into LemmyNet:main Jul 20, 2023
@MV-GH MV-GH deleted the bug/linkhandling branch July 20, 2023 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App crashes when opening specific link
2 participants