With the new direction, we have put the comments on the way side first to get the stuff running. Attached patches install the comment table just like in the 1.0 release and the JS and the form does much the same thing as 1.0.

Of course, the major difference is here we are doing it via Views. And so it begs the question, should this be a field in Views or should it be a style plugin?

The advantage to doing a style plugin is that you can control the view cleaner. Adjust how the fields are laid on on the screen. And it opens up theming possibilities.

On the other hand, is it really needed? Does it really add anything? Im not so sure.

For displaying see #391740: Need to display comments to activities

Comments

sirkitree’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
sirkitree’s picture

Category: task » feature
Status: Needs review » Postponed

Postponed until we make sure that we're actually on the right track here. Let's get a solid framework down first and then start in on these features.

liliplanet’s picture

Is there perhaps any update on this pls? Have tried the patch, but unfortunately not happening :)

alippai’s picture

I've a working activty_comments module, I'll post it here, when I finish it - but I have to talk about this with sirkitree.

sirkitree’s picture

Yes there have been many changes to the module since this original patch was made which is why I'm sure it applies no longer. If anyone has updated code that applied to the latest dev that would be most appreciated.

alippai’s picture

Assigned: Scott Reynolds » alippai
Status: Postponed » Needs work
StatusFileSize
new2.93 KB

initial commit, only for review

alippai’s picture

StatusFileSize
new3.01 KB

added doxygen, next step is the default view code

liliplanet’s picture

Hi alippai,

So excited, thank you. Alippai, installed and added 'Activity comments: Comment text' to the view. What I'm perhaps missing is the css in the activity views, so that users can add a comment?

Look forward to your updates :)

Lilian

alippai’s picture

StatusFileSize
new4.37 KB

added the default view and @todo comments

alippai’s picture

Liliplanet: this is still an alpha, or pre-alpha module which will add comment functionality (like on Facebook) to the activity module. I've attached a default view in comment #9, you can try it, but it's completely untested. I've more projects to work on today, so I'm slow now, maybe tomorrow I can work more quickly.

liliplanet’s picture

Looking forward, thank you Alippai!

alippai’s picture

better and more flexible views integration coming today

alippai’s picture

Status: Needs work » Needs review
StatusFileSize
new7.99 KB
new7.99 KB

So here is a better solution, it's uncompleted, but sirkitree you can see that I've changed the views integration from style plugins to fields. I don't know how to fix it, maybe we don't need to fix it, but now there is db_query call in pre_render.

This code needs review only by sirkitree or who wants to help with designing the db and the code.

liliplanet’s picture

Hi,

So excited! Testing .. and form shows fine on view. When I add a comment ..

receive following error: "user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE 60 = unsupported type for db_type_placeholder' at line 1 query: UPDATE activity SET WHERE 60 = unsupported type for db_type_placeholder in /Users/local/includes/common.inc on line 3436.

This will be a fabulous enhancement, thank you!

alippai’s picture

more work, there are now new fields, works only with js enabled

alippai’s picture

StatusFileSize
new10.48 KB

missed the attachment

Scott Reynolds’s picture

Status: Needs review » Needs work

Comments:
1.) remove all JavaScript and use AHAH (http://drupal.org/node/331941 and http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....)

$form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('add'),
    '#ahah' => array(
      'path' => 'activity/comments/insert',
      'wrapper' => 'activity_comments-' . $aid,
      'method' => 'replace',
      'effect' => 'fade',
    ),
    '#submit' => array('activity_comments_form_submit'),
  );

and

/**
 * Insert comments menu callback.
 */
function activity_comments_comment_insert() {
  drupal_set_message('go');
  // We're starting in step #3, preparing for #4.
  $form_state = array('storage' => NULL, 'submitted' => FALSE);
  $form_build_id = $_POST['form_build_id'];
  // Step #4.
  $form = form_get_cache($form_build_id, $form_state);

  // Preparing for #5.
  $args = $form['#parameters'];
  $form_id = array_shift($args);
  $form_state['post'] = $form['#post'] = $_POST;
  $form['#programmed'] = $form['#redirect'] = FALSE;

  // Step #5.
  drupal_process_form($form_id, $form, $form_state);
  $limit = $form_state['values']['limit']; // The form item will have a '#type' => 'value' called limit for this purpose
  // Step #9.
  $output = theme('status_messages') . theme('activity_comments_comments', $comments, $limit); // @TODO add in all comments for this activity here

  // Final rendering callback.
  drupal_json(array('status' => TRUE, 'data' => $output));
}

2.) theme function for all comments needs to render ALL the comments and those that are below the limit need to be hidden by CSS. Add a simple link to then show All

/**
 * Views row style theme function for embed comments display.
 * 
 * Don't add a wrapper around the comments, it breaks the AJAX functionality.
 * 
 * @todo move to tpl.php file?!
 */
function theme_activity_comments_comments($comments = array(), $limit) {
  $items = array();
  $count = 0;
  foreach($comments as $comment) {
    if (++$count > $limit) {
      theme('activity_comments_comment', $comment, TRUE); // where TRUE tells the activity_comments_comment theme function to hide it
    }
    else { 
      $items[] = theme('activity_comments_comment', $comment);
    }
  }
  return theme('item_list', $items) . l('show all', '#', array('html' => TRUE, 'attributes' => array('class' => 'activity-comments-show-all'))));
}

Write a JS file that uses Drupal.behaviors instead of document.ready(), and attach to show all a click function.

Drupal.behaviors.activityCommentsShowAll = function (context) {
  $('.activity-comments-show-all:not(activity-comments-show-all-processed)'.click( 
  // show the rest and flip the direction so next click will hide them
).addclass('activity-comments-show-all-processed');
};

3.) Remove drupal_add_js('jquery.forms') this is added by the expand_ahah process function, no need for it in the handler.

Ok so there is some of the issues I see. Not all code here will work as written, i have written them only here in this textarea not in an IDE. There are other issues as well with things like code style http://drupal.org/coding-standards

But this should get you started again.

Scott Reynolds’s picture

Status: Needs work » Needs review
StatusFileSize
new36.82 KB

Ok so pretty excited about this. i reworked it and I think i got it setup so it should be easy to extend. I compressed the 3 fields (activity all link, comment form, and the comment listing) into one field. Its a form with a bunch of markup in it. Using form_alters you should be able to move things around pretty easily.

It also works without JS (even the CSS rules handle that case as well).

Uses AHAH for the form submission. Lil bit of JS to handle the Default text (focus, blur events) and the 'show all' link.

What I need help with is getting rid of the damn list styling...

.item-list ul.activity-comment-list {
  list-style: none;
  margin: 0.35em 0 0 0.5em;
}

that didn't work. And any other styling, Im pretty blah at CSS.

Heres a screen shot
http://skitch.com/supermanscott/ndcc5/scotts-contrib

Scott Reynolds’s picture

StatusFileSize
new36.82 KB

Forgot to add in the additional permission to the form wrapper so anon users for instance couldn't post if they weren't allowed via admin/user/permissions

Scott Reynolds’s picture

I also like it better without the form label ('#title')

$form['activity_form_items']['activity_comment'] = array(
    '#type' => 'textfield',
    '#maxlength' => 250,
    '#size' => 32,
    '#default_value' => t('Write a comment'),
    '#attributes' => array('class' => 'activity-comment-text'),
  );
pribeh’s picture

Hey Scott and alippai, great work this. I'm going to try this on a fresh copy of my site but I'm getting the following when trying to post a comment:

warning: array_shift() [function.array-shift]: The argument should be an array in /Users/thomascermak/Sites/londonfuse/sites/all/modules/activity_comments/activity_comments.module on line 71.
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, '' was given in /Users/thomascermak/Sites/londonfuse/includes/form.inc on line 366.

Again, I'm going to try this on a fresh install.

Scott Reynolds’s picture

Assigned: alippai » Scott Reynolds

That has to do with the AHAH stuff and its pretty strange. It basically is telling us that Drupal.ahah didn't post the form values properly.

Have you used a previous version of this before?

Are you sure the activity_comments.js is the proper one? As the old JS file grab the form button and posted other values that wouldn't match what AHAH posts. And because I didn't change the menu path, it will cause problems. Problems just like this.

pribeh’s picture

Will check all these things later today. Thanks Scott.

Scott Reynolds’s picture

StatusFileSize
new37.57 KB

Ok spent some more time on this today

http://skitch.com/supermanscott/ndi5i/activity-comments

Improvements / Fixes

  1. AHAH doesn't mess up the html structure :-D
  2. Made sure the form submit buttons always had unique id that was reproducible on each rendering (fixed AHAH not attaching after adding a comment)
  3. Moved Show All up to above the comment lists
  4. Added the count of the comments to the show all title (says Show all X comments)
  5. made activity_comments_comment into a template file
  6. fixed security hole in theme layer by check_plain the comment body
  7. removed ability to expand collapse. Facebook doesn't do this and i figure they had some usability testing for this. Also made the JS simpler which I like
  8. improved default styling

TODO

  1. Delete comment. Write an menu access callback and leverage that when rendering the link in the 'form'
  2. JS cleanup

This is much closer to a finished product. Please take a chance to review.

@sirkitree do we want this to be rolled in with Activity download or would it be nicer as a separate project? drupal.org/project/activity_comments is open.

Also, I looked into auto growing the comment form like Facebook does. Involves a lil more JS but doable. There is a jQuery plugin that might do this ? sortof...
http://plugins.jquery.com/project/autogrow

Really what Facebook does is on focus add rows to the textarea and show the submit button.

Open Questions

  1. Do we make the comment a textarea with a format? This would allow for WYSIWG as well as the autogrow thingie. Perhaps a textarea is more appropriate its what is used for node comments.
  2. Do we want to toggle expand/collapse? I followed Facebook for this question but willing to debate
  3. Do we make this a separate downloadable project?
Scott Reynolds’s picture

Probably also need some JS clean up

  • surround the behaviors in the function( jquery thingie) following D7 coding sugguestions
  •     form_id = $(this).parents('form').parents('.activity-comments-hide-comments').removeClass('activity-comments-hide-comments');
    

    becomes

    $(this).parents('.activity-comments-hide-comments').removeClass('activity-comments-hide-comments');
    
alippai’s picture

I've checked your code, it works perfectly except that it should not load all the comments. We should do that Facebook way, so load the extra comments via ajax.
On a page with 50 activities it means additional ~1-500 comments, which is not a good idea imho. (we need to load, process, transfer them and load them into the dom).

rjbrown99’s picture

Scott - another option for the facebook-style growing of the box is jQuery Elastic. I have successfully used this on my drupal sites for a similar function. I am using this on my site as a textarea and autogrow is enabled with no ability to turn it off.

I have a question about the intent of this module. Let's take an activity message like this:

"User XYZ commented 'this is a comment' about the node XYZ."

With this module, would an activity comment on that message be related to the activity message itself, or would it be posted as the next comment attached to the node XYZ? I.E. is it a new conversation about the activity message or is it a continuation of the conversation taking place on the node? I could see some value in both approaches, but for my personal use I'd want the conversations to relate back to the node itself.

Thanks in advance.

Scott Reynolds’s picture

it means additional ~1-500 comments

I took my facebook feeds a 'representative' sample of the number of comments on messages. I had a total of 64 comments on 65 Facebook messages for an average of .98 comments per activity.

And thats Facebook. Who here knows of any site doing the same amount of traffic as Facebook? Not so sure its worth the effort.

I guess I would argue I don't want this performance improvement to hold it up. And it does add a level of trouble. It will slow down frontend performance (now its just a class toggle which means Show All is nearly instantaneous). You have to keep track of values and add another menu callback. There is some work there and its non-trivial.

Edit: The mode of the data was 8.

Scott Reynolds’s picture

With this module, would an activity comment on that message be related to the activity message itself, or would it be posted as the next comment attached to the node XYZ?

The comment is attached only to the activity message.

pribeh’s picture

Confirmed. #24 fixed all my problems. Great stuff!

Scott Reynolds’s picture

StatusFileSize
new38.08 KB

Addressed my TODOs from #24

One issue is the delete. It uses the drupal_get_destionation(). Which is fine usually. But if you were to submit a new comment. Then delete that comment, the redirect would be to the JS callback not back to the View.

It is because the drupal_get_destination() for the AHAH callback. The form will have to pass in the current path to the AHAH callback somehow? Not sure on how to achieve just yet.

sirkitree’s picture

Sorry guys, I've been extremely busy with client work and am just now able to spend some time on this, so first of great work! You've really been kicking ass lately Scott!

Secondly - I really think this is large enough to warrant another project. I'm already having trouble keeping up with my current module maintainer-ship responsibilities and another large functionality piece is more than I think I can handle.

That being said, Scott, you've pretty much taken over the 2.x branch (and kudos!) so if you would rather maintain the comment portion within this project as a submodule, I say go for it. I leave it to you as I'm only really able to take a co-maintainer-ship role on the 2.x branch at this point.

I'll try to give this a proper review tomorrow.

Scott Reynolds’s picture

alippai asked me what was missing for this project so far

Here is my short todo
1.) Delete after you post a comment redirects you to the JSON response page. yuck
2.) Should we toggle expand and collapse instead of a show all. FB doesn't do that, but...
3.) Do we make the comment a textarea with a format? This would allow for WYSIWG as well as the autogrow thingie. Perhaps a textarea is more appropriate its what is used for node comments.

At least for number 3, we need to come up with an answer only because as a Feature request this will surface, so we better have a thought out answer for it.

Scott Reynolds’s picture

Any thoughts on #33's three points. Would like to commit a patch this weekend

sirkitree’s picture

2) fb actually shows you the original message, how many are in between, and then like the last one or two. I think it is sufficient to simply show them all and leave any toggling up to themers.

3) I do not think it being a textarea with a format is necessary, but a small textarea makes sense. K.I.S.S.

DrakeRemory’s picture

StatusFileSize
new17.93 KB

I just fixed 1.) from #33 with a few lines of javascript. Since this bug only happens when js is enabled it is ok to fix it with js.

I added this at line 231 in activity_comments.module. This just passes the current destination to our settings in js.
drupal_add_js(array('activity_comments' => array('destination' => drupal_get_destination())), 'setting');

This was added to activity_comments.js.

/**
 * Hanldes the destination for the delete link
 */
Drupal.behaviors.activityDestination = function(context){
  //alert();
  $('.activity-comment-wrapper .comment-link a').each(function() {
    var href = $(this).attr('href').split('?destination=')[0] + '?' + Drupal.settings.activity_comments.destination;
    $(this).attr('href', href);
  });
};
sirkitree’s picture

Other than the small typo in the main comment and not needing that commented alert(); - Looks alright.

Scott Reynolds’s picture

Status: Needs review » Needs work

ok change that to this as the above didn't affect the delete link which was the problem. And it prevents it from running on all the comments that have already been processed

/**
   * Hanldes the destination for the delete link
   */
  Drupal.behaviors.activityDestination = function(context){
    $('.activity-comments-delete a:not(.activity-destination-processed)').each(function() {
      var href = $(this).attr('href').split('?destination=')[0] + '?' + Drupal.settings.activity_comments.destination;
      $(this).attr('href', href).addClass('activity-destination-processed');
    });
  };

still a problem with Views3. we hard code aid

return drupal_get_form('activity_comments_form', $values->aid, $this->options['limit'], $this->options['order']);

Hopefully, i can improve once more then I will commit

Scott Reynolds’s picture

Status: Needs work » Needs review
StatusFileSize
new30.36 KB

I think this is it. Would love a review

sorrow’s picture

It seems to be working nicely, I’ve got a comment field in place and they’re updating/submitting fine. Only problem I see is within the view itself, I’ve got “Error: handler for activity > updates doesn't exist!” showing in the Sort criteria and “Missing style plugin” showing for the Style, the latter then disables Fields. In terms of the actual output, it’s emitting a HTML List (it reverts to this because of the missing style?). Additionally, when there’s more than one comment added to an activity it creates duplicates of that activity in the stream (turning on Distinct rectifies that). As initially stated though, it’s definitely functioning ok and not spitting out any errors.

Scott Reynolds’s picture

Ahh right so that default view needs to go. I have forgotten about that.

What you really want to do to create a View is this
http://skitch.com/supermanscott/nek79/edit-view-all-activity-scotts-contrib

Scott Reynolds’s picture

Status: Needs review » Needs work

Meant to note it needs work

Scott Reynolds’s picture

Status: Needs work » Needs review
StatusFileSize
new29.91 KB

Ok so in order to post comments, you need to use the field as describe in 41 (http://skitch.com/supermanscott/nek79/edit-view-all-activity-scotts-contrib)

But I decided to add a 'feature' that was partically implemented before, create a View of all the comments. So now you can do this:
1.) Create a View just of Activity Comments: http://skitch.com/supermanscott/nexim/views-scotts-contrib
2.) Relate this View to bring in more fields/filters/arguments http://skitch.com/supermanscott/nexic/edit-view-comment-test-scotts-contrib
3.) Add in these fields: http://skitch.com/supermanscott/nexit/edit-view-comment-test-scotts-contrib

I also removed the broken default view that referenced the old style plugin. Fixed a number of bad views handlers (views_handler_(field/filter)_number doesn't exist, its numeric)

We are close. I would like to store the last comment id in the stats table so that it can be pulled in along side the Activity View if you aren't using the comment form handler.

Does all this make sense?

DrakeRemory’s picture

StatusFileSize
new1.54 KB
new471 bytes

I added an implementation of drupal_alter in activity_comments_form_submit so other modules can react to the insertion of an activity comment. I also attached a rules event implementation. I'm using it to send out an email to the user who carried out the activity. Maybe someone's interested.

DrakeRemory’s picture

StatusFileSize
new1.54 KB

I mixed up the users in the previous rules module. This one is correct.

pribeh’s picture

#43-5 works extremely well together. I can see DrakeRemory's rules module coming in handy - tested mail/rules implementation and seems to work.

Question for you guys: is it possible to make a (configurable) "comment" link that once clicked would load the comment input field - like on FB? The view would look a lot cleaner if it wasn't initially populated with lots of comment input fields.

You guys rock.

pribeh’s picture

Never-mind, I figured out the conflict I reported is with FBSS.

pribeh’s picture

I've been trying to add user pictures to comments via template_preprocess_activity_comments_comment but to no avail. Any help? Thanks.

Bilmar’s picture

subscribing

DrakeRemory’s picture

/**
 * Preprocessor for activity-comment.tpl.php template file.
 */
function phptemplate_preprocess_activity_comments_comment(&$vars, $hook) {
  $account = user_load($vars['comment']->uid);
  $vars['picture'] = theme('user_picture', $account);
}

Afterwards you have a $picture variable in your template file.

pribeh’s picture

I'm stupid, nevermind.

tsi’s picture

Subscribing

youkho’s picture

Can't believe i've missed that now it's gonna be a long night of testings keep up the great work guys

BenK’s picture

Subscribing....

zuzu83’s picture

Subscribing.... and FB comment link fonction #46

Scott Reynolds’s picture

Status: Needs review » Fixed

Ok committed a minimal implementation that handles what I think is the 90% case. It provides three fields for an Activity View, one is for posting comments, one is the comment count and the other is the comment timestamp.

The two remaining sub issues:
#683124: Create Activity Comments as a base table
#683130: Rules Integration for posting an Activity Comment

http://drupal.org/cvs?commit=313486

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

adam_c’s picture

I appologise if this is glaringly obvious but I cannot seem to get the comments list to hide comments and display the 'show all x comments' link. I have had a look through the code and it looks as though there is a limit of 10 set in the code and after that it starts hiding.

I can make far more then 10 comments and nothing happens. Am i missing something?

Michsk’s picture

With the latest dev i'm still having the delete redirect problem. So when i post a comment and delete it i get the above AHAH issue.