package api import ( "net/url" "strings" ) // Permalink is the web link to a message, in the form Chatto's "Copy link" // gives: /chat/-/[/]/m/ on the server's origin, // where "-" means the server the link is on. DMs use the room ID too. The // web app's /user/ form names the viewer's partner, so it means a // different room to each side of the DM. func (c *Client) Permalink(roomID, threadID, messageID string) string { segs := []string{roomID} if threadID != "" && threadID != messageID { segs = append(segs, threadID) } segs = append(segs, "m", messageID) for i, s := range segs { segs[i] = url.PathEscape(s) } origin := c.ServerURL if u, err := url.Parse(c.ServerURL); err == nil && u.Host != "" { origin = u.Scheme + "://" + u.Host } return origin + "/chat/-/" + strings.Join(segs, "/") }