Fix string replacement

Fixes only the first occurence of `/` being replaced when parsing the
current meta doc's `last` date.
This commit is contained in:
Râu Cao 2022-08-11 10:33:57 +01:00
parent e663a46242
commit 9fb8829901
Signed by: raucao
GPG Key ID: 15E65F399D084BA9

View File

@ -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){