Skip to content

Commit

Permalink
Added notifications and nested timelines
Browse files Browse the repository at this point in the history
  • Loading branch information
RasmusLindroth committed Apr 7, 2020
1 parent 8f5d121 commit 17f6b02
Show file tree
Hide file tree
Showing 14 changed files with 1,523 additions and 653 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ You can find Linux binaries under [releases](https://github.com/RasmusLindroth/t

### Currently supported commands
* `:q` `:quit` exit
* `:timeline` home, local, federated, direct
* `:timeline` home, local, federated, direct, notifications
* `:tl` h, l, f, d, n (a shorter form of the former)

Explanation of the non obvious keys when viewing a toot
* `V` = view. In this mode you can scroll throught the text of the toot if it doesn't fit the screen
Expand Down Expand Up @@ -45,11 +46,9 @@ you will have to add `go/bin` to your `$PATH`.
### On my TODO-list:
* Support for config files (theme, default image/video viewer)
* Multiple accounts
* View users profiles
* Support search
* Support tags
* Support lists
* Notifications
* Better error handling (in other words, don't crash the whole program)

### Thanks to
Expand Down
192 changes: 180 additions & 12 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"errors"
"fmt"

"github.com/mattn/go-mastodon"
)
Expand Down Expand Up @@ -98,27 +99,194 @@ func (api *API) GetThread(s *mastodon.Status) ([]*mastodon.Status, int, error) {
return thread, len(cont.Ancestors), nil
}

func (api *API) Boost(s *mastodon.Status) error {
_, err := api.Client.Reblog(context.Background(), s.ID)
return err
func (api *API) GetUserStatuses(u mastodon.Account) ([]*mastodon.Status, error) {
return api.Client.GetAccountStatuses(context.Background(), u.ID, nil)
}

func (api *API) Unboost(s *mastodon.Status) error {
_, err := api.Client.Unreblog(context.Background(), s.ID)
return err
func (api *API) GetUserStatusesOlder(u mastodon.Account, s *mastodon.Status) ([]*mastodon.Status, bool, error) {
pg := &mastodon.Pagination{
MaxID: s.ID,
}

statuses, err := api.Client.GetAccountStatuses(context.Background(), u.ID, pg)
if err != nil {
return statuses, false, err
}

if pg.MinID == "" {
return statuses, false, err
}

return statuses, true, err
}

func (api *API) Favorite(s *mastodon.Status) error {
_, err := api.Client.Favourite(context.Background(), s.ID)
return err
func (api *API) GetUserStatusesNewer(u mastodon.Account, s *mastodon.Status) ([]*mastodon.Status, bool, error) {
pg := &mastodon.Pagination{
MinID: s.ID,
}

statuses, err := api.Client.GetAccountStatuses(context.Background(), u.ID, pg)
if err != nil {
return statuses, false, err
}

if pg.MaxID == "" {
return statuses, false, err
}

return statuses, true, err
}

func (api *API) Unfavorite(s *mastodon.Status) error {
_, err := api.Client.Unfavourite(context.Background(), s.ID)
return err
func (api *API) GetNotifications() ([]*mastodon.Notification, error) {
return api.Client.GetNotifications(context.Background(), nil)
}

func (api *API) GetNotificationsOlder(n *mastodon.Notification) ([]*mastodon.Notification, bool, error) {
pg := &mastodon.Pagination{
MaxID: n.ID,
}

statuses, err := api.Client.GetNotifications(context.Background(), pg)
if err != nil {
return statuses, false, err
}

if pg.MinID == "" {
return statuses, false, err
}

return statuses, true, err
}

func (api *API) GetNotificationsNewer(n *mastodon.Notification) ([]*mastodon.Notification, bool, error) {
pg := &mastodon.Pagination{
MinID: n.ID,
}

statuses, err := api.Client.GetNotifications(context.Background(), pg)
if err != nil {
return statuses, false, err
}

if pg.MaxID == "" {
return statuses, false, err
}

return statuses, true, err
}

func (api *API) BoostToggle(s *mastodon.Status) (*mastodon.Status, error) {
if s == nil {
return nil, fmt.Errorf("No status")
}

if s.Reblogged == true {
return api.Unboost(s)
}
return api.Boost(s)
}

func (api *API) Boost(s *mastodon.Status) (*mastodon.Status, error) {
status, err := api.Client.Reblog(context.Background(), s.ID)
return status, err
}

func (api *API) Unboost(s *mastodon.Status) (*mastodon.Status, error) {
status, err := api.Client.Unreblog(context.Background(), s.ID)
return status, err
}

func (api *API) FavoriteToogle(s *mastodon.Status) (*mastodon.Status, error) {
if s == nil {
return nil, fmt.Errorf("No status")
}

if s.Favourited == true {
return api.Unfavorite(s)
}
return api.Favorite(s)
}

func (api *API) Favorite(s *mastodon.Status) (*mastodon.Status, error) {
status, err := api.Client.Favourite(context.Background(), s.ID)
return status, err
}

func (api *API) Unfavorite(s *mastodon.Status) (*mastodon.Status, error) {
status, err := api.Client.Unfavourite(context.Background(), s.ID)
return status, err
}

func (api *API) DeleteStatus(s *mastodon.Status) error {
//TODO: check user here?
return api.Client.DeleteStatus(context.Background(), s.ID)
}

func (api *API) UserRelation(u mastodon.Account) (*mastodon.Relationship, error) {
relations, err := api.Client.GetAccountRelationships(context.Background(), []string{string(u.ID)})

if err != nil {
return nil, err
}
if len(relations) == 0 {
return nil, fmt.Errorf("no accounts found")
}
return relations[0], nil
}

func (api *API) FollowToggle(u mastodon.Account) (*mastodon.Relationship, error) {
relation, err := api.UserRelation(u)
if err != nil {
return nil, err
}
if relation.Following {
return api.UnfollowUser(u)
}
return api.FollowUser(u)
}

func (api *API) FollowUser(u mastodon.Account) (*mastodon.Relationship, error) {
return api.Client.AccountFollow(context.Background(), u.ID)
}

func (api *API) UnfollowUser(u mastodon.Account) (*mastodon.Relationship, error) {
return api.Client.AccountUnfollow(context.Background(), u.ID)
}

func (api *API) BlockToggle(u mastodon.Account) (*mastodon.Relationship, error) {
relation, err := api.UserRelation(u)
if err != nil {
return nil, err
}
if relation.Blocking {
return api.UnblockUser(u)
}
return api.BlockUser(u)
}

func (api *API) BlockUser(u mastodon.Account) (*mastodon.Relationship, error) {
return api.Client.AccountBlock(context.Background(), u.ID)
}

func (api *API) UnblockUser(u mastodon.Account) (*mastodon.Relationship, error) {
return api.Client.AccountUnblock(context.Background(), u.ID)
}

func (api *API) MuteToggle(u mastodon.Account) (*mastodon.Relationship, error) {
relation, err := api.UserRelation(u)
if err != nil {
return nil, err
}
if relation.Blocking {
return api.UnmuteUser(u)
}
return api.MuteUser(u)
}

func (api *API) MuteUser(u mastodon.Account) (*mastodon.Relationship, error) {
return api.Client.AccountMute(context.Background(), u.ID)
}

func (api *API) UnmuteUser(u mastodon.Account) (*mastodon.Relationship, error) {
return api.Client.AccountUnmute(context.Background(), u.ID)
}
10 changes: 8 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ import (
)

type Config struct {
Style StyleConfig
Media MediaConfig
General GeneralConfig
Style StyleConfig
Media MediaConfig
}

type GeneralConfig struct {
DateTodayFormat string
DateFormat string
}

type StyleConfig struct {
Expand Down
Loading

0 comments on commit 17f6b02

Please sign in to comment.