<commit_before>angular.module('classeur.core.sync.contentSync', [])
  .factory('clContentSyncSvc',
    function ($rootScope, $timeout, $q, clRestSvc, clSetInterval, clSocketSvc, clUserSvc, clUserActivity, clSyncDataSvc, clFileSvc, clToast, clDiffUtils, clEditorSvc, clEditorContentSvc, clUserInfoSvc, clUid, clIsNavigatorOnline, clIsSyncWindow, clEditorLayoutSvc) {
      var loadingTimeout = 30 * 1000 // 30 sec
      var textMaxSize = 200000
      var backgroundUpdateContentEvery = 30 * 1000 // 30 sec
      var clContentSyncSvc = {}
      var watchCtx

      function setWatchCtx (ctx) {
        watchCtx = ctx
        clContentSyncSvc.watchCtx = ctx
      }
      clSocketSvc.addMsgHandler('userToken', setWatchCtx.cl_bind(null, null))

      function setLoadedContent (file, serverContent) {
        file.setLoaded()
        file.content.text = serverContent.text
        file.content.properties = ({}).cl_extend(serverContent.properties)
        file.content.discussions = ({}).cl_extend(serverContent.discussions)
        file.content.comments = ({}).cl_extend(serverContent.comments)
        file.content.state = {}
        // addToDaos calls init
        if (!file.addToDaos) {
          clFileSvc.init() // Will delete the content if called while file is not in the daos
        }
      }

      function setLoadingError (file, error) {
        if (file.state === 'loading') {
          file.state = undefined
        }
        error
          ? clToast(error)
          : clToast.notAccessible(file)
      }

      function applyServerContent (file, oldContent, serverContent) {
        var newContent = clDiffUtils.mergeFlattenContent(oldContent, file.content, serverContent)
        file.content.text = newContent.text
        file.content.properties = newContent.properties
        file.content.discussions = newContent.discussions
        file.content.comments = newContent.comments
        clEditorContentSvc.applyContent(true)
      }

      function watchContent (file) {
        if (watchCtx) {<commit_msg>Fixed major bug causing content with comments to be garbled. See #113 and #126<commit_after>angular.module('classeur.core.sync.contentSync', [])
  .factory('clContentSyncSvc',
    function ($rootScope, $timeout, $q, clRestSvc, clSetInterval, clSocketSvc, clUserSvc, clUserActivity, clSyncDataSvc, clFileSvc, clToast, clDiffUtils, clEditorSvc, clEditorContentSvc, clUserInfoSvc, clUid, clIsNavigatorOnline, clIsSyncWindow, clEditorLayoutSvc) {
      var loadingTimeout = 30 * 1000 // 30 sec
      var textMaxSize = 200000
      var backgroundUpdateContentEvery = 30 * 1000 // 30 sec
      var clContentSyncSvc = {}
      var watchCtx

      function setWatchCtx (ctx) {
        watchCtx = ctx
        clContentSyncSvc.watchCtx = ctx
      }
      clSocketSvc.addMsgHandler('userToken', setWatchCtx.cl_bind(null, null))

      function setLoadedContent (file, serverContent) {
        file.setLoaded()
        file.content.text = serverContent.text
        file.content.properties = clDiffUtils.cloneObject(serverContent.properties)
        file.content.discussions = clDiffUtils.cloneObject(serverContent.discussions)
        file.content.comments = clDiffUtils.cloneObject(serverContent.comments)
        file.content.state = {}
        // addToDaos calls init
        if (!file.addToDaos) {
          clFileSvc.init() // Will delete the content if called while file is not in the daos
        }
      }

      function setLoadingError (file, error) {
        if (file.state === 'loading') {
          file.state = undefined
        }
        error
          ? clToast(error)
          : clToast.notAccessible(file)
      }

      function applyServerContent (file, oldContent, serverContent) {
        var newContent = clDiffUtils.mergeFlattenContent(oldContent, file.content, serverContent)
        file.content.text = newContent.text
        file.content.properties = newContent.properties
        file.content.discussions = newContent.discussions
        file.content.comments = newContent.comments
        clEditorContentSvc.applyContent(true)
      }

      function watchContent (file) {
        if (watchCtx) {
{'fraction_non_alphanumeric': 0.0929054054054054, 'fraction_numerical': 0.012065637065637066, 'mean_word_length': 2.884723523898782, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2734492', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1183, 'n_words': 253}