Dynamic SideMenu Badge Counts Per User (Read/Unread)

Hello Cuba team,

I’ve become curious about SideMenu badges. The only information I’ve found is here.

In a test project, I’ve extended the Main Screen, and in the controller, I was able to set a badge using the onInit() event. Simple text, and it worked fine (aside from an existing vertical alignment issue with the badge).

But this got me thinking about how to use SideMenu badges to display the number of database entries for each user that haven’t been clicked on yet.

This idea seems to open a much bigger issue: How to track these for each user.

If it were a simple boolean field in general, it would be relatively easy to set an entry as viewed. But this is needing a design to keep track for each user.

I hope this makes sense. Can someone give me a hint as to which direction I should go to implement this idea?

Thanks,
Adam

Hi,

You will need something like readByUsers field in your Entry entity that should contain a serialized list of user logins for those users who already read the message (e.g. comma separated logins). To keep track of unread counts per user you may use a special database table and a separate entity. Then update this table when new message occurs for user by calculating how many messages are unread.

Finally, set badge counts dynamically for any menu items:

int unreadCount = mailService.getPersonalUnreadCount();
sideMenu.getMenuItemNN("messagesItemId").setBadgeText(Integer.toString(unreadCount));