Closed WilhelmOks closed 1 year ago
Can you please send a link to the mention? I want to debug this myself in order to figure out the issue, since I've worked on the link features for quite a long time and I didn't know it might be broken on some occasions. It worked on every single mention and link I've seen up to this point...
I haven't saved the link to that rant, sorry. Maybe you can try to search for that specific urls and find that rant or just create your own comment containing multiple different youtube links.
Turns out that this is more fundamental than just an edge case.
I wrote the range calculator without adding the scenario where multiple links have the same shortened link in the body into the mix.
I have devised a solution for this issue and I will open a pull request for approving it in a few moments.
I found a comment from ElectroArchiver on devRant (posted 3 hours ago), which has 3 youtube links in it. And for this edge case, the calculatedRange property in Link contains wrong values.
This is a log of the links property in the debugger:
There are 3 url links and one mention link. The calculatedRange has (28, 29) for each of the 3 links, which is wrong. The reason is that SwiftRant calculates the range by searching for the link.title. And the title is the same for all 3 links because it is shortened. So it finds only the first occurence for all of the 3 links.
To fix this, we could just use link.start and link.end to calculate the range. But those are both nil for "mention" type links. So, we need to make a check for that and calculate mention links based on the title.
This is what I did as a workaround in my JoyRant client for now:
I think this should be implemented in Link.calculatedRange in SwiftRant.