Skip to content

Commit 44814f1

Browse files
1.0.23 (#201)
* Removing directstream shouldn't crash tut * update version * Ignore tut binary (#194) When I do 'go build .' it yields a 'tut' file in the current directory that's not currently ignored. * Print error when failing to connect (#193) When setting up, network errors wouldn't print any useful information: Instance: bsd.network Couldn't connect to instance: https://bsd.network Try again or press ^C. Now: Instance: bsd.network Couldn't connect to instance https://bsd.network: Get "https://bsd.network/api/v1/instance": x509: certificate signed by unknown authority Try again or press ^C. (Turns out I didn't have root certificates installed.) * set config with flag and env * list tags that you follow * fix help * update readme * remove unused field * user search and multiple tags Co-authored-by: Sijmen J. Mulder <[email protected]>
1 parent 404e21e commit 44814f1

26 files changed

+612
-229
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
Makefile
33
bin/
44
TODO.md
5+
tut

README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ You can find Linux binaries under [releases](https://github.com/RasmusLindroth/t
6363
* `:requests` see following requests
6464
* `:saved` alias for bookmarks
6565
* `:tag` followed by the hashtag e.g. `:tag linux`
66+
* `:tags` list of followed tags
6667
* `:unfollow-tag` followed by the hashtag to unfollow e.g. `:unfollow-tag tut`
6768
* `:user` followed by a username e.g. `:user rasmus` to narrow a search include
6869
* `:window` switch window by index (zero indexed) e.g. `:window 0` for the first window.
@@ -169,14 +170,18 @@ Commands:
169170
example-config - creates the default configuration file in the current directory and names it ./config.example.ini
170171
171172
Flags:
172-
--help -h - prints this message
173-
--version -v - prints the version
174-
--new-user -n - add one more user to tut
175-
--user <name> -u <name> - login directly to user named <name>
176-
Don't use a = between --user and the <name>
177-
If two users are named the same. Use full name like [email protected]
173+
-h --help prints this message
174+
-v --version prints the version
175+
-n --new-user add one more user to tut
176+
-c --config <path> load config.ini from <path>
177+
-d --config-dir <path> load all config from <path>
178+
-u --user <name> login directly to user named <name>
179+
If two users are named the same. Use full name like [email protected]
178180
```
179181

182+
If you don't want to set `--config` or `--config-dir` everytime you can set
183+
the environment variables `TUT_CONF` and `TUT_CONF_DIR` instead.
184+
180185
## Templates
181186
You can customise how toots and user profiles are displayed with a
182187
Go [text/template](https://pkg.go.dev/text/template).

api/feed.go

+40-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"context"
5+
"strings"
56

67
"github.com/RasmusLindroth/go-mastodon"
78
)
@@ -156,7 +157,14 @@ func (ac *AccountClient) GetConversations(pg *mastodon.Pagination) ([]Item, erro
156157

157158
func (ac *AccountClient) GetUsers(search string) ([]Item, error) {
158159
var items []Item
159-
users, err := ac.Client.AccountsSearch(context.Background(), search, 10)
160+
var users []*mastodon.Account
161+
var err error
162+
if strings.HasPrefix(search, "@") && len(strings.Split(search, "@")) == 3 {
163+
users, err = ac.Client.AccountsSearch(context.Background(), search, 10, true)
164+
}
165+
if len(users) == 0 || err != nil {
166+
users, err = ac.Client.AccountsSearch(context.Background(), search, 10, false)
167+
}
160168
if err != nil {
161169
return items, err
162170
}
@@ -257,6 +265,18 @@ func (ac *AccountClient) GetUserPinned(id mastodon.ID) ([]Item, error) {
257265
return items, nil
258266
}
259267

268+
func (ac *AccountClient) GetTags(pg *mastodon.Pagination) ([]Item, error) {
269+
var items []Item
270+
tags, err := ac.Client.TagsFollowed(context.Background(), pg)
271+
if err != nil {
272+
return items, err
273+
}
274+
for _, t := range tags {
275+
items = append(items, NewTagItem(t))
276+
}
277+
return items, nil
278+
}
279+
260280
func (ac *AccountClient) GetLists() ([]Item, error) {
261281
var items []Item
262282
lists, err := ac.Client.GetLists(context.Background())
@@ -302,3 +322,22 @@ func (ac *AccountClient) GetTag(pg *mastodon.Pagination, search string) ([]Item,
302322
}
303323
return ac.getStatusSimilar(fn, "public")
304324
}
325+
326+
func (ac *AccountClient) GetTagMultiple(pg *mastodon.Pagination, search string) ([]Item, error) {
327+
fn := func() ([]*mastodon.Status, error) {
328+
var s string
329+
td := mastodon.TagData{}
330+
parts := strings.Split(search, " ")
331+
for i, p := range parts {
332+
if i == 0 {
333+
s = p
334+
continue
335+
}
336+
if len(p) > 0 {
337+
td.Any = append(td.Any, p)
338+
}
339+
}
340+
return ac.Client.GetTimelineHashtagMultiple(context.Background(), s, false, &td, pg)
341+
}
342+
return ac.getStatusSimilar(fn, "public")
343+
}

api/item.go

+41
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,44 @@ func (s *ListItem) Filtered() (bool, string) {
392392
func (n *ListItem) Pinned() bool {
393393
return false
394394
}
395+
396+
func NewTagItem(item *mastodon.Tag) Item {
397+
return &TagItem{id: newID(), item: item, showSpoiler: true}
398+
}
399+
400+
type TagItem struct {
401+
id uint
402+
item *mastodon.Tag
403+
showSpoiler bool
404+
}
405+
406+
func (t *TagItem) ID() uint {
407+
return t.id
408+
}
409+
410+
func (t *TagItem) Type() MastodonType {
411+
return TagType
412+
}
413+
414+
func (t *TagItem) ToggleSpoiler() {
415+
}
416+
417+
func (t *TagItem) ShowSpoiler() bool {
418+
return true
419+
}
420+
421+
func (t *TagItem) Raw() interface{} {
422+
return t.item
423+
}
424+
425+
func (t *TagItem) URLs() ([]util.URL, []mastodon.Mention, []mastodon.Tag, int) {
426+
return nil, nil, nil, 0
427+
}
428+
429+
func (t *TagItem) Filtered() (bool, string) {
430+
return false, ""
431+
}
432+
433+
func (t *TagItem) Pinned() bool {
434+
return false
435+
}

api/stream.go

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
ProfileType
1717
NotificationType
1818
ListsType
19+
TagType
1920
)
2021

2122
type StreamType uint
@@ -193,6 +194,8 @@ func (ac *AccountClient) RemoveGenericReceiver(rec *Receiver, st StreamType, dat
193194
id = "LocalStream"
194195
case FederatedStream:
195196
id = "FederatedStream"
197+
case DirectStream:
198+
id = "DirectStream"
196199
case TagStream:
197200
id = "TagStream" + data
198201
case ListStream:

api/tags.go

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package api
33
import (
44
"context"
55
"errors"
6+
7+
"github.com/RasmusLindroth/go-mastodon"
68
)
79

810
func (ac *AccountClient) FollowTag(tag string) error {
@@ -33,3 +35,17 @@ func (ac *AccountClient) UnfollowTag(tag string) error {
3335
}
3436
return nil
3537
}
38+
39+
func (ac *AccountClient) TagToggleFollow(tag *mastodon.Tag) (*mastodon.Tag, error) {
40+
var t *mastodon.Tag
41+
var err error
42+
switch tag.Following {
43+
case true:
44+
t, err = ac.Client.TagUnfollow(context.Background(), tag.Name)
45+
case false:
46+
t, err = ac.Client.TagFollow(context.Background(), tag.Name)
47+
default:
48+
t, err = ac.Client.TagFollow(context.Background(), tag.Name)
49+
}
50+
return t, err
51+
}

auth/add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func AddAccount(ad *AccountData) *mastodon.Client {
3535
})
3636
_, err = client.GetInstance(context.Background())
3737
if err != nil {
38-
fmt.Printf("\nCouldn't connect to instance: %s\nTry again or press ^C.\n", server)
38+
fmt.Printf("\nCouldn't connect to instance %s:\n%s\nTry again or press ^C.\n", server, err)
3939
fmt.Println("--------------------------------------------------------------")
4040
} else {
4141
break

config.example.ini

+10-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ leader-timeout=1000
152152
# Available commands: home, direct, local, federated, clear-notifications,
153153
# compose, edit, history, blocking, bookmarks, saved, favorited, boosts,
154154
# favorites, following, followers, muting, newer, preferences, profile,
155-
# notifications, lists, tag, window, list-placement, list-split, proportions
155+
# notifications, lists, tag, tags, window, list-placement, list-split,
156+
# proportions
156157
#
157158
# The shortcuts are up to you, but keep them quite short and make sure they
158159
# don't collide. If you have one shortcut that is "f" and an other one that is
@@ -666,6 +667,14 @@ link-open="[O]pen",'o','O'
666667
# default="[Y]ank",'y','Y'
667668
link-yank="[Y]ank",'y','Y'
668669

670+
# Open tag feed
671+
# default="[O]pen",'o','O'
672+
tag-open-feed="[O]pen",'o','O'
673+
674+
# Toggle follow on tag
675+
# default="[F]ollow","Un[F]ollow",'f','F'
676+
tag-follow="[F]ollow","Un[F]ollow",'f','F'
677+
669678
# Edit spoiler text on new toot
670679
# default="[C]W text",'c','C'
671680
compose-edit-spoiler="[C]W text",'c','C'

0 commit comments

Comments
 (0)