diff options
| author | r <r@freesoftwareextremist.com> | 2024-02-05 13:08:23 +0000 | 
|---|---|---|
| committer | r <r@freesoftwareextremist.com> | 2024-02-05 13:08:23 +0000 | 
| commit | 11ea3b4d47a732fe1c6abc39ce452f899f70859f (patch) | |
| tree | 80a8fbba346c4bc6e9fe695620911c9749e8ae46 /mastodon | |
| parent | ce0195a8104f34ff18f831754c428aec904c0f89 (diff) | |
| download | bloat-11ea3b4d47a732fe1c6abc39ce452f899f70859f.tar.gz bloat-11ea3b4d47a732fe1c6abc39ce452f899f70859f.zip | |
Add inline follow/unfollow buttons on follow list page
Diffstat (limited to 'mastodon')
| -rw-r--r-- | mastodon/accounts.go | 44 | 
1 files changed, 40 insertions, 4 deletions
| diff --git a/mastodon/accounts.go b/mastodon/accounts.go index c9e0065..1a0ac2e 100644 --- a/mastodon/accounts.go +++ b/mastodon/accounts.go @@ -14,7 +14,7 @@ import (  )  type AccountPleroma struct { -	Relationship Relationship `json:"relationship"` +	Relationship *Relationship `json:"relationship"`  }  // Account hold information for mastodon account. @@ -73,7 +73,7 @@ func (c *Client) GetAccount(ctx context.Context, id string) (*Account, error) {  			return nil, err  		}  		if len(rs) > 0 { -			account.Pleroma = &AccountPleroma{*rs[0]} +			account.Pleroma = &AccountPleroma{rs[0]}  		}  	}  	return &account, nil @@ -221,10 +221,40 @@ func (c *Client) GetAccountStatuses(ctx context.Context, id string, onlyMedia bo  	return statuses, nil  } +func (c *Client) getMissingRelationships(ctx context.Context, accounts []*Account) ([]*Account, error) { +	var ids []string +	for _, a := range accounts { +		if a.Pleroma == nil || len(a.Pleroma.Relationship.ID) < 1 { +			ids = append(ids, a.ID) +		} +	} +	if len(ids) < 1 { +		return accounts, nil +	} +	rs, err := c.GetAccountRelationships(ctx, ids) +	if err != nil { +		return nil, err +	} +	rsm := make(map[string]*Relationship, len(rs)) +	for _, r := range rs { +		rsm[r.ID] = r +	} +	for _, a := range accounts { +		a.Pleroma = &AccountPleroma{rsm[a.ID]} +	} +	return accounts, nil +} +  // GetAccountFollowers return followers list.  func (c *Client) GetAccountFollowers(ctx context.Context, id string, pg *Pagination) ([]*Account, error) {  	var accounts []*Account -	err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/followers", url.PathEscape(string(id))), nil, &accounts, pg) +	params := url.Values{} +	params.Set("with_relationships", strconv.FormatBool(true)) +	err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/followers", url.PathEscape(string(id))), params, &accounts, pg) +	if err != nil { +		return nil, err +	} +	accounts, err = c.getMissingRelationships(ctx, accounts)  	if err != nil {  		return nil, err  	} @@ -234,7 +264,13 @@ func (c *Client) GetAccountFollowers(ctx context.Context, id string, pg *Paginat  // GetAccountFollowing return following list.  func (c *Client) GetAccountFollowing(ctx context.Context, id string, pg *Pagination) ([]*Account, error) {  	var accounts []*Account -	err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/following", url.PathEscape(string(id))), nil, &accounts, pg) +	params := url.Values{} +	params.Set("with_relationships", strconv.FormatBool(true)) +	err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/following", url.PathEscape(string(id))), params, &accounts, pg) +	if err != nil { +		return nil, err +	} +	accounts, err = c.getMissingRelationships(ctx, accounts)  	if err != nil {  		return nil, err  	} | 
