{"action":"created","comment":{"url":"https://api.github.com/repos/67P/rs-messages-importer/pulls/comments/149377027","pull_request_review_id":74758960,"id":149377027,"diff_hunk":"@@ -0,0 +1,222 @@\n+var fs          = require('fs');\n+var glob        = require(\"glob\");\n+var async       = require('async');\n+var Promise     = require('bluebird');\n+var ProgressBar = require('progress');\n+var path        = require('path');\n+var program     = null;\n+var parseString = require('xml2js').parseString;\n+\n+var RemoteStorage = require(\"remotestoragejs\");\n+var ChatMessages = require(\"remotestorage-module-chat-messages\");\n+var remoteStorage = new RemoteStorage({ modules: [ ChatMessages.default ] });\n+var dailyLogs = {};\n+\n+var collectFiles = function() {\n+  var dir = program.input;\n+  var mucServer = program.adiumMuc;\n+\n+  if (!fs.existsSync(dir)) {\n+    console.log('Input directory doesn\\'t contain Adium logs (should be in ~/Library/Application\\ Support/Adium\\ 2.0/Users/Default/Logs/Jabber.[adium-user]/)');\n+    return false;\n+  }\n+  else {\n+    var logsDir = dir;\n+    var pattern = logsDir+'/**/*'+mucServer+'*.xml';\n+    var files = glob.sync(pattern);\n+\n+    // if (program.zncNetwork && !program.zncChannel) {\n+    //   files = files.filter(function(filename) {\n+    //     var r = new RegExp(program.zncUser+'\\/'+program.zncNetwork+'\\/', 'i');\n+    //     return filename.match(r);\n+    //   });\n+    // }\n+\n+    // if (program.zncChannel) {\n+    //   files = files.filter(function(filename) {\n+    //     var r = new RegExp(program.zncUser+'\\/'+program.zncNetwork+'\\/'+program.zncChannel+'/', 'i');\n+    //     return filename.match(r);\n+    //   });\n+    // }\n+\n+    return files;\n+  }\n+};\n+\n+var setupRemoteStorage = function() {\n+  var pending = Promise.defer();\n+  pending.resolve();\n+\n+  remoteStorage.access.claim(\"messages-irc\", \"rw\");\n+  // remoteStorage.caching.disable(\"/\");\n+\n+  remoteStorage.on('connected', function() {\n+    console.log(\"Remote storage connected\\n\");\n+    pending.resolve();\n+  });\n+  remoteStorage.on('error', function(error) {\n+    console.error('Error:', error);\n+    process.exit(1);\n+  });\n+\n+  remoteStorage.connect(program.rsUser, program.rsToken);\n+\n+  return pending.promise;\n+};\n+\n+var importFromFiles = function(dir, files) {\n+  var pending = Promise.defer();\n+  if (files.length === 0) { pending.resolve(); }\n+\n+  console.log('Parsing '+files.length+' log files from '+dir);\n+\n+  async.eachSeries(files, (filename, callback) => {\n+    let baseName = path.basename(filename);\n+    let matches = baseName.match(/(.+)@.+\\ \\((\\d{4}-\\d{2}-\\d{2}).+\\)\\.xml$/i)\n+    let network = '5apps'\n+    let room = matches[1];\n+    let dateStr = matches[2];\n+    let dateId  = dateStr.replace(/\\-/g, '\\/');\n+\n+    parseFile(filename, dateStr).then(function(messages) {\n+      if (messages.length > 0) {\n+        dailyLogs[network] = dailyLogs[network] || {};\n+        dailyLogs[network][room] = dailyLogs[network][room] || {};\n+        dailyLogs[network][room][dateId] = messages;\n+        callback();\n+      } else {\n+        callback();\n+      }\n+    });\n+  }, () => {\n+    pending.resolve();\n+  });\n+\n+  return pending.promise;\n+};\n+\n+var writeDailyLogsToStorage = function() {\n+  let pending = Promise.defer();\n+  let networks = Object.keys(dailyLogs);\n+  var mucServer = program.adiumMuc;\n+\n+  async.eachSeries(networks, (network, networkCallback) => {\n+    let rooms = Object.keys(dailyLogs[network]);\n+\n+    async.eachSeries(rooms, (room, channelCallback) => {\n+      let days = Object.keys(dailyLogs[network][room]);\n+\n+      console.log(`\\nWriting archives for ${network}/${room} to storage`);\n+      let bar = new ProgressBar(':bar Progress: :current/:total (:percent) ETA: :etas', {\n+        total: days.length,\n+        width: 80\n+      });\n+\n+      async.eachSeries(days, (day, dayCallback) => {\n+        let messages = dailyLogs[network][room][day];\n+        let indexToday = days.findIndex(x => x === day);\n+        let previousDay, nextDay;\n+\n+        if (indexToday > 0) {\n+          previousDay = days[indexToday-1];\n+        }\n+        if (indexToday !== (days.length-1)) {\n+          nextDay = days[indexToday+1];\n+        }\n+\n+        var archive = new remoteStorage.chatMessages.DailyArchive({\n+          server: { type: 'xmpp', name: network, xmppMUC: mucServer },\n+          channelName: room,\n+          date: new Date(messages[0].timestamp),\n+          isPublic: program.rsPublic || false,\n+          previous: previousDay,\n+          next: nextDay\n+        });\n+\n+        archive.addMessages(messages, true).then(() => {\n+          bar.tick();\n+          dayCallback();\n+        }, (error) => {\n+          console.log('Something went wrong:', error);\n+        });\n+      }, () => {\n+        channelCallback();\n+      });\n+    }, () => {\n+      networkCallback();\n+      pending.resolve();\n+    });\n+  }, () => {\n+    pending.resolve();\n+  });\n+\n+  return pending.promise;\n+};\n+\n+var parseFile = function(filename, dateStr) {\n+  let pending = Promise.defer();\n+  let messages = [];\n+  let content = fs.readFileSync(filename);\n+  let r;\n+  let doc = parseString(content, function (err, result) { r = result; });\n+\n+  if(r && r['chat'] && r['chat']['message']) {\n+    r['chat']['message'].forEach(function(m, index) {\n+      let message = {}\n+      if (program.noisy) {\n+        // TODO\n+      }\n+\n+      message.timestamp = Date.parse(m['$']['time']);\n+      message.from = m['$']['sender'];\n+      if(m['div'][0]['span']) {\n+        message.text = m['div'][0]['span'][0]['_'];\n+      } else if(m['div'][0]['a']) {\n+        message.text = m['div'][0]['a'][0]['_'];\n+      }\n+      message.type = \"text\";\n+\n+      if (Object.keys(message).length !== 0) {\n+        messages.push(message);\n+      }\n+\n+      if (index === r['chat']['message'].length-1) {\n+        pending.resolve(messages);\n+      }\n+    });\n+  } else {\n+    pending.resolve(messages);\n+  }\n+\n+  return pending.promise;\n+};\n+\n+module.exports = function(prog) {\n+\n+  program = prog;\n+\n+  if (!fs.existsSync(program.input)) {\n+    console.error('Input directory doesn\\'t exist');\n+    process.exit(1);","path":"importers/adium.js","position":200,"original_position":200,"commit_id":"9b8d92e95cc57fe4ee5619393c00e3d85d083e58","original_commit_id":"9b8d92e95cc57fe4ee5619393c00e3d85d083e58","user":{"login":"skddc","id":842,"avatar_url":"https://avatars1.githubusercontent.com/u/842?v=4","gravatar_id":"","url":"https://api.github.com/users/skddc","html_url":"https://github.com/skddc","followers_url":"https://api.github.com/users/skddc/followers","following_url":"https://api.github.com/users/skddc/following{/other_user}","gists_url":"https://api.github.com/users/skddc/gists{/gist_id}","starred_url":"https://api.github.com/users/skddc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skddc/subscriptions","organizations_url":"https://api.github.com/users/skddc/orgs","repos_url":"https://api.github.com/users/skddc/repos","events_url":"https://api.github.com/users/skddc/events{/privacy}","received_events_url":"https://api.github.com/users/skddc/received_events","type":"User","site_admin":false},"body":"This same check is in line 16?","created_at":"2017-11-07T14:11:03Z","updated_at":"2017-11-07T14:11:03Z","html_url":"https://github.com/67P/rs-messages-importer/pull/3#discussion_r149377027","pull_request_url":"https://api.github.com/repos/67P/rs-messages-importer/pulls/3","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/67P/rs-messages-importer/pulls/comments/149377027"},"html":{"href":"https://github.com/67P/rs-messages-importer/pull/3#discussion_r149377027"},"pull_request":{"href":"https://api.github.com/repos/67P/rs-messages-importer/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/67P/rs-messages-importer/pulls/3","id":151091806,"html_url":"https://github.com/67P/rs-messages-importer/pull/3","diff_url":"https://github.com/67P/rs-messages-importer/pull/3.diff","patch_url":"https://github.com/67P/rs-messages-importer/pull/3.patch","issue_url":"https://api.github.com/repos/67P/rs-messages-importer/issues/3","number":3,"state":"open","locked":false,"title":"Support importing Adium logs","user":{"login":"gregkare","id":43297,"avatar_url":"https://avatars0.githubusercontent.com/u/43297?v=4","gravatar_id":"","url":"https://api.github.com/users/gregkare","html_url":"https://github.com/gregkare","followers_url":"https://api.github.com/users/gregkare/followers","following_url":"https://api.github.com/users/gregkare/following{/other_user}","gists_url":"https://api.github.com/users/gregkare/gists{/gist_id}","starred_url":"https://api.github.com/users/gregkare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gregkare/subscriptions","organizations_url":"https://api.github.com/users/gregkare/orgs","repos_url":"https://api.github.com/users/gregkare/repos","events_url":"https://api.github.com/users/gregkare/events{/privacy}","received_events_url":"https://api.github.com/users/gregkare/received_events","type":"User","site_admin":false},"body":"Connected to #2","created_at":"2017-11-07T11:45:36Z","updated_at":"2017-11-07T14:11:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dd5f0c5d639afcc829cc3c3dd6a5192c01b41506","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/67P/rs-messages-importer/pulls/3/commits","review_comments_url":"https://api.github.com/repos/67P/rs-messages-importer/pulls/3/comments","review_comment_url":"https://api.github.com/repos/67P/rs-messages-importer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/67P/rs-messages-importer/issues/3/comments","statuses_url":"https://api.github.com/repos/67P/rs-messages-importer/statuses/9b8d92e95cc57fe4ee5619393c00e3d85d083e58","head":{"label":"67P:feature/2-adium_logs","ref":"feature/2-adium_logs","sha":"9b8d92e95cc57fe4ee5619393c00e3d85d083e58","user":{"login":"67P","id":9769503,"avatar_url":"https://avatars1.githubusercontent.com/u/9769503?v=4","gravatar_id":"","url":"https://api.github.com/users/67P","html_url":"https://github.com/67P","followers_url":"https://api.github.com/users/67P/followers","following_url":"https://api.github.com/users/67P/following{/other_user}","gists_url":"https://api.github.com/users/67P/gists{/gist_id}","starred_url":"https://api.github.com/users/67P/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/67P/subscriptions","organizations_url":"https://api.github.com/users/67P/orgs","repos_url":"https://api.github.com/users/67P/repos","events_url":"https://api.github.com/users/67P/events{/privacy}","received_events_url":"https://api.github.com/users/67P/received_events","type":"Organization","site_admin":false},"repo":{"id":38201442,"name":"rs-messages-importer","full_name":"67P/rs-messages-importer","owner":{"login":"67P","id":9769503,"avatar_url":"https://avatars1.githubusercontent.com/u/9769503?v=4","gravatar_id":"","url":"https://api.github.com/users/67P","html_url":"https://github.com/67P","followers_url":"https://api.github.com/users/67P/followers","following_url":"https://api.github.com/users/67P/following{/other_user}","gists_url":"https://api.github.com/users/67P/gists{/gist_id}","starred_url":"https://api.github.com/users/67P/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/67P/subscriptions","organizations_url":"https://api.github.com/users/67P/orgs","repos_url":"https://api.github.com/users/67P/repos","events_url":"https://api.github.com/users/67P/events{/privacy}","received_events_url":"https://api.github.com/users/67P/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/67P/rs-messages-importer","description":"CLI for importing chat messages to RemoteStorage accounts","fork":false,"url":"https://api.github.com/repos/67P/rs-messages-importer","forks_url":"https://api.github.com/repos/67P/rs-messages-importer/forks","keys_url":"https://api.github.com/repos/67P/rs-messages-importer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/67P/rs-messages-importer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/67P/rs-messages-importer/teams","hooks_url":"https://api.github.com/repos/67P/rs-messages-importer/hooks","issue_events_url":"https://api.github.com/repos/67P/rs-messages-importer/issues/events{/number}","events_url":"https://api.github.com/repos/67P/rs-messages-importer/events","assignees_url":"https://api.github.com/repos/67P/rs-messages-importer/assignees{/user}","branches_url":"https://api.github.com/repos/67P/rs-messages-importer/branches{/branch}","tags_url":"https://api.github.com/repos/67P/rs-messages-importer/tags","blobs_url":"https://api.github.com/repos/67P/rs-messages-importer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/67P/rs-messages-importer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/67P/rs-messages-importer/git/refs{/sha}","trees_url":"https://api.github.com/repos/67P/rs-messages-importer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/67P/rs-messages-importer/statuses/{sha}","languages_url":"https://api.github.com/repos/67P/rs-messages-importer/languages","stargazers_url":"https://api.github.com/repos/67P/rs-messages-importer/stargazers","contributors_url":"https://api.github.com/repos/67P/rs-messages-importer/contributors","subscribers_url":"https://api.github.com/repos/67P/rs-messages-importer/subscribers","subscription_url":"https://api.github.com/repos/67P/rs-messages-importer/subscription","commits_url":"https://api.github.com/repos/67P/rs-messages-importer/commits{/sha}","git_commits_url":"https://api.github.com/repos/67P/rs-messages-importer/git/commits{/sha}","comments_url":"https://api.github.com/repos/67P/rs-messages-importer/comments{/number}","issue_comment_url":"https://api.github.com/repos/67P/rs-messages-importer/issues/comments{/number}","contents_url":"https://api.github.com/repos/67P/rs-messages-importer/contents/{+path}","compare_url":"https://api.github.com/repos/67P/rs-messages-importer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/67P/rs-messages-importer/merges","archive_url":"https://api.github.com/repos/67P/rs-messages-importer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/67P/rs-messages-importer/downloads","issues_url":"https://api.github.com/repos/67P/rs-messages-importer/issues{/number}","pulls_url":"https://api.github.com/repos/67P/rs-messages-importer/pulls{/number}","milestones_url":"https://api.github.com/repos/67P/rs-messages-importer/milestones{/number}","notifications_url":"https://api.github.com/repos/67P/rs-messages-importer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/67P/rs-messages-importer/labels{/name}","releases_url":"https://api.github.com/repos/67P/rs-messages-importer/releases{/id}","deployments_url":"https://api.github.com/repos/67P/rs-messages-importer/deployments","created_at":"2015-06-28T14:18:56Z","updated_at":"2017-11-07T14:07:10Z","pushed_at":"2017-11-07T11:45:37Z","git_url":"git://github.com/67P/rs-messages-importer.git","ssh_url":"git@github.com:67P/rs-messages-importer.git","clone_url":"https://github.com/67P/rs-messages-importer.git","svn_url":"https://github.com/67P/rs-messages-importer","homepage":null,"size":28,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"67P:master","ref":"master","sha":"ff1351d4928b8fa2f1016e39e945adf4166badfe","user":{"login":"67P","id":9769503,"avatar_url":"https://avatars1.githubusercontent.com/u/9769503?v=4","gravatar_id":"","url":"https://api.github.com/users/67P","html_url":"https://github.com/67P","followers_url":"https://api.github.com/users/67P/followers","following_url":"https://api.github.com/users/67P/following{/other_user}","gists_url":"https://api.github.com/users/67P/gists{/gist_id}","starred_url":"https://api.github.com/users/67P/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/67P/subscriptions","organizations_url":"https://api.github.com/users/67P/orgs","repos_url":"https://api.github.com/users/67P/repos","events_url":"https://api.github.com/users/67P/events{/privacy}","received_events_url":"https://api.github.com/users/67P/received_events","type":"Organization","site_admin":false},"repo":{"id":38201442,"name":"rs-messages-importer","full_name":"67P/rs-messages-importer","owner":{"login":"67P","id":9769503,"avatar_url":"https://avatars1.githubusercontent.com/u/9769503?v=4","gravatar_id":"","url":"https://api.github.com/users/67P","html_url":"https://github.com/67P","followers_url":"https://api.github.com/users/67P/followers","following_url":"https://api.github.com/users/67P/following{/other_user}","gists_url":"https://api.github.com/users/67P/gists{/gist_id}","starred_url":"https://api.github.com/users/67P/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/67P/subscriptions","organizations_url":"https://api.github.com/users/67P/orgs","repos_url":"https://api.github.com/users/67P/repos","events_url":"https://api.github.com/users/67P/events{/privacy}","received_events_url":"https://api.github.com/users/67P/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/67P/rs-messages-importer","description":"CLI for importing chat messages to RemoteStorage accounts","fork":false,"url":"https://api.github.com/repos/67P/rs-messages-importer","forks_url":"https://api.github.com/repos/67P/rs-messages-importer/forks","keys_url":"https://api.github.com/repos/67P/rs-messages-importer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/67P/rs-messages-importer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/67P/rs-messages-importer/teams","hooks_url":"https://api.github.com/repos/67P/rs-messages-importer/hooks","issue_events_url":"https://api.github.com/repos/67P/rs-messages-importer/issues/events{/number}","events_url":"https://api.github.com/repos/67P/rs-messages-importer/events","assignees_url":"https://api.github.com/repos/67P/rs-messages-importer/assignees{/user}","branches_url":"https://api.github.com/repos/67P/rs-messages-importer/branches{/branch}","tags_url":"https://api.github.com/repos/67P/rs-messages-importer/tags","blobs_url":"https://api.github.com/repos/67P/rs-messages-importer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/67P/rs-messages-importer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/67P/rs-messages-importer/git/refs{/sha}","trees_url":"https://api.github.com/repos/67P/rs-messages-importer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/67P/rs-messages-importer/statuses/{sha}","languages_url":"https://api.github.com/repos/67P/rs-messages-importer/languages","stargazers_url":"https://api.github.com/repos/67P/rs-messages-importer/stargazers","contributors_url":"https://api.github.com/repos/67P/rs-messages-importer/contributors","subscribers_url":"https://api.github.com/repos/67P/rs-messages-importer/subscribers","subscription_url":"https://api.github.com/repos/67P/rs-messages-importer/subscription","commits_url":"https://api.github.com/repos/67P/rs-messages-importer/commits{/sha}","git_commits_url":"https://api.github.com/repos/67P/rs-messages-importer/git/commits{/sha}","comments_url":"https://api.github.com/repos/67P/rs-messages-importer/comments{/number}","issue_comment_url":"https://api.github.com/repos/67P/rs-messages-importer/issues/comments{/number}","contents_url":"https://api.github.com/repos/67P/rs-messages-importer/contents/{+path}","compare_url":"https://api.github.com/repos/67P/rs-messages-importer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/67P/rs-messages-importer/merges","archive_url":"https://api.github.com/repos/67P/rs-messages-importer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/67P/rs-messages-importer/downloads","issues_url":"https://api.github.com/repos/67P/rs-messages-importer/issues{/number}","pulls_url":"https://api.github.com/repos/67P/rs-messages-importer/pulls{/number}","milestones_url":"https://api.github.com/repos/67P/rs-messages-importer/milestones{/number}","notifications_url":"https://api.github.com/repos/67P/rs-messages-importer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/67P/rs-messages-importer/labels{/name}","releases_url":"https://api.github.com/repos/67P/rs-messages-importer/releases{/id}","deployments_url":"https://api.github.com/repos/67P/rs-messages-importer/deployments","created_at":"2015-06-28T14:18:56Z","updated_at":"2017-11-07T14:07:10Z","pushed_at":"2017-11-07T11:45:37Z","git_url":"git://github.com/67P/rs-messages-importer.git","ssh_url":"git@github.com:67P/rs-messages-importer.git","clone_url":"https://github.com/67P/rs-messages-importer.git","svn_url":"https://github.com/67P/rs-messages-importer","homepage":null,"size":28,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/67P/rs-messages-importer/pulls/3"},"html":{"href":"https://github.com/67P/rs-messages-importer/pull/3"},"issue":{"href":"https://api.github.com/repos/67P/rs-messages-importer/issues/3"},"comments":{"href":"https://api.github.com/repos/67P/rs-messages-importer/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/67P/rs-messages-importer/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/67P/rs-messages-importer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/67P/rs-messages-importer/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/67P/rs-messages-importer/statuses/9b8d92e95cc57fe4ee5619393c00e3d85d083e58"}},"author_association":"NONE"}}
{"actor":{"display_login":"skddc"}}