當前位置: 首頁>>代碼示例>>Golang>>正文


Golang User.FeedById方法代碼示例

本文整理匯總了Golang中github.com/urandom/readeef/content.User.FeedById方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.FeedById方法的具體用法?Golang User.FeedById怎麽用?Golang User.FeedById使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/urandom/readeef/content.User的用法示例。


在下文中一共展示了User.FeedById方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: getFeedTags

func getFeedTags(user content.User, id data.FeedId) (resp responseError) {
	resp = newResponse()

	repo := user.Repo()
	tf := repo.TaggedFeed(user)
	if uf := user.FeedById(id); uf.HasErr() {
		resp.err = uf.Err()
		return
	} else {
		tf.Data(uf.Data())
	}

	tags := tf.Tags()

	if tf.HasErr() {
		resp.err = tf.Err()
		return
	}

	t := make([]string, len(tags))
	for _, tag := range tags {
		t = append(t, tag.String())
	}

	resp.val["Tags"] = t
	return
}
開發者ID:urandom,項目名稱:readeef,代碼行數:27,代碼來源:feed.go

示例2: setFeedTags

func setFeedTags(user content.User, id data.FeedId, tagValues []data.TagValue) (resp responseError) {
	resp = newResponse()

	feed := user.FeedById(id)
	if feed.HasErr() {
		resp.err = feed.Err()
		return
	}

	repo := user.Repo()
	tf := repo.TaggedFeed(user)
	tf.Data(feed.Data())
	tags := make([]content.Tag, len(tagValues))
	for i := range tagValues {
		tags[i] = repo.Tag(user)
		tags[i].Value(tagValues[i])
	}
	tf.Tags(tags)
	if tf.UpdateTags(); tf.HasErr() {
		resp.err = tf.Err()
		return
	}

	resp.val["Success"] = true
	resp.val["Id"] = id
	return
}
開發者ID:RavenB,項目名稱:readeef,代碼行數:27,代碼來源:feed.go

示例3: readState

func readState(user content.User, id string, beforeId data.ArticleId, timestamp int64) (resp responseError) {
	resp = newResponse()

	var ar content.ArticleRepo

	o := data.ArticleUpdateStateOptions{}

	if timestamp > 0 {
		t := time.Unix(timestamp/1000, 0)
		o.BeforeDate = t
	}

	if beforeId > 0 {
		o.BeforeId = beforeId
	}

	switch {
	case id == "all":
		ar = user
	case id == "favorite":
		o.FavoriteOnly = true
		ar = user
	case strings.HasPrefix(id, "popular:"):
		// Can't bulk set state to popular articles
	case strings.HasPrefix(id, "tag:"):
		tag := user.Repo().Tag(user)
		tag.Data(data.Tag{Value: data.TagValue(id[4:])})

		ar = tag
	default:
		var feedId int64
		if feedId, resp.err = strconv.ParseInt(id, 10, 64); resp.err != nil {
			/* TODO: non-fatal error */
			return
		}

		ar = user.FeedById(data.FeedId(feedId))
	}

	if ar != nil {
		ar.ReadState(true, o)

		if e, ok := ar.(content.Error); ok && e.HasErr() {
			resp.err = e.Err()
			return
		}
	}

	resp.val["Success"] = true
	return
}
開發者ID:urandom,項目名稱:readeef,代碼行數:51,代碼來源:feed.go

示例4: removeFeed

func removeFeed(user content.User, fm *readeef.FeedManager, id data.FeedId) (resp responseError) {
	resp = newResponse()

	feed := user.FeedById(id)
	if feed.Delete(); feed.HasErr() {
		resp.err = feed.Err()
		return
	}

	fm.RemoveFeed(feed)

	resp.val["Success"] = true
	return
}
開發者ID:urandom,項目名稱:readeef,代碼行數:14,代碼來源:feed.go

示例5: search

func search(user content.User, searchIndex readeef.SearchIndex, query, highlight, feedId string) (resp responseError) {
	resp = newResponse()

	if strings.HasPrefix(feedId, "tag:") {
		tag := user.Repo().Tag(user)
		tag.Value(data.TagValue(feedId[4:]))

		tag.Highlight(highlight)
		resp.val["Articles"], resp.err = tag.Query(query, searchIndex.Index), tag.Err()
	} else {
		if id, err := strconv.ParseInt(feedId, 10, 64); err == nil {
			f := user.FeedById(data.FeedId(id))
			resp.val["Articles"], resp.err = f.Query(query, searchIndex.Index), f.Err()
		} else {
			user.Highlight(highlight)
			resp.val["Articles"], resp.err = user.Query(query, searchIndex.Index), user.Err()
		}
	}

	return
}
開發者ID:RavenB,項目名稱:readeef,代碼行數:21,代碼來源:search.go

示例6: performSearch

func performSearch(user content.User, sp content.SearchProvider, query, feedId string, limit, offset int) (ua []content.UserArticle, err error) {
	defer func() {
		if rec := recover(); rec != nil {
			err = fmt.Errorf("Error during search: %s", rec)
		}
	}()

	if strings.HasPrefix(feedId, "tag:") {
		tag := user.Repo().Tag(user)
		tag.Data(data.Tag{Value: data.TagValue(feedId[4:])})

		ua, err = tag.Query(query, sp, limit, offset), tag.Err()
	} else {
		if id, err := strconv.ParseInt(feedId, 10, 64); err == nil {
			f := user.FeedById(data.FeedId(id))
			ua, err = f.Query(query, sp, limit, offset), f.Err()
		} else {
			ua, err = user.Query(query, sp, limit, offset), user.Err()
		}
	}

	return
}
開發者ID:urandom,項目名稱:readeef,代碼行數:23,代碼來源:feed.go

示例7: markFeedAsRead

func markFeedAsRead(user content.User, id string, timestamp int64) (resp responseError) {
	resp = newResponse()

	t := time.Unix(timestamp/1000, 0)

	switch {
	case id == "all":
		if user.ReadBefore(t, true); user.HasErr() {
			resp.err = user.Err()
			return
		}
	case id == "favorite" || strings.HasPrefix(id, "popular:"):
		// Favorites are assumbed to have been read already
	case strings.HasPrefix(id, "tag:"):
		tag := user.Repo().Tag(user)
		tag.Value(data.TagValue(id[4:]))
		if tag.ReadBefore(t, true); tag.HasErr() {
			resp.err = tag.Err()
			return
		}
	default:
		var feedId int64
		if feedId, resp.err = strconv.ParseInt(id, 10, 64); resp.err != nil {
			/* TODO: non-fatal error */
			return
		}

		feed := user.FeedById(data.FeedId(feedId))
		if feed.ReadBefore(t, true); feed.HasErr() {
			resp.err = feed.Err()
			return
		}
	}

	resp.val["Success"] = true
	return
}
開發者ID:RavenB,項目名稱:readeef,代碼行數:37,代碼來源:feed.go

示例8: setFeedTags

func setFeedTags(user content.User, id data.FeedId, tagValues []data.TagValue) (resp responseError) {
	resp = newResponse()

	feed := user.FeedById(id)
	if feed.HasErr() {
		resp.err = feed.Err()
		return
	}

	repo := user.Repo()
	tf := repo.TaggedFeed(user)
	tf.Data(feed.Data())

	filtered := make([]data.TagValue, 0, len(tagValues))
	for _, v := range tagValues {
		v = data.TagValue(strings.TrimSpace(string(v)))
		if v != "" {
			filtered = append(filtered, v)
		}
	}

	tags := make([]content.Tag, len(filtered))
	for i := range filtered {
		tags[i] = repo.Tag(user)
		tags[i].Data(data.Tag{Value: filtered[i]})
	}
	tf.Tags(tags)
	if tf.UpdateTags(); tf.HasErr() {
		resp.err = tf.Err()
		return
	}

	resp.val["Success"] = true
	resp.val["Id"] = id
	return
}
開發者ID:urandom,項目名稱:readeef,代碼行數:36,代碼來源:feed.go

示例9: getFeedArticles

func getFeedArticles(user content.User, sp content.SearchProvider,
	id string, minId, maxId data.ArticleId, limit int, offset int, olderFirst bool,
	unreadOnly bool) (resp responseError) {

	resp = newResponse()

	if limit > 200 {
		limit = 200
	}

	var as content.ArticleSorting
	var ar content.ArticleRepo
	var ua []content.UserArticle

	o := data.ArticleQueryOptions{Limit: limit, Offset: offset, UnreadOnly: unreadOnly, UnreadFirst: true}

	if maxId > 0 {
		o.AfterId = maxId
		resp.val["MaxId"] = maxId
	}

	if id == "favorite" {
		o.FavoriteOnly = true
		ar = user
		as = user
	} else if id == "all" {
		ar = user
		as = user
	} else if strings.HasPrefix(id, "popular:") {
		o.IncludeScores = true
		o.HighScoredFirst = true
		o.BeforeDate = time.Now()
		o.AfterDate = time.Now().AddDate(0, 0, -5)

		if id == "popular:all" {
			ar = user
			as = user
		} else if strings.HasPrefix(id, "popular:tag:") {
			tag := user.Repo().Tag(user)
			tag.Data(data.Tag{Value: data.TagValue(id[12:])})

			ar = tag
			as = tag
		} 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
			}

			ar = f
			as = f
		}
	} else if strings.HasPrefix(id, "search:") && sp != nil {
		var query string
		id = id[7:]
		parts := strings.Split(id, ":")

		if parts[0] == "tag" {
			id = strings.Join(parts[:2], ":")
			query = strings.Join(parts[2:], ":")
		} else {
			id = strings.Join(parts[:1], ":")
			query = strings.Join(parts[1:], ":")
		}

		sp.SortingByDate()
		if olderFirst {
			sp.Order(data.AscendingOrder)
		} else {
			sp.Order(data.DescendingOrder)
		}

		ua, resp.err = performSearch(user, sp, query, id, limit, offset)
	} else if strings.HasPrefix(id, "tag:") {
		tag := user.Repo().Tag(user)
		tag.Data(data.Tag{Value: data.TagValue(id[4:])})

		as = tag
		ar = tag
	} 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
		}
//.........這裏部分代碼省略.........
開發者ID:urandom,項目名稱:readeef,代碼行數:101,代碼來源:feed.go

示例10: Handler


//.........這裏部分代碼省略.........
			case "isLoggedIn":
				if _, ok := ttRssSessions[req.Sid]; ok {
					con = ttRssGenericContent{Status: true}
				} else {
					con = ttRssGenericContent{Status: false}
				}
			case "getUnread":
				var ar content.ArticleRepo
				o := data.ArticleCountOptions{UnreadOnly: true}

				if req.IsCat {
					tagId := data.TagId(req.FeedId)
					if tagId > 0 {
						ar = user.TagById(tagId)
					} else if tagId == TTRSS_CAT_UNCATEGORIZED {
						ar = user
						o.UntaggedOnly = true
					} else if tagId == TTRSS_CAT_SPECIAL {
						ar = user
						o.FavoriteOnly = true
					}
				} else {
					switch req.FeedId {
					case TTRSS_FAVORITE_ID:
						ar = user
						o.FavoriteOnly = true
					case TTRSS_FRESH_ID:
						ar = user
						o.AfterDate = time.Now().Add(TTRSS_FRESH_DURATION)
					case TTRSS_ALL_ID, 0:
						ar = user
					default:
						if req.FeedId > 0 {
							feed := user.FeedById(req.FeedId)
							if feed.HasErr() {
								err = feed.Err()
								break
							}

							ar = feed
						}

					}

				}

				if ar == nil {
					con = ttRssGenericContent{Unread: "0"}
				} else if con == nil {
					con = ttRssGenericContent{Unread: strconv.FormatInt(ar.Count(o), 10)}
				}
			case "getCounters":
				if req.OutputMode == "" {
					req.OutputMode = "flc"
				}
				cContent := ttRssCountersContent{}

				o := data.ArticleCountOptions{UnreadOnly: true}
				unreadCount := user.Count(o)
				cContent = append(cContent,
					ttRssCounter{Id: "global-unread", Counter: unreadCount})

				feeds := user.AllFeeds()
				cContent = append(cContent,
					ttRssCounter{Id: "subscribed-feeds", Counter: int64(len(feeds))})
開發者ID:urandom,項目名稱:readeef,代碼行數:66,代碼來源:tt_rss.go

示例11: getFeedArticles

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)
		}

//.........這裏部分代碼省略.........
開發者ID:RavenB,項目名稱:readeef,代碼行數:101,代碼來源:feed.go

示例12: Handler


//.........這裏部分代碼省略.........
				}
			}

			if val := r.PostFormValue("mark"); val != "" {
				if val == "item" {
					logger.Infof("Marking fever item '%s' as '%s'\n", r.PostFormValue("id"), r.PostFormValue("as"))

					var id int64
					var article content.UserArticle

					id, err = strconv.ParseInt(r.PostFormValue("id"), 10, 64)
					if err != nil {
						break
					}

					article, err = user.ArticleById(data.ArticleId(id), data.ArticleQueryOptions{SkipSessionProcessors: true}), user.Err()
					if err != nil {
						break
					}

					switch r.PostFormValue("as") {
					case "read":
						article.Read(true)
					case "saved":
						article.Favorite(true)
					case "unsaved":
						article.Favorite(false)
					default:
						err = errors.New("Unknown 'as' action")
					}
					if err == nil {
						err = article.Err()
					}
				} else if val == "feed" || val == "group" {
					logger.Infof("Marking fever %s '%s' as '%s'\n", val, r.PostFormValue("id"), r.PostFormValue("as"))
					if r.PostFormValue("as") != "read" {
						err = errors.New("Unknown 'as' action")
						break
					}

					var id, timestamp int64

					id, err = strconv.ParseInt(r.PostFormValue("id"), 10, 64)
					if err != nil {
						break
					}

					timestamp, err = strconv.ParseInt(r.PostFormValue("before"), 10, 64)
					if err != nil {
						break
					}

					t := time.Unix(timestamp, 0)

					if val == "feed" {
						var feed content.UserFeed

						feed, err = user.FeedById(data.FeedId(id)), feed.Err()
						if err != nil {
							break
						}

						feed.ReadState(true, data.ArticleUpdateStateOptions{
							BeforeDate: t,
						})
						err = feed.Err()
					} else if val == "group" {
						if id == 1 || id == 0 {
							user.ReadState(true, data.ArticleUpdateStateOptions{
								BeforeDate: t,
							})
							err = user.Err()
						} else {
							err = errors.New(fmt.Sprintf("Unknown group %d\n", id))
						}
					}
				}
			}
		}

		var b []byte
		if err == nil {
			b, err = json.Marshal(resp)
		}

		if err == nil {
			w.Write(b)
		} else {
			if reqType == "" {
				reqType = "modifying fever data"
			} else {
				reqType = "getting " + reqType + " for fever"
			}
			webfw.GetLogger(c).Print(fmt.Errorf("Error %s: %v", reqType, err))

			w.WriteHeader(http.StatusInternalServerError)
		}

	})
}
開發者ID:urandom,項目名稱:readeef,代碼行數:101,代碼來源:fever.go


注:本文中的github.com/urandom/readeef/content.User.FeedById方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。