Skip to content

Commit

Permalink
1.0.32 (#240)
Browse files Browse the repository at this point in the history
* bump version

* add ws and bug fix for conversations

* fix so autocomplete works with new version of tview

* fix poll and url length
  • Loading branch information
RasmusLindroth authored Dec 31, 2022
1 parent a765172 commit a730588
Show file tree
Hide file tree
Showing 24 changed files with 222 additions and 81 deletions.
7 changes: 5 additions & 2 deletions api/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ func (ac *AccountClient) GetConversations(pg *mastodon.Pagination) ([]Item, erro
return items, err
}
for _, c := range conversations {
if c.LastStatus == nil {
continue
}
item := NewStatusItem(c.LastStatus, false)
items = append(items, item)
}
Expand All @@ -165,10 +168,10 @@ func (ac *AccountClient) GetUsers(search string) ([]Item, error) {
var users []*mastodon.Account
var err error
if strings.HasPrefix(search, "@") && len(strings.Split(search, "@")) == 3 {
users, err = ac.Client.AccountsSearch(context.Background(), search, 10, true)
users, err = ac.Client.AccountsSearchResolve(context.Background(), search, 10, true)
}
if len(users) == 0 || err != nil {
users, err = ac.Client.AccountsSearch(context.Background(), search, 10, false)
users, err = ac.Client.AccountsSearchResolve(context.Background(), search, 10, false)
}
if err != nil {
return items, err
Expand Down
45 changes: 45 additions & 0 deletions api/instance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package api

func (ac *AccountClient) GetCharLimit() int {
if ac.Instance != nil {
return ac.Instance.Configuration.Statuses.MaxCharacters
}
if ac.InstanceOld == nil || ac.InstanceOld.Configuration == nil || ac.InstanceOld.Configuration.Statuses == nil {
return 500
}
s := ac.InstanceOld.Configuration.Statuses
if val, ok := (*s)["max_characters"]; ok {
return val
}
return 500
}

func (ac *AccountClient) GetLengthURL() int {
if ac.Instance != nil {
return ac.Instance.Configuration.Statuses.CharactersReservedPerURL
}
if ac.InstanceOld == nil || ac.InstanceOld.Configuration == nil || ac.InstanceOld.Configuration.Statuses == nil {
return 23
}
s := ac.InstanceOld.Configuration.Statuses
if val, ok := (*s)["characters_reserved_per_url"]; ok {
return val
}
return 23
}

func (ac *AccountClient) GetPollOptions() (options, chars int) {
if ac.Instance != nil {
return ac.Instance.Configuration.Polls.MaxOptions, ac.Instance.Configuration.Polls.MaxCharactersPerOption
}
if ac.InstanceOld == nil || ac.InstanceOld.Configuration == nil || ac.InstanceOld.Configuration.Polls == nil {
return 4, 50
}
s := ac.InstanceOld.Configuration.Polls
opts, okOne := (*s)["max_options"]
c, okTwo := (*s)["max_characters_per_option"]
if okOne && okTwo {
return opts, c
}
return 4, 50
}
21 changes: 18 additions & 3 deletions api/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ func toggleHelper(s *mastodon.Status, comp bool, on, off statusToggleFunc) (*mas
}

func (ac *AccountClient) BoostToggle(s *mastodon.Status) (*mastodon.Status, error) {
ns := util.StatusOrReblog(s)
reblogged := false
if ns.Reblogged != nil {
reblogged = ns.Reblogged.(bool)
}
return toggleHelper(s,
util.StatusOrReblog(s).Reblogged,
reblogged,
ac.Boost, ac.Unboost,
)
}
Expand All @@ -54,8 +59,13 @@ func (ac *AccountClient) Unboost(s *mastodon.Status) (*mastodon.Status, error) {
}

func (ac *AccountClient) FavoriteToogle(s *mastodon.Status) (*mastodon.Status, error) {
ns := util.StatusOrReblog(s)
favorited := false
if ns.Favourited != nil {
favorited = ns.Favourited.(bool)
}
return toggleHelper(s,
util.StatusOrReblog(s).Favourited,
favorited,
ac.Favorite, ac.Unfavorite,
)
}
Expand All @@ -71,8 +81,13 @@ func (ac *AccountClient) Unfavorite(s *mastodon.Status) (*mastodon.Status, error
}

func (ac *AccountClient) BookmarkToogle(s *mastodon.Status) (*mastodon.Status, error) {
ns := util.StatusOrReblog(s)
bookmarked := false
if ns.Bookmarked != nil {
bookmarked = ns.Bookmarked.(bool)
}
return toggleHelper(s,
util.StatusOrReblog(s).Bookmarked,
bookmarked,
ac.Bookmark, ac.Unbookmark,
)
}
Expand Down
14 changes: 7 additions & 7 deletions api/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *Stream) RemoveReceiver(r *Receiver) {
func (s *Stream) listen() {
for e := range s.incoming {
switch e.(type) {
case *mastodon.UpdateEvent, *mastodon.NotificationEvent, *mastodon.DeleteEvent, *mastodon.ErrorEvent:
case *mastodon.UpdateEvent, *mastodon.ConversationEvent, *mastodon.NotificationEvent, *mastodon.DeleteEvent, *mastodon.ErrorEvent:
for _, r := range s.receivers {
go func(rec *Receiver, e mastodon.Event) {
rec.mux.Lock()
Expand Down Expand Up @@ -133,17 +133,17 @@ func (ac *AccountClient) NewGenericStream(st StreamType, data string) (rec *Rece
var ch chan mastodon.Event
switch st {
case HomeStream:
ch, err = ac.Client.StreamingUser(context.Background())
ch, err = ac.WSClient.StreamingWSUser(context.Background())
case LocalStream:
ch, err = ac.Client.StreamingPublic(context.Background(), true)
ch, err = ac.WSClient.StreamingWSPublic(context.Background(), true)
case FederatedStream:
ch, err = ac.Client.StreamingPublic(context.Background(), false)
ch, err = ac.WSClient.StreamingWSPublic(context.Background(), false)
case DirectStream:
ch, err = ac.Client.StreamingDirect(context.Background())
ch, err = ac.WSClient.StreamingWSDirect(context.Background())
case TagStream:
ch, err = ac.Client.StreamingHashtag(context.Background(), data, false)
ch, err = ac.WSClient.StreamingWSHashtag(context.Background(), data, false)
case ListStream:
ch, err = ac.Client.StreamingList(context.Background(), mastodon.ID(data))
ch, err = ac.WSClient.StreamingWSList(context.Background(), mastodon.ID(data))
default:
panic("invalid StreamType")
}
Expand Down
10 changes: 6 additions & 4 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ type RequestData struct {
}

type AccountClient struct {
Client *mastodon.Client
Streams map[string]*Stream
Me *mastodon.Account
Filters []*mastodon.Filter
Client *mastodon.Client
Streams map[string]*Stream
Me *mastodon.Account
WSClient *mastodon.WSClient
InstanceOld *mastodon.Instance
Instance *mastodon.InstanceV2
}

type User struct {
Expand Down
4 changes: 0 additions & 4 deletions config.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ notifications-to-hide=
# default=false
quote-reply=false

# If you're on an instance with a custom character limit you can set it here.
# default=500
char-limit=500

# If you want to show icons in the list of toots.
# default=true
show-icons=true
Expand Down
2 changes: 0 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ type General struct {
MaxWidth int
NotificationFeed bool
QuoteReply bool
CharLimit int
ShortHints bool
ShowFilterPhrase bool
ListPlacement ListPlacement
Expand Down Expand Up @@ -848,7 +847,6 @@ func parseGeneral(cfg *ini.File) General {

general.NotificationFeed = cfg.Section("general").Key("notification-feed").MustBool(true)
general.QuoteReply = cfg.Section("general").Key("quote-reply").MustBool(false)
general.CharLimit = cfg.Section("general").Key("char-limit").MustInt(500)
general.MaxWidth = cfg.Section("general").Key("max-width").MustInt(0)
general.ShortHints = cfg.Section("general").Key("short-hints").MustBool(false)
general.ShowFilterPhrase = cfg.Section("general").Key("show-filter-phrase").MustBool(true)
Expand Down
4 changes: 0 additions & 4 deletions config/default_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ notifications-to-hide=
# default=false
quote-reply=false
# If you're on an instance with a custom character limit you can set it here.
# default=500
char-limit=500
# If you want to show icons in the list of toots.
# default=true
show-icons=true
Expand Down
2 changes: 1 addition & 1 deletion docs/man/tut.1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
. ftr VB CB
. ftr VBI CBI
.\}
.TH "tut" "1" "2022-12-29" "tut 1.0.31" ""
.TH "tut" "1" "2022-12-31" "tut 1.0.32" ""
.hy
.SH NAME
.PP
Expand Down
4 changes: 2 additions & 2 deletions docs/man/tut.1.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% tut(1) tut 1.0.31
% tut(1) tut 1.0.32
% Rasmus Lindroth
% 2022-12-29
% 2022-12-31

# NAME
tut - a Mastodon TUI
Expand Down
10 changes: 1 addition & 9 deletions docs/man/tut.5
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
. ftr VB CB
. ftr VBI CBI
.\}
.TH "tut" "5" "2022-12-29" "tut 1.0.31" ""
.TH "tut" "5" "2022-12-31" "tut 1.0.32" ""
.hy
.SH NAME
.PP
Expand Down Expand Up @@ -231,14 +231,6 @@ If you always want to quote original message when replying.
.P
.PD
\f[B]quote-reply\f[R]=\f[I]false\f[R]
.SS char-limit
.PP
If you\[aq]re on an instance with a custom character limit you can set
it here.
.PD 0
.P
.PD
\f[B]char-limit\f[R]=\f[I]500\f[R]
.SS show-icons
.PP
If you want to show icons in the list of toots.
Expand Down
8 changes: 2 additions & 6 deletions docs/man/tut.5.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% tut(5) tut 1.0.31
% tut(5) tut 1.0.32
% Rasmus Lindroth
% 2022-12-29
% 2022-12-31

# NAME
tut - configuration for tut(1)
Expand Down Expand Up @@ -116,10 +116,6 @@ Hide notifications of this type. If you have multiple you separate them with a c
If you always want to quote original message when replying.
**quote-reply**=*false*

## char-limit
If you\'re on an instance with a custom character limit you can set it here.
**char-limit**=*500*

## show-icons
If you want to show icons in the list of toots.
**show-icons**=*true*
Expand Down
2 changes: 1 addition & 1 deletion docs/man/tut.7
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
. ftr VB CB
. ftr VBI CBI
.\}
.TH "tut" "7" "2022-12-29" "tut 1.0.31" ""
.TH "tut" "7" "2022-12-31" "tut 1.0.32" ""
.hy
.SH NAME
.PP
Expand Down
4 changes: 2 additions & 2 deletions docs/man/tut.7.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% tut(7) tut 1.0.31
% tut(7) tut 1.0.32
% Rasmus Lindroth
% 2022-12-29
% 2022-12-31

# NAME
tut - keys and commands inside of tut(1)
Expand Down
26 changes: 26 additions & 0 deletions feed/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,32 @@ func (f *Feed) startStream(rec *api.Receiver, timeline string, err error) {
go func() {
for e := range rec.Ch {
switch t := e.(type) {
case *mastodon.ConversationEvent:
if t.Conversation.LastStatus == nil {
continue
}
s := api.NewStatusItem(t.Conversation.LastStatus, false)
f.itemsMux.Lock()
found := false
if len(f.streams) > 0 {
for _, item := range f.items {
switch v := item.Raw().(type) {
case *mastodon.Status:
if t.Conversation.LastStatus.ID == v.ID {
found = true
break
}
}
}
}
if !found {
f.items = append([]api.Item{s}, f.items...)
f.Updated(DesktopNotificationHolder{
Type: DesktopNotificationMention,
})
f.apiData.MinID = t.Conversation.LastStatus.ID
}
f.itemsMux.Unlock()
case *mastodon.UpdateEvent:
s := api.NewStatusItem(t.Status, false)
f.itemsMux.Lock()
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/RasmusLindroth/tut
go 1.18

require (
github.com/RasmusLindroth/go-mastodon v0.0.17
github.com/RasmusLindroth/go-mastodon v0.0.20
github.com/adrg/xdg v0.4.0
github.com/atotto/clipboard v0.1.4
github.com/gdamore/tcell/v2 v2.5.3
Expand All @@ -12,12 +12,13 @@ require (
github.com/icza/gox v0.0.0-20221026131554-a08a8cdc726a
github.com/microcosm-cc/bluemonday v1.0.21
github.com/pelletier/go-toml/v2 v2.0.6
github.com/rivo/tview v0.0.0-20221221172820-02e38ea9604c
github.com/rivo/tview v0.0.0-20221229180733-b86a50a5126c
github.com/rivo/uniseg v0.4.3
github.com/spf13/pflag v1.0.5
golang.org/x/exp v0.0.0-20221227203929-1b447090c38c
golang.org/x/exp v0.0.0-20221230185412-738e83a70c30
golang.org/x/net v0.4.0
gopkg.in/ini.v1 v1.67.0
mvdan.cc/xurls/v2 v2.4.0
)

require (
Expand Down
Loading

0 comments on commit a730588

Please sign in to comment.