Skip to content
This repository was archived by the owner on Jun 3, 2023. It is now read-only.

Add feed page that displays recipes pertaining to users' followed tags. - #89

Open
nonsensicle wants to merge 7 commits into
masterfrom
CustomFeed
Open

Add feed page that displays recipes pertaining to users' followed tags.#89
nonsensicle wants to merge 7 commits into
masterfrom
CustomFeed

Conversation

@nonsensicle

Copy link
Copy Markdown
Contributor

Currently, these recipes cannot be sorted using a SortingMethod because a Firestore OR query cannot be constructed programmatically and thus cannot be sorted as normal queries.

…s. Currently, these recipes cannot be sorted using a SortingMethod.
List<String> followedTagIds = followedTagIds(userId);
// Query for recipes matching the followed tag Ids.
return recipesMatchingAnyTags(followedTagIds);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to do sorting, you could add some code like this (does sort on our end without firestore's help):

switch (sortingMethod) {
      case TOP:
        System.out.println("Sorting by: TOP");
        Collections.sort(
            results, Collections.reverseOrder(Comparator.comparingLong(RecipeMetadata::getVotes)));
        break;
      case NEW:
        System.out.println("Sorting by: NEW");
        Collections.sort(results,
            Collections.reverseOrder(Comparator.comparingLong(RecipeMetadata::getTimestamp)));
        break;
    }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, getVotes and getTimestamp are simple getters I added on my branch

boolean isTagQuery = (tagIDs != null && tagIDs.length > 0 && !tagIDs[0].equals("None"));
boolean isCreatorQuery = (creatorToken != null && !creatorToken.equals("None"));
boolean isFollowedTagsQuery = (isCreatorQuery && sortingMethod == SortingMethod.TAGS);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the user wants to sort by new or top for their custom feed? I feel like we should have some other flag to determine whether it's a followedTagsQuery

break;
}
metadata.addAll(
getRecipeMetadataQuery(recipes.whereEqualTo("tagIds." + tagId, true), SortingMethod.TOP));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably not the way we want to go about doing this... considering that there's no limit on the number of recipes in each tag, eventually, the feed will consist of literally just the one tag.

Also: it might be better to have a timestamp limit rather than a hard recipe limit, so maybe change to using that?
For example, the limit might be recipes from last week for now, and later, we can think about changing that as a potential feature.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradleypickard @hari387 im not sure how hard it would be, but we could try a top of last week, top of last month, top of all time sort of thing... for now i'll hard code as Last Week since getting a lot more recipes than that is going to be significantly more complicated

@hari387 hari387 linked an issue Aug 31, 2020 that may be closed by this pull request
@nonsensicle
nonsensicle requested a review from hanpeiz September 1, 2020 23:55
try {
return followedTagsRecipes.subList(
(page * RECIPES_PER_PAGE), ((page + 1) * RECIPES_PER_PAGE));
} catch (IndexOutOfBoundsException e) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't you get this exception when you try to get the last page?

for (String tagId : tagIds) {
// Get only relevant recipes from the last week.
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.WEEK_OF_YEAR, -1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work when it is currently the first week of the year?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question -- I'll have to look into it, but I think it should

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Customizable Feed

4 participants