Update data model, documentation #4

Merged
raucao merged 4 commits from feature/2-update_data_model into master 2021-09-10 12:34:41 +00:00
4 changed files with 149 additions and 150 deletions

No files matched your search

+2 -1
View File
@@ -1 +1,2 @@
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var r in n)("object"==typeof exports?exports:t)[r]=n[r]}}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var s=n[r]={exports:{},id:r,loaded:!1};return t[r].call(s.exports,s,s.exports,e),s.loaded=!0,s.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e){"use strict";function n(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}Object.defineProperty(e,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s=function(t,e){var s={type:"object",properties:{"@context":{type:"string",default:"https://kosmos.org/ns/v1",enum:["https://kosmos.org/ns/v1"]},"@id":{type:"string",required:!0},"@type":{type:"string",default:"ChatChannel",enum:["ChatChannel"]},name:{type:"string",required:!0},ircURI:{type:"string",format:"uri"},xmppURI:{type:"string",format:"uri"},today:{type:"object",properties:{"@id":{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$",required:!0},"@type":{type:"string",default:"ChatLog",pattern:"^ChatLog$"},messageType:{type:"string",default:"InstantMessage",pattern:"^InstantMessage$"},previous:{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$"},next:{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$"},messages:{type:"array",required:!0,items:{type:"object",properties:{date:{type:"string",format:"date-time"},user:{type:"string"},text:{type:"string"},type:"string",default:"text",enum:["text","join","leave","action"]}}}}}},required:[]};t.declareType("daily-archive","https://kosmos.org/ns/v1",s),e.declareType("daily-archive","https://kosmos.org/ns/v1",s);var i=function(n){if(n.isPublic=n.isPublic||!1,"object"!==("undefined"==typeof n?"undefined":r(n)))throw"options must be an object";if("object"!==r(n.server)||"string"!=typeof n.server.type||"string"!=typeof n.server.name)throw'server must be an object containing at least server "type" and "name"';if("string"!=typeof n.channelName)throw"channelName must be a string";if(!(n.date instanceof Date))throw"date must be a date object";if("boolean"!=typeof n.isPublic)throw"isPublic must be a boolean value";switch(this.server=n.server,this.channelName=n.channelName,this.date=n.date,this.isPublic=n.isPublic,this.parsedDate=o(this.date),this.dateId=this.parsedDate.year+"/"+this.parsedDate.month+"/"+this.parsedDate.day,this.server.type){case"irc":if(this.channelName.match(/^#/)){var s=this.channelName.replace(/^#/,"");this.path=this.server.name+"/channels/"+s+"/"+this.dateId}else this.path=this.server.name+"/users/"+this.channelName+"/"+this.dateId;break;default:this.path=this.server.name+"/"+this.channelName+"/"+this.dateId}this.client=this.isPublic?e:t,this.previous=n.previous,this.next=n.next};i.prototype={addMessage:function(t){var e=this;return this.isPublic&&!this.channelName.match(/^#/)?Promise.resolve(!1):(t.type=t.type||"text",this.client.getObject(this.path).then(function(n){return"object"===("undefined"==typeof n?"undefined":r(n))?e._updateDocument(n,t):e._createDocument(t)}))},addMessages:function(t,e){var n=this;return this.isPublic&&!this.channelName.match(/^#/)?Promise.resolve(!1):(e=e||!1,t.forEach(function(t){t.type=t.type||"text"}),e?this._createDocument(t):this.client.getObject(this.path).then(function(e){return"object"===("undefined"==typeof e?"undefined":r(e))?n._updateDocument(e,t):n._createDocument(t)}))},remove:function(){return this.client.remove(this.path)},_updateDocument:function(t,e){return console.debug("[chat-messages] Updating archive document",t),Array.isArray(e)?e.forEach(function(e){t.today.messages.push(e)}):t.today.messages.push(e),this._sync(t)},_createDocument:function(t){var e=this;console.debug("[chat-messages] Creating new archive document");var n=this._buildArchiveObject();return Array.isArray(t)?t.forEach(function(t){n.today.messages.push(t)}):n.today.messages.push(t),this.previous||this.next?(this.previous&&(n.today.previous=this.previous),this.next&&(n.today.next=this.next),this._sync(n)):this._updatePreviousArchive().then(function(t){return"object"===("undefined"==typeof t?"undefined":r(t))&&(n.today.previous=t.today["@id"]),e._sync(n)})},_buildArchiveObject:function(){var t=this.channelName.replace(/#/,""),e={"@id":"chat-messages/"+this.server.name+"/channels/"+t+"/","@type":"ChatChannel",name:this.channelName,today:{"@id":this.dateId,"@type":"ChatLog",messageType:"InstantMessage",messages:[]}};switch(this.server.type){case"irc":this.channelName.match(/^#/)||(e["@id"]="chat-messages/"+this.server.name+"/users/"+this.channelName+"/"),e.ircURI=this.server.ircURI+"/"+t;break;case"xmpp":e.xmppURI="xmpp:"+this.channelName+"@"+this.server.xmppMUC}return e},_updatePreviousArchive:functiLine truncated
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ChatMessages=e():t.ChatMessages=e()}(self,(function(){return(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function n(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function a(t){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function s(t){return 1===(t=String(t)).length&&(t="0"+t),t}t.d(e,{default:()=>o});const o={name:"chat-messages",builder:function(t,e){var r={type:"object",properties:{"@context":{type:"string",default:"https://kosmos.org/ns/v1",enum:["https://kosmos.org/ns/v1"]},"@id":{type:"string",required:!0},"@type":{type:"string",default:"ChatChannel",enum:["ChatChannel"]},service:{type:"object",properties:{domain:{type:"string",required:!0},protocol:{type:"string",required:!0}}},name:{type:"string",required:!0},type:{type:"string",required:!0,enum:["room","person"]},today:{type:"object",properties:{"@id":{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$",required:!0},"@type":{type:"string",default:"ChatLog",pattern:"^ChatLog$"},messageType:{type:"string",default:"InstantMessage",pattern:"^InstantMessage$"},previous:{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$"},next:{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$"},messages:{type:"array",required:!0,items:{type:"object",properties:{date:{type:"string",format:"date-time"},user:{type:"string"},text:{type:"string"},type:"string",default:"text",enum:["text","join","leave","action"]}}}}}},required:[]};return t.declareType("daily-archive","https://kosmos.org/ns/v1",r),e.declareType("daily-archive","https://kosmos.org/ns/v1",r),{exports:{DailyArchive:function(){function r(n){if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,r),n.isPublic=n.isPublic||!1,n.channelType=n.channelType||"room","object"!==a(n))throw"options must be an object";if("object"!==a(n.service)||"string"!=typeof n.service.protocol||"string"!=typeof n.service.domain)throw'service must be an object containing at least service "protocol" and "domain"';if("string"!=typeof n.channelName)throw"channelName must be a string";if(!(n.date instanceof Date))throw"date must be a date object";if("boolean"!=typeof n.isPublic)throw"isPublic must be a boolean value";var i;if(this.service=n.service,this.channelName=n.channelName,this.channelType=n.channelType,this.date=n.date,this.isPublic=n.isPublic||!1,this.parsedDate={year:(i=this.date).getUTCFullYear(),month:s(i.getUTCMonth()+1),day:s(i.getUTCDate())},this.dateId=this.parsedDate.year+"/"+this.parsedDate.month+"/"+this.parsedDate.day,"room"===this.channelType){var o=this.channelName.replace(/#/,"");this.path="".concat(this.service.domain,"/channels/").concat(o,"/").concat(this.dateId)}else this.path="".concat(this.service.domain,"/users/").concat(this.channelName,"/").concat(this.dateId);this.client=this.isPublic?e:t,this.previous=n.previous,this.next=n.next}var o,c;return o=r,(c=[{key:"addMessage",value:function(t){var e=this;return this.isPublic&&!this.channelName.match(/^#/)?Promise.resolve(!1):(t.type=t.type||"text",this.client.getObject(this.path).then((function(n){return"object"===a(n)?e._updateDocument(n,t):e._createDocument(t)})))}},{key:"addMessages",value:function(t,e){var n=this;return this.isPublic&&!this.channelName.match(/^#/)?Promise.resolve(!1):(e=e||!1,t.forEach((function(t){t.type=t.type||"text"})),e?this._createDocument(t):this.client.getObject(this.path).then((function(e){return"object"===a(e)?n._updateDocument(e,t):n._createDocument(t)})))}},{key:"remove",value:function(){return this.client.remove(this.path)}},{key:"_updateDocument",value:function(t,e){return console.debug("[chat-messages] Updating archive document",t),Array.isArray(e)?e.forEach((function(e)Line truncated
//# sourceMappingURL=build.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap fea08dbeb235bc9f8782","webpack:///./index.js","webpack:///external {\"root\":\"RemoteStorage\",\"commonjs2\":\"remotestoragejs\",\"commonjs\":\"remotestoragejs\",\"amd\":\"remotestoragejs\"}"],"names":["RemoteStorage","require","defineModule","privateClient","publicClient","archiveSchema","declareType","DailyArchive","options","isPublic","server","type","name","channelName","date","Date","parsedDate","parseDate","dateId","year","month","day","match","replace","path","client","previous","next","prototype","addMessage","message","Promise","resolve","getObject","then","archive","_updateDocument","_createDocument","addMessages","messages","overwrite","forEach","remove","log","Array","isArray","today","push","_sync","_buildArchiveObject","_updatePreviousArchive","roomName","ircURI","xmppMUC","_findPreviousArchive","substring","length","storeObject","monthPath","yearPath","basePath","getListing","listing","days","Object","keys","map","i","parseInt","filter","pad","Math","max","toString","months","substr","years","obj","error","console","num","String","getUTCFullYear","getUTCMonth","getUTCDate","exports"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;;;;;ACtCA,KAAIA,gBAAgB,mBAAAC,CAAQ,CAAR,CAApB;;AAEAD,eAAcE,YAAd,CAA2B,eAA3B,EAA4C,UAAUC,aAAV,EAAyBC,YAAzB,EAAuC;;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,OAAMC,gBAAgB;AACpB,aAAQ,QADY;AAEpB,mBAAc;AACZ,mBAAY;AACV,iBAAQ,QADE;AAEV,oBAAW,0BAFD;AAGV,iBAAQ,CAAC,0BAAD;AAHE,QADA;AAMZ,cAAO;AACL,iBAAQ,QADH;AAEL,qBAAY;AAFP,QANK;AAUZ,gBAAS;AACP,iBAAQ,QADD;AAEP,oBAAW,aAFJ;AAGP,iBAAQ,CAAC,aAAD;AAHD,QAVG;AAeZ,eAAQ;AACN,iBAAQ,QADF;AAEN,qBAAY;AAFN,QAfI;AAmBZ,iBAAU;AACR,iBAAQ,QADA;AAER,mBAAU;AAFF,QAnBE;AAuBZ,kBAAW;AACT,iBAAQ,QADC;AAET,mBAAU;AAFD,QAvBC;AA2BZ,gBAAS;AACP,iBAAQ,QADD;AAEP,uBAAc;AACZ,kBAAO;AACL,qBAAQ,QADH;AAEL,wB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K6B,UAAU,EAAGvC,KAAKU,KAAK3B,OAAO,GACpD2D,EAAW1C,KAAKU,KAAK6B,UAAU,EAAGvC,KAAKU,KAAK3B,OAAO,GACnD4D,EAAW3C,KAAKU,KAAK6B,UAAU,EAAGvC,KAAKU,KAAK3B,OAAO,IAEzD,OAAOiB,KAAKW,OAAOiC,WAAWH,GAAWrB,MAAK,SAACyB,GAC7C,IAAMC,EAAO3E,OAAO4E,KAAKF,GAASG,KAAI,SAACC,GAAD,OAAOC,SAASD,MAAID,KAAI,SAACC,GAC7D,OAAQA,EAAIC,SAAS,EAAKjD,WAAWK,KAAQ2C,EAAI,QAChDE,QAAO,SAASF,GAAI,OAAY,MAALA,KAE9B,GAAIH,EAAK/D,OAAS,EAAG,CACnB,IAAMuB,EAAM1B,EAAIwE,KAAKC,IAAL,MAAAD,KAAI,EAAQN,IAAMQ,YAClC,OAAO,EAAK3C,OAAOQ,UAAUsB,EAAUnC,GAIzC,OAAO,EAAKK,OAAOiC,WAAWF,GAAUtB,MAAK,SAACyB,GAC5C,IAAMU,EAASpF,OAAO4E,KAAKF,GAASG,KAAI,SAACC,GAAD,OAAOC,SLine truncated
+145 -147
View File
@@ -16,18 +16,20 @@ const ChatMessages = function (privateClient, publicClient) {
/**
* Schema: chat-messages/daily
*
* Represents one day of chat messages
* Represents one calendar day of chat messages
*
* Example:
*
* (start code)
* @example
* {
* "@context": "https://kosmos.org/ns/v1",
* "@id": "chat-messages/freenode/channels/kosmos/",
* "@id": "chat-messages/irc.libera.chat/channels/kosmos/",
* "@type": "ChatChannel",
* "service": {
* "domain": "irc.libera.chat",
* "protocol": "IRC",
* },
* "name": "#kosmos",
* "ircURI": "irc://irc.freenode.net/kosmos",
* "today": {
* "type": "room",
* "today": {
* "@id": "2015/01/01",
* "@type": "ChatLog",
* "messageType": "InstantMessage",
@@ -40,9 +42,7 @@ const ChatMessages = function (privateClient, publicClient) {
* ]
* }
* }
* (end code)
*/
const archiveSchema = {
"type": "object",
"properties": {
@@ -60,17 +60,27 @@ const ChatMessages = function (privateClient, publicClient) {
"default": "ChatChannel",
"enum": ["ChatChannel"]
},
"service": {
"type": "object",
"properties": {
"domain": {
"type": "string",
"required": true
},
"protocol": {
"type": "string",
"required": true
}
}
},
"name": {
"type": "string",
"required": true
},
"ircURI": {
"type": {
"type": "string",
"format": "uri"
},
"xmppURI": {
"type": "string",
"format": "uri"
"required": true,
"enum": [ "room", "person" ]
},
"today": {
"type": "object",
@@ -135,56 +145,55 @@ const ChatMessages = function (privateClient, publicClient) {
publicClient.declareType("daily-archive", "https://kosmos.org/ns/v1", archiveSchema);
/**
* Class: DailyArchive
* A daily archive stores chat messages by calendar day.
*
* A daily archive stores IRC messages by day.
*
* Parameters (object):
* server - Chat server info (see <DailyArchive.server>)
* channelName - Name of room/channel
* date - Date of archive day
* isPublic - Store logs in public folder (defaults to false)
* previous - Date of previous log file as YYYY/MM/DD;
* looked up automatically when not given
* next - Date of next log file as YYYY/MM/DD;
* looked up automatically when not given
*
* Example for IRC:
*
* (start code)
* const archive = new chatMessages.DailyArchive({
* server: {
* type: 'irc',
* name: 'freenode',
* ircURI: 'irc://irc.freenode.net'
* },
* channelName: '#kosmos',
* date: new Date(),
* isPublic: true
* });
* (end code)
*
* Example for XMPP:
*
* (start code)
* const archive = new chatMessages.DailyArchive({
* server: {
* type: 'xmpp',
* name: '5apps',
* xmppMUC: 'muc.5apps.com'
* },
* channelName: 'watercooler',
* date: new Date(),
* isPublic: false
* });
* (end code)
* @class
*/
class DailyArchive {
/**
* @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
*
* @example
* // IRC archive:
* const archive = new chatMessages.DailyArchive({
* service: {
* protocol: 'IRC',
* domain: 'irc.libera.chat',
* },
* channelName: '#kosmos-dev',
* channelType: 'room',
* date: new Date(),
* isPublic: true
* });
*
* // XMPP archive:
* const archive = new chatMessages.DailyArchive({
* service: {
* protocol: 'XMPP',
* domain: 'kosmos.chat',
* },
* channelName: 'kosmos-dev',
* channelType: 'room',
* date: new Date(),
* isPublic: false
* });
*
*/
constructor (options) {
//
// Defaults
//
options.isPublic = options.isPublic || false;
options.isPublic = options.isPublic || false;
options.channelType = options.channelType || "room";
//
// Validate options
@@ -192,10 +201,10 @@ const ChatMessages = function (privateClient, publicClient) {
if (typeof options !== "object") {
throw "options must be an object";
}
if (typeof options.server !== "object" ||
typeof options.server.type !== "string" ||
typeof options.server.name !== "string") {
throw "server must be an object containing at least server \"type\" and \"name\"";
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\"";
}
if (typeof options.channelName !== "string") {
throw "channelName must be a string";
@@ -208,104 +217,82 @@ const ChatMessages = function (privateClient, publicClient) {
}
/**
* Property: server
*
* Contains information about the chat server/network
*
* Properties:
* type - Type of server/protocol (e.g. "irc", "xmpp", "campfire", "slack")
* name - Shortname/id/alias of network/server (e.g. "freenode", "mycompanyname")
* ircURI - (optional) IRC URI of network (e.g. "irc://irc.freenode.net/")
* xmppMUC - (optional) XMPP MUC service host (e.g. "conference.jabber.org")
* @property {object} service
* @property {string} service.protocol - Type of chat service/protocol (e.g. "IRC", "XMPP", "campfire", "slack")
* @property {string} service.domain - Domain of the chat service (e.g. "irc.libera.chat", "kosmos.chat")
*/
this.server = options.server;
this.service = options.service;
/**
* Property: channelName
*
* Name of the IRC channel (e.g. "#kosmos")
* @property {string} channelName - Name of channel (e.g. "#kosmos")
*/
this.channelName = options.channelName;
/**
* Property: date
*
* Date of the archive's content
* @property {string} channelType - Type of channel ("room" or "person")
*/
this.channelType = options.channelType;
/**
* @property {string} date - Gregorian calendar date of the archive's content
*/
this.date = options.date;
/**
* Property: isPublic
*
* `true` for public archives, `false` for private ones
* @property {boolean} isPublic - `true` for public archives, `false` for private ones
*/
this.isPublic = options.isPublic;
this.isPublic = options.isPublic || false;
/**
* Property: parsedDate
*
* Object containing padded year, month and day of date
* @property {object} parsedDate - Contains padded year, month and day of date
* @property {string} year
* @property {string} month
* @property {string} day
*/
this.parsedDate = parseDate(this.date);
/**
* Property: dateId
*
* Date string in the form of YYYY/MM/DD
* @property {string} dateId - Date string in the form of YYYY/MM/DD
*/
this.dateId = this.parsedDate.year+'/'+this.parsedDate.month+'/'+this.parsedDate.day;
/**
* Property: path
*
* Document path of the archive file
* @property {string} path - Document path of the archive file
*/
switch (this.server.type) {
case 'irc':
if (this.channelName.match(/^#/)) {
// normal chatroom
const channelName = this.channelName.replace(/^#/,'');
this.path = `${this.server.name}/channels/${channelName}/${this.dateId}`;
} else {
// user direct message
this.path = `${this.server.name}/users/${this.channelName}/${this.dateId}`;
}
break;
default:
this.path = `${this.server.name}/${this.channelName}/${this.dateId}`;
break;
if (this.channelType === "room") {
// Normal chatroom
const channelName = this.channelName.replace(/#/,'');
this.path = `${this.service.domain}/channels/${channelName}/${this.dateId}`;
} else {
// User direct message
this.path = `${this.service.domain}/users/${this.channelName}/${this.dateId}`;
}
/**
* Property: client
*
* Public or private BaseClient, depending on isPublic
* @property {object} client - Public or private remoteStorgage.js BaseClient
*/
this.client = this.isPublic ? publicClient : privateClient;
/**
* Property: previous
*
* Date of previous log file as YYYY/MM/DD
* @property {string} previous - Date of previous log file as YYYY/MM/DD
*/
this.previous = options.previous;
/**
* Property: next
*
* Date of next log file as YYYY/MM/DD
* @property {string} next - Date of next log file as YYYY/MM/DD
*/
this.next = options.next;
}
/*
* Method: addMessage
* @param {object} message
* @param {string} message.timestamp - Timestamp of the message
* @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
*
* Parameters (object):
* timestamp - Timestamp of the message
* from - The sender of the message
* text - The message itself
* type - Type of message (one of text, join, leave, action)
* @returns {Promise}
*/
addMessage (message) {
if (this.isPublic && !this.channelName.match(/^#/)) {
@@ -324,15 +311,13 @@ const ChatMessages = function (privateClient, publicClient) {
}
/*
* Method: addMessages
*
* Like <addMessage>, but for multiple messages at once. Useful for bulk
* imports of messages.
*
* Parameters:
* messages - Array of message objects (see params for addMessage)
* overwrite - If true, creates a new archive file and overwrites the
* old one. Defaults to false.
* @param {Array} messages - Array of message objects (see params for addMessage)
* @param {boolean} overwrite - If true, creates a new archive file and overwrites the old one. Defaults to false.
*
* @returns {Promise}
*/
addMessages (messages, overwrite) {
if (this.isPublic && !this.channelName.match(/^#/)) {
@@ -359,18 +344,20 @@ const ChatMessages = function (privateClient, publicClient) {
}
/*
* Method: remove
*
* Deletes the entire archive document from storage
*
* @returns {Promise}
*/
remove () {
return this.client.remove(this.path);
}
/*
* Method: _updateDocument
*
* Updates and writes an existing archive document
*
* @returns {Promise}
*
* @private
*/
_updateDocument (archive, messages) {
console.debug('[chat-messages] Updating archive document', archive);
@@ -387,9 +374,11 @@ const ChatMessages = function (privateClient, publicClient) {
}
/*
* Method: _createDocument
*
* Creates and writes a new archive document
*
* @returns {Promise}
*
* @private
*/
_createDocument (messages) {
console.debug('[chat-messages] Creating new archive document');
@@ -421,17 +410,21 @@ const ChatMessages = function (privateClient, publicClient) {
}
/*
* Method: _buildArchiveObject
*
* Builds the object to be stored in remote storage
*
* @returns {object}
*
* @private
*/
_buildArchiveObject () {
const roomName = this.channelName.replace(/#/,'');
const archive = {
"@id": "chat-messages/"+this.server.name+"/channels/"+roomName+"/",
"@id": "chat-messages/"+this.service.domain+"/channels/"+roomName+"/",
"@type": "ChatChannel",
"service": this.service,
"name": this.channelName,
"type": this.channelType,
"today": {
"@id": this.dateId,
"@type": "ChatLog",
@@ -440,15 +433,14 @@ const ChatMessages = function (privateClient, publicClient) {
}
};
switch (this.server.type) {
case 'irc':
switch (this.service.protocol) {
case 'IRC':
if (!this.channelName.match(/^#/)) {
archive["@id"] = "chat-messages/"+this.server.name+"/users/"+this.channelName+"/";
archive["@id"] = "chat-messages/"+this.service.domain+"/users/"+this.channelName+"/";
}
archive["ircURI"] = this.server.ircURI+"/"+roomName;
break;
case 'xmpp':
archive["xmppURI"] = `xmpp:${this.channelName}@${this.server.xmppMUC}`;
case 'XMPP':
// XMPP-specific adjustments
break;
}
@@ -456,9 +448,11 @@ const ChatMessages = function (privateClient, publicClient) {
}
/*
* Method: _updatePreviousArchive
*
* Finds the previous archive document and updates its today.next value
*
* @returns {boolean|Promise}
*
* @private
*/
_updatePreviousArchive () {
return this._findPreviousArchive().then((archive) => {
@@ -478,9 +472,11 @@ const ChatMessages = function (privateClient, publicClient) {
}
/*
* Method: _findPreviousArchive
*
* Returns the previous archive document
*
* @returns {Promise}
*
* @private
*/
_findPreviousArchive () {
const monthPath = this.path.substring(0, this.path.length-2);
@@ -542,9 +538,11 @@ const ChatMessages = function (privateClient, publicClient) {
}
/*
* Method: _sync
*
* Write archive document
*
* @returns {Promise}
*
* @private
*/
_sync (obj) {
console.debug('[chat-messages] Writing archive object', obj);
+1 -1
View File
@@ -3,7 +3,7 @@ const isProd = (process.env.NODE_ENV === 'production');
const path = require('path');
module.exports = {
entry: ['./index.js'],
entry: ['./src/chat-messages.js'],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'build.js',