Hello,

I'm the author of the Facebook-style Statuses module (FBSS). FBSS allows users to have a "status" like on Facebook or Twitter. Users can also write messages on other users' profiles.

I've had Activity integration for awhile now, but recently a user brought up a concern in the issue queue. Essentially, right now FBSS integration with Activity shows four fields on the Activity publisher template: one for the user on whose profile the status was posted (if the status was not a self-update); one for the user who posted the status (if the status was not a self-update); one for the user who posted the status (if the status was a self-update); and one for "everyone else."

This user's problem was that they wanted different templates shown to "everyone" depending on whether the status was a self-update or not. For example, if User A posts "I am happy" as their status, then the public message should be "User A says I am happy". But if User A writes "Hello" on User B's profile, then the public message should be "User A said Hello to User B."

I've altered the Activity publishing form to add an extra "everyone" field, and I'm saving the templates into a system variable. However, as far as I can tell, there's no convenient way to change the template for the message text before it gets processed and stored in the {activity_messages} table. In order to do that, I have to wait until hook_activity_message_recorded() gets called, look up the {activity_targets} table, and then change the contents of the {activity_messages} table. That's slow and difficult, although I've worked out the code to do it if necessary.

Is there an easier way to do this? Doing a str_replace() over the message in hook_activity_messages_alter() is impossible because (A) the template is entirely different and (B) there is no way to tell the language or the $context.

Thanks,
Ice

CommentFileSizeAuthor
#5 fbss_activity.png51.38 KBicecreamyou

Comments

Scott Reynolds’s picture

Project: Activity » Facebook status
Version: 6.x-2.x-dev » 6.x-1.x-dev
Category: support » task

Instead you should make two triggers. One for when a user updates there status an one for when a user writes on another profile. Then you are able to craft messages properly.

These two 'actions' are VERY distinct with a different actors in play (posting your own status is just one actor, You. Posting on someones profile, there are two actor's Author and Profile user)

Scott Reynolds’s picture

Title: Alter [everyone-pattern] before saving an activity record » Add additional trigger for when someone sends a user a message

That was someone of an incomplete statement, I should have completed it.

Its more then just a problem with the Everyone message. For instance, your example, the message for User A when he writes on User B's wall will be different as well. Basically, you will have to alter ALL message templates.

1.) Message for User A (You wrote on User B's profile)
2.) Add a message for User B (User A wrote on your profile)
3.) Change the Public message (User A wrote on User B's profile)

Thus, the motivation to create a new trigger and expose that as well to Activity.

This is different from the Comment problem #565748: Add comment activity message field for when comment author and node author is the same user as only one message template would need to be altered depending on the Actors involved.

yelvington’s picture

Title: Add additional trigger for when someone sends a user a message » Alter [everyone-pattern] before saving an activity record
Project: Facebook status » Facebook-style Statuses (Microblog)
Component: Code » Miscellaneous

Changing this to the appropriate project, which is not fbstatus.

Scott Reynolds’s picture

Title: Alter [everyone-pattern] before saving an activity record » Add additional trigger for when someone sends a user a message
Component: Miscellaneous » Code - Functionality

Preserving my title and Component. Sry for the confusion.

icecreamyou’s picture

Title: Add additional trigger for when someone sends a user a message » Alter [everyone-pattern] before saving an activity record
Project: Facebook-style Statuses (Microblog) » Activity
Version: 6.x-1.x-dev » 6.x-2.x-dev
Component: Code - Functionality » Code
Category: task » support
Status: Active » Closed (won't fix)
StatusFileSize
new51.38 KB

Nope, everything works with one trigger, and it's been working great for the past few months. It's impractical and counter-intuitive to have multiple triggers for the same event (submission of the status update form). The only issue at hand is determining the template to use for a second message to everyone.

(Part of the reason it works is because the system treats a self-update as having two actors, it's just that they both refer to the same object.)

The attached image shows what the Activity publisher template looks like. Below are the scenarios for different events that can happen and the messages that are shown to various users.

== EVENT: User A updates his status ==
User A sees: You updated your status.
Everyone else sees: User A has a new status.

== EVENT: User A writes a message on User B's profile. ==
User A sees: You wrote a message on User B's profile.
User B sees: User A wrote a message on your profile.
Everyone else sees: User A wrote a message on User B's profile.

In terms of interaction, these may seem like slightly different events, but in terms of code, they are exactly the same.

The structure described above is how everything is currently working, and also exactly how I want it to work. There are no acrobatics required to make it happen this way; the code is straightforward except when it comes to having different templates for the Public message. My question was simply if there is a way to more easily access additional information in the hooks that Activity offers, and if there is not that's okay as well since my existing code is working.

Scott Reynolds’s picture

Category: support » task
Status: Closed (won't fix) » Fixed

Well I will point out that you have made, in my estimation, a bad design decision. As then the FBSS module will have to keep track of the different values for the messages itself.

But to answer your original question, there is this and only this

// allow other modules to change the messages based on the activity type
  drupal_alter('activity_messages', $messages, $type);

Please note, that it isn't [everyone-pattern] but [everyone-pattern-{$language_id}]

Scott Reynolds’s picture

...

It's impractical and counter-intuitive to have multiple triggers for the same event (submission of the status update form)
...
In terms of interaction, these may seem like slightly different events, but in terms of code, they are exactly the same.

Wow, I passed over this before. Just because the form has the same $form_id doesn't mean that for a user its counter-intuitive....

Anyways, my solution, you would just have to create another op and your there. Thats it

 //Trigger integration. Don't call if the status is blank because that will save an undesirable Activity 2 record.
    if (module_exists('trigger') && $time) {
      $op = 'fbss_submitted';
      if ($user->uid != $account->uid) {
        $op = 'fbss_submitted_other';
      }
      module_invoke_all('facebook_status', $op, $account, $user, $object);
    }

And if you don't want to go that far...

/**
 * Implementation of hook_facebook_status().
 * or
 * Implementation of hook_trigger_name().
 */
function facebook_status_facebook_status($op, $owner, $poster, $status) {
  if (!in_array($op, array('fbss_submitted'))) {
    return;
  }
  if ($owner->uid != $poster->uid) {
    $op = 'fbss_submitted_other';
  }
  $aids = _trigger_get_hook_aids('facebook_status', $op);

And with different ops you can have different Activity templates. So this is not an issue at all with Activity.

icecreamyou’s picture

I'm aware of the language part, I have it working for every language across multiple $ops.

If I split the trigger, where does it stop? Does there have to be a different trigger for editing and deleting too? Doesn't that seem awkward?

I will think about this a little more. Thanks for your help thus far.

Scott Reynolds’s picture

If I split the trigger, where does it stop? Does there have to be a different trigger for editing and deleting too? Doesn't that seem awkward?

Is editing and deleting put through exactly the same trigger and action? This makes me worry, as you are the only maintainer thus far that has written Activity2 integration by yourself. And this is disheartening..

What was the point of making Actions and Triggers the basis of Activity if people were just going to ignore it....

And how is that awkward? The messages should clearly be different. Should node edit and delete have the same messages as node insert? Please back up your assertions that it is awkward or counter-intuitive.

And the reality is, the form alter you did for the everyone message is probably more work then exposing more $op's to Activity2. This whole conversation is completely surreal to me and it is very disheartening. I think these things are obvious and clearly they are not and puts all the assumptions of Activity2 into a bad light...

edit: I hope this is where the confusion lies, I really do. But what Im sugguesting is not a completly new hook_trigger_name() and all that, but a new $op. That is all. I try to make this clear in #7

icecreamyou’s picture

No, editing and deleting are separate actions! That would certainly be ridiculous to combine them. I'm saying that I may also have to split editing and deleting statuses based on whether the status in question was posted to one's own profile or to another's profile.

I completely understand the purpose of different Triggers and Actions and how they relate to Activity. My concern is unique to FBSS in that something I thought of as one action -- submitting the status form -- could involve either one or two actors. The question at stake here is simply which method will create the most intuitive UI for users.

Let me try to be a little clearer.

The part that felt unintuitive to me was that if I as a site administrator to go the Activity templates page, I think "I'm going to add a template for when a user edits a status." It doesn't immediately occur to me that there could be two different kinds of editing a status based on where the status was posted.

On the other hand, once I go to the template creation screen and it shows me a list of triggers with descriptions, the distinction may become clear. So I'm currently leaning towards your suggestion of splitting each of the three existing triggers (status submission, status editing, and status deletion). (The result will be six triggers.)

icecreamyou’s picture

I think I should also point out that part of the reason I opened this issue is that I think the Activity 2 API is relatively clear and useful (at the very least compared to Activity 1) so I was encouraged by this fact to explore some of the flexibility it offered. FBSS has unusual circumstances that occasionally make it necessary to stretch the limits of some APIs in ways that they weren't originally envisioned to be used, and this is simply a case where I tried to find a way to make the interface as clear to site administrators as possible at the potential expense of clarity of code.

sirkitree’s picture

hrm. maybe it's time to bundle activity_user status into activity2 so that users can have a great example of how to use the API's we offer. It does sort of duplicate some of FBSS, but it serves as a really good example of how a module can accomplish something solely upon Activity2's APIs.

icecreamyou’s picture

Does it not seem ridiculous to you to duplicate functionality just to demonstrate how an API can be used? I understand how it can be used, and I've used it correctly in FBSS for months. The documentation is reasonably clear, and there are already fine examples of how the API is used within the existing Activity package. It's not even Activity's API that you're talking about, it's the Actions API in core!

icecreamyou’s picture

Also, writing *anything* for the sole purpose of demonstrating an API is in dubious territory. Attempting to duplicate the functionality of a very powerful and stable module with thousands of hours of development work, in a way that could not possibly be maintained anywhere near as well as FBSS is, is simply absurd. It's the equivalent of me building an Activity system in FBSS just to demonstrate how statuses could be displayed. If you want to build a good example of how the Activity API should be used, write a patch for FBSS, don't waste time and effort on duplicated functionality that could never approach FBSS's flexibility anyway, please!

By the way, Mr. Reynolds, you helped a bit with the original Activity 2 integration way back in early June.

Scott Reynolds’s picture

Status: Fixed » Closed (fixed)

that could not possibly be maintained anywhere near as well as FBSS is

I would point out that are two projects are used in conjunction a lot. and if you were to stop maintaining yours, this project would suffer.

Plus its already built, we needed something leaner for a project then FBSS and we need a little more functionality. Sirkitree and I happen to be very proud of what we created.

It's the equivalent of me building an Activity system in FBSS just to demonstrate how statuses could be displayed.

Thats not true either. It doesn't touch the level of complexity, activity_user_status is a simple module and it will always remain simple...

But regardless, this is way off topic. This issue is closed, my concerns were understood and a direction has been chosen.

icecreamyou’s picture

I didn't mean to imply that Activity isn't well-maintained; Activity and FBSS are used together and if Activity stopped being maintained then FBSS would suffer as well. I use Activity 2 on several sites and I like it a lot. I just meant that, as part of a larger project, it's unlikely that activity_user_status would get the same kind of focus that I can give to a dedicated project like FBSS.