<commit_before>/**
* Copyright 2016 PT Inovação e Sistemas SA
* Copyright 2016 INESC-ID
* Copyright 2016 QUOBIS NETWORKS SL
* Copyright 2016 FRAUNHOFER-GESELLSCHAFT ZUR FOERDERUNG DER ANGEWANDTEN FORSCHUNG E.V
* Copyright 2016 ORANGE SA
* Copyright 2016 Deutsche Telekom AG
* Copyright 2016 Apizee
* Copyright 2016 TECHNISCHE UNIVERSITAT BERLIN
*
* 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.
**/

/**
* The Group Chat API is used to control a Group Chat instance.
* @author <NAME> [<EMAIL>]
* @version 0.1.0
*/

class ChatController {

  constructor(syncher, discovery, domain, search) {

    if (!syncher) throw Error('Syncher is a necessary dependecy');
    if (!discovery) throw Error('Discover is a necessary dependecy');
    if (!domain) throw Error('Domain is a necessary dependecy');
    if (!search) throw Error('Search is a necessary dependecy');

    let _this = this;
    _this._syncher = syncher;
    _this.discovery = discovery;
    _this.search = search;
    _this.myIdentity = null;
    _this.controllerMode = 'reporter';

    _this._objectDescURL = 'hyperty-catalogue://catalogue.' + domain + '/.well-known/dataschema/Communication';
  }

  set dataObjectReporter(dataObjectReporter) {

    if (!dataObjectReporter) throw new Error('The data object reporter is necessary parameter');
    let _this = this;

    _this.controllerMode = 'reporter';

    dataObjectReporter.onSubscription(function(event) {
      event.accept();
      console.log('[GroupChatManager.ChatController] event', event);
      console.log('[GroupChatManager.ChatController]New user has subscribe this object: ', dataObjectReporter.data, event.identity);

      let participant = event.identity.userProfile;

      console.log('[GroupChatManager.ChatController] new participant', participant);
      if (event.identity.legacy) {
        participant.legacy = event.identity.legacy;
      }

      // TODO: check why the data is empty when we resume;
      let found = Object.values(dataObjectReporter.data.participants || {}).find((user) => {
        console.log('find: ', user.identity.userURL, participant.userURL);
        return user.identity.userURL === participant.userURL;
      });

      dataObjectReporter.data.cseq += 1;
      dataObjectReporter.data.lastModified = new Date().toJSON();

      dataObjectReporter.data.participants[participant.userURL] = { identity: participant };

      console.log('communicationObject OBJ chatcontroller', dataObjectReporter.data.participants);

      console.log('[GroupChatManager.ChatController - onSubscription] ', found, participant);
      if (!found) {
        console.log('[GroupChatManager.ChatController - this._onUserAdded] ', this._onUserAdded);
        if (this._onUserAdded) this._onUserAdded(participant);
      }<commit_msg>Fix the add users to the reporter side<commit_after>/**
* Copyright 2016 PT Inovação e Sistemas SA
* Copyright 2016 INESC-ID
* Copyright 2016 QUOBIS NETWORKS SL
* Copyright 2016 FRAUNHOFER-GESELLSCHAFT ZUR FOERDERUNG DER ANGEWANDTEN FORSCHUNG E.V
* Copyright 2016 ORANGE SA
* Copyright 2016 Deutsche Telekom AG
* Copyright 2016 Apizee
* Copyright 2016 TECHNISCHE UNIVERSITAT BERLIN
*
* 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.
**/

/**
* The Group Chat API is used to control a Group Chat instance.
* @author <NAME> [<EMAIL>]
* @version 0.1.0
*/

class ChatController {

  constructor(syncher, discovery, domain, search) {

    if (!syncher) throw Error('Syncher is a necessary dependecy');
    if (!discovery) throw Error('Discover is a necessary dependecy');
    if (!domain) throw Error('Domain is a necessary dependecy');
    if (!search) throw Error('Search is a necessary dependecy');

    let _this = this;
    _this._syncher = syncher;
    _this.discovery = discovery;
    _this.search = search;
    _this.myIdentity = null;
    _this.controllerMode = 'reporter';

    _this._objectDescURL = 'hyperty-catalogue://catalogue.' + domain + '/.well-known/dataschema/Communication';
  }

  set dataObjectReporter(dataObjectReporter) {

    if (!dataObjectReporter) throw new Error('The data object reporter is necessary parameter');
    let _this = this;

    _this.controllerMode = 'reporter';

    dataObjectReporter.onSubscription(function(event) {
      event.accept();
      console.log('[GroupChatManager.ChatController] event', event);
      console.log('[GroupChatManager.ChatController]New user has subscribe this object: ', dataObjectReporter.data, event.identity);

      let participant = event.identity.userProfile;

      console.log('[GroupChatManager.ChatController] new participant', participant);
      if (event.identity.legacy) {
        participant.legacy = event.identity.legacy;
      }

      // TODO: check why the data is empty when we resume;
      let found = Object.values(dataObjectReporter.data.participants || {}).find((user) => {
        console.log('find: ', user.identity.userURL, participant.userURL);
        return user.identity.userURL === participant.userURL;
      });

      dataObjectReporter.data.cseq += 1;
      dataObjectReporter.data.lastModified = new Date().toJSON();

      dataObjectReporter.data.participants[participant.userURL] = { identity: participant };

      console.log('communicationObject OBJ chatcontroller', dataObjectReporter.data.participants);

      console.log('[GroupChatManager.ChatController - onSubscription] ', found, participant);
      if (!found) {
        console.log('[GroupChatManager.ChatController - this._onUserAdded] ', _this._onUserAdded);
        if (_this._onUserAdded) _this._onUserAdded(participant);
      }
{'fraction_non_alphanumeric': 0.10410958904109589, 'fraction_numerical': 0.0121765601217656, 'mean_word_length': 3.955505279034691, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2636938', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1828, 'n_words': 563}