mirror of
https://github.com/muesli/telephant
synced 2025-02-16 19:48:24 +00:00
Open new panes for hashtags that get clicked on
This commit is contained in:
parent
d306687d88
commit
2284cad564
4 changed files with 71 additions and 4 deletions
|
@ -203,6 +203,42 @@ func (mod *Account) Unfollow(id string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Tag starts a hashtag stream
|
||||
func (mod *Account) Tag(token string, ch chan interface{}) error {
|
||||
tt, err := mod.client.GetTimelineHashtag(context.Background(), token, false, &mastodon.Pagination{
|
||||
Limit: initialFeedCount,
|
||||
})
|
||||
if err != nil {
|
||||
ev := accounts.ErrorEvent{
|
||||
Message: err.Error(),
|
||||
Internal: false,
|
||||
}
|
||||
mod.evchan <- ev
|
||||
return err
|
||||
}
|
||||
for i := len(tt) - 1; i >= 0; i-- {
|
||||
ch <- mod.handleStatus(tt[i])
|
||||
}
|
||||
|
||||
s, err := mod.client.StreamingHashtag(context.Background(), token, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-mod.SigChan:
|
||||
return
|
||||
case item := <-s:
|
||||
mod.handleStreamEvent(item, ch)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadConversation loads a message conversation
|
||||
func (mod *Account) LoadConversation(id string) ([]accounts.MessageEvent, error) {
|
||||
var r []accounts.MessageEvent
|
||||
|
@ -290,7 +326,11 @@ func parseBody(s *mastodon.Status) string {
|
|||
body = r.ReplaceAllString(body, "$1...")
|
||||
|
||||
for _, u := range s.Mentions {
|
||||
body = strings.Replace(body, u.URL, fmt.Sprintf("telephant://user/%s", u.ID), -1)
|
||||
body = strings.Replace(body, u.URL, fmt.Sprintf("telephant://mastodon/user/%s", u.ID), -1)
|
||||
}
|
||||
for _, t := range s.Tags {
|
||||
r = regexp.MustCompile("<a href=\"(.[^\"]*)/tags/" + t.Name + "\"")
|
||||
body = r.ReplaceAllString(body, "<a href=\"telephant://mastodon/tag/"+t.Name+"\"")
|
||||
}
|
||||
return body
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ type UIBridge struct {
|
|||
_ func(id string, follow bool) `slot:"followButton"`
|
||||
_ func(id string) `slot:"loadConversation"`
|
||||
_ func(id string) `slot:"loadAccount"`
|
||||
_ func(token string) `slot:"tag"`
|
||||
|
||||
_ func(idx int64) `slot:"closePane"`
|
||||
|
||||
|
@ -104,6 +105,7 @@ func setupQmlBridges() {
|
|||
uiBridge.ConnectFollowButton(follow)
|
||||
uiBridge.ConnectLoadConversation(loadConversation)
|
||||
uiBridge.ConnectLoadAccount(loadAccount)
|
||||
uiBridge.ConnectTag(tag)
|
||||
uiBridge.ConnectClosePane(closePane)
|
||||
|
||||
profileBridge = NewProfileBridge(nil)
|
||||
|
|
|
@ -218,9 +218,15 @@ ColumnLayout {
|
|||
opacity: (accountBridge.username == message.author && (message.like || message.forward)) ? 0.4 : 1.0
|
||||
onLinkActivated: function(link) {
|
||||
if (link.startsWith("telephant://")) {
|
||||
var us = link.split("/")
|
||||
uiBridge.loadAccount(us[us.length-1])
|
||||
accountPopup.open()
|
||||
var us = link.substr(12, link.length).split("/")
|
||||
|
||||
if (us[1] == "user") {
|
||||
uiBridge.loadAccount(us[us.length-1])
|
||||
accountPopup.open()
|
||||
}
|
||||
if (us[1] == "tag") {
|
||||
uiBridge.tag(us[us.length-1])
|
||||
}
|
||||
} else
|
||||
Qt.openUrlExternally(link)
|
||||
}
|
||||
|
|
19
telephant.go
19
telephant.go
|
@ -191,6 +191,25 @@ func loadAccount(id string) {
|
|||
}
|
||||
}
|
||||
|
||||
// tag
|
||||
func tag(token string) {
|
||||
model := NewMessageModel(nil)
|
||||
evchan := make(chan interface{})
|
||||
go handleEvents(evchan, model)
|
||||
|
||||
log.Println("Hashtag:", token)
|
||||
if err := tc.Tag(token, evchan); err != nil {
|
||||
accountBridge.SetError(err.Error())
|
||||
log.Println("Error retrieving hashtag:", err)
|
||||
return
|
||||
}
|
||||
|
||||
var pane = NewPane(nil)
|
||||
pane.Name = "Tag: #" + token
|
||||
pane.Model = model
|
||||
paneModel.AddPane(pane)
|
||||
}
|
||||
|
||||
// closePane closes a pane
|
||||
func closePane(idx int64) {
|
||||
fmt.Println("Closing pane", idx)
|
||||
|
|
Loading…
Add table
Reference in a new issue