Author SHA1 Message Date
basti dcf117e1dd Add a couple of message properties 2022-01-04 13:34:30 -06:00
basti a0bec9a12c WIP Introduce Channel class
This is a breaking change, introducing a new Channel class to hold the
channel meta information, and functions to open either the last
DailyArchive, or one for a specified date.
2022-01-04 13:13:21 -06:00
8 changed files with 1028 additions and 6380 deletions

No files matched your search

-23
View File
@@ -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
+1 -2
View File
@@ -1,3 +1,2 @@
/*! For license information please see build.js.LICENSE.txt */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("ChatMessages",[],e):"object"==typeof exports?exports.ChatMessages=e():t.ChatMessages=e()}(this,(()=>(()=>{var t={666:t=>{var e=function(t){"use strict";var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=e&&e.prototype instanceof v?e:v,a=Object.create(o.prototype),i=new P(n||[]);return a._invoke=function(t,e,r){var n=l;return function(o,a){if(n===p)throw new Error("Generator is already running");if(n===y){if("throw"===o)throw a;return M()}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var c=k(i,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===l)throw n=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var s=h(t,e,r);if("normal"===s.type){if(n=r.done?y:f,s.arg===d)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n=y,r.method="throw",r.arg=s.arg)}}}(t,r,i),a}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l="suspendedStart",f="suspendedYield",p="executing",y="completed",d={};function v(){}function g(){}function m(){}var b={};s(b,a,(function(){return this}));var w=Object.getPrototypeOf,x=w&&w(w(N([])));x&&x!==r&&n.call(x,a)&&(b=x);var j=m.prototype=v.prototype=Object.create(b);function L(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function _(t,e){function r(o,a,i,c){var s=h(t[o],t,a);if("throw"!==s.type){var u=s.arg,l=u.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,i,c)}),(function(t){r("throw",t,i,c)})):e.resolve(l).then((function(t){u.value=t,i(u)}),(function(t){return r("throw",t,i,c)}))}c(s.arg)}var o;this._invoke=function(t,n){function a(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(a,a):a()}}function k(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,k(t,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var o=h(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,d;var a=o.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,d):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function N(t){if(t){var r=t[a];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}return{next:M}}function M(){return{value:e,done:!0}}return g.prototype=m,s(j,"constructor",m),s(m,"constructor",g),g.displayName=s(m,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,s(t,c,"GeneratorFunction")),t.prototype=Object.create(j),t},t.awrap=function(t){return{__await:t}},L(_.prototype),s(_.prototype,i,(function(){return this})),t.AsyncIterator=_,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new _(u(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},L(j),s(j,c,"Generator"),s(j,a,(function(){return this})),s(j,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=N,P.prototype={constructor:P,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return c.type="throw",c.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!oLine truncated
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("ChatMessages",[],e):"object"==typeof exports?exports.ChatMessages=e():t.ChatMessages=e()}(this,(function(){return(()=>{var t={666:t=>{var e=function(t){"use strict";var e,r=Object.prototype,n=r.hasOwnProperty,a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",o=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var a=e&&e.prototype instanceof d?e:d,i=Object.create(a.prototype),o=new M(n||[]);return i._invoke=function(t,e,r){var n=l;return function(a,i){if(n===f)throw new Error("Generator is already running");if(n===y){if("throw"===a)throw i;return E()}for(r.method=a,r.arg=i;;){var o=r.delegate;if(o){var s=P(o,r);if(s){if(s===m)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===l)throw n=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=f;var c=h(t,e,r);if("normal"===c.type){if(n=r.done?y:p,c.arg===m)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=y,r.method="throw",r.arg=c.arg)}}}(t,r,o),i}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l="suspendedStart",p="suspendedYield",f="executing",y="completed",m={};function d(){}function g(){}function v(){}var b={};c(b,i,(function(){return this}));var w=Object.getPrototypeOf,x=w&&w(w(C([])));x&&x!==r&&n.call(x,i)&&(b=x);var j=v.prototype=d.prototype=Object.create(b);function k(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function L(t,e){function r(a,i,o,s){var c=h(t[a],t,i);if("throw"!==c.type){var u=c.arg,l=u.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,o,s)}),(function(t){r("throw",t,o,s)})):e.resolve(l).then((function(t){u.value=t,o(u)}),(function(t){return r("throw",t,o,s)}))}s(c.arg)}var a;this._invoke=function(t,n){function i(){return new e((function(e,a){r(t,n,e,a)}))}return a=a?a.then(i,i):i()}}function P(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,P(t,r),"throw"===r.method))return m;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var a=h(n,t.iterator,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,m;var i=a.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,m):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function M(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function C(t){if(t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,o=function r(){for(;++a<t.length;)if(n.call(t,a))return r.value=t[a],r.done=!1,r;return r.value=e,r.done=!0,r};return o.next=o}}return{next:E}}function E(){return{value:e,done:!0}}return g.prototype=v,c(j,"constructor",v),c(v,"constructor",g),g.displayName=c(v,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,c(t,s,"GeneratorFunction")),t.prototype=Object.create(j),t},t.awrap=function(t){return{__await:t}},k(L.prototype),c(L.prototype,o,(function(){return this})),t.AsyncIterator=L,t.async=function(e,r,n,a,i){void 0===i&&(i=Promise);var o=new L(u(e,r,n,a),i);return t.isGeneratorFunction(r)?o:o.next().then((function(t){return t.done?t.value:o.next()}))},k(j),c(j,s,"Generator"),c(j,i,(function(){return this})),c(j,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=C,M.prototype={constructor:M,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function a(n,a){return s.type="throw",s.arg=t,r.next=n,a&&(r.method="next"Line truncated
//# sourceMappingURL=build.js.map
-1
View File
@@ -1 +0,0 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"build.js","mappings":";CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,eAAgB,GAAIH,GACD,iBAAZC,QACdA,QAAsB,aAAID,IAE1BD,EAAmB,aAAIC,GACxB,CATD,CASGK,MAAM,yBCFT,IAAIC,EAAW,SAAUL,GACvB,aAEA,IAEIM,EAFAC,EAAKC,OAAOC,UACZC,EAASH,EAAGI,eAEZC,EAA4B,mBAAXC,OAAwBA,OAAS,CAAC,EACnDC,EAAiBF,EAAQG,UAAY,aACrCC,EAAsBJ,EAAQK,eAAiB,kBAC/CC,EAAoBN,EAAQO,aAAe,gBAE/C,SAASjB,EAAOkB,EAAKC,EAAKC,GAOxB,OANAd,OAAOe,eAAeH,EAAKC,EAAK,CAC9BC,MAAOA,EACPE,YAAY,EACZC,cAAc,EACdC,UAAU,IAELN,EAAIC,EACb,CACA,IAEEnB,EAAO,CAAC,EAAG,GAKb,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A8Bb,SAAShC,EAAOiC,GACd,GAAIA,EAAU,CACZ,IAAIC,EAAiBD,EAASzF,GAC9B,GAAI0F,EACF,OAAOA,EAAezC,KAAKwC,GAG7B,GAA6B,mBAAlBA,EAASd,KAClB,OAAOc,EAGT,IAAKE,MAAMF,EAASG,QAAS,CAC3B,IAAIC,GAAK,EAAGlB,EAAO,SAASA,IAC1B,OAASkB,EAAIJ,EAASG,QACpB,GAAIhG,EAAOqD,KAAKwC,EAAUI,GAGxB,OAFAlB,EAAKnE,MAAQiF,EAASI,GACtBlB,EAAK9B,MAAO,EACL8B,EAOX,OAHAA,EAAKnE,MAAQhB,EACbmF,EAAK9B,MAAO,EAEL8B,GAGT,OAAOA,EAAKA,KAAOA,GAKvB,MAAO,CAAEA,KAAM1C,GAIjB,SAASA,IACP,MAAO,CAAEzB,MAAOhB,EAAWqD,MAAM,GA+MnC,OA7mBAK,EAAkBvD,UAAYwD,EAC9B/D,EAAOqE,EAAI,cAAeN,GAC1B/D,EAAO+D,EAA4B,cAAeD,GAClDA,EAAkB4C,YAAc1G,EAC9B+D,EACA/C,EACA,qBAaFlB,EAAQ6G,oBAAsB,SAASC,GACrC,IAAIC,EAAyB,mBAAXD,GAAyBA,EAAOE,YAClD,QAAOD,IACHA,IAAS/C,GAG2B,uBAAnC+C,EAAKH,aAAeG,EAAKE,QAIhCjH,EAAQkH,KAAO,SAASJ,GAQtB,OAPItG,OAAO2G,eACT3G,OAAO2G,eAAeL,EAAQ7C,IAE9B6C,EAAOM,UAAYnD,EACnB/D,EAAO4G,EAAQ5F,EAAmB,sBAEpC4F,EAAOrG,UAAYD,OAAO4B,OAAOmC,GAC1BuC,GAOT9G,EAAQqH,MAAQ,SAAS1E,GACvB,MLine truncated
+859 -6161
View File
File diff suppressed because it is too large. Load diff
+8 -11
View File
@@ -1,13 +1,13 @@
{
"name": "remotestorage-module-chat-messages",
"version": "2.1.1",
"version": "2.1.0",
"description": "Stores chat messages in daily archive files",
"main": "./dist/build.js",
"scripts": {
"build": "NODE_ENV=production webpack",
"dev": "webpack -w",
"start": "npm run dev",
"test": "mocha tests/",
"test": "echo \"Error: no test specified\" && exit 1",
"version": "npm run build && git add dist/"
},
"author": "Kosmos Contributors <mail@kosmos.org> (https://kosmos.org)",
@@ -18,14 +18,11 @@
"url": "https://gitea.kosmos.org/kosmos/rs-module-chat-messages.git"
},
"devDependencies": {
"@babel/core": "^7.18.10",
"@babel/preset-env": "^7.18.10",
"babel-loader": "^8.2.5",
"chai": "^4.3.6",
"mocha": "^10.0.0",
"regenerator-runtime": "^0.13.9",
"sinon": "^14.0.0",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
"@babel/core": "^7.14.8",
"@babel/preset-env": "^7.14.9",
"babel-loader": "^8.2.2",
"webpack": "^5.48.0",
"webpack-cli": "^4.8.0",
"regenerator-runtime": "^0.13.9"
}
}
+159 -67
View File
@@ -199,55 +199,45 @@ const ChatMessages = function (privateClient, publicClient) {
publicClient.declareType("daily-archive-meta", "https://kosmos.org/ns/v2/chat-channel-meta", archiveMetaSchema);
/**
* A daily archive stores chat messages by calendar day.
* A chat channel
*
* @class
*/
class DailyArchive {
class Channel {
/**
* @param {object} options
* @param {object} options.service
* @param {string} options.service.protocol - Type of chat service/protocol (e.g. "IRC", "XMPP", "Campfire", "Slack")
* @param {string} options.service.domain - Domain of the chat service (e.g. "irc.libera.chat", "kosmos.chat")
* @param {string} options.channelName - Name of room/channel (e.g. "#kosmos")
* @param {string} [options.channelType] - Type of channel ("room" or "person")
* @param {date} options.date - Date of archive day
* @param {boolean} [options.isPublic] - Store logs in public folder (defaults to false)
* @param {string} [options.previous] - Date of previous log file as `YYYY/MM/DD`. Looked up automatically when not given
* @param {string} [options.next] - Date of next log file as `YYYY/MM/DD`. looked up automatically when not given
* @param {string} options.name - Name of room/channel (e.g. "#kosmos")
* @param {string} [options.type] - Type of channel ("room" or "person")
*
* @example
* // IRC archive:
* const archive = new chatMessages.DailyArchive({
* // IRC channel:
* const channel = new remoteStorage.chatMessages.Channel({
* service: {
* protocol: 'IRC',
* domain: 'irc.libera.chat',
* },
* channelName: '#kosmos-dev',
* channelType: 'room',
* date: new Date(),
* isPublic: true
* name: '#kosmos-dev',
* type: 'room'
* });
*
* // XMPP archive:
* const archive = new chatMessages.DailyArchive({
* // XMPP channel:
* const channel = new remoteStorage.chatMessages.Channel({
* service: {
* protocol: 'XMPP',
* domain: 'kosmos.chat',
* },
* channelName: 'kosmos-dev',
* channelType: 'room',
* date: new Date(),
* isPublic: false
* name: 'kosmos-dev',
* type: 'room'
* });
*
*/
constructor (options) {
//
// Defaults
//
options.isPublic = options.isPublic || false;
options.channelType = options.channelType || "room";
options.type = options.type || "room";
//
// Validate options
@@ -258,16 +248,10 @@ const ChatMessages = function (privateClient, publicClient) {
if (typeof options.service !== "object" ||
typeof options.service.protocol !== "string" ||
typeof options.service.domain !== "string") {
throw "service must be an object containing at least service \"protocol\" and \"domain\"";
throw "options.service must be an object containing at least service \"protocol\" and \"domain\"";
}
if (typeof options.channelName !== "string") {
throw "channelName must be a string";
}
if (!(options.date instanceof Date)) {
throw "date must be a date object";
}
if (typeof options.isPublic !== "boolean") {
throw "isPublic must be a boolean value";
if (typeof options.name !== "string") {
throw "options.name must be a string";
}
/**
@@ -278,14 +262,130 @@ const ChatMessages = function (privateClient, publicClient) {
this.service = options.service;
/**
* @property {string} channelName - Name of channel (e.g. "#kosmos")
* @property {string} name - Name of channel (e.g. "#kosmos")
*/
this.channelName = options.channelName;
this.name = options.name;
/**
* @property {string} channelType - Type of channel ("room" or "person")
* @property {string} type - Type of channel ("room" or "person")
*/
this.channelType = options.channelType;
this.type = options.type;
/**
* @property {string} path - Base directory path of the channel archives
*/
if (this.type === "room") {
// Normal chatroom
const name = this.name.replace(/#/,'');
this.path = `${this.service.domain}/channels/${name}`;
} else {
// User direct messages
this.path = `${this.service.domain}/users/${this.name}`;
}
/**
* @property {string} metaPath - Path of the channel's metadata document
*/
this.metaPath = `${this.path}/meta`;
}
/*
* Returns the last stored DailyArchive, or a new one for the current day.
*
* @param {object} options
* @param {boolean} [options.public] - Public or private archive. Defaults to 'false'.
*
* @returns {Promise}
*/
async openLastDailyArchive (options={}) {
const client = options.public ? publicClient : privateClient;
const meta = await client.getObject(this.metaPath);
if (meta && meta.last) {
return new DailyArchive({
channel: this,
date: new Date(meta.last.replace(/\//g,'-')),
isPublic: options.public
});
} else {
return new DailyArchive({
channel: this,
date: new Date(),
isPublic: options.public
});
}
}
/*
* Returns a DailyArchive for the given date
*
* @param {object} options
* @param {date} options.date - Date of archive day
* @param {boolean} [options.public] - Public or private archive. Defaults to 'false'.
*
* @returns {Promise}
*/
openDailyArchive (options={}) {
if (!(options.date instanceof Date)) {
throw 'options.date must be a date object';
}
return new DailyArchive({
channel: this,
date: options.date,
isPublic: options.public
});
}
}
/**
* A daily archive stores chat messages by calendar day.
*
* @class
*/
class DailyArchive {
/**
* @param {object} options
* @param {string} options.channel - A Channel instance
* @param {date} options.date - Date of archive day
* @param {boolean} [options.isPublic] - Store logs in public folder (defaults to false)
* @param {string} [options.previous] - Date of previous log file as `YYYY/MM/DD`. Looked up automatically when not given
* @param {string} [options.next] - Date of next log file as `YYYY/MM/DD`. Looked up automatically when not given
*
* @example
* const channel = new remoteStorage.chatMessages.Channel({ ...options })
* const archive = new chatMessages.DailyArchive({
* channel: channel,
* date: new Date(),
* isPublic: true
* });
*/
constructor (options) {
//
// Defaults
//
options.isPublic = options.isPublic || false;
//
// Validate options
//
if (typeof options !== "object") {
throw "options must be an object";
}
if (!(options.channel instanceof Channel)) {
throw "options.channel must be a Channel object";
}
if (!(options.date instanceof Date)) {
throw "options.date must be a date object";
}
if (typeof options.isPublic !== "boolean") {
throw "options.isPublic must be a boolean value";
}
/**
* @property {Channel} channel - A Channel instance
*/
this.channel = options.channel;
/**
* @property {string} date - Gregorian calendar date of the archive's content
@@ -310,27 +410,15 @@ const ChatMessages = function (privateClient, publicClient) {
*/
this.dateId = this.parsedDate.year+'/'+this.parsedDate.month+'/'+this.parsedDate.day;
/**
* @property {string} channelPath - Base directory path of the channel archives
*/
if (this.channelType === "room") {
// Normal chatroom
const channelName = this.channelName.replace(/^#/,'');
this.channelPath = `${this.service.domain}/channels/${channelName}`;
} else {
// User direct messages
this.channelPath = `${this.service.domain}/users/${this.channelName}`;
}
/**
* @property {string} path - Path of the archive document
*/
this.path = `${this.channelPath}/${this.dateId}`;
this.path = `${this.channel.path}/${this.dateId}`;
/**
* @property {string} metaPath - Path of the channel's metadata document
*/
this.metaPath = `${this.channelPath}/meta`;
this.metaPath = `${this.channel.path}/meta`;
/**
* @property {object} client - Public or private remoteStorgage.js BaseClient
@@ -354,12 +442,14 @@ const ChatMessages = function (privateClient, publicClient) {
* @param {string} message.from - The sender of the message
* @param {string} message.text - The message itself
* @param {string} message.type - Type of message (one of text, join, leave, action)
* @param {string} [message.id] - Unique ID of message. TODO implement
* @param {string} [message.id] - Unique ID of message.
* @param {string} [message.sid] - Unique stanza ID of message (XMPP only)
* @param {boolean} [message.edited] - If the message has been edited
*
* @returns {Promise}
*/
addMessage (message) {
if (this.isPublic && !this.channelName.match(/^#/)) {
if (this.isPublic && !this.channel.name.match(/^#/)) {
return Promise.resolve(false);
}
@@ -384,7 +474,7 @@ const ChatMessages = function (privateClient, publicClient) {
* @returns {Promise}
*/
addMessages (messages, overwrite) {
if (this.isPublic && !this.channelName.match(/^#/)) {
if (this.isPublic && !this.channel.name.match(/^#/)) {
return Promise.resolve(false);
}
@@ -489,14 +579,14 @@ const ChatMessages = function (privateClient, publicClient) {
* @private
*/
_buildArchiveObject () {
const roomName = this.channelName.replace(/^#/,'');
const roomName = this.channel.name.replace(/#/,'');
const archive = {
"@id": "chat-messages/"+this.service.domain+"/channels/"+roomName+"/",
"@id": "chat-messages/"+this.channel.service.domain+"/channels/"+roomName+"/",
"@type": "ChatChannel",
"service": this.service,
"name": this.channelName,
"type": this.channelType,
"service": this.channel.service,
"name": this.channel.name,
"type": this.channel.type,
"today": {
"@id": this.dateId,
"@type": "ChatLog",
@@ -505,10 +595,10 @@ const ChatMessages = function (privateClient, publicClient) {
}
};
switch (this.service.protocol) {
switch (this.channel.service.protocol) {
case 'IRC':
if (!this.channelName.match(/^#/)) {
archive["@id"] = "chat-messages/"+this.service.domain+"/users/"+this.channelName+"/";
if (!this.channel.name.match(/^#/)) {
archive["@id"] = "chat-messages/"+this.channel.service.domain+"/users/"+this.channel.name+"/";
}
break;
case 'XMPP':
@@ -616,7 +706,7 @@ const ChatMessages = function (privateClient, publicClient) {
}
// 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');
meta.last = this.dateId;
await this.client.storeObject('daily-archive-meta', this.metaPath, meta);
@@ -630,10 +720,10 @@ 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.channel.name.replace(/#/,'');
const meta = {
'@id': `chat-messages/${this.service.domain}/channels/${roomName}/meta`,
'@id': `chat-messages/${this.channel.service.domain}/channels/${roomName}/meta`,
'@type': 'ChatChannelMeta',
first: first,
last: this.dateId // TODO might have to search for last?
@@ -667,16 +757,18 @@ const ChatMessages = function (privateClient, publicClient) {
*
* @private
*/
async _sync (archive) {
console.debug(`[chat-messages] Writing archive object with ${archive.today.messages.length} messages`);
async _sync (obj) {
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');
return true;
},function(error){
console.warn('[chat-messages] Error trying to store object', error);
return error;
});
// TODO await this.client.startSync();
}
};
-114
View File
@@ -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() });
});
});
});
});