matterhorn-chat / matterhorn

A feature-rich Unix terminal client for the Mattermost chat system
BSD 3-Clause "New" or "Revised" License
1.05k stars 77 forks source link

Some mattermost conversation links open in web browser #806

Open setharnold opened 1 year ago

setharnold commented 1 year ago

Hello, usually internal links to conversations in matterhorn render with <post link> but once in a while internal links render with the full URL. These full-URL links open with Firefox rather than within matterhorn.

The Yank-all view of a message that renders with the full URL and opens in Firefox:

aha, https://chat.canonical.com/canonical/pl/n8swhud1u7nemea8catj165gme

The Yank-all view of a message that renders with <post link> and opens within matterhorn:

just forwarding Lukasz message here in case you missed it:
https://chat.canonical.com/canonical/pl/ksiw1geiqjn63kr8wr1xawooto

I would prefer if these links always opened within matterhorn. I would prefer if the link text were visible, so that it is an option to select it and copy it via mouse.

Thanks

external-link internal-link

jtdaugherty commented 1 year ago

If this is happening, it's because Matterhorn doesn't recognize one of those URLs as a post link for your server for some reason. Are the URLs you included above both representative examples, with the first one being an example that doesn't get recognized as a post link?

jtdaugherty commented 1 year ago

(By which I mean examples of actual URLs from your server.)

setharnold commented 1 year ago

Yes, I copied both of those examples without changing or obfuscating either of them. They both look like what I expect and both of them take me to the intended conversation when I load them with Firefox.

Now that I load them both back-to-back, I see one is to a 'private channel' and one is to a 'public channel'. (None of our channels are fully public, we require authenticating with our SSO system to connect. But we do use the private channels to limit visibility of conversations.)

Thanks

jtdaugherty commented 1 year ago

Was the user account that had this problem a member of the private channel at the time this behavior was observed?

jtdaugherty commented 1 year ago

(And was it the private channel's link that was misbehaving?)

setharnold commented 1 year ago

Unfortunately, I just came across another link that renders as the URL and loads in Firefox that goes to a public channel. (I even knew two examples wasn't enough to draw a conclusion but wanted to believe. sigh.)

btw, [https://chat.canonical.com/canonical/pl/pi1kfyhhetd33rfaek5jfrnifr](https://chat.canonical.com/canonical/pl/pi1kfyhhetd33rfaek5jfrnifr)

Renders as:

btw, <<https://chat.canonical.com/canonical/pl/pi1kfyhhetd33rfaek5jfrnifr>>

I believe all the people who posted the links were members of the channels at the time that they posted the links.

jtdaugherty commented 1 year ago

(Actually, channel membership won't matter at all. I thought it might, but Matterhorn doesn't even know which channel a post is in, just by looking at the post link. It only identifies a post link by looking at the URL structure.)

jtdaugherty commented 1 year ago

Another question: when these links were not being rendered as expected, what was the Mattermost team that contained the channel in which the broken links were rendered? (The team in the URL is canonical.)

setharnold commented 1 year ago

I only connect to one Mattermost server, run by Canonical. As far as I know, all the channels are part of the Canonical team.

jtdaugherty commented 1 year ago

To confirm explicitly, then, matterhorn is not showing a team list at the top of the screen, then, right? For example, I'm on two Mattermost "teams" so the first line in my matterhorn UI says Teams (1/2): when the first team is selected.

setharnold commented 1 year ago

Correct:

   Team: Canonical
    + @seth-arnold
      Unread: 16
▲ ──Public Channels*──
jtdaugherty commented 1 year ago

Okay, thanks. Just for your awareness: a "team" is a group of channels and users within a server, and every server has at least one team. You are currently a member of just one, although your server could have others that you aren't a member of. But in this case it doesn't matter because all of the post links you showed are links to posts on channels in your team, so they should be rendered as post links. (If Matterhorn sees a link to a post in a different team, it won't render it as a post link since that can't necessarily be treated as such.)

This is a bit of a puzzle. I'll think about it some more and see if I have more questions for you, but right now I don't have any theories about why you're seeing this behavior.

taratatach commented 1 year ago

Hi.

I'm facing the same issue.

I wonder if this could happen when the linked message is pretty old and not part of the messages in Matterhorn's memory (or recent history).

jtdaugherty commented 1 year ago

@taratatach If matterhorn can tell that a link is to a post, then it will always fetch that post and put it into the history. (It must do this since the next step is to select the post in selection mode.)

setharnold commented 12 months ago

In https://github.com/matterhorn-chat/matterhorn/issues/816 I pointed out that my client had two connections to my company's mattermost instance via Kubernetes and loadbalancers. Earlier, @jtdaugherty said:

it's because Matterhorn doesn't recognize one of those URLs as a post link for your server for some reason.

This is a mighty big leap to make, but what are the chances that the "post link for your server" is doing some IP-address based equality checks rather than DNS-name based equality checks or making an API call to retrieve the contents of the link and inspect the data for a team uuid or something?

In which case, there might not be any pattern to which links are considered on the same server and which are considered to be on another server, because the getaddrinfo() call (or whatever API is actually used) might be returning an IP address from the list at random:

$ host chat.canonical.com
chat.canonical.com is an alias for prod-is.ps5.kubernetes-ingress.canonical.com.
prod-is.ps5.kubernetes-ingress.canonical.com has address 185.125.189.99
prod-is.ps5.kubernetes-ingress.canonical.com has address 185.125.189.101
prod-is.ps5.kubernetes-ingress.canonical.com has address 185.125.189.100

Thanks

jtdaugherty commented 12 months ago

@setharnold post links are detected solely by inspecting the string of the URL that mentions the post (here). No API calls or DNS resolutions are involved.

setharnold commented 12 months ago

A leap too far! thanks again for indulging my curiosity @jtdaugherty.

setharnold commented 9 months ago

Is there a way I can force matterhorn to load an URL? eg, a recent message from a colleague renders like this:

[01:11:46] NNNN:
             lorem ipsum sic semper fudge
             <https://chat.canonical.com/canonical/pl/zikxg3g9wtb3bywic58ebgrmaw>

The built-in url opening goes through xdg-open to firefox which loads that link in the web interface. What I would love is some way to go to this conversation within matterhorn directly. For example, maybe /join https://chat.canonical.com/canonical/pl/zikxg3g9wtb3bywic58ebgrmaw or /goto https://chat.canonical.com/canonical/pl/zikxg3g9wtb3bywic58ebgrmaw or something similar.

Does this feature exist? If not, would you like a new issue for it?

Thanks

jtdaugherty commented 9 months ago

Is there a way I can force matterhorn to load an URL?

Not right now. It can only open URLs that appear in messages.

What I would love is some way to go to this conversation within matterhorn directly.

In general, Matterhorn will do this if you open a post URL. If you open a post URL and it uses the open command as you describe, then that's an instance of the bug that this ticket is about, and I don't have any leads right now on why that would be happening. If Matterhorn uses the open command to open the URL, then for some reason it has concluded that the URL is not a post URL.

I'll update Matterhorn so that it logs some of the information it's using to do post URL matching. Perhaps that way we can see why it isn't properly identifying post URLs.

jtdaugherty commented 9 months ago

There's now a patch on develop that will log the team URL data that Matterhorn uses to do post URL identification. For anyone here with post URL loading problems, if you want to build from source, then running the develop build with logging enabled will result in a log that contains lines like

[2024-02-21 03:05:03.046352 UTC] [LogGeneral] [*] Team base URL for team ID TI {unTI = Id {unId = "3k4349mapfyh88hrxzprbm3yiw"}}: TeamBaseURL (TeamURLName "foo") (ServerBaseURL "https://mattermost.example.com/")
[2024-02-21 03:05:03.046354 UTC] [LogGeneral] [*] Team base URL for team ID TI {unTI = Id {unId = "5k97pnsfjpbrbenrceggq49g8h"}}: TeamBaseURL (TeamURLName "bar") (ServerBaseURL "https://mattermost.example.com/")

If you end up doing that, please post that here along with one of the post URLs you're using that isn't working.