I simulate events in increasing timestamp order and, for events sharing a timestamp, I process all OFFLINE events before MESSAGE events (because status changes are applied before messages at the same time). I keep an offline_until time for each user (the time they become online again); a user is online at time T iff T >= offline_until[user]. On an OFFLINE event at time t for user id I set offline_until[id] = t + 60. On a MESSAGE event at time t I parse the mentions string token-by-token:
- ALL increments every user's count (offline or online).
- HERE increments the count for every user currently online at time t.
- idX increments user X (count each occurrence; duplicates count separately).