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 { |
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 |