func getFeedArticles(user content.User, id string, limit int, offset int, newerFirst bool, unreadOnly bool) (resp responseError) { resp = newResponse() if limit > 50 { limit = 50 } user.SortingByDate() if newerFirst { user.Order(data.DescendingOrder) } else { user.Order(data.AscendingOrder) } if id == "favorite" { resp.val["Articles"], resp.err = user.FavoriteArticles(limit, offset), user.Err() } else if id == "popular:all" { resp.val["Articles"], resp.err = user.ScoredArticles(time.Now().AddDate(0, 0, -5), time.Now(), limit, offset), user.Err() } else if id == "all" { if unreadOnly { resp.val["Articles"], resp.err = user.UnreadArticles(limit, offset), user.Err() } else { resp.val["Articles"], resp.err = user.Articles(limit, offset), user.Err() } } else if strings.HasPrefix(id, "popular:") { if strings.HasPrefix(id, "popular:tag:") { tag := user.Repo().Tag(user) tag.Value(data.TagValue(id[12:])) tag.SortingByDate() if newerFirst { tag.Order(data.DescendingOrder) } else { tag.Order(data.AscendingOrder) } resp.val["Articles"], resp.err = tag.ScoredArticles(time.Now().AddDate(0, 0, -5), time.Now(), limit, offset), tag.Err() } else { var f content.UserFeed var feedId int64 feedId, resp.err = strconv.ParseInt(id[8:], 10, 64) if resp.err != nil { resp.err = errors.New("Unknown feed id " + id) return } if f = user.FeedById(data.FeedId(feedId)); f.HasErr() { /* TODO: non-fatal error */ resp.err = f.Err() return } f.SortingByDate() if newerFirst { f.Order(data.DescendingOrder) } else { f.Order(data.AscendingOrder) } resp.val["Articles"], resp.err = f.ScoredArticles(time.Now().AddDate(0, 0, -5), time.Now(), limit, offset), f.Err() } } else if strings.HasPrefix(id, "tag:") { tag := user.Repo().Tag(user) tag.Value(data.TagValue(id[4:])) tag.SortingByDate() if newerFirst { tag.Order(data.DescendingOrder) } else { tag.Order(data.AscendingOrder) } if unreadOnly { resp.val["Articles"], resp.err = tag.UnreadArticles(limit, offset), tag.Err() } else { resp.val["Articles"], resp.err = tag.Articles(limit, offset), tag.Err() } } else { var f content.UserFeed var feedId int64 feedId, resp.err = strconv.ParseInt(id, 10, 64) if resp.err != nil { resp.err = errors.New("Unknown feed id " + id) return } if f = user.FeedById(data.FeedId(feedId)); f.HasErr() { /* TODO: non-fatal error */ resp.err = f.Err() return } if newerFirst { f.Order(data.DescendingOrder) } else { f.Order(data.AscendingOrder) } f.SortingByDate() if unreadOnly { resp.val["Articles"], resp.err = f.UnreadArticles(limit, offset), f.Err() } else { resp.val["Articles"], resp.err = f.Articles(limit, offset), f.Err() } } return }