Fix unread DirectMessage count and improve DB handling