<commit_before>const debug = require('debug')('yunity:profilePage');

export default class ProfilePageCtrl {
  
  constructor($scope, $attrs, yAPI, yChat, $stateParams, $location) {
    'ngInject';
    Object.assign(this, {
      $scope, $location,
      yAPI, yChat,
      
      error: null
    });
    
    const own = ("own" in $attrs);
    const userID = (own ? yAPI.session.user.id : $stateParams.id);
    
    Object.assign($scope, {
      user: { id: userID, loaded: false },
      ownProfile: (userID == yAPI.session.user.id)
    })
    
    yAPI.apiCall('/users/' + userID)
      .then((ret) => {
        $scope.user = ret.data.users[0];
        $scope.user.loaded = true;
      })
      .catch((error) => {
        this.error = 'User not found';
      });
    
  }
  
  sendMessage() {
    let chat = this.yChat.getExistingChat($scope.user.id, this.yAPI.session.chats);
    if (chat) {
      this.$location.path('/chat/' + chat.id);
    } else {
      this.$location.path('/chat/new/' + this.user.id );
    }
  }
  
}
<commit_msg>Fix profile chat button<commit_after>const debug = require('debug')('yunity:profilePage');

export default class ProfilePageCtrl {
  
  constructor($scope, $attrs, yAPI, yChat, $stateParams, $location) {
    'ngInject';
    Object.assign(this, {
      $scope, $location,
      yAPI, yChat,
      
      error: null
    });
    
    const own = ("own" in $attrs);
    const userID = (own ? yAPI.session.user.id : $stateParams.id);
    
    Object.assign($scope, {
      user: { id: userID, loaded: false },
      ownProfile: (userID == yAPI.session.user.id)
    })
    
    yAPI.apiCall('/users/' + userID)
      .then((ret) => {
        $scope.user = ret.data.users[0];
        $scope.user.loaded = true;
      })
      .catch((error) => {
        this.error = 'User not found';
      });
    
  }
  
  sendMessage() {
    const chat = this.yChat.getExistingChat(this.$scope.user.id, this.yAPI.session.chats);
    if (chat) {
      this.$location.path('/chat/' + chat.id);
    } else {
      this.$location.path('/chat/new/' + this.$scope.user.id );
    }
  }
  
}

{'fraction_non_alphanumeric': 0.17236467236467237, 'fraction_numerical': 0.000949667616334283, 'mean_word_length': 2.2415384615384615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6707717', 'n_tokens_mistral': 726, 'n_tokens_neox': 727, 'n_words': 131}