account.go
changeset 205 b27e7d229fdd
parent 204 5cf1e0b45073
child 206 9197fdf25388
equal deleted inserted replaced
204:5cf1e0b45073 205:b27e7d229fdd
    34 
    34 
    35 // updateRelationship returns a Relationship entity
    35 // updateRelationship returns a Relationship entity
    36 // The operation 'op' can be "follow", "unfollow", "block", "unblock",
    36 // The operation 'op' can be "follow", "unfollow", "block", "unblock",
    37 // "mute", "unmute".
    37 // "mute", "unmute".
    38 // The id is optional and depends on the operation.
    38 // The id is optional and depends on the operation.
    39 func (mc *Client) updateRelationship(op string, id int64) (*Relationship, error) {
    39 func (mc *Client) updateRelationship(op string, id int64, params apiCallParams) (*Relationship, error) {
    40 	var endPoint string
    40 	var endPoint string
    41 	method := rest.Post
    41 	method := rest.Post
    42 	strID := strconv.FormatInt(id, 10)
    42 	strID := strconv.FormatInt(id, 10)
    43 
    43 
    44 	switch op {
    44 	switch op {
    47 	default:
    47 	default:
    48 		return nil, ErrInvalidParameter
    48 		return nil, ErrInvalidParameter
    49 	}
    49 	}
    50 
    50 
    51 	var rel Relationship
    51 	var rel Relationship
    52 	if err := mc.apiCall(endPoint, method, nil, nil, nil, &rel); err != nil {
    52 	if err := mc.apiCall(endPoint, method, params, nil, nil, &rel); err != nil {
    53 		return nil, err
    53 		return nil, err
    54 	}
    54 	}
    55 	return &rel, nil
    55 	return &rel, nil
    56 }
    56 }
    57 
    57 
   192 	return mc.getMultipleAccountsHelper("following", o)
   192 	return mc.getMultipleAccountsHelper("following", o)
   193 }
   193 }
   194 
   194 
   195 // FollowAccount follows an account
   195 // FollowAccount follows an account
   196 func (mc *Client) FollowAccount(accountID int64) (*Relationship, error) {
   196 func (mc *Client) FollowAccount(accountID int64) (*Relationship, error) {
   197 	rel, err := mc.updateRelationship("follow", accountID)
   197 	rel, err := mc.updateRelationship("follow", accountID, nil)
   198 	if err != nil {
   198 	if err != nil {
   199 		return nil, err
   199 		return nil, err
   200 	}
   200 	}
   201 	if rel == nil {
   201 	if rel == nil {
   202 		return nil, ErrEntityNotFound
   202 		return nil, ErrEntityNotFound
   204 	return rel, nil
   204 	return rel, nil
   205 }
   205 }
   206 
   206 
   207 // UnfollowAccount unfollows an account
   207 // UnfollowAccount unfollows an account
   208 func (mc *Client) UnfollowAccount(accountID int64) (*Relationship, error) {
   208 func (mc *Client) UnfollowAccount(accountID int64) (*Relationship, error) {
   209 	rel, err := mc.updateRelationship("unfollow", accountID)
   209 	rel, err := mc.updateRelationship("unfollow", accountID, nil)
   210 	if err != nil {
   210 	if err != nil {
   211 		return nil, err
   211 		return nil, err
   212 	}
   212 	}
   213 	if rel == nil {
   213 	if rel == nil {
   214 		return nil, ErrEntityNotFound
   214 		return nil, ErrEntityNotFound
   236 	return &account, nil
   236 	return &account, nil
   237 }
   237 }
   238 
   238 
   239 // BlockAccount blocks an account
   239 // BlockAccount blocks an account
   240 func (mc *Client) BlockAccount(accountID int64) (*Relationship, error) {
   240 func (mc *Client) BlockAccount(accountID int64) (*Relationship, error) {
   241 	rel, err := mc.updateRelationship("block", accountID)
   241 	rel, err := mc.updateRelationship("block", accountID, nil)
   242 	if err != nil {
   242 	if err != nil {
   243 		return nil, err
   243 		return nil, err
   244 	}
   244 	}
   245 	if rel == nil {
   245 	if rel == nil {
   246 		return nil, ErrEntityNotFound
   246 		return nil, ErrEntityNotFound
   248 	return rel, nil
   248 	return rel, nil
   249 }
   249 }
   250 
   250 
   251 // UnblockAccount unblocks an account
   251 // UnblockAccount unblocks an account
   252 func (mc *Client) UnblockAccount(accountID int64) (*Relationship, error) {
   252 func (mc *Client) UnblockAccount(accountID int64) (*Relationship, error) {
   253 	rel, err := mc.updateRelationship("unblock", accountID)
   253 	rel, err := mc.updateRelationship("unblock", accountID, nil)
   254 	if err != nil {
   254 	if err != nil {
   255 		return nil, err
   255 		return nil, err
   256 	}
   256 	}
   257 	if rel == nil {
   257 	if rel == nil {
   258 		return nil, ErrEntityNotFound
   258 		return nil, ErrEntityNotFound
   259 	}
   259 	}
   260 	return rel, nil
   260 	return rel, nil
   261 }
   261 }
   262 
   262 
   263 // MuteAccount mutes an account
   263 // MuteAccount mutes an account
   264 func (mc *Client) MuteAccount(accountID int64) (*Relationship, error) {
   264 // Note that with current Mastodon API, muteNotifications defaults to true
   265 	rel, err := mc.updateRelationship("mute", accountID)
   265 // when it is not provided.
       
   266 func (mc *Client) MuteAccount(accountID int64, muteNotifications *bool) (*Relationship, error) {
       
   267 	var params apiCallParams
       
   268 
       
   269 	if muteNotifications != nil {
       
   270 		params = make(apiCallParams)
       
   271 		if *muteNotifications {
       
   272 			params["notifications"] = "true"
       
   273 		} else {
       
   274 			params["notifications"] = "false"
       
   275 		}
       
   276 	}
       
   277 
       
   278 	rel, err := mc.updateRelationship("mute", accountID, params)
   266 	if err != nil {
   279 	if err != nil {
   267 		return nil, err
   280 		return nil, err
   268 	}
   281 	}
   269 	if rel == nil {
   282 	if rel == nil {
   270 		return nil, ErrEntityNotFound
   283 		return nil, ErrEntityNotFound
   272 	return rel, nil
   285 	return rel, nil
   273 }
   286 }
   274 
   287 
   275 // UnmuteAccount unmutes an account
   288 // UnmuteAccount unmutes an account
   276 func (mc *Client) UnmuteAccount(accountID int64) (*Relationship, error) {
   289 func (mc *Client) UnmuteAccount(accountID int64) (*Relationship, error) {
   277 	rel, err := mc.updateRelationship("unmute", accountID)
   290 	rel, err := mc.updateRelationship("unmute", accountID, nil)
   278 	if err != nil {
   291 	if err != nil {
   279 		return nil, err
   292 		return nil, err
   280 	}
   293 	}
   281 	if rel == nil {
   294 	if rel == nil {
   282 		return nil, ErrEntityNotFound
   295 		return nil, ErrEntityNotFound