<commit_before>import { Component, OnInit, OnDestroy } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Socket } from '../../../services/socketio.service';
import { TranslateService } from '@ngx-translate/core';
import { User } from '../../../services/user.service';

import clipboardCheck from '@iconify/icons-fa-solid/clipboard-check';
import brushIcon from '@iconify/icons-bi/brush';
import envelopeFill from '@iconify/icons-bi/envelope-fill';
import plusIcon from '@iconify/icons-bi/plus';
import share from '@iconify/icons-bi/share';
import trash2Icon from '@iconify/icons-bi/trash2';
import trashIcon from '@iconify/icons-bi/trash';
import xIcon from '@iconify/icons-bi/x';

@Component({
  templateUrl: '../html/messages.component.html',
  styleUrls: ['../css/messages.component.css']
})

export class MessagesComponent implements OnInit, OnDestroy {
  public addDestError: number;
  public answerText: string;
  public currentPage: number;
  public linkSaved: number;
  public msgSent: number;
  public msgToUser: string;
  public msgTitle: string;
  public msgText: string;
  
  private currentCategory: number;
  private msgList: any;
  private msgPageNb: number;
  private currentMsg: any;
  private deleteMode: number;
  private destList: any;
  private sub:any;
  
  //Icons
  brushIcon    = brushIcon;
  clipboardCheck = clipboardCheck;
  envelopeFill = envelopeFill;
  plusIcon     = plusIcon;
  share        = share;
  trash2Icon   = trash2Icon;
  trashIcon    = trashIcon;
  xIcon        = xIcon;
  
  constructor(private http: HttpClient, public user: User, private socket: Socket, public translate: TranslateService) {
    this.addDestError = 0;
    this.answerText = '';
    this.currentPage = 1;
    this.linkSaved = 0;
    this.msgSent = 0;
    this.msgToUser = '';
    this.msgTitle = '';
    this.msgText = '';
    
    this.currentCategory = 0;
    this.msgList = [];
    this.msgPageNb = 1;
    this.currentMsg = {
      id: 0,
      content: '',
      msg_type: 0
    };
    this.deleteMode = 0;
    this.destList = [];
  }
  
  ngOnInit() {
    this.user.checkPermissions([1]);
    
    this.socket.on('msgPage', (newMsgList:any) => {
      for(let i in newMsgList.list) {
        newMsgList.list[i].isChecked = true;
      }
      this.msgList   = newMsgList.list;
      this.msgPageNb = newMsgList.nb;
      
      if(this.currentPage > newMsgList.nb) {
        this.currentPage = parseInt(newMsgList.nb);
        
        //If the requested page was too high
        this.setPage(this.currentPage);
      }
    });
    
    this.socket.on('msgInfo', (msgInfo:any) => {
      this.currentMsg = msgInfo;
    });
    
    this.socket.on('msgRefresh', () => {
      this.setPage(this.currentPage);
      this.messageLoad({'id': this.currentMsg});
    });
    
    this.setPage(this.currentPage);
  }
  
  ngOnDestroy() {
    this.socket.removeListener('msgPage');
    this.socket.removeListener('msgInfo');
    this.socket.removeListener('msgRefresh');
    this.sub.unsubscribe();
  }
  
  addDest(username:string, callback:any=null) {
    this.addDestError = 0;
    if(username.length == 0) {
      if(callback) {
        callback();
      }
      return;
    }
    
    let url = this.socket.url+'/api/playerProfile/'+username+'.json';
    
    this.sub = this.http.get(url).subscribe((res:any) => {
      if(res && res.membre_id) {
        this.removeDest(res.membre_id);
        this.destList.push({
          'id': res.membre_id,
          'username': res.username
        });
      }
      else if(!callback) {
        this.addDestError = 1;<commit_msg>Unsubscribe only when required<commit_after>import { Component, OnInit, OnDestroy } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Socket } from '../../../services/socketio.service';
import { TranslateService } from '@ngx-translate/core';
import { User } from '../../../services/user.service';

import clipboardCheck from '@iconify/icons-fa-solid/clipboard-check';
import brushIcon from '@iconify/icons-bi/brush';
import envelopeFill from '@iconify/icons-bi/envelope-fill';
import plusIcon from '@iconify/icons-bi/plus';
import share from '@iconify/icons-bi/share';
import trash2Icon from '@iconify/icons-bi/trash2';
import trashIcon from '@iconify/icons-bi/trash';
import xIcon from '@iconify/icons-bi/x';

@Component({
  templateUrl: '../html/messages.component.html',
  styleUrls: ['../css/messages.component.css']
})

export class MessagesComponent implements OnInit, OnDestroy {
  public addDestError: number;
  public answerText: string;
  public currentPage: number;
  public linkSaved: number;
  public msgSent: number;
  public msgToUser: string;
  public msgTitle: string;
  public msgText: string;
  
  private currentCategory: number;
  private msgList: any;
  private msgPageNb: number;
  private currentMsg: any;
  private deleteMode: number;
  private destList: any;
  private sub:any;
  
  //Icons
  brushIcon    = brushIcon;
  clipboardCheck = clipboardCheck;
  envelopeFill = envelopeFill;
  plusIcon     = plusIcon;
  share        = share;
  trash2Icon   = trash2Icon;
  trashIcon    = trashIcon;
  xIcon        = xIcon;
  
  constructor(private http: HttpClient, public user: User, private socket: Socket, public translate: TranslateService) {
    this.addDestError = 0;
    this.answerText = '';
    this.currentPage = 1;
    this.linkSaved = 0;
    this.msgSent = 0;
    this.msgToUser = '';
    this.msgTitle = '';
    this.msgText = '';
    
    this.currentCategory = 0;
    this.msgList = [];
    this.msgPageNb = 1;
    this.currentMsg = {
      id: 0,
      content: '',
      msg_type: 0
    };
    this.deleteMode = 0;
    this.destList = [];
  }
  
  ngOnInit() {
    this.user.checkPermissions([1]);
    
    this.socket.on('msgPage', (newMsgList:any) => {
      for(let i in newMsgList.list) {
        newMsgList.list[i].isChecked = true;
      }
      this.msgList   = newMsgList.list;
      this.msgPageNb = newMsgList.nb;
      
      if(this.currentPage > newMsgList.nb) {
        this.currentPage = parseInt(newMsgList.nb);
        
        //If the requested page was too high
        this.setPage(this.currentPage);
      }
    });
    
    this.socket.on('msgInfo', (msgInfo:any) => {
      this.currentMsg = msgInfo;
    });
    
    this.socket.on('msgRefresh', () => {
      this.setPage(this.currentPage);
      this.messageLoad({'id': this.currentMsg});
    });
    
    this.setPage(this.currentPage);
  }
  
  ngOnDestroy() {
    this.socket.removeListener('msgPage');
    this.socket.removeListener('msgInfo');
    this.socket.removeListener('msgRefresh');
    if(this.sub) {
      this.sub.unsubscribe();
    }
  }
  
  addDest(username:string, callback:any=null) {
    this.addDestError = 0;
    if(username.length == 0) {
      if(callback) {
        callback();
      }
      return;
    }
    
    let url = this.socket.url+'/api/playerProfile/'+username+'.json';
    
    this.sub = this.http.get(url).subscribe((res:any) => {
      if(res && res.membre_id) {
        this.removeDest(res.membre_id);
        this.destList.push({
          'id': res.membre_id,
          'username': res.username
        });
      }
      else if(!callback) {
        this.addDestError = 1;
{'fraction_non_alphanumeric': 0.13942307692307693, 'fraction_numerical': 0.00467032967032967, 'mean_word_length': 2.8001043841336117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3819497', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2358, 'n_words': 463}