| Project: | Activity |
| Version: | 6.x-2.x-dev |
| Component: | Miscellaneous |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
I'm not sure if this is a feature or support request, but lets start it like this.
I would like to have a activity feed with all the activity in the site. New content, comments, status updates (from facebook_status), user relationships etc. Then I want to naturally use Views to display this list with "Like" button next to each activity item.
How is this supposed to work? I have these flags to start with: like_status, like_comment and like_content. I managed to add the like link for comments and new content, but when I try to add like link for status updates, they also come visible for comments and content.
I have defined relationships in Views to each flag, but the one for facebook_status doesn't seem to work right, or I'm not using it in a right way. I'm trying to use a view of type activity, because I cannot use fbss-type view.
Comments
#1
I noticed also that the like link for the comment doesn't assign the flag to the comment, but to the node. This is because there is no Activity: Comment relationship. But still the like links for FBSS behave differently as mentioned above.
#2
This isn't related to FBSS.
Actions recorded by Activity are their own entity, and they represent other entities of assorted types. It isn't possible to have Flag links in a view that are for multiple entity types. (Well, technically it's possible, but the code to do it doesn't exist and it doesn't lend itself well to a generic solution.)
#3
The easiest way is to create a flag type for activity. And then, because Activity is the common denominator, it becomes super easy.
I should point out, that the flag type does not exist yet. you will have to create a module that provides it.
#4
Of course, creating a flag type for Activity still means that flagging an Activity action is not the same as flagging a node/comment/status. So you will have two different flag counts if you allow nodes/comments/statuses to be flagged when they are viewed directly.
#5
subscribing .. very interested to be able to flag eg 'like' on activity
#6
Yeah, as Ice pointed, flagging activity is not the same as flagging content. I think it would be more important to flag content so that for example liking could also affect the node's or comment's popularity.
Currently I'm using Views to list statuses and flagging them works ok. Then I'm trying to use Activity + Views to list other activity and it would be nice at least to be able to give new content (nodes and comments) flags.
#7
Well as you already figured out, the way to do it like you want is to create relationships. #794532: Relationship to comments for Views
#8
I don't think you are going to want to do this. Going down this road is full of peril. First, a comment has a nid therefore, the node relationship will be active giving you a 'Flag this node' link. The User relationship will also be active, giving you a 'flag this user' link. Then with comments, you will also have the 'flag this comment' link as that will be active.
That is what hook_flag is for.
<?php
// I forget the parameters
function MY_MODULE_flag() {
if ($flag->type == 'activity') {
// Load the activity record.
if ($activity_record->type == 'comment') {
update_flag_counts('comment', $activity_record->eid);
}
elseif ($activity_record->type == 'node') {
update_flag_counts('node', $activity_record->nid);
}
}
}
?>
#9
You also probably should look into creating custom relationships to the Activity Table and the node/comment table. This relationship would say "Must be activity.type = 'node' and activity.op = 'insert'" and "Must be activity.type = 'comment' and activity.op = 'insert'"
Can't do that reliably with the Filters would have to do that with the Relationship
#10
I think it would be possible to write a specific Views field that would display a flag relevant to whatever content the activity action for that row was referencing. It would have logic similar to what Scot was suggesting in #8 and I don't think it would require any relationships. However you would have to know ahead of time what the machine names of your flags were for each flag type (which is why I said in #2 "it doesn't lend itself well to a generic solution").
#11
I'm closing this, as it can be accomplished with several one off techniques.
1.) Create specific relationships based on your flags
2.) Create specific Views Fields based on your specific flags and add the logic to handle the type of the activity -> flag type mapping
I do still happen to be a fan of creating a flag type for Activity. It lowers the barrier, making the field completely generic and providing a way to add your business logic (i.e. affecting popularity) via hook_flag. As a general solution / idea I think its a good thing.
#12
I agree, Scott. I'm willing to help test if you write a flag type for Activity and need help -- just drop me a line on IRC or Twitter or email.
#13
I too would really like the ability to flag activity feeds, I don't need any of the complexity of linking those flags to their respective nodes/ statuses.
#14
Im willing to sponsor $30 for this if someone could complete it in a week. I don't need the whole bells and whistles, just the ability to flag activity items (as well as count them). The flags do not need to affect the original node or comments etc.
You will need to be able to flag all activity types such as new/updated nodes and comments and facebook statuses alike to be displayed in views.
I realise this is short notice but from what I can tell, just flagging activity (and not their respective nodes etc) should not be a major job.
#15
Actually, on second thought, I'm having too many issues trying to have node activies and FBSS activities in the same view so Im ditching the design and going to try a different design.
#16
Hi oxford-dev,
Are you considering splitting the Activity and FBSS's into 2 views? I'm also contemplating that, mostly for the 'like' on FBSS and not being able to flag activity.
If that's you plan, let me know if you come across any issues ..
#17
As others have already said it would be great to have a flag on all activity types that actually incremented the flag for the piece of content that the activity record referenced. It's probably possible, but the back-end is so complicated that I would implement it in its own module. I would estimate 10-15 hours.
Just flagging activity without updating the referenced content's flags is relatively easy -- probably 1-2 hours.
Unfortunately I don't have the time to do either right now. In the mean time, splitting views is one option.
#18
Yeah I'm planning on splitting them into 2 different views. There just does not appear to be a way to make the 2 live in harmony right now, hopefully in the future there will.
I also think having flags that work on activity feeds and their respective nodes etc would be a great benefit, i would love that feature.
#19
Actually im changing my mind again. Even though im splitting FBSS and general activity up, I still want to display the FBSS feeds through activity, that way I don't have to install yet another module to get comments working for FBSS's.
Ice, do you think $30 would be enough for you spare 1-2 hours of your valuable time to get the basic activity flag working?
#20
Attached is a module that enables Flags on Activity records. You'll have to create the flag yourself through the Flag UI and then add it to your view by adding a Flag relationship and then the Flag field. I neglected to implement any hooks to delete flag records when their associated entities (activity records or users) were deleted, which just means you'll eventually end up with a few more database records than you need.
I will not support this module and I do not make any guarantees that it works, although I tested it briefly and it worked for me.
It took me an hour. $30 is significantly below what I would normally charge, but feel free to donate whatever amount you want if this helps you.
Cheers
#21
Thanks for that, ill be sure to leave a donation!
I've been testing and it appears to be working well, there is just one little niggly issue which in my case happens to be a big issue and that is the lack of tokens available on the flag create form. I only actually need one and that is the flag count, could you please point me in the right direction to accessing this token please? I've had a look through other modules which use flags to see if I could see what they are doing differently but I cant seem to find any such differences.
#22
Hmm. Normally the token would be [flag-FLAG_NAME-token]. It looks like that might only work if the module actually defines tokens though? In this case it would be up to the Activity module to do that. Here's an implementation (not tested):
<?php
/**
* Implementation of hook_token_list().
*/
function activity_token_list($type = 'all') {
if ($type == 'activity') {
$tokens['activity'] = array(
'user' => t('The themed name of the user on whose profile the status was posted.'),
'user-name' => t('The safe but unthemed name of the user on whose profile the status was posted.'),
'user-name-raw' => t('The name of the user on whose profile the status was posted. WARNING: raw user input.'),
'user-id' => t('The User ID of the user on whose profile the status was posted.'),
'message' => t('The safe activity message.'),
'message-raw' => t('The completely unfiltered status text. WARNING: raw user input.'),
);
$tokens['activity'] += token_get_date_token_info(t('The activity record created'), 'status-time-');
return $tokens;
}
}
/**
* Implementation of hook_token_values().
*/
function activity_token_values($type, $record = NULL, $options = array()) {
if ($type == 'activity' && !empty($record)) {
$account = user_load($record->uid);
$m = db_fetch_object(db_result("SELECT * FROM {activity_messages} WHERE amid = %d", $record->aid));
$values = array(
'user' => theme('username', $account),
'user-name' => check_plain($account->name),
'user-name-raw' => $account->name,
'user-id' => $account->uid,
'message' => check_plain($m->message);
'message-raw' => $m->message;
);
$values += token_get_date_token_values($record->created, 'created-time-');
return $values;
}
}
?>
That would have to be put in activity.module. Again, not tested, I really have no idea whether it works or whether it even fixes the problem.
Scott, any thoughts?
#23
Thanks for that I appreciate it!
I had a play around and there are a couple of issues, those 2 functions are already declared elsewhere in the file so its not happy about that, the differences between your snippet and the existing functions are quite large, they approach things differently.
Also I get an exception saying that token_get_date_token_info cannot be found.
This is very useful stuff and can only improve this effort, however its the core flag tokens that im after namely the flag count.
I tried to borrow code from flag.token.inc but to no avail.
I then looked through the FBSS code to see how then managed it but in the equivilant functions there is no clear mention of flag count.
There does seem to be something in FBSS which does not appear in Activity and that is ' function get_flag_action($content_id) ' found in facebook_status.flag.inc
Does this function need to be inserted into activity?
#24
The get_flag_action() function is the last one in activity_flag.flag.inc:
<?phpfunction get_flag_action($content_id) {
$flag_action = parent::get_flag_action($content_id);
$record = $this->fetch_content($content_id);
$flag_action->content_title = $record->message;
//There's no good place to direct the content URL.
//Just go to the owner's profile.
$flag_action->content_url = _flag_url('user/'. $record->uid);
return $flag_action;
}
?>
Weird that I missed Activity's token implementation. But Activity doesn't provide tokens for itself -- maybe that's the reason. My code (in the replace_tokens() function) assumes that there will be specific "Activity" tokens. I don't really know. But I've already spent more time than I have on this so I can't look into it right now.
#25
I've managed to get it working, the issue was that some places the flag was called 'activity' and other places it was called 'activity_flag'. By changing all references to 'flag_Activity' it now appears to be working as expected.
I've also merged the existing 2 functions from the activity module with the 2 you outlined above so that all possible tokens are listed.
<?php
function activity_token_list($type = 'all') {
if ($type == 'activity' || $type == 'all' || function_exists($type .'_activity_token_list')) {
$token_list = array();
foreach (activity_get_module_info() as $module => $info) {
if (function_exists($module .'_activity_token_list')) {
$token_list = array_merge($token_list, call_user_func($module .'_activity_token_list', $module));
}
}
$token_list['activity'] = array(
'user' => t('The themed name of the user on whose profile the status was posted.'),
'user-name' => t('The safe but unthemed name of the user on whose profile the status was posted.'),
'user-name-raw' => t('The name of the user on whose profile the status was posted. WARNING: raw user input.'),
'user-id' => t('The User ID of the user on whose profile the status was posted.'),
'message' => t('The safe activity message.'),
'message-raw' => t('The completely unfiltered status text. WARNING: raw user input.'),
);
return $token_list;
}
function activity_token_values($type, $object = NULL, $options = array()) {
$token_values = array();
foreach (activity_get_module_info() as $module => $info) {
if (function_exists($module .'_activity_token_values')) {
if ($type == $module) {
$token_values = array_merge($token_values, call_user_func($module .'_activity_token_values', $module, $object));
}
}
}
$account = user_load($object->uid);
$m = db_fetch_object(db_result("SELECT * FROM {activity_messages} WHERE amid = %d", $object->aid));
$values = array(
'user' => theme('username', $account),
'user-name' => check_plain($account->name),
'user-name-raw' => $account->name,
'user-id' => $account->uid,
'message' => check_plain($m->message),
'message-raw' => $m->message,
);
$token_values = array_merge($token_values, $values);
return $token_values;
}
?>
Thanks for your help
#26
Here is the updated module:
#27
Sweet.
One day I'll have to work on making this comprehensive, so the flags actually flag the content they're associated with.
In the mean time, it's great to have this though.
#28
subscribing. Thanks so much for this Ice.
#29
subscribe