1

I want like Facebook notification add icon when a user relationships or flag friends ( User Relationships or Flag Friend module) published some new content.

I followed this good tutorial who is the closest to do that : How to allow users to manage their own Message Stack messages?. It works perfectly, but only for the current user and not relationships or friends. I also found How to implement Facebook style Notifications for Organic Group posts?.

I would use not only for the current user but for user relationships like a Facebook notification. I tried many ways: using Rules, Views or custom development (the most closest with hook_node_insert and user_relationships_load } but without success.

The problem is you need to notify individually each of the friends, so that they can manage there own notifications. If not each time a friend removes a notification, it's removed for ALL friends.

I add a custom field of user that is fill by one each time a new content is publish with a custom module this is working but I not find a way to JOIN the QUERY with the relationship table or friends tables.

function my_module_node_insert($node){
if($node->type == 'mytype'){
db_update('field_data_field_my_field_name')
->expression('field_my_field_name_value', 'field_my_field_name_value + 
:amount', array(':amount' => 1))
->execute();    
//or you also can use regular query
//db_query("UPDATE {field_data_field_my_field_name} SET 
//field_my_field_name_value = field_my_field_name_value + 1");
}
}

Here is the screen of the views of list "all friends" default views of Flag friends module

enter image description here

2

When it comes to Facebook type notifications, the Message module is indeed very useful. I'll give an example below of using one view's results view_with_users in another view's contextual filter my_messages_view.

For this to work, in your main messages view, you have to go into your contextual filter's settings (probably Message Author or something), then scroll to the bottom and click Allow multiple values. Instead of the usual Provide default: Current User, we will send all the friends to the view with a module.

Note: In the below example, I've sent the current user's uid to the additional view as an example, but your screenshot doesn't have that contextual filter so it's either not needed, or you may need to tweak the friends view to work programmatically.

custom_views_args.module

<?php

function custom_views_args_views_pre_view(&$view, &$display_id, &$args){ 
    global $user;
    // Target our Messages view
    if($view->name == 'my_messages_view') { 
        // Get users from our friends view
        $friends = views_get_view_result('view_with_users', 'view_display_name', $user->uid);
        // Add each uid to array
        $friends_array = [];
            foreach($friends as $friend){
            $friends_array[] = $friend->uid;
        }
        // Add current user's uid to array as well
        $friends_array[] = $user->uid;
        // Create + separated Contextual Filter
        $messages_con_filter = implode("+", $friends_array);

        // Send the filter to the Messages view
        // $args[0] is the first filter in the list in the view
        $args[0] = $messages_con_filter;

    }
}

See this thread for more info about Facebook-style notification. There may be other useful threads but I happened to answer that one. OP's question should give you some useful pointers. My answer there is quite specific but might give you ideas on how to make messages "seen".

Pierre wrote this in the comments above.

for each of those friends such notification can be marked as read by each friend individually

If you use a non-global Flag for "seen", then it will do the above.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.