How to make menu badges count disappear after the page is viewed? With reference to my previous question which was a little confusing or I should say it was mixed up with two different problems. I am posting my question again with clarification.

I have created a view, which shows activity logged by Message module. I then created a menu badge using menu badges module which shows the numbers on the menu item. - In start, when there is no activity, it shows 0, After there is new activity, say 2 new activities, the number changes to 2, which is correct, but when the page is viewed the count remains the same and does not decrease or disappear i.e 2, which is wrong. This is the problem. When the page is viewed, the number must disappear until and unless there is new activity.

Currently I am using Message:Message ID in the field to count. I have 3 different message types and I am showing it in one view. Actually, I am trying to create a notifications system. When, the user you are following does some activity, you will be notified.

Coming back to issue. For example, the menu badges module comes with a default badge for the private messages module (it allows users to send/receive messages to/from each other). It is working perfectly as the badge disappears when the users reads all the private messages and it reduces as well. Private messages module does not provide a view so i cannot see how it is working with the menu badges module.

Extra clarifications:


if the user visited the page containing the view that shows 2 rows corresponding to those 2 new activities, then both of those 2 new activities should no longer be included in the counter for its menu badge.
I wont use a pager. All items will be listed on the same page.
We only want menu badges to show count of new activities which the user haven't seen yet i.e the user haven't visited the page containing the activities-logs/notifications. Simply, when the user visits the page, the menu badges count must disappear.
Visiting the page means user has seen the notifications/new activities and now the count should not be visible as there is no new activity. As it happens on stackexchange websites: when you click the notification, the count disappears.
To make the Menu Badges counter disappear when visiting the page at notifications/new (as in your question), is something you can do by using a special feature of the Rules module, i.e. a technique that is similar to what is described in the answer to "How to execute VBO list of nodes in Rules on After updating an existing user account event?". Read on for more details about the steps to be completed, specific to your question here.

Step 1:

Create a VBO view of your unread messages, similar to what is described in my answer to "How to allow users to manage their own Message Stack messages?".

Step 2:

Create a custom Rules Component that will execute the VBO list of unread Messages, and which looks like so:

{ "rules_mark_all_unread_messages_read" : {
    "LABEL" : "Mark all unread messages read",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "views_bulk_operations" ],
    "ON" : { "init" : [] },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "2" : "2" } }
        }
      },
      { "text_matches" : {
          "text" : [ "site:current-page:url" ],
          "match" : "user\/\\d+\/messages\/unread",
          "operation" : "regex"
        }
      }
    ],
    "DO" : [
      { "views_bulk_operations_action_load_list" : {
          "USING" : { "view" : "messages_by_user|page_3" },
          "PROVIDE" : { "entity_list" : { "unread_msgs_list" : "A list of unread messages" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "unread-msgs-list" ] },
          "ITEM" : { "current_msg" : "Current message" },
          "DO" : [
            { "component_rules_flag_a_message" : { "message_to_flag" : [ "current-msg" ] } },
            { "drupal_message" : { "message" : "The message with ID [current-msg:mid] (created [current-msg:timestamp]) was marked as read." } }
          ]
        }
      }
    ]
  }
}


Some more details about the rule above:


Rules Event: Drupal is initializing
Rules Conditions:


only for authenticated users.
check if the path being visited is user/%/messages/unread (adapt this path if you use another path).

Rules Actions:


Create a list of unflagged messages.
Loop over each of the unflagged messages found, and flag those messages.



This rule also performs an extra "set message" action, so that you can see what it does if you want to try it in your own site (it shows a message (oeps!) for each message being flagged). Remove that message after QA-testing if you want.

That's it, works like a charm!

Note: this solution can also be used in combination with the solution detailed in the related answer. So maybe you want to set a special permission if you want to combine both solutions, so that admins only can mark selected messages as read or unread, if needed.