vendor/github.com/McKael/madon/v3/notifications.go
changeset 270 df7e9dff1b66
parent 268 4dd196a4ee7c
equal deleted inserted replaced
269:c50e88700432 270:df7e9dff1b66
     6 
     6 
     7 package madon
     7 package madon
     8 
     8 
     9 import (
     9 import (
    10 	"fmt"
    10 	"fmt"
    11 	"strconv"
       
    12 
    11 
    13 	"github.com/sendgrid/rest"
    12 	"github.com/sendgrid/rest"
    14 )
    13 )
    15 
    14 
    16 // GetNotifications returns the list of the user's notifications
    15 // GetNotifications returns the list of the user's notifications
    52 }
    51 }
    53 
    52 
    54 // GetNotification returns a notification
    53 // GetNotification returns a notification
    55 // The returned notification can be nil if there is an error or if the
    54 // The returned notification can be nil if there is an error or if the
    56 // requested notification does not exist.
    55 // requested notification does not exist.
    57 func (mc *Client) GetNotification(notificationID int64) (*Notification, error) {
    56 func (mc *Client) GetNotification(notificationID ActivityID) (*Notification, error) {
    58 	if notificationID < 1 {
    57 	if notificationID == "" {
    59 		return nil, ErrInvalidID
    58 		return nil, ErrInvalidID
    60 	}
    59 	}
    61 
    60 
    62 	var endPoint = "notifications/" + strconv.FormatInt(notificationID, 10)
    61 	var endPoint = "notifications/" + notificationID
    63 	var notification Notification
    62 	var notification Notification
    64 	if err := mc.apiCall("v1/"+endPoint, rest.Get, nil, nil, nil, &notification); err != nil {
    63 	if err := mc.apiCall("v1/"+endPoint, rest.Get, nil, nil, nil, &notification); err != nil {
    65 		return nil, err
    64 		return nil, err
    66 	}
    65 	}
    67 	if notification.ID == 0 {
    66 	if notification.ID == "" {
    68 		return nil, ErrEntityNotFound
    67 		return nil, ErrEntityNotFound
    69 	}
    68 	}
    70 	return &notification, nil
    69 	return &notification, nil
    71 }
    70 }
    72 
    71 
    73 // DismissNotification deletes a notification
    72 // DismissNotification deletes a notification
    74 func (mc *Client) DismissNotification(notificationID int64) error {
    73 func (mc *Client) DismissNotification(notificationID ActivityID) error {
    75 	if notificationID < 1 {
    74 	if notificationID == "" {
    76 		return ErrInvalidID
    75 		return ErrInvalidID
    77 	}
    76 	}
    78 
    77 
    79 	endPoint := "notifications/dismiss"
    78 	endPoint := "notifications/dismiss"
    80 	params := apiCallParams{"id": strconv.FormatInt(notificationID, 10)}
    79 	params := apiCallParams{"id": notificationID}
    81 	err := mc.apiCall("v1/"+endPoint, rest.Post, params, nil, nil, &Notification{})
    80 	err := mc.apiCall("v1/"+endPoint, rest.Post, params, nil, nil, &Notification{})
    82 	return err
    81 	return err
    83 }
    82 }
    84 
    83 
    85 // ClearNotifications deletes all notifications from the Mastodon server for
    84 // ClearNotifications deletes all notifications from the Mastodon server for