Rewrite chat code relating to unread messages line