// 顶部导航栏的话题列表。 // 如果用户已经登陆,则获取用户关注的话题, // 如果未登陆则获取全站的最流行话题列表. func getTopNavTopics(ctx *goku.HttpContext, user *models.User) { var topics []models.Topic topicLen := 35 if user == nil { topics, _ = models.Topic_GetTops(1, topicLen) } else { tuser, _ := models.User_GetFollowTopics(user.Id, 1, topicLen, "link_count desc") if len(tuser) < topicLen { // 不够 topicLen 条,则合并 tall, _ := models.Topic_GetTops(1, topicLen-len(tuser)) topics = make([]models.Topic, 0, len(tall)) tmp := map[string]bool{} for _, v := range tuser { tmp[v.Name] = true } topics = append(topics, tuser...) for _, v := range tall { if _, ok := tmp[v.Name]; !ok { topics = append(topics, v) } } } else { topics = tuser } } ctx.ViewData["TopNavTopics"] = topics }
* 查看用户信息页 */ Get("show", func(ctx *goku.HttpContext) goku.ActionResulter { userId, _ := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64) user := models.User_GetById(userId) if user == nil { ctx.ViewData["errorMsg"] = "用户不存在" return ctx.Render("error", nil) } links := models.Link_ByUser(user.Id, 1, golink.PAGE_SIZE) friends, _ := models.UserFollow_Friends(user.Id, 1, 12) followers, _ := models.UserFollow_Followers(user.Id, 1, 12) followTopics, _ := models.User_GetFollowTopics(user.Id, 1, 12) ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx) ctx.ViewData["Friends"] = friends ctx.ViewData["Followers"] = followers ctx.ViewData["FollowTopics"] = followTopics ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE return ctx.View(models.User_ToVUser(user, ctx)) }).Filters(filters.NewRequireLoginFilter()). /** * 获取用户信息 * 用于浮动层 */ Get("pbox-info", func(ctx *goku.HttpContext) goku.ActionResulter {