Challenge Displaying User Post on Other User Profile in Activity 2 View

pribeh - October 16, 2009 - 02:52
Project:Facebook-style Statuses (Microblog)
Version:6.x-2.x-dev
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:fixed
Description

Hi Ice,

Let me know if I should push this over to the Activity 2.x threads. I've setup a view utilizing Activity 2.x and Flag 2.x to display a user's activity (comments, nodes, statuses) plus that of the users they are "following" (like Twitter) on their profile page. My problem is that I can't figure out why if say user 1 posts a status on user 2's profile (using the conventional status update form like I always have) it doesn't show up on user 2's activity view (when logged in as user 2) on their profile. I've attached the view. Sorry if the answer is sitting right in front of me.

Thomas

#1

pribeh - October 16, 2009 - 02:53

Oooooops. Forgot the attachment :)

AttachmentSize
user_follow_activity.txt 7.4 KB

#2

IceCreamYou - October 16, 2009 - 04:12
Status:active» fixed

The Activity record gets assigned to the user who performed the action -- in this case, the user who posted the status1. Conventionally, it's not possible to get the listing you're asking in Activity. There is something called Realms though that's supposed to allow you to do something similar to this. Flag Friend implements a realm that's supposed to allow you to show the activity of people with whom you are friends. However, I haven't tested it, so I'm not sure if this makes it possible to provide a listing of a user's actions and the actions done to that user. Go to admin/settings/activity to enable realms.

If that doesn't work, this is really an issue for the Activity queue. The question is not specific to FBSS, but rather the question is whether it is possible to build a view of Activity messages from both actions by a certain user and actions done to that user. Another example of where this could be useful is the user reference fields for CCK, any of the modules that allow adding multiple authors to a node, PrivateMsg, or even comments on a user's node.

Let me know if you have any luck.

1Actually, since you mention it, it does kind of make more sense to have the Activity record be assigned to the user who receives the message in the case of FBSS. Maybe I'll switch that, as it would seem to solve this problem.

Also--and this is not related to the issue, but it's something for you to keep in mind--Activity stores records historically. That means if a user writes a status, the exact text of the resulting Activity message at that time will get stored into the {activity_messages} table in the database. If a user edits or deletes the status later, the Activity message will still stick around with the same text that it had originally. (The same goes for everything else too -- nodes, comments, etc. -- but it's more noticeable with FBSS because usually the Activity message contains the whole status text [which is relatively likely to be changed] as opposed to a node title for example [which usually doesn't change].)

#3

pribeh - October 16, 2009 - 13:50

I understand what you're saying ;) - I think it would make sense to set the activity (of user 1 posting status on user 2's wall) as assigned to user 2. I'm sure you're thinking of this: but would changing this make the status then not show up in user 1's own activity view? Or would (can?) both the users' have the status assigned to them?

Ya, on an aside, as for activity 2.x: I know the static nature to the activity messages is a drawback but neither Facebook nor Twitter allow editing of statuses so with Fuse (the one website of mine that hinges on your module) I'm forbidding editing of any status. Also, publicmind has decided that for our module we're developing to work with FBSS we cannot allow for user editing of the module's statuses. But then of course there's the issue of which delete handler (activity's or fbss'?) to use. Is there a way to get activity module to delete it's record of a status once a status has been deleted? Perhaps a request for Scott?

Again, off topic :), I know you seem kind of split between supporting Heartbeat and Activity 2.x right now. Both are great modules. Do you know yet which you're going to put FBSS's weight behind down the road yet, which you would recommend using with FBSS?

#4

IceCreamYou - October 16, 2009 - 21:51

Yes, changing the user who is recorded into the Activity database will just switch the user with whom you're experiencing this problem, so it wouldn't really be a solution. Like I said though, realms might cover it.

In order for Activity records to be deleted at the same time as FBSS' records, something has to keep track of the association between them. I'm not sure, but I don't think that's possible at the moment; and besides, it would require another table in the database.

You're right that I've been a little frustrated with Activity, because some of its design decisions are not particularly compatible with the nature of FBSS. However, I'm going to continue to support it as much as I can. There's no need to explicitly support Heartbeat because Heartbeat relies on Rules, so FBSS' integration with Rules means that it also works with Heartbeat (or at least, it will once the Rules integration gets fixed...).

#5

pribeh - October 20, 2009 - 20:28

I'm going to stick with simply using Flag instead of Flag_Friend because I'm only looking to offer the "follow" function to users. The switch of ownership from user 1 to user 2 (profile-owner) should work fine for me. Thanks.

#6

IceCreamYou - October 20, 2009 - 21:01
Status:fixed» postponed

Sorry, just looked into it and it's not reasonable to change the active user because Activity uses the core Trigger system. If I switched it, users could end up with odd results like showing a "You posted on [user]'s profile" message to the recipient.

I don't really understand how realms are supposed to work in Activity right now, but I've been meaning to look into that because I'm hoping it will solve some of the conceptual barriers with FBSS. Otherwise, as I said in #2,

If that doesn't work, this is really an issue for the Activity queue. The question is not specific to FBSS, but rather the question is whether it is possible to build a view of Activity messages from both actions by a certain user and actions done to that user. Another example of where this could be useful is the user reference fields for CCK, any of the modules that allow adding multiple authors to a node, PrivateMsg, or even comments on a user's node.

#7

pribeh - October 20, 2009 - 21:23

Great, thanks Ice. I'll bring this up in the activity queue.

#8

Scott Reynolds - October 20, 2009 - 22:44

Ya so this is must def doable with the Access side of things (realms).

In fact, you example of

even comments on a user's node

Is part of Activity2 core. See comment.activity.inc.

So just grab a hold of the Access side of the API (ref the Flag issue, Flag friend provides this, User Relationship patch).

#9

Scott Reynolds - October 20, 2009 - 22:45

#10

IceCreamYou - October 20, 2009 - 23:11

Okay good, I was hoping for that. Thanks Scott. It'll be at least a week before I have time to look into this again but I will see what I can do when I get a chance.

#11

pribeh - October 21, 2009 - 00:30

Wicked - thanks.

#12

IceCreamYou - November 13, 2009 - 07:08
Status:postponed» active

From what I understand from reading the code in Activity itself, comment.activity.inc, the Flag Friend integration with Activity, and DEVELOPER.txt, grants and realms in Activity have to do with access to Activity records. What we're trying to do here is not related to access -- we want every user to be able to see all the activity that was directed to one user. In other words, there is an implied "recipient" of the actions here -- that is, there are two users involved, the "acting" user and the "acted upon" user -- and we want anyone to be able to see all the activity records for a given user regardless of whether the user in question was acting or acted upon.

Let's switch the analogy to comments for a second to see if that clarifies things.

Bob and Joe comment on a node that Susie created. Susie also comments on her own node. Susie and George comment on a node that Alex created. David is not friends with any of them, and has never posted a node or a comment. David goes to a view showing Susie's activity. What David expects to see is this:

Bob commented on Susie's node.
Joe commented on Susie's node.
Susie commented on her own node.
Susie commented on Alex's node.

To switch back to status updates, comments become status messages and nodes become the user's "wall":

Bob wrote a message on Susie's wall.
Joe wrote a message on Susie's wall.
Susie updated her status.
Susie wrote a message on Alex's wall.

From what I can tell -- and please correct me if I'm wrong, as I may have missed something -- that is not what access/grants/realms control.

So, Scott: do you understand what I'm trying to get at here? And is there any way to do this currently?

#13

Scott Reynolds - November 19, 2009 - 18:31

So ok fine I will tell you how to build that View if you will (the comment one, the status one still can't be built yet as its missing Activity Access implementation).

The important step, is to set the context for the Activity Access system. This is done through the argument Activity Access: Activity Context User. That is used to then set it so its Susie that is the Activity Access Context user. Then David will see Susie's activity just like he expects there based on Susie's Activity Access Grants.

That argument is of course optional, if not set it defaults to the logged in user.

Hope that helps.

#14

IceCreamYou - November 19, 2009 - 21:42

@Scott, the problem is that from what I understand, for what you're describing to work, there would have to be an access grant to David. That's impractical because for each status created there would have to be an access grant for every user on the site. Is there something I'm missing here?

#15

Scott Reynolds - November 19, 2009 - 22:32

nope there is no access grant for david. You set the 'context' for the Activity Access system as Susie.

Re-read my comment, I understand completely, wouldn't build a system that foolish :-D

#16

IceCreamYou - November 21, 2009 - 21:11
Status:active» needs review

After discussion with Scott on IRC, I've just committed code that should make all this work. However, I'm having problems with my test site, so I couldn't confirm that it works beyond checking that it doesn't crash anything. If someone (pribeh?) could check it out, that would be greatly appreciated.

#17

pribeh - November 22, 2009 - 00:09

K, I'll get to this tomorrow.

#18

Scott Reynolds - November 22, 2009 - 01:53
Status:needs review» needs work

<?php
function facebook_status_activity_grants($activity, $object, $type) {
return array(
  
'facebook_status_owner' => array($object->uid),
  
'facebook_status_poster' => array($object->pid),
);
}
?>

Unfort, that won't work with all activities. Its close, and flag_friend does something very similar but that is because with Flag Friend you want to save access control for EVERY Activity. With fb status, you only want to save access records for fb status messages.

That is why this is passed in the $type.

<?php
function facebook_status_activity_grants($activity, $object, $type) {
 
$realms = array();
  if (
$type == 'fb_status') {
    
$realms['facebook_status_owner'] = array($object->uid);

    
// No need to save both if they are equal. Just takes up more disk space.
    
if ($object->pid != $object->uid) {
      
$realms['facebook_status_poster'] = array($object->pid);
     }
   );
  }
  return
$realms;
}
?>

Another example can be found in comment.activity.inc, where it saves the comment access realm when the $activity has a nid.

#19

IceCreamYou - November 22, 2009 - 02:01
Status:needs work» needs review

Nice, thanks Scott, I committed the changes.

#20

pribeh - November 23, 2009 - 03:28

Hi Ice,

I tried cloning the activity_all view changing various settings to include such filters as:

Activity Access: Allow Access to the Actor
Activity Access: Facebook_status (with both facebook_status_poster and _owner checked)

And I do not see the expected results. What else should I be, or not be, providing in the view?

Thanks

#21

IceCreamYou - November 23, 2009 - 03:34

Presumably you should be adding the Activity Access: Activity Context User argument, not filters. You might need to remove the Node access: access filter as well. Other than that I'm not sure.

#22

pribeh - November 23, 2009 - 04:41

I don't see an "Activity Access: Activity Context User" argument. I have an "Activity: User" argument turned on but without any of the filters there appears to be no specification of what goes into the feed and hence displays all activity by users. Using the Activity Access: Allow Access filter to the Actor at least narrows it down to the logged in user. The Access Flag and Comment filters do the same for those related activities. I would only assume that the Facebook_status access would do the same. Perhaps we require the assistance of activity master Scott.

#23

IceCreamYou - November 23, 2009 - 05:52

Do you have Activity Access Control enabled for FBSS at admin/settings/activity? The argument should be the only one under the group Activity Access...

#24

pribeh - November 23, 2009 - 15:37

I must need glasses. Anyway, I found the argument but for it to work for me I also need to have the Activity Acces: Facebook_status Access filter setup (with both facebook_status_poster and _owner checked) for it to work. Regardless, I'm super delighted to see it actually working. Kudos to you guys. You're amazing.

#25

IceCreamYou - November 23, 2009 - 21:04
Status:needs review» fixed

Sweet, I'm glad it's working... Activity decided to stop showing any messages at all on my dev site even though they're recorded in the database, so I still haven't personally tested this. However, I probably just accidentally screwed with some files along the way, so I think this issue qualifies as fixed.

#26

pribeh - November 23, 2009 - 22:44

Ya, I'm having some other issues with how Activity Access is working but I brought it up in a separate issue. Seems like lots of changes are being made to each release now so I wouldn't be surprised if anything breaks. Nonetheless, I'm hope it's all for the better.

 
 

Drupal is a registered trademark of Dries Buytaert.