Direct messages and unread counts (Real-time Chat)

Add dm <from <to <text ([dm] <from: <text - <to), unread counters and read. Every message adds 1 unread for each recipient in that room (DMs live in a room named dm:<a+<b, names sorted). read <user <room (or read <user @<other for a DM) prints <user read <room: <n unread and resets it. unread <user prints <user unread: <room=<n, … (rooms sorted, only non-zero) or none.

Input: As before.

Output: As before.

Difficulty: Medium. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.

Hint

  • Keep counts in a map keyed by (user, room).

More Real-time Chat practice