parent
d149093ce3
commit
6b0df6d8da
@ -0,0 +1,22 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package structs
|
||||
|
||||
import "time"
|
||||
|
||||
type Activity struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID int64 `json:"user_id"` // Receiver user
|
||||
OpType string `json:"op_type"`
|
||||
ActUserID int64 `json:"act_user_id"`
|
||||
ActUser *User `json:"act_user"`
|
||||
RepoID int64 `json:"repo_id"`
|
||||
Repo *Repository `json:"repo"`
|
||||
CommentID int64 `json:"comment_id"`
|
||||
Comment *Comment `json:"comment"`
|
||||
RefName string `json:"ref_name"`
|
||||
IsPrivate bool `json:"is_private"`
|
||||
Content string `json:"content"`
|
||||
Created time.Time `json:"created"`
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package swagger
|
||||
|
||||
import (
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
)
|
||||
|
||||
// ActivityFeedsList
|
||||
// swagger:response ActivityFeedsList
|
||||
type swaggerActivityFeedsList struct {
|
||||
// in:body
|
||||
Body []api.Activity `json:"body"`
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package convert
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
perm_model "code.gitea.io/gitea/models/perm"
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
)
|
||||
|
||||
func ToActivity(ctx context.Context, ac *activities_model.Action, doer *user_model.User) *api.Activity {
|
||||
p, err := access_model.GetUserRepoPermission(ctx, ac.Repo, doer)
|
||||
if err != nil {
|
||||
log.Error("GetUserRepoPermission[%d]: %v", ac.RepoID, err)
|
||||
p.AccessMode = perm_model.AccessModeNone
|
||||
}
|
||||
|
||||
result := &api.Activity{
|
||||
ID: ac.ID,
|
||||
UserID: ac.UserID,
|
||||
OpType: ac.OpType.String(),
|
||||
ActUserID: ac.ActUserID,
|
||||
ActUser: ToUser(ctx, ac.ActUser, doer),
|
||||
RepoID: ac.RepoID,
|
||||
Repo: ToRepo(ctx, ac.Repo, p.AccessMode),
|
||||
RefName: ac.RefName,
|
||||
IsPrivate: ac.IsPrivate,
|
||||
Content: ac.Content,
|
||||
Created: ac.CreatedUnix.AsTime(),
|
||||
}
|
||||
|
||||
if ac.Comment != nil {
|
||||
result.CommentID = ac.CommentID
|
||||
result.Comment = ToComment(ctx, ac.Comment)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func ToActivities(ctx context.Context, al activities_model.ActionList, doer *user_model.User) []*api.Activity {
|
||||
result := make([]*api.Activity, 0, len(al))
|
||||
for _, ac := range al {
|
||||
result = append(result, ToActivity(ctx, ac, doer))
|
||||
}
|
||||
return result
|
||||
}
|
Loading…
Reference in New Issue