Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local user and post count to nodeinfo responses #1325

Merged
merged 2 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions internal/api/model/well-known.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ type NodeInfoServices struct {

// NodeInfoUsage represents usage information about this server, such as number of users.
type NodeInfoUsage struct {
Users NodeInfoUsers `json:"users"`
Users NodeInfoUsers `json:"users"`
LocalPosts int `json:"localPosts"`
}

// NodeInfoUsers is a stub for usage information, currently empty.
type NodeInfoUsers struct{}
type NodeInfoUsers struct {
Total int `json:"total"`
}
16 changes: 15 additions & 1 deletion internal/processing/federation/getnodeinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ func (p *processor) GetNodeInfo(ctx context.Context) (*apimodel.Nodeinfo, gtserr
openRegistration := config.GetAccountsRegistrationOpen()
softwareVersion := config.GetSoftwareVersion()

host := config.GetHost()
userCount, err := p.db.CountInstanceUsers(ctx, host)
if err != nil {
return nil, gtserror.NewErrorInternalError(err, "Unable to query instance user count")
tsmethurst marked this conversation as resolved.
Show resolved Hide resolved
}

postCount, err := p.db.CountInstanceStatuses(ctx, host)
if err != nil {
return nil, gtserror.NewErrorInternalError(err, "Unable to query instance status count")
}

return &apimodel.Nodeinfo{
Version: nodeInfoVersion,
Software: apimodel.NodeInfoSoftware{
Expand All @@ -68,7 +79,10 @@ func (p *processor) GetNodeInfo(ctx context.Context) (*apimodel.Nodeinfo, gtserr
},
OpenRegistrations: openRegistration,
Usage: apimodel.NodeInfoUsage{
Users: apimodel.NodeInfoUsers{},
Users: apimodel.NodeInfoUsers{
Total: userCount,
},
LocalPosts: postCount,
},
Metadata: make(map[string]interface{}),
}, nil
Expand Down