Retrieving a post's likes - getstream-io

In my application, I have a 'user_post' feed which is responsible for storing the posts of a user. I would like a way to retrieve the likes of each individual post.
If I added a feed called 'post_like' I could store the likes of each post in their own feed. Is this approach efficient?

I'd suggest using a notification feed for that, not a flat feed. Set the verb to 'like' or whatever is appropriate for your app, and the actor is the user who 'liked' the original activity. When you call the user's notification feed, you'll get a list of all users who liked it.
If you store the likes in your own database and send the like to us with a foreign ID then you can always remove the activity later if they 'un-like' something afterward.

Related

What is the best way to add a user feed to his own timeline?

I would like to build an Instagram-like social app, where on the user timeline, you also have his own activities displayed. My first thought was to follow his own user feed but from what I read in this blog post: https://getstream.io/blog/best-practices-for-instagram-style-feeds/
We recommend blocking a user's timeline feed from following their own user feed
Can someone explain why it would be a bad practice ? How could I implement my use case if that is the case ?
Thanks !
Looking at this myself. I think the logic they describe is incorrect. The full statement in context make a little more sense in terms of what I think they mean.
We recommend blocking a user's timeline feed from following their own
user feed, and also blocking users from seeing/following another
user's timeline feed.
The first part of the sentence I believe is backwards. What I think it should says is that the "user" feed should be blocked from following the "timeline" feed. The user feed should just contain actions that the user performed, so it shouldn't contain data from the timeline feed. But if you want the user's activities to appear in the timeline feed than it seems to me that you should definetly make the user's timeline feed follow thier user feed, and prevent the user's timeline feed from unfollowing their own user feed.
The second part that says you should block users from following another user's timeline feed. I believe this is correct because the timeline feed is a series of peronalised items for an individual user. It doesn't make sense to follow another user's timeline feed.
This is how I have implemented my logic and it seems to be working so far, but if I come across any issues with it I'll come back here and update this answer.

Getting a list of BuildFire plugin users from the Widget side

I am developing a plugin that allows the user the post content that I am storing in an object in publicData. To identify the user that posted the data, I am storing the _id that is returned from buildfire.auth.getCurrentUser() in that publicData object along with the content of the post.
Is there a way I can access a list of the users of my plugin, then iterate through that to find the user with the corresponding _id? A list of the users of my plugin must exist somewhere, I just do not know how to/if I can access it.
Any help on this would be greatly appreciated!
I would recommend caching the user object's nonsensitive data. Remember, you have a bit more access to the logged-in user over fetching another user profile using the user id. https://github.com/BuildFire/sdk/wiki/How-to-use-Auth#buildfireauth-getuserprofileoptionscallback
Since the user profile picture URL is really an API, you don't have to worry about the user changing it since it will always return the latest. The other property I recommend you cache is the Display name (not the first name and last name) since that rarely changes as well. This way your performance wont suffer and you can do a lazy fetch for a distinct list of user ids an update them as needed. KNowing most wont need an UI updates since nothing changed

Update object info for old post

I am sending user id(stored in our own DB) as actor while posting activity on getstream. In object field I am sending other info of user such as name/dob etc. which are in our database too.
Suppose some one updates the user info e.g. name in our application, the object will still have old information in the post. How can this scenario be handled in best possible way?
All activities stored in Getstream are normalized, thus there is no way for you to update usernames stored within activities. Best practice is to not store data directly in the Getstream activity but store a reference to the data inside your own database (as you are doing right now for the actor field).
{
"actor": "user:$USER_ID"
"object": "post:$POST_ID"
}
Where $USER_ID is the id of the user in you local database and $POST_ID is the id of the post (this can be any sort of data e.g. comment, post, like) in your local database). You are also allowed to store extra (custom) fields on the Getstream API.
When you use one of Getstream's integration packages you get this functionality for free. You could have a look at these packages to see how they handle this.

How to remove activity from multiple feeds?

I'm using notification feeds where users get a notification when other users add replies into a forum thread they are part of.
I'd like to know how I can remove activities from all feeds when the reply is deleted?
I can't seem to find any information about that. The examples show how I can remove an activity from one users feed. But I don't necessarily know all the users that might have the activity on their notifications feed.
Or is there a way to get a list of notification feeds that contain activities with a foreign id?
When you delete an activity from a feed, a delete is propagated to every feed that received that activity via follow relationship or to field. In your example, if you delete the activity from the "origin" feed you should be OK. If that's not the case you should probably expand your question with more detail.
Since you mentioned it: deletes by foreign_id allow you to delete all activities from one feed that share the same foreign_id value. For example: say that you have many activities in a feed with foreign_id "post:42" and you want to delete them all in once, you can perform a delete on foreign_id="post:42".

Efficient way to read+write data from CouchDB

I am implementing an application that includes a user who logs in to access a document stored in a hosted CouchDB store. The user provides their credentials to the app, and once the app authenticates them, the app then has two jobs:
Get the Document ID associated with that user's data
Update the "lastOpened" value stored in that document
I am having to do those two things in a way that seems rather inefficient: I read a View which maps the app's user identifier (their email address in this case) to their Document ID. Once I have the Document ID (and have added it to the session for later use) I then have to request the Document, uptick the "lastOpened" value, then save the Document back to the store.
That looks like 3 trips to the database to me: 1. Get the Document ID from the View, 2. Get the Document, using that ID, 3. Save the updated Document.
Is there anyway to reduce that work to fewer database trips?
If you can change the document structure, you could use the user's login name as the document ID. That way, you don't have to use a view. Using update handlers, you could even do all the work in one request.
That looks like 3 trips to the database to me: 1. Get the Document ID from the View, 2. Get the Document, using that ID, 3. Save the updated Document.
Is there anyway to reduce that work to fewer database trips?
You can fetch document from a view by adding "?include_docs=true" query parameter in request. So two steps instead of three.

Resources