I have created a message view using the Message module. I want this view to show the current user activity and activity of the user he is following using the "follow" flag (user). i.e own + following.

The Message module comes with a "message subscribe" flag, but I do not want to use that. What should be the setting of my view particularly the relationship and contextual filters?

1 Answer 1


About the Message module and user activity

Even though you're question doesn't really say so, I'm assuming that:

  • "activity" in this question is about message instances created by the Message module, targeted to the current user.
  • "activity of the user he is following" is about message instances target to the current user (also), though they are about events related to any of the followed users (indicated by your follow-flag).

If these assumptions are correct, then your question is about creating a view of various flavors of messages (typically created using various Message Types), which are all targeted to the current user.

Creating a view about Messages by user

Add a new view

  • View name "Messages by user".
  • Show Message.
  • Type All.
  • Create a page (not a block)

Create a table display of this view

For this question here, you only need a single table display, of All messages.

To differentiate this "All", think of additional displays you might want to add later on, such as:

  • Read messages
  • Unread messages

Add Contextual Filters

  • Message: User uid, and for "When the filter value is NOT in the URL" use "Provide default value" with Type "User ID from logged in user".

Add Relationships

"Message: User uid" will result in the messages targeted to the current user, so that one you need for sure.

I suggest you create a first display only using the above relationship (to check the results you get so far). Then clone this display into another one, in which you add another relationship like "Flags: follow (by current user)" (assuming that follow corresponds to your follow-flag). By swapping between the 2 displays, you can decide which one you really want, or just keep both.

Add Fields

  • Message: Message ID (Msg ID)
  • Message: Timestamp (Created on)
  • Message: Render message (Get text) (Text)
  • (User) User: Name (User), and use "Exclude from display" for this field, which is only needed to add a "Global: Text area" to the views headers which contains something like Messages for user [name].

Add Sort criteria

  • Message: Timestamp (desc)

Further Refinements

  • Filter criteria: none

  • Page settings:

    • Path: /user/%/messages
    • Menu tab: Messages

Make the Messages manage-able

If you complete the above steps, you'll have a view that shows all relevant messages ... and that's really it. It won't be obvious for a user to remember which messages have been read already, and which ones are new (= unread). Try it for yourself (to experience the pain ..).

To implement a facility to mark messages as read/unread, just perform the steps explained in "How to allow users to manage their own Message Stack messages?", which can be summarized like so:

  1. Create a flag (using the the Flag module).
  2. Create a view 'Messages by user' (= improved version of the view specifications described above).
  3. Use Rules to flag/unflag messages.
  4. Trigger the Rules Component to mark messages (using the VBO module).
  5. Create notifications about Unread Messages (using the "Menu Badges" module). So that whenever a new message gets created, the user gets a notification in the format of an iOS-like (red) badge with the number of unread messages.

Fruit of your labor

If you follow the above steps, the result of it is something similar to an eMail client inbox, whereas the eMail "messages" are not real eMails, but instances of messages created by the Message module.

  • looks good. I will try
    – Umair
    Dec 13, 2016 at 8:10
  • I tried both scenarios mentioned in "Add relationship" section above, but not working as i want. 1. The "Message: User uid" is showing only current user activity. 2. Then i tried "Flags: follow (by current user)" with "Message: User uid" in contextual filter, it was showing only current user activity. Then I removed it from contextual filter. The view showed activity of all users including who I am not following. Then I checked "include only flagged content" and it was showing messages from users I am following.
    – Umair
    Jan 4, 2017 at 16:20
  • Both "current user activity" and "activity of user flagged" should show in a single view.
    – Umair
    Jan 4, 2017 at 16:22
  • What if we can do it in rules. In the "user for which to log the message", the user who flagged the content author should only see the activity message. What do you say? I think it is better approach. It is better because if we use the approach from the answer, when someone starts following you with the follow flag, that activity is logged for you. Now the user who is following you, will also receive the message log as he is following you. Even though the message log was only concerned to you.
    – Umair
    Jan 4, 2017 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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