code.gitea.io/gitea@v1.21.7/services/convert/activity.go (about) 1 // Copyright 2023 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package convert 5 6 import ( 7 "context" 8 9 activities_model "code.gitea.io/gitea/models/activities" 10 perm_model "code.gitea.io/gitea/models/perm" 11 access_model "code.gitea.io/gitea/models/perm/access" 12 user_model "code.gitea.io/gitea/models/user" 13 "code.gitea.io/gitea/modules/log" 14 api "code.gitea.io/gitea/modules/structs" 15 ) 16 17 func ToActivity(ctx context.Context, ac *activities_model.Action, doer *user_model.User) *api.Activity { 18 p, err := access_model.GetUserRepoPermission(ctx, ac.Repo, doer) 19 if err != nil { 20 log.Error("GetUserRepoPermission[%d]: %v", ac.RepoID, err) 21 p.AccessMode = perm_model.AccessModeNone 22 } 23 24 result := &api.Activity{ 25 ID: ac.ID, 26 UserID: ac.UserID, 27 OpType: ac.OpType.String(), 28 ActUserID: ac.ActUserID, 29 ActUser: ToUser(ctx, ac.ActUser, doer), 30 RepoID: ac.RepoID, 31 Repo: ToRepo(ctx, ac.Repo, p), 32 RefName: ac.RefName, 33 IsPrivate: ac.IsPrivate, 34 Content: ac.Content, 35 Created: ac.CreatedUnix.AsTime(), 36 } 37 38 if ac.Comment != nil { 39 result.CommentID = ac.CommentID 40 result.Comment = ToAPIComment(ctx, ac.Repo, ac.Comment) 41 } 42 43 return result 44 } 45 46 func ToActivities(ctx context.Context, al activities_model.ActionList, doer *user_model.User) []*api.Activity { 47 result := make([]*api.Activity, 0, len(al)) 48 for _, ac := range al { 49 result = append(result, ToActivity(ctx, ac, doer)) 50 } 51 return result 52 }