Handle viewer engagement flags0:00
The next detail that we need to focus on are the queries because as it is right now, they don't show whether or not the viewing profile has liked or reposted them. So let's do that. Now, this isn't going to be as straightforward as I would like because these are pages that anyone can view. If someone is signed in, then we need to be sure that we load the hasLight and the hasReposted flags for the viewing profile.
that we load the hasLight and the hasReposted flags for the viewing profile. But if no one is signed in, well we don't need to show that information, but we still need those flags. So what I want to do then is something like what we did with the timeline query, so that if we are going to show a Post and the thread of that Post, maybe we would do something like this to where we have postThreadQuery. Then we could say that we want it for the given post.
thread query. Then we could say that we want it for the given Post with the given Viewer, but the Viewer might not be signed in. In which case we would take that into account so that in this particular case we would have the Post and then we would, you know, send that to the view. That of course, means that we need to extract our current code into one of these query classes, but that's easy enough to do.
Create PostThreadQuery1:15
to extract our current code into one of these query classes, but that's easy enough to do. So let's copy our timelineQuery.php file and let's just paste it right here inside of the Querys folder and we'll call it PostThreadQuery. Now of course, the information that this is going to work on is gonna be a little bit different because this is for a single post that we already have. So we will have a private $post and we'll call it post. Then we'll say that we may
So we will have a private post and we'll call it post. Then we'll say that we may or may not have a profile to view it, in which case we have that four method. So that we will have profile, not profile, we'll have posts post profile viewer so that we can pass that information in. And then when it comes to the rest of this class, you know, we don't need to page an eight. We don't need to get, we don't really even need a
we don't need to page an eight. We don't need to get, we don't really even need a base query here. So what we'll do is we'll rename this to just load so that inside of the controller we will do this. We'll call load and that will give us all of the loaded information for the Post so that we can pass it on to the view. And of course we're gonna need to get rid of just about everything here,
And of course we're gonna need to get rid of just about everything here, but then we don't need the normalized method because there's nothing to normalize. And the reason why there's nothing to normalize is because it doesn't matter what post we are viewing, this is the top level post. So if it's just a normal post that was created or a reply or a quoted repost, you know, those are all top level. But when it comes to a, a pure repost, you know,
or a quoted repost, you know, those are all top level. But when it comes to a, a pure repost, you know, the only id that we really know is that of the original post. So what we are viewing is the original post that was reposted. So we don't have to normalize anything. The post that we are working with is the actual post that we are working with. So when it comes to load, this is going to return our post.
that we are working with. So when it comes to load, this is going to return our Post so that then we can just take our code from the PostController and we will use that as our starting point so that inside of the load method, we'll just paste that in and there we go. We start loading that. Now of course this is now this Post, in which case we need to return this Post. And now we just need to make our modifications here so
Avoid branching with viewerId3:26
to return this post. And now we just need to make our modifications here so that we load all of the engagement data that we need. Now we can approach this in a couple of different ways. The, the first and most obvious way is to just kind of branch our code, which of course would naturally work, but it also kind of complicates things because then we, well depending upon how we branch it, we could use when methods so that when we have a viewerId, then we would do, you know,
we could use when methods so that when we have a viewerId, then we would do, you know, this certain set of queries and if not, then we would do this other set of queries. You know, what if we did something like this though? So that's, there's no branching. Uh, it's just kind of simple. So that's, we'll say that we have a viewerId based upon if we have a viewer, but if not, then we'll just use the value of 0.
based upon if we have a viewer, but if not, then we'll just use the value of 0 because we aren't going to have a profile with an idea of 0. So this gives us the opportunity so that we still perform the same database queries, but now that viewer idea is 0. You know, it's not going to load any extra information there, but it's still going to set the flags that we need. And this way we don't have to branch our code.
there, but it's still going to set the flags that we need. And this way we don't have to branch our code and that sounds great. So this is what we're gonna do and when we need to load our data, we still load our replies with count. But here we can add the withExists and we want the likes as hasLiked. And you know what, we could type all of that out, but let's just lift it from what we currently have.
And you know what, we could type all of that out, but let's just lift it from what we currently have. So likes as hasLiked where the profileId and in this case we aren't going to use the viewerId. We are going to use the viewerId variable. And then we would do the same thing for reposts, as hasReposted where the profileId is the viewerId. So that's gonna work there. We will need this again because we then have with followed
We will need this again because we then have with followed by profile, parents, profile, then we have the replies with the count. Then we need our withExists once again, so that we can also include the profile and parent profile and oldest. And then we will load the count and we will load existsWith, with, you guessed it, the same information that we have.
and we will load exists with, you guessed it, the same information that we have. And that will load all of the likes and the reposts or at least it will load the hasLiked and hasReposted regardless. So that's now all we need is a use statement for this query. And we of course need to make sure that this actually works. So in our timeline, let's find a Post where we have either liked or we have reposted because we will view the page for that Post.
Test signed-out post view6:09
where we have either liked or we have reposted because we will view the page for that post. Here's one right here. So if we navigate to this post, we should see that we did repost it and I believe there's another one here to where we liked it. So let's just find that I have to scroll for days I think. And eventually we find one. There it is. Let's take a look at that page. And sure enough, we see the like, but let's also look at this from the perspective of a User
And sure enough, we see the like, but let's also look at this from the perspective of a User that is not signed in. We should hopefully still see while we see an internal server error. And that is because of the reply form and that's because we are currently showing the reply form on every Post. So let's open up the Post component. Let's find the XReplyForm.
So let's open up the Post component. Let's find the XReply form and let's comment that out so that if we hop back to the browser with no cookies, then we can see we have our post and nothing is lit up. We don't have any other errors and so therefore we can be sure that this is working as it should and that's great. But we have other queries that we need to fix. The next being the query for the profile page, this is so
Build ProfilePageQuery7:14
But we have other queries that we need to fix. The next being the query for the profile page, this is so that if we go to a profile page, uh, we shouldn't get a 404. Looks like that there's a trailing curly brace. So again, we have details that we need to fix and that is probably inside of the Post component. So let's open that up again and let's see where that link is created. Uh, let's see. I believe it's right here.
and let's see where that link is created. Uh, let's see. I believe it's right here. Profile, yes, there's that trailing curly brace. So with that fixed, we can go to someone's profile and we want to display these posts, but we want to use a Query class to do that. So that's, we can have posts equals, and we'll call it ProfilePageQuery. And it will be kind of similar to what we just did for the Post.
And it will be kind of similar to what we just did for the Post. In that we'll have a four method we'll pass in the profile that we want to look at. Then we will pass in the profile of the viewer. If there is one, then we will get to those posts so that we can display them, which means let's take our timeline query, that's copy and paste. It will change the name to profilePageQuery.
that's copy and paste. It will change the name to profilePageQuery. And this is going to be a little similar. And that's now we will have two profiles. So we have a profile which, uh, let's call this subject. Then we will have our viewer, which may or may not exist. We will have this four method so that we can have profile subject and then profile viewers so that we can then pass that information to the constructor. And in this particular case, we do need page eight.
that information to the constructor. And in this particular case, we do need page eight. We do need to get, and we will need to normalize this so that our base query is gonna be a little bit different. So we still want to return our posts, but if we take a look at the ProfileController, we can grab this, we'll cut it out, and then we will add a use statement for our ProfilePageQuery, which
and then we will add a use statement for our Profile page query, which is not showing up. Maybe it will now. Nope. Okay, we'll come back to that. Alright, so our base query, we will fetch our Post where they were made by this subjectId. We don't want in the replies we want with repostOf, but this is where we will need to include some extra things because yes, we do want to include the count, but we also want with the Profile so
because yes, we do want to include the count, but we also want with the profile so that then we get the counts once again. But then we have our withExists, in which case it's going to be exactly like what we have inside of our timeline query. So let's just copy that and we will paste that in. We want to get the latest, but we don't want to get, we want whatever's going to call or use this query to do that.
we want whatever's going to call or use this query to do that. Now the viewerId, we need to do exactly what we did in the other query class so that we will have viewerId is equal to this viewerId or it's zero. And then we can use this viewerId variable where we get the likes and the reposts. And that's the only place that we need to do that. So that then everything is normalized.
And that's the only place that we need to do that. So that then everything is normalized. And yeah, that should be that. So inside of our ProfileController, we should be able, well, it's still not gonna let us, so let's use app()->make('queries.profile'). Oh, that's why never changed the name of the class. That's kind of important to do. So, um, yeah, we changed the name of that class so that then we can use that query.
So, um, yeah, we changed the name of that class so that then we can use that query and everything should work there so that if we take a look at the profile, uh, here we can see the like is being done. Uh, there's also a repost gave her one. So if we find the post that starts with, well, I, I guess we didn't see that, but we can see that, you know, our engagement is being loaded here. So that is good.
Add ProfileWithRepliesQuery11:18
our engagement is being loaded here. So that is good. And if we navigate to the profile for a User that is not signed in, everything still works as it should. So now we just need to do the same thing for the replies on the profile page. So that we'll have profile with replies, query, and it's gonna be almost exactly the same. So we could just copy that, paste that there, and we just need to make that work.
So we could just copy that, paste that there, and we just need to make that work. Of course, we need to change the name of this to profileWithRepliesQuery, in which case, let's take the profilePageQuery, let's copy and paste that. Let's change the name to profileWithRepliesQuery. And we of course need to change the name because I don't wanna make that mistake again.
And we of course need to change the name because I don't wanna make that mistake again. But once again, we have the Profile subject. Then we may or may not have the ViewerProfile. We have the four method, page eight, everything is set up except for the base query. So we just need to grab what we have here and we want to use that inside of our new Query class. Let's get a use statement for that new ProfileWithRepliesQuery.
Let's get a use statement for that new Profile with Replies, query. And then our base query is going to resemble almost exactly the same. The main difference is going to start right here where we start pulling in all the other information such as the repost of just like we did previously. We want with count, but we also want with the profile, then we want the repost of profile, the parentProfile,
but we also want with the profile, then we want the repost of profile, the parent profile, then the replies. But of course we don't have profile here. We have this subject. Then we get our counts and after our counts we should get our likes and reposted. So let's just copy what we have and we will paste that in so that then we'll get the latest, we return the builder
and we will paste that in so that then we'll get the latest, we return the builder and everything should work like it did before. Let's be sure that while we have some profiles here to where it should be this subject, the same right here. And I believe that's it. So if we take a look at the withReplies page, if we scroll down far enough, we see where our signed in Profile has interacted with a Post, here's another instance.
where our signed in profile has interacted with a post, here's another instance. But for the user that has not signed in, we still see the posts and we still see the counts, but we don't have any engagement and that's exactly as it should be. Well, I think we've reached a point to where we can kind of call this done. I don't wanna call it done. I'm one of those people that I could just keep going and going.
I don't wanna call it done. I'm one of those people that I could just keep going and going. I can find things that need to be fixed or things that need to be re-implemented or little details that need to be, you know, done. But I think it's time that we just throw this over to Jeffrey.
