MCPcopy Index your code
hub / github.com/writefreely/writefreely / viewStats

Function viewStats

account.go:1028–1099  ·  view source on GitHub ↗
(app *App, u *User, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

1026}
1027
1028func viewStats(app *App, u *User, w http.ResponseWriter, r *http.Request) error {
1029 var c *Collection
1030 var err error
1031 vars := mux.Vars(r)
1032 alias := vars["collection"]
1033 if alias != "" {
1034 c, err = app.db.GetCollection(alias)
1035 if err != nil {
1036 return err
1037 }
1038 if c.OwnerID != u.ID {
1039 return ErrCollectionNotFound
1040 }
1041 c.hostName = app.cfg.App.Host
1042 }
1043
1044 topPosts, err := app.db.GetTopPosts(u, alias, c.hostName)
1045 if err != nil {
1046 log.Error("Unable to get top posts: %v", err)
1047 return err
1048 }
1049
1050 flashes, _ := getSessionFlashes(app, w, r, nil)
1051 titleStats := ""
1052 if c != nil {
1053 titleStats = c.DisplayTitle() + " "
1054 }
1055
1056 silenced, err := app.db.IsUserSilenced(u.ID)
1057 if err != nil {
1058 if err == ErrUserNotFound {
1059 return err
1060 }
1061 log.Error("view stats: %v", err)
1062 return err
1063 }
1064 obj := struct {
1065 *UserPage
1066 VisitsBlog string
1067 Collection *Collection
1068 TopPosts *[]PublicPost
1069 APFollowers int
1070 EmailEnabled bool
1071 EmailSubscribers int
1072 Silenced bool
1073 }{
1074 UserPage: NewUserPage(app, r, u, titleStats+"Stats", flashes),
1075 VisitsBlog: alias,
1076 Collection: c,
1077 TopPosts: topPosts,
1078 EmailEnabled: app.cfg.Email.Enabled(),
1079 Silenced: silenced,
1080 }
1081 obj.UserPage.CollAlias = c.Alias
1082 if app.cfg.App.Federation {
1083 folls, err := app.db.GetAPFollowers(c)
1084 if err != nil {
1085 return err

Callers

nothing calls this directly

Calls 10

DisplayTitleMethod · 0.95
getSessionFlashesFunction · 0.85
NewUserPageFunction · 0.85
showUserPageFunction · 0.85
IsUserSilencedMethod · 0.80
EnabledMethod · 0.80
GetEmailSubscribersMethod · 0.80
GetCollectionMethod · 0.65
GetTopPostsMethod · 0.65
GetAPFollowersMethod · 0.65

Tested by

no test coverage detected