"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "vendor/code.gitea.io/sdk/gitea/notifications.go" between
gitea-1.13.1.tar.gz and gitea-1.13.2.tar.gz

About: Gitea allows to set up a self-hosted code hosting Git service (a fork of Gogs).

notifications.go  (gitea-1.13.1):notifications.go  (gitea-1.13.2)
// Copyright 2020 The Gitea Authors. All rights reserved. // Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package gitea package gitea
import ( import (
"fmt" "fmt"
"net/url" "net/url"
"time" "time"
"github.com/hashicorp/go-version"
)
var (
version1_12_3, _ = version.NewVersion("1.12.3")
) )
// NotificationThread expose Notification on API // NotificationThread expose Notification on API
type NotificationThread struct { type NotificationThread struct {
ID int64 `json:"id"` ID int64 `json:"id"`
Repository *Repository `json:"repository"` Repository *Repository `json:"repository"`
Subject *NotificationSubject `json:"subject"` Subject *NotificationSubject `json:"subject"`
Unread bool `json:"unread"` Unread bool `json:"unread"`
Pinned bool `json:"pinned"` Pinned bool `json:"pinned"`
UpdatedAt time.Time `json:"updated_at"` UpdatedAt time.Time `json:"updated_at"`
skipping to change at line 78 skipping to change at line 84
} }
for _, s := range opt.Status { for _, s := range opt.Status {
query.Add("status-types", string(s)) query.Add("status-types", string(s))
} }
return query.Encode() return query.Encode()
} }
// Validate the CreateUserOption struct // Validate the CreateUserOption struct
func (opt ListNotificationOptions) Validate(c *Client) error { func (opt ListNotificationOptions) Validate(c *Client) error {
if len(opt.Status) != 0 { if len(opt.Status) != 0 {
return c.CheckServerVersionConstraint(">=1.12.3") return c.checkServerVersionGreaterThanOrEqual(version1_12_3)
} }
return nil return nil
} }
// QueryEncode encode options to url query // QueryEncode encode options to url query
func (opt *MarkNotificationOptions) QueryEncode() string { func (opt *MarkNotificationOptions) QueryEncode() string {
query := make(url.Values) query := make(url.Values)
if !opt.LastReadAt.IsZero() { if !opt.LastReadAt.IsZero() {
query.Add("last_read_at", opt.LastReadAt.Format(time.RFC3339)) query.Add("last_read_at", opt.LastReadAt.Format(time.RFC3339))
} }
skipping to change at line 101 skipping to change at line 107
} }
if len(opt.ToStatus) != 0 { if len(opt.ToStatus) != 0 {
query.Add("to-status", string(opt.ToStatus)) query.Add("to-status", string(opt.ToStatus))
} }
return query.Encode() return query.Encode()
} }
// Validate the CreateUserOption struct // Validate the CreateUserOption struct
func (opt MarkNotificationOptions) Validate(c *Client) error { func (opt MarkNotificationOptions) Validate(c *Client) error {
if len(opt.Status) != 0 || len(opt.ToStatus) != 0 { if len(opt.Status) != 0 || len(opt.ToStatus) != 0 {
return c.CheckServerVersionConstraint(">=1.12.3") return c.checkServerVersionGreaterThanOrEqual(version1_12_3)
} }
return nil return nil
} }
// CheckNotifications list users's notification threads // CheckNotifications list users's notification threads
func (c *Client) CheckNotifications() (int64, *Response, error) { func (c *Client) CheckNotifications() (int64, *Response, error) {
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != n il {
return 0, nil, err return 0, nil, err
} }
new := struct { new := struct {
New int64 `json:"new"` New int64 `json:"new"`
}{} }{}
resp, err := c.getParsedResponse("GET", "/notifications/new", jsonHeader, nil, &new) resp, err := c.getParsedResponse("GET", "/notifications/new", jsonHeader, nil, &new)
return new.New, resp, err return new.New, resp, err
} }
// GetNotification get notification thread by ID // GetNotification get notification thread by ID
func (c *Client) GetNotification(id int64) (*NotificationThread, *Response, erro r) { func (c *Client) GetNotification(id int64) (*NotificationThread, *Response, erro r) {
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != n il {
return nil, nil, err return nil, nil, err
} }
thread := new(NotificationThread) thread := new(NotificationThread)
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/notifications/threa ds/%d", id), nil, nil, thread) resp, err := c.getParsedResponse("GET", fmt.Sprintf("/notifications/threa ds/%d", id), nil, nil, thread)
return thread, resp, err return thread, resp, err
} }
// ReadNotification mark notification thread as read by ID // ReadNotification mark notification thread as read by ID
// It optionally takes a second argument if status has to be set other than 'rea d' // It optionally takes a second argument if status has to be set other than 'rea d'
func (c *Client) ReadNotification(id int64, status ...NotifyStatus) (*Response, error) { func (c *Client) ReadNotification(id int64, status ...NotifyStatus) (*Response, error) {
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != n il {
return nil, err return nil, err
} }
link := fmt.Sprintf("/notifications/threads/%d", id) link := fmt.Sprintf("/notifications/threads/%d", id)
if len(status) != 0 { if len(status) != 0 {
link += fmt.Sprintf("?to-status=%s", status[0]) link += fmt.Sprintf("?to-status=%s", status[0])
} }
_, resp, err := c.getResponse("PATCH", link, nil, nil) _, resp, err := c.getResponse("PATCH", link, nil, nil)
return resp, err return resp, err
} }
// ListNotifications list users's notification threads // ListNotifications list users's notification threads
func (c *Client) ListNotifications(opt ListNotificationOptions) ([]*Notification Thread, *Response, error) { func (c *Client) ListNotifications(opt ListNotificationOptions) ([]*Notification Thread, *Response, error) {
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != n il {
return nil, nil, err return nil, nil, err
} }
if err := opt.Validate(c); err != nil { if err := opt.Validate(c); err != nil {
return nil, nil, err return nil, nil, err
} }
link, _ := url.Parse("/notifications") link, _ := url.Parse("/notifications")
link.RawQuery = opt.QueryEncode() link.RawQuery = opt.QueryEncode()
threads := make([]*NotificationThread, 0, 10) threads := make([]*NotificationThread, 0, 10)
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &threads ) resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &threads )
return threads, resp, err return threads, resp, err
} }
// ReadNotifications mark notification threads as read // ReadNotifications mark notification threads as read
func (c *Client) ReadNotifications(opt MarkNotificationOptions) (*Response, erro r) { func (c *Client) ReadNotifications(opt MarkNotificationOptions) (*Response, erro r) {
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != n il {
return nil, err return nil, err
} }
if err := opt.Validate(c); err != nil { if err := opt.Validate(c); err != nil {
return nil, err return nil, err
} }
link, _ := url.Parse("/notifications") link, _ := url.Parse("/notifications")
link.RawQuery = opt.QueryEncode() link.RawQuery = opt.QueryEncode()
_, resp, err := c.getResponse("PUT", link.String(), nil, nil) _, resp, err := c.getResponse("PUT", link.String(), nil, nil)
return resp, err return resp, err
} }
// ListRepoNotifications list users's notification threads on a specific repo // ListRepoNotifications list users's notification threads on a specific repo
func (c *Client) ListRepoNotifications(owner, reponame string, opt ListNotificat ionOptions) ([]*NotificationThread, *Response, error) { func (c *Client) ListRepoNotifications(owner, reponame string, opt ListNotificat ionOptions) ([]*NotificationThread, *Response, error) {
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != n il {
return nil, nil, err return nil, nil, err
} }
if err := opt.Validate(c); err != nil { if err := opt.Validate(c); err != nil {
return nil, nil, err return nil, nil, err
} }
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/notifications", owner, rep oname)) link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/notifications", owner, rep oname))
link.RawQuery = opt.QueryEncode() link.RawQuery = opt.QueryEncode()
threads := make([]*NotificationThread, 0, 10) threads := make([]*NotificationThread, 0, 10)
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &threads ) resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &threads )
return threads, resp, err return threads, resp, err
} }
// ReadRepoNotifications mark notification threads as read on a specific repo // ReadRepoNotifications mark notification threads as read on a specific repo
func (c *Client) ReadRepoNotifications(owner, reponame string, opt MarkNotificat ionOptions) (*Response, error) { func (c *Client) ReadRepoNotifications(owner, reponame string, opt MarkNotificat ionOptions) (*Response, error) {
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != n il {
return nil, err return nil, err
} }
if err := opt.Validate(c); err != nil { if err := opt.Validate(c); err != nil {
return nil, err return nil, err
} }
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/notifications", owner, rep oname)) link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/notifications", owner, rep oname))
link.RawQuery = opt.QueryEncode() link.RawQuery = opt.QueryEncode()
_, resp, err := c.getResponse("PUT", link.String(), nil, nil) _, resp, err := c.getResponse("PUT", link.String(), nil, nil)
return resp, err return resp, err
} }
 End of changes. 10 change blocks. 
9 lines changed or deleted 15 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)