while (len >= 0) {
    var dialog = dialogs[len];
    if (dialog.type) {
        if (dialog.type == "chat") {
            chats.push(dialog);