function maxId(messages) {
    var max = 0;
    for (var key in messages) {
      var id = parseInt(key);
      if (id >= max) max = id;