Skip to content

Commit a730588

Browse files
1.0.32 (#240)
* bump version * add ws and bug fix for conversations * fix so autocomplete works with new version of tview * fix poll and url length
1 parent a765172 commit a730588

24 files changed

+222
-81
lines changed

api/feed.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ func (ac *AccountClient) GetConversations(pg *mastodon.Pagination) ([]Item, erro
154154
return items, err
155155
}
156156
for _, c := range conversations {
157+
if c.LastStatus == nil {
158+
continue
159+
}
157160
item := NewStatusItem(c.LastStatus, false)
158161
items = append(items, item)
159162
}
@@ -165,10 +168,10 @@ func (ac *AccountClient) GetUsers(search string) ([]Item, error) {
165168
var users []*mastodon.Account
166169
var err error
167170
if strings.HasPrefix(search, "@") && len(strings.Split(search, "@")) == 3 {
168-
users, err = ac.Client.AccountsSearch(context.Background(), search, 10, true)
171+
users, err = ac.Client.AccountsSearchResolve(context.Background(), search, 10, true)
169172
}
170173
if len(users) == 0 || err != nil {
171-
users, err = ac.Client.AccountsSearch(context.Background(), search, 10, false)
174+
users, err = ac.Client.AccountsSearchResolve(context.Background(), search, 10, false)
172175
}
173176
if err != nil {
174177
return items, err

api/instance.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package api
2+
3+
func (ac *AccountClient) GetCharLimit() int {
4+
if ac.Instance != nil {
5+
return ac.Instance.Configuration.Statuses.MaxCharacters
6+
}
7+
if ac.InstanceOld == nil || ac.InstanceOld.Configuration == nil || ac.InstanceOld.Configuration.Statuses == nil {
8+
return 500
9+
}
10+
s := ac.InstanceOld.Configuration.Statuses
11+
if val, ok := (*s)["max_characters"]; ok {
12+
return val
13+
}
14+
return 500
15+
}
16+
17+
func (ac *AccountClient) GetLengthURL() int {
18+
if ac.Instance != nil {
19+
return ac.Instance.Configuration.Statuses.CharactersReservedPerURL
20+
}
21+
if ac.InstanceOld == nil || ac.InstanceOld.Configuration == nil || ac.InstanceOld.Configuration.Statuses == nil {
22+
return 23
23+
}
24+
s := ac.InstanceOld.Configuration.Statuses
25+
if val, ok := (*s)["characters_reserved_per_url"]; ok {
26+
return val
27+
}
28+
return 23
29+
}
30+
31+
func (ac *AccountClient) GetPollOptions() (options, chars int) {
32+
if ac.Instance != nil {
33+
return ac.Instance.Configuration.Polls.MaxOptions, ac.Instance.Configuration.Polls.MaxCharactersPerOption
34+
}
35+
if ac.InstanceOld == nil || ac.InstanceOld.Configuration == nil || ac.InstanceOld.Configuration.Polls == nil {
36+
return 4, 50
37+
}
38+
s := ac.InstanceOld.Configuration.Polls
39+
opts, okOne := (*s)["max_options"]
40+
c, okTwo := (*s)["max_characters_per_option"]
41+
if okOne && okTwo {
42+
return opts, c
43+
}
44+
return 4, 50
45+
}

api/status.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ func toggleHelper(s *mastodon.Status, comp bool, on, off statusToggleFunc) (*mas
3939
}
4040

4141
func (ac *AccountClient) BoostToggle(s *mastodon.Status) (*mastodon.Status, error) {
42+
ns := util.StatusOrReblog(s)
43+
reblogged := false
44+
if ns.Reblogged != nil {
45+
reblogged = ns.Reblogged.(bool)
46+
}
4247
return toggleHelper(s,
43-
util.StatusOrReblog(s).Reblogged,
48+
reblogged,
4449
ac.Boost, ac.Unboost,
4550
)
4651
}
@@ -54,8 +59,13 @@ func (ac *AccountClient) Unboost(s *mastodon.Status) (*mastodon.Status, error) {
5459
}
5560

5661
func (ac *AccountClient) FavoriteToogle(s *mastodon.Status) (*mastodon.Status, error) {
62+
ns := util.StatusOrReblog(s)
63+
favorited := false
64+
if ns.Favourited != nil {
65+
favorited = ns.Favourited.(bool)
66+
}
5767
return toggleHelper(s,
58-
util.StatusOrReblog(s).Favourited,
68+
favorited,
5969
ac.Favorite, ac.Unfavorite,
6070
)
6171
}
@@ -71,8 +81,13 @@ func (ac *AccountClient) Unfavorite(s *mastodon.Status) (*mastodon.Status, error
7181
}
7282

7383
func (ac *AccountClient) BookmarkToogle(s *mastodon.Status) (*mastodon.Status, error) {
84+
ns := util.StatusOrReblog(s)
85+
bookmarked := false
86+
if ns.Bookmarked != nil {
87+
bookmarked = ns.Bookmarked.(bool)
88+
}
7489
return toggleHelper(s,
75-
util.StatusOrReblog(s).Bookmarked,
90+
bookmarked,
7691
ac.Bookmark, ac.Unbookmark,
7792
)
7893
}

api/stream.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (s *Stream) RemoveReceiver(r *Receiver) {
8181
func (s *Stream) listen() {
8282
for e := range s.incoming {
8383
switch e.(type) {
84-
case *mastodon.UpdateEvent, *mastodon.NotificationEvent, *mastodon.DeleteEvent, *mastodon.ErrorEvent:
84+
case *mastodon.UpdateEvent, *mastodon.ConversationEvent, *mastodon.NotificationEvent, *mastodon.DeleteEvent, *mastodon.ErrorEvent:
8585
for _, r := range s.receivers {
8686
go func(rec *Receiver, e mastodon.Event) {
8787
rec.mux.Lock()
@@ -133,17 +133,17 @@ func (ac *AccountClient) NewGenericStream(st StreamType, data string) (rec *Rece
133133
var ch chan mastodon.Event
134134
switch st {
135135
case HomeStream:
136-
ch, err = ac.Client.StreamingUser(context.Background())
136+
ch, err = ac.WSClient.StreamingWSUser(context.Background())
137137
case LocalStream:
138-
ch, err = ac.Client.StreamingPublic(context.Background(), true)
138+
ch, err = ac.WSClient.StreamingWSPublic(context.Background(), true)
139139
case FederatedStream:
140-
ch, err = ac.Client.StreamingPublic(context.Background(), false)
140+
ch, err = ac.WSClient.StreamingWSPublic(context.Background(), false)
141141
case DirectStream:
142-
ch, err = ac.Client.StreamingDirect(context.Background())
142+
ch, err = ac.WSClient.StreamingWSDirect(context.Background())
143143
case TagStream:
144-
ch, err = ac.Client.StreamingHashtag(context.Background(), data, false)
144+
ch, err = ac.WSClient.StreamingWSHashtag(context.Background(), data, false)
145145
case ListStream:
146-
ch, err = ac.Client.StreamingList(context.Background(), mastodon.ID(data))
146+
ch, err = ac.WSClient.StreamingWSList(context.Background(), mastodon.ID(data))
147147
default:
148148
panic("invalid StreamType")
149149
}

api/types.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ type RequestData struct {
88
}
99

1010
type AccountClient struct {
11-
Client *mastodon.Client
12-
Streams map[string]*Stream
13-
Me *mastodon.Account
14-
Filters []*mastodon.Filter
11+
Client *mastodon.Client
12+
Streams map[string]*Stream
13+
Me *mastodon.Account
14+
WSClient *mastodon.WSClient
15+
InstanceOld *mastodon.Instance
16+
Instance *mastodon.InstanceV2
1517
}
1618

1719
type User struct {

config.example.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ notifications-to-hide=
110110
# default=false
111111
quote-reply=false
112112

113-
# If you're on an instance with a custom character limit you can set it here.
114-
# default=500
115-
char-limit=500
116-
117113
# If you want to show icons in the list of toots.
118114
# default=true
119115
show-icons=true

config/config.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ type General struct {
158158
MaxWidth int
159159
NotificationFeed bool
160160
QuoteReply bool
161-
CharLimit int
162161
ShortHints bool
163162
ShowFilterPhrase bool
164163
ListPlacement ListPlacement
@@ -848,7 +847,6 @@ func parseGeneral(cfg *ini.File) General {
848847

849848
general.NotificationFeed = cfg.Section("general").Key("notification-feed").MustBool(true)
850849
general.QuoteReply = cfg.Section("general").Key("quote-reply").MustBool(false)
851-
general.CharLimit = cfg.Section("general").Key("char-limit").MustInt(500)
852850
general.MaxWidth = cfg.Section("general").Key("max-width").MustInt(0)
853851
general.ShortHints = cfg.Section("general").Key("short-hints").MustBool(false)
854852
general.ShowFilterPhrase = cfg.Section("general").Key("show-filter-phrase").MustBool(true)

config/default_config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ notifications-to-hide=
112112
# default=false
113113
quote-reply=false
114114
115-
# If you're on an instance with a custom character limit you can set it here.
116-
# default=500
117-
char-limit=500
118-
119115
# If you want to show icons in the list of toots.
120116
# default=true
121117
show-icons=true

docs/man/tut.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
. ftr VB CB
1515
. ftr VBI CBI
1616
.\}
17-
.TH "tut" "1" "2022-12-29" "tut 1.0.31" ""
17+
.TH "tut" "1" "2022-12-31" "tut 1.0.32" ""
1818
.hy
1919
.SH NAME
2020
.PP

docs/man/tut.1.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
% tut(1) tut 1.0.31
1+
% tut(1) tut 1.0.32
22
% Rasmus Lindroth
3-
% 2022-12-29
3+
% 2022-12-31
44

55
# NAME
66
tut - a Mastodon TUI

0 commit comments

Comments
 (0)