vogloblinsky / angular-simple-chat

AngularJS chat directive
31 stars 14 forks source link

How to delete messages #4

Open khackskjs opened 8 years ago

khackskjs commented 8 years ago

I can not find how to delete messages. I thought re-assigning messages array, I could have solved but I couldn't.

I just write down code in my thought. The question is how to refresh message like just opening chat room.

// in html
<div ng-controller="ChatRoomCtrl as AppView">
        <simple-chat id="simple-chat"
            messages="AppView.messages"
            local-user="AppView.you"
            send-function="AppView.sendMessage"
            send-button-text="Send"
            composer-placeholder-text="Write your message here"
            show-user-avatar="true"
            show-composer="true"
        ></simple-chat>
</div>

// in controller
app.cointroller('ChatRoomCtrl', ChatRoomCtrl);
function ChatRoomCtrl($scope) {
  var vm = this;
  vm.messages = [];

  //after some messages send/receive,
  // I wanna reduce message length;
  function reduceMessages() {
    var len = vm.messages.length;
    vm.messages = vm.messages.splice(len - 100, len);
  }
}
cvelasco88 commented 5 years ago

I test it doing "pop" to my message array and it worked