 
   $scope.search = () ->
     $location.url '/search'
-
-  $scope.searchText = ''
 
   $scope.filterByNameOrSkill = (users,searchText) ->
     filteredUsers = []

    if _.indexOf($scope.usersCommunicatedWith, user.id) == -1 and user.id != $scope.currentUser.id
      User.createConversationWithMessage($scope.currentUser, user, messageText).success (response) ->
        noty { text: 'Successfully sent a message!', type: 'success'}
        $scope.usersCommunicatedWith.push user.id
        reloadUser()
      .error (response) ->

      conversation = _.find($scope.conversations, (conversation) -> conversation.created_by == user.id || conversation.created_for == user.id)
      User.createMessageTo($scope.currentUser, user, messageText, conversation.id).success (response) ->
        noty { text: 'Successfully sent a message!', type: 'success'}
        console.log '$scope.messageText: ', $scope.messageText = ''
      .error (response) ->
        noty { text: 'Message cannot be sent! Please try again', type: 'error'}
    $(".modal").modal('hide')
    return

  User.loadAll().then (result) ->
    $scope.users = result.users

  reloadUser()

  $scope.messageText = ''

  $scope.searchText = ''

]

