Compare commits
No commits in common. "master" and "v2.1.0" have entirely different histories.
23
.drone.yml
23
.drone.yml
@ -1,23 +0,0 @@
|
|||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
name: node 14
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: test
|
|
||||||
image: node:14
|
|
||||||
commands:
|
|
||||||
- npm install
|
|
||||||
- npm run build
|
|
||||||
- npm test
|
|
||||||
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
name: node 16
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: test
|
|
||||||
image: node:16
|
|
||||||
commands:
|
|
||||||
- npm install
|
|
||||||
- npm run build
|
|
||||||
- npm test
|
|
3
dist/build.js
vendored
3
dist/build.js
vendored
File diff suppressed because one or more lines are too long
1
dist/build.js.LICENSE.txt
vendored
1
dist/build.js.LICENSE.txt
vendored
@ -1 +0,0 @@
|
|||||||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
2
dist/build.js.map
vendored
2
dist/build.js.map
vendored
File diff suppressed because one or more lines are too long
7040
package-lock.json
generated
7040
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "remotestorage-module-chat-messages",
|
"name": "remotestorage-module-chat-messages",
|
||||||
"version": "2.1.1",
|
"version": "2.1.0",
|
||||||
"description": "Stores chat messages in daily archive files",
|
"description": "Stores chat messages in daily archive files",
|
||||||
"main": "./dist/build.js",
|
"main": "./dist/build.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "NODE_ENV=production webpack",
|
"build": "NODE_ENV=production webpack",
|
||||||
"dev": "webpack -w",
|
"dev": "webpack -w",
|
||||||
"start": "npm run dev",
|
"start": "npm run dev",
|
||||||
"test": "mocha tests/",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"version": "npm run build && git add dist/"
|
"version": "npm run build && git add dist/"
|
||||||
},
|
},
|
||||||
"author": "Kosmos Contributors <mail@kosmos.org> (https://kosmos.org)",
|
"author": "Kosmos Contributors <mail@kosmos.org> (https://kosmos.org)",
|
||||||
@ -18,14 +18,11 @@
|
|||||||
"url": "https://gitea.kosmos.org/kosmos/rs-module-chat-messages.git"
|
"url": "https://gitea.kosmos.org/kosmos/rs-module-chat-messages.git"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.18.10",
|
"@babel/core": "^7.14.8",
|
||||||
"@babel/preset-env": "^7.18.10",
|
"@babel/preset-env": "^7.14.9",
|
||||||
"babel-loader": "^8.2.5",
|
"babel-loader": "^8.2.2",
|
||||||
"chai": "^4.3.6",
|
"webpack": "^5.48.0",
|
||||||
"mocha": "^10.0.0",
|
"webpack-cli": "^4.8.0",
|
||||||
"regenerator-runtime": "^0.13.9",
|
"regenerator-runtime": "^0.13.9"
|
||||||
"sinon": "^14.0.0",
|
|
||||||
"webpack": "^5.74.0",
|
|
||||||
"webpack-cli": "^4.10.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -315,7 +315,7 @@ const ChatMessages = function (privateClient, publicClient) {
|
|||||||
*/
|
*/
|
||||||
if (this.channelType === "room") {
|
if (this.channelType === "room") {
|
||||||
// Normal chatroom
|
// Normal chatroom
|
||||||
const channelName = this.channelName.replace(/^#/,'');
|
const channelName = this.channelName.replace(/#/,'');
|
||||||
this.channelPath = `${this.service.domain}/channels/${channelName}`;
|
this.channelPath = `${this.service.domain}/channels/${channelName}`;
|
||||||
} else {
|
} else {
|
||||||
// User direct messages
|
// User direct messages
|
||||||
@ -489,7 +489,7 @@ const ChatMessages = function (privateClient, publicClient) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_buildArchiveObject () {
|
_buildArchiveObject () {
|
||||||
const roomName = this.channelName.replace(/^#/,'');
|
const roomName = this.channelName.replace(/#/,'');
|
||||||
|
|
||||||
const archive = {
|
const archive = {
|
||||||
"@id": "chat-messages/"+this.service.domain+"/channels/"+roomName+"/",
|
"@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"
|
// Only update document if current date is newer than known "last"
|
||||||
if (Date.parse(meta.last.replace(/\//g,'-')) < Date.parse(this.date)) {
|
if (Date.parse(meta.last.replace('/','-')) > Date.parse(this.date)) {
|
||||||
console.debug('[chat-messages]', 'Updating meta document for channel');
|
console.debug('[chat-messages]', 'Updating meta document for channel');
|
||||||
meta.last = this.dateId;
|
meta.last = this.dateId;
|
||||||
await this.client.storeObject('daily-archive-meta', this.metaPath, meta);
|
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,
|
// 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.
|
// because older versions of the module did not write a meta doc.
|
||||||
const first = await this._findFirstArchive();
|
const first = await this._findFirstArchive();
|
||||||
const roomName = this.channelName.replace(/^#/,'');
|
const roomName = this.channelName.replace(/#/,'');
|
||||||
|
|
||||||
const meta = {
|
const meta = {
|
||||||
'@id': `chat-messages/${this.service.domain}/channels/${roomName}/meta`,
|
'@id': `chat-messages/${this.service.domain}/channels/${roomName}/meta`,
|
||||||
@ -667,10 +667,10 @@ const ChatMessages = function (privateClient, publicClient) {
|
|||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
async _sync (archive) {
|
async _sync (obj) {
|
||||||
console.debug(`[chat-messages] Writing archive object with ${archive.today.messages.length} messages`);
|
console.debug(`[chat-messages] Writing archive object with ${obj.today.messages.length} messages`);
|
||||||
|
|
||||||
return this.client.storeObject('daily-archive', this.path, archive).then(function(){
|
return this.client.storeObject('daily-archive', this.path, obj).then(function(){
|
||||||
console.debug('[chat-messages] Archive written to remote storage');
|
console.debug('[chat-messages] Archive written to remote storage');
|
||||||
return true;
|
return true;
|
||||||
},function(error){
|
},function(error){
|
||||||
|
@ -1,114 +0,0 @@
|
|||||||
const expect = require('chai').expect;
|
|
||||||
const sandbox = require("sinon").createSandbox();
|
|
||||||
const ChatMessages = require('../dist/build');
|
|
||||||
|
|
||||||
const rsClient = {
|
|
||||||
declareType: function() {},
|
|
||||||
getObject: function() {},
|
|
||||||
getListing: function() {},
|
|
||||||
storeObject: function() {},
|
|
||||||
remove: function() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('ChatMessages', function () {
|
|
||||||
|
|
||||||
describe('constructor', function () {
|
|
||||||
let chatMessages;
|
|
||||||
|
|
||||||
before(function() {
|
|
||||||
chatMessages = new ChatMessages.builder(rsClient, rsClient);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('behaves like a remoteStorage module', function () {
|
|
||||||
expect(chatMessages).to.be.an('object');
|
|
||||||
expect(chatMessages.exports).to.be.an('object');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('exports the desired functionality', function () {
|
|
||||||
expect(chatMessages.exports.DailyArchive).to.be.a('function');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('DailyArchive', function () {
|
|
||||||
let archive;
|
|
||||||
|
|
||||||
before(function() {
|
|
||||||
chatMessages = (new ChatMessages.builder(rsClient, rsClient)).exports;
|
|
||||||
|
|
||||||
archive = new chatMessages.DailyArchive({
|
|
||||||
service: { protocol: 'IRC', domain: 'irc.libera.chat' },
|
|
||||||
channelName: '#kosmos',
|
|
||||||
date: new Date('2022-08-11')
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('constructor', function () {
|
|
||||||
it('creates an archive instance with the desired properties', function () {
|
|
||||||
expect(archive).to.be.an('object');
|
|
||||||
expect(archive.service.protocol).to.eq('IRC');
|
|
||||||
expect(archive.service.domain).to.eq('irc.libera.chat');
|
|
||||||
expect(archive.channelName).to.eq('#kosmos');
|
|
||||||
expect(archive.channelType).to.eq('room');
|
|
||||||
expect(archive.date).to.be.a('date');
|
|
||||||
expect(archive.parsedDate.year).to.eq(2022);
|
|
||||||
expect(archive.parsedDate.month).to.eq('08');
|
|
||||||
expect(archive.parsedDate.day).to.eq('11');
|
|
||||||
expect(archive.dateId).to.eq('2022/08/11');
|
|
||||||
expect(archive.isPublic).to.eq(false);
|
|
||||||
expect(archive.channelPath).to.eq('irc.libera.chat/channels/kosmos');
|
|
||||||
expect(archive.path).to.eq('irc.libera.chat/channels/kosmos/2022/08/11');
|
|
||||||
expect(archive.metaPath).to.eq('irc.libera.chat/channels/kosmos/meta');
|
|
||||||
expect(archive.client).to.eq(rsClient);
|
|
||||||
expect(archive.previous).to.be.an('undefined');
|
|
||||||
expect(archive.next).to.be.an('undefined');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#_updateArchiveMetaDocument', function () {
|
|
||||||
describe('meta up to date', function () {
|
|
||||||
before(function() {
|
|
||||||
sandbox.stub(archive.client, 'getObject').withArgs(archive.metaPath)
|
|
||||||
.returns({
|
|
||||||
'@id': `chat-messages/irc.libera.chat/channels/kosmos/meta`,
|
|
||||||
'@type': 'ChatChannelMeta',
|
|
||||||
first: '2021/01/01', last: '2022/08/11'
|
|
||||||
})
|
|
||||||
sandbox.stub(archive.client, 'storeObject');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not store a new archive', async function () {
|
|
||||||
await archive._updateArchiveMetaDocument();
|
|
||||||
sandbox.assert.notCalled(archive.client.storeObject);
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function() { sandbox.restore() });
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('meta needs updating', function () {
|
|
||||||
before(function() {
|
|
||||||
sandbox.stub(archive.client, 'getObject').withArgs(archive.metaPath)
|
|
||||||
.returns({
|
|
||||||
'@id': archive.metaPath,
|
|
||||||
'@type': 'ChatChannelMeta',
|
|
||||||
first: '2021/01/01', last: '2022/08/10'
|
|
||||||
})
|
|
||||||
sandbox.stub(archive.client, 'storeObject');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('stores a new archive', async function () {
|
|
||||||
await archive._updateArchiveMetaDocument();
|
|
||||||
sandbox.assert.calledWithMatch(
|
|
||||||
archive.client.storeObject,
|
|
||||||
'daily-archive-meta', archive.metaPath, {
|
|
||||||
'@id': archive.metaPath, '@type': 'ChatChannelMeta',
|
|
||||||
first: '2021/01/01', last: '2022/08/11'
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function() { sandbox.restore() });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
Loading…
x
Reference in New Issue
Block a user