Sync with Madon library update; use limit API parameter
authorMikael Berthe <mikael@lilotux.net>
Fri, 28 Apr 2017 15:39:32 +0200
changeset 20 b0ccc09f07a2
parent 19 4c81f4393773
child 21 9e94836dc081
Sync with Madon library update; use limit API parameter The --limit argument will be used in the API query. Note that the Mastodon server does not have the same maximum "limit" value for for the different end points. (We do not check the user value in madonctl.)
cmd/accounts.go
cmd/notifications.go
cmd/status.go
cmd/timelines.go
--- a/cmd/accounts.go	Fri Apr 28 13:31:40 2017 +0200
+++ b/cmd/accounts.go	Fri Apr 28 15:39:32 2017 +0200
@@ -238,6 +238,7 @@
 // accountSubcommandsRunE is a generic function for status subcommands
 func accountSubcommandsRunE(subcmd string, args []string) error {
 	opt := accountsOpts
+	var limOpts *madon.LimitParams
 
 	if opt.accountUID != "" {
 		if opt.accountID > 0 {
@@ -249,7 +250,7 @@
 		if err := madonInit(true); err != nil {
 			return err
 		}
-		accList, err := gClient.SearchAccounts(opt.accountUID, 2)
+		accList, err := gClient.SearchAccounts(opt.accountUID, &madon.LimitParams{Limit: 2})
 		if err != nil || len(accList) < 1 {
 			errPrint("Cannot find user '%s': %v", opt.accountUID, err)
 			os.Exit(1)
@@ -325,6 +326,13 @@
 		}
 	}
 
+	if opt.limit > 0 {
+		if limOpts == nil {
+			limOpts = new(madon.LimitParams)
+		}
+		limOpts.Limit = int(opt.limit)
+	}
+
 	// All account subcommands need to have signed in
 	if err := madonInit(true); err != nil {
 		return err
@@ -344,26 +352,26 @@
 		obj = account
 	case "search":
 		var accountList []madon.Account
-		accountList, err = gClient.SearchAccounts(strings.Join(args, " "), int(opt.limit))
+		accountList, err = gClient.SearchAccounts(strings.Join(args, " "), limOpts)
 		obj = accountList
 	case "followers":
 		var accountList []madon.Account
-		accountList, err = gClient.GetAccountFollowers(opt.accountID)
-		if opt.limit > 0 {
+		accountList, err = gClient.GetAccountFollowers(opt.accountID, limOpts)
+		if opt.limit > 0 && len(accountList) > int(opt.limit) {
 			accountList = accountList[:opt.limit]
 		}
 		obj = accountList
 	case "following":
 		var accountList []madon.Account
-		accountList, err = gClient.GetAccountFollowing(opt.accountID)
-		if opt.limit > 0 {
+		accountList, err = gClient.GetAccountFollowing(opt.accountID, limOpts)
+		if opt.limit > 0 && len(accountList) > int(opt.limit) {
 			accountList = accountList[:opt.limit]
 		}
 		obj = accountList
 	case "statuses":
 		var statusList []madon.Status
-		statusList, err = gClient.GetAccountStatuses(opt.accountID, opt.onlyMedia, opt.excludeReplies)
-		if opt.limit > 0 {
+		statusList, err = gClient.GetAccountStatuses(opt.accountID, opt.onlyMedia, opt.excludeReplies, limOpts)
+		if opt.limit > 0 && len(statusList) > int(opt.limit) {
 			statusList = statusList[:opt.limit]
 		}
 		obj = statusList
@@ -382,8 +390,8 @@
 	case "follow-requests":
 		if opt.list {
 			var followRequests []madon.Account
-			followRequests, err = gClient.GetAccountFollowRequests()
-			if opt.limit > 0 {
+			followRequests, err = gClient.GetAccountFollowRequests(limOpts)
+			if opt.limit > 0 && len(followRequests) > int(opt.limit) {
 				followRequests = followRequests[:opt.limit]
 			}
 			obj = followRequests
@@ -404,22 +412,22 @@
 		}
 	case "favourites":
 		var statusList []madon.Status
-		statusList, err = gClient.GetFavourites()
-		if opt.limit > 0 {
+		statusList, err = gClient.GetFavourites(limOpts)
+		if opt.limit > 0 && len(statusList) > int(opt.limit) {
 			statusList = statusList[:opt.limit]
 		}
 		obj = statusList
 	case "blocks":
 		var accountList []madon.Account
-		accountList, err = gClient.GetBlockedAccounts()
-		if opt.limit > 0 {
+		accountList, err = gClient.GetBlockedAccounts(limOpts)
+		if opt.limit > 0 && len(accountList) > int(opt.limit) {
 			accountList = accountList[:opt.limit]
 		}
 		obj = accountList
 	case "mutes":
 		var accountList []madon.Account
-		accountList, err = gClient.GetMutedAccounts()
-		if opt.limit > 0 {
+		accountList, err = gClient.GetMutedAccounts(limOpts)
+		if opt.limit > 0 && len(accountList) > int(opt.limit) {
 			accountList = accountList[:opt.limit]
 		}
 		obj = accountList
@@ -441,8 +449,8 @@
 	case "reports":
 		if opt.list {
 			var reports []madon.Report
-			reports, err = gClient.GetReports()
-			if opt.limit > 0 {
+			reports, err = gClient.GetReports(limOpts)
+			if opt.limit > 0 && len(reports) > int(opt.limit) {
 				reports = reports[:opt.limit]
 			}
 			obj = reports
--- a/cmd/notifications.go	Fri Apr 28 13:31:40 2017 +0200
+++ b/cmd/notifications.go	Fri Apr 28 15:39:32 2017 +0200
@@ -42,6 +42,7 @@
 
 func notificationRunE(cmd *cobra.Command, args []string) error {
 	opt := notificationsOpts
+	var limOpts *madon.LimitParams
 
 	if !opt.list && !opt.clear && opt.notifID < 1 {
 		return errors.New("missing parameters")
@@ -51,13 +52,18 @@
 		return err
 	}
 
+	if accountsOpts.limit > 0 {
+		limOpts = new(madon.LimitParams)
+		limOpts.Limit = int(accountsOpts.limit)
+	}
+
 	var obj interface{}
 	var err error
 
 	if opt.list {
 		var notifications []madon.Notification
-		notifications, err = gClient.GetNotifications()
-		if accountsOpts.limit > 0 {
+		notifications, err = gClient.GetNotifications(limOpts)
+		if accountsOpts.limit > 0 && len(notifications) > int(accountsOpts.limit) {
 			notifications = notifications[:accountsOpts.limit]
 		}
 		obj = notifications
--- a/cmd/status.go	Fri Apr 28 13:31:40 2017 +0200
+++ b/cmd/status.go	Fri Apr 28 15:39:32 2017 +0200
@@ -163,6 +163,14 @@
 	var obj interface{}
 	var err error
 
+	var limOpts *madon.LimitParams
+	if opt.limit > 0 {
+		if limOpts == nil {
+			limOpts = new(madon.LimitParams)
+		}
+		limOpts.Limit = int(opt.limit)
+	}
+
 	switch subcmd {
 	case "show":
 		var status *madon.Status
@@ -178,15 +186,15 @@
 		obj = context
 	case "reblogged-by":
 		var accountList []madon.Account
-		accountList, err = gClient.GetStatusRebloggedBy(opt.statusID)
-		if opt.limit > 0 {
+		accountList, err = gClient.GetStatusRebloggedBy(opt.statusID, limOpts)
+		if opt.limit > 0 && len(accountList) > int(opt.limit) {
 			accountList = accountList[:opt.limit]
 		}
 		obj = accountList
 	case "favourited-by":
 		var accountList []madon.Account
-		accountList, err = gClient.GetStatusFavouritedBy(opt.statusID)
-		if opt.limit > 0 {
+		accountList, err = gClient.GetStatusFavouritedBy(opt.statusID, limOpts)
+		if opt.limit > 0 && len(accountList) > int(opt.limit) {
 			accountList = accountList[:opt.limit]
 		}
 		obj = accountList
--- a/cmd/timelines.go	Fri Apr 28 13:31:40 2017 +0200
+++ b/cmd/timelines.go	Fri Apr 28 15:39:32 2017 +0200
@@ -7,6 +7,8 @@
 
 import (
 	"github.com/spf13/cobra"
+
+	"github.com/McKael/madon"
 )
 
 var timelineOpts struct {
@@ -39,6 +41,12 @@
 
 func timelineRunE(cmd *cobra.Command, args []string) error {
 	opt := timelineOpts
+	var limOpts *madon.LimitParams
+
+	if opt.limit > 0 {
+		limOpts = new(madon.LimitParams)
+		limOpts.Limit = int(opt.limit)
+	}
 
 	tl := "home"
 	if len(args) > 0 {
@@ -50,13 +58,13 @@
 		return err
 	}
 
-	sl, err := gClient.GetTimelines(tl, opt.local)
+	sl, err := gClient.GetTimelines(tl, opt.local, limOpts)
 	if err != nil {
 		errPrint("Error: %s", err.Error())
 		return nil
 	}
 
-	if opt.limit > 0 {
+	if opt.limit > 0 && len(sl) > int(opt.limit) {
 		sl = sl[:opt.limit]
 	}