Related objects in activity feed - getstream-io

I'm building an activity feed application, where a user can like/comments on each activity feed. I went through GetStream.io documentation and looks like I'll have to send the activity with object ids.
{
id:"ef696c12-69ab-11e4-8080-80003644b625",
actor:"User:1",
object:"Comment:12",
started_at:"2014-11-11T15:06:16+01:00",
target:"Feed:100",
time:"2014-11-11T14:06:30.494",
verb:"add"
}
User:1 and Feed:12 are the objects in my application database? Does it mean that, while retrieving activities, I'll have to hit my database to retrieve the complete feeds?
Say the Feed:12 had few likes and comments earlier from other users. How do I get the complete set of likes/comments on user timeline feed?
What if I want to customize the view, say I want to show all users (image, name, the profile like etc) along with comment with timestamp similar to FB? Do I need to send these attributes as additional parameters for each feed?
Thanks,

Yes, when you fetch a feed from Stream and we give you back these references like user:1 or comment:12, we expect that you'd "enrich" those details from your database.
Typically what our users do is track the name of the model (eg, user) and the user_id (eg, 1). When you get the feed and put it into a hash map, you'll iterate over the activities, pull out all of the actor attributes, and do a single lookup like select * from user where id in (1,3,5,6,9,12) so that you're only hitting your database one time for all user objects or all comment objects or whatever. Then, replace those activities in your hash map so now you'd have actor: <object for User 9> and any other attributes you'd need for your UI presentment.
Then do the same for other references you pass in the activity, and so on.
Things we DON'T recommend are putting in string references for things that could change on your side. For example, if you had actor: "user:ian" instead of my user_id, if I ever change my username later then things probably wouldn't work properly on your side.

Related

Avoiding duplicates in different feeds with getstream.io

Let's say I want to build a system where each user has access to a notification feed and an aggregated feed, with the following groups:
user as flat feed
hashtag as flat feed
notification as notification feed
timeline as aggregated feed
We also have the following relations:
user:b follows hashtag:a
user:b follows user:a
Now consider the following situation:
If user A posts with hashtag A, I would like user B to get an activity in its notification feed (thanks to relation 1). But I also would also like all followers of user A to see in their timeline that user A did something. Then, user B will get the activity in its notification feed, and in its timeline (because of relation 2): there is a duplicate.
Is there a way to avoid this situation ?
A naive way would be to manually filter the feed and prune the aggregated activities we do not want to see. But this of course seems non optimal.
Thank you very much!
You can use discard rules to avoid activities matching one of rule from getting added to a follower's feed.
This is usually something you use to avoid own activities from showing up in your notification feed.
Here's the link to the docs on Discard Rules:
https://getstream.io/docs/#discard-rules

How can we know ID of the document on client side

I have recently learned tutorial about restful APIs.In that, my instructor suggested me that if we want to delete any document we should pass id in the parameter of the request. But now I am confused How do we handle this implementation on the client side.I mean how can even the programmer on the front side could be aware of that particular document ID. Does he need to go to the database each time?
Common practice for accessing a record in db is to use its unique identifier, to get or update or delete the record.
On the client side (if you mean user interface) when user wants to delete a document, he/she must see the document somewhere in the interface. Suppose a page with a table containing a list of all (for instance) books in the db. On each row, you have book title and author's name and the id of the book document in the db.
So you can use that id to call the delete rest API.
In a nutshell, when you want to delete something you must have got it from db to simply see it, so the id is at your hand.
When you want to delete a some doc from the database you need to get all documents to the front end to see what do we need to do to this data right ?
Imagine any database GUI that u have worked with..
let's say phpmyadmin when using mysqli
in that case you have php mydamin's GUI so that u can clearly see what are the tables and how things persist in the database. you need to see that in order for you to make decision
. Like that you will need to bring at least a portion of that data to the front end for user to see it and choose what portion of data the user want's to make changes or delete.
so when we have a set of data in the front end like a list, if a user select one item from that list the id or the name of that item can be send to the server side and make the task if the user wishes to do
that's why you need an Id or a identification field of that particular data..

A way to mark notification as seen without reading the notification feed?

My situation is the following:
I'm using the stream-js library. I add entries to the notification feeds of users for certain events - comments, follows, etc. After I write to their feed I also send a push notification to that user's device.
If a user clicks on a push notification I want to be able to mark the corresponding activity as seen. There's currently no way to do that since the add or addToMany calls do not return the ids of the added activities for me to send in the notification payload.
Ideally I'd want a way to mark a notification feed item as seen either by an activity group id or by some other unique id (or the foreignId). Is there a way to do that? If not, what is the alternative?
Two parts to this answer:
Getting the ID of an activity that you just added
The addActivity call in the various Stream client libraries (I'm using stream-js in this case) will return back the created activity, which should include the activity ID. Response looks something like this:
{
actor: 'ken',
duration: '9.65ms',
foreign_id: '',
id: '8b5d69a9-8b73-11e8-98ab-12cb9e7b86a4',
object: 'some-object',
origin: null,
target: '',
time: '2018-07-19T16:48:21.045496',
verb: 'add-activity'
}
Marking notification feed items as seen or read
The way to mark a notification feed item as seen or read is a little funky - first, you get the feed, like you would normally do, but you'll also pass in the mark_seen or mark_read options. (true will mark all items as seen or read, and an array of activity group IDs will mark only those items.)
From that call, the notification feed will be returned without the items marked as seen or read - but the next call to retrieve the notification feed will have the items marked accordingly.
More docs on that here: https://getstream.io/docs/flat_feeds/#notification_feeds
activity ID --> activity group ID
You might have noticed that you get the activity ID when adding the activity, but you need to pass in the activity group ID when marking items seen or read.
All notification feeds are actually aggregated feeds as well - by default, the aggregation format that they use is just the activity ID, which means that there will be only one activity per activity group, and the activity group ID will be the same as the activity ID. So, you can just use the activity ID returned by the addActivity call to get the notification feed and mark that activity group as seen or read.
If you're not using the default aggregation format (e.g., the activity group ID is not the same as the activity ID), then you'll likely have to retrieve the notification feed and grab the necessary activity group ID from there.

How to perform these operations on entity group

In my app a user has friends. A user can send send requests and confirm friends (marked by the status attribute) and can delete friends. A user can only have X number of friends with X number of pending friends. To store this I have a Kind which doesn't exists , then there is a child Entity called Friends. Looks like this:
Friends
-Key((NonExistantKindParent,my_username), friends_username)
-status
-created_date
The key consists an ancestor which does exists, and the id is the user's username. The children entities will be the all the friends of that user. As a result of this each friendship will be stored twice, once for friend1 and again once for friend2. They are in entity groups so that they can be strongly consistent and I can perform transactions (for example if a user adds a friend it needs to write to both user who requested the friendship and the requestee friend). There are much more operations I need, but I am trying to understand how to do the following in which then I can apply that knowledge to other operations I need:
To get all of user's friends order by the date they were created (only username of friend is needed).
To get all of user's confirmed friends (status = 'confirmed').
Reading the docs at: https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.30.3/datastore/query?method=select I am confused how to query entitiy groups. For a couple of those queries I need to apply a property filter and an ancestor filter it looks like but am unsure how? If I needed to just query a non-entity group the docs are quite useful.
A property filter is applied using query#filter, and an ancestor query is set with query#hasAncestor.

Sitecore Custom User Profile - where is it stored how can it be queried

I have created a custom User profile template and object in the core database in Sitecore (as per the Security API Cookbook).
I can select this programmatically (as per the Security API Cookbook) so that my extranet users have an extended profile, that covers all the usual suspects (Address, phone, email format etc.)
However, where is this data stored? And how do I access it if I want to query the database to return a subset of users based on this profile data.
A typical requirement for an extranet member system is to extract a list of users to contact either in an email or a phone type campaign. Can this be done with the Sitecore membership system?
UPDATE>
I'm going to take a guess and say the profile data is stored in aspnet_Profile.PropertyValuesBinary .. which would make it nigh on impossible to query and not suited to my purpose. That is unfortunate. So to extend my question, if that is the case, is it possible to get Sitecore to store those values in the text field so they are searchable?
The standard Microsoft implementation of the SqlProfileProvider (which is used in Sitecore by default) stores the user profile information in the aspnet_Profile table. All the properties are serialized into the PropertyNames / PropertyValuesString columns. The PropertyValuesBinary is used to store the binary data (images). You can find more details if you look at the code of System.Web.Profile.SqlProfileProvider, SetPropertyValues method.
Next, all the custom properties you define in the user profile, are serialized to the SerializedData property of the Profile class, and it is again serialized to the PropertyNames / PropertyValuesString columns like any other property.
Also, couple of properties are stored in aspnet_Membership table (for some reason) - Email and Comment.
So, if you are going to query the users by Email, you can use FindUsersByEmail method of MembershipProvider. Otherwise, if you plan to filter by another property value, I suppose, you'll have to get all users and filter the obtained collection.
Hope this helps.
I faced this exact problem last week, didn't come up with a permanent solution, but to solve my particular issue, I wrote a little helper page and added it as a Sitecore application to be accessed from the CMS interface. All it did was query all users, and determine if they had any of like 5-6 profile properties assigned.
var userList = Sitecore.Security.Accounts.UserManager.GetUsers();
That is the relevant line to grab the users, it returns Sitecore.Common.IFilterable
So if you need to do something where you're grabbing profile info from all users, you cn do something like this:
foreach (Sitecore.Security.Accounts.User user in userList)
{
Sitecore.Security.UserProfile profile = user.Profile;
string whatever = profile["Whatever"];
//add whatever to a list or something
}
This worked out very well for my purposes, but I don't know how feasible it will be in your situation.

Resources