diff --git a/src/chat-messages.js b/src/chat-messages.js index 8f73967..e6cffca 100644 --- a/src/chat-messages.js +++ b/src/chat-messages.js @@ -315,7 +315,7 @@ const ChatMessages = function (privateClient, publicClient) { */ if (this.channelType === "room") { // Normal chatroom - const channelName = this.channelName.replace(/#/,''); + const channelName = this.channelName.replace(/^#/,''); this.channelPath = `${this.service.domain}/channels/${channelName}`; } else { // User direct messages @@ -489,7 +489,7 @@ const ChatMessages = function (privateClient, publicClient) { * @private */ _buildArchiveObject () { - const roomName = this.channelName.replace(/#/,''); + const roomName = this.channelName.replace(/^#/,''); const archive = { "@id": "chat-messages/"+this.service.domain+"/channels/"+roomName+"/", @@ -616,7 +616,7 @@ const ChatMessages = function (privateClient, publicClient) { } // Only update document if current date is newer than known "last" - if (Date.parse(meta.last.replace('/','-')) > Date.parse(this.date)) { + if (Date.parse(meta.last.replace(/\//g,'-')) > Date.parse(this.date)) { console.debug('[chat-messages]', 'Updating meta document for channel'); meta.last = this.dateId; await this.client.storeObject('daily-archive-meta', this.metaPath, meta); @@ -630,7 +630,7 @@ const ChatMessages = function (privateClient, publicClient) { // When creating a new meta doc, we need to find the oldest archive, // because older versions of the module did not write a meta doc. const first = await this._findFirstArchive(); - const roomName = this.channelName.replace(/#/,''); + const roomName = this.channelName.replace(/^#/,''); const meta = { '@id': `chat-messages/${this.service.domain}/channels/${roomName}/meta`, @@ -667,10 +667,10 @@ const ChatMessages = function (privateClient, publicClient) { * * @private */ - async _sync (obj) { - console.debug(`[chat-messages] Writing archive object with ${obj.today.messages.length} messages`); + async _sync (archive) { + console.debug(`[chat-messages] Writing archive object with ${archive.today.messages.length} messages`); - return this.client.storeObject('daily-archive', this.path, obj).then(function(){ + return this.client.storeObject('daily-archive', this.path, archive).then(function(){ console.debug('[chat-messages] Archive written to remote storage'); return true; },function(error){