<commit_before>// (C) Copyright 2015 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { Component, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';
import { Content } from 'ionic-angular';
import { CoreEventsProvider } from '@providers/events';
import { CoreSitesProvider } from '@providers/sites';
import { AddonMessagesProvider } from '../../providers/messages';
import { CoreDomUtilsProvider } from '@providers/utils/dom';

/**
 * Component that displays the list of confirmed contacts.
 */
@Component({
    selector: 'addon-messages-confirmed-contacts',
    templateUrl: 'addon-messages-confirmed-contacts.html',
})
export class AddonMessagesConfirmedContactsComponent implements OnInit, OnDestroy {
    @Output() onUserSelected = new EventEmitter<{userId: number, onInit?: boolean}>();
    @ViewChild(Content) content: Content;

    loaded = false;
    canLoadMore = false;
    loadMoreError = false;
    contacts = [];
    selectedUserId: number;

    protected memberInfoObserver;

    constructor(private domUtils: CoreDomUtilsProvider, eventsProvider: CoreEventsProvider, sitesProvider: CoreSitesProvider,
            private messagesProvider: AddonMessagesProvider) {

        this.onUserSelected = new EventEmitter();

        // Update block status of a user.
        this.memberInfoObserver = eventsProvider.on(AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT, (data) => {
            if (data.userBlocked || data.userUnblocked) {
                const user = this.contacts.find((user) => user.id == data.userId);
                if (user) {
                    user.isblocked = data.userBlocked;
                }
            } else if (data.contactRemoved) {
                const index = this.contacts.findIndex((contact) => contact.id == data.userId);
                if (index >= 0) {
                    this.contacts.splice(index, 1);
                }
            }
        }, sitesProvider.getCurrentSiteId());
    }

    /**
     * Component loaded.
     */
    ngOnInit(): void {
        this.fetchData().then(() => {
            if (this.contacts.length) {
                this.selectUser(this.contacts[0].id, true);
            }
        }).finally(() => {
            this.loaded = true;
        });
<commit_msg>MOBILE-2734 messages: Refresh contacts when request is confirmed<commit_after>// (C) Copyright 2015 <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { Component, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';
import { Content } from 'ionic-angular';
import { CoreEventsProvider } from '@providers/events';
import { CoreSitesProvider } from '@providers/sites';
import { AddonMessagesProvider } from '../../providers/messages';
import { CoreDomUtilsProvider } from '@providers/utils/dom';

/**
 * Component that displays the list of confirmed contacts.
 */
@Component({
    selector: 'addon-messages-confirmed-contacts',
    templateUrl: 'addon-messages-confirmed-contacts.html',
})
export class AddonMessagesConfirmedContactsComponent implements OnInit, OnDestroy {
    @Output() onUserSelected = new EventEmitter<{userId: number, onInit?: boolean}>();
    @ViewChild(Content) content: Content;

    loaded = false;
    canLoadMore = false;
    loadMoreError = false;
    contacts = [];
    selectedUserId: number;

    protected memberInfoObserver;

    constructor(private domUtils: CoreDomUtilsProvider, eventsProvider: CoreEventsProvider, sitesProvider: CoreSitesProvider,
            private messagesProvider: AddonMessagesProvider) {

        this.onUserSelected = new EventEmitter();

        // Update block status of a user.
        this.memberInfoObserver = eventsProvider.on(AddonMessagesProvider.MEMBER_INFO_CHANGED_EVENT, (data) => {
            if (data.userBlocked || data.userUnblocked) {
                const user = this.contacts.find((user) => user.id == data.userId);
                if (user) {
                    user.isblocked = data.userBlocked;
                }
            } else if (data.contactRemoved) {
                const index = this.contacts.findIndex((contact) => contact.id == data.userId);
                if (index >= 0) {
                    this.contacts.splice(index, 1);
                }
            } else if (data.contactRequestConfirmed) {
                this.refreshData();
            }
        }, sitesProvider.getCurrentSiteId());
    }

    /**
     * Component loaded.
     */
    ngOnInit(): void {
        this.fetchData().then(() => {
            if (this.contacts.length) {
                this.selectUser(this.contacts[0].id, true);
            }
        }).finally(() => {
            this.loaded = true;
        });

{'fraction_non_alphanumeric': 0.11385099685204617, 'fraction_numerical': 0.004547044421126268, 'mean_word_length': 2.6920593931568755, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1220179', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1495, 'n_words': 435}