13 Commits

7 changed files with 46 additions and 25 deletions

View File

@@ -4,19 +4,37 @@
Stores chat messages in daily archive documents. Stores chat messages in daily archive documents.
Please feel free to open GitHub issues for questions, feature requests, ## Usage
protocol proposals, and whatever else you like.
## Protocols Open a daily archive and write messages to it:
### Currently supported ```js
const RemoteStorage = require("remotestoragejs");
const ChatMessages = require("remotestorage-module-chat-messages");
const remoteStorage = new RemoteStorage({ modules: [ ChatMessages ] });
* IRC const archive = new remoteStorage.chatMessages.DailyArchive({
* XMPP service: {
protocol: 'IRC',
domain: 'irc.libera.chat'
},
channelName: '#kosmos',
date: new Date(),
isPublic: true // Channel logs will be written to public folder
});
### Planned const messages = [
{ "date": "2015-06-05T17:35:28.454Z", "user": "jimmy", "text": "knock knock" },
{ "date": "2015-06-05T17:36:05.123Z", "user": "walter", "text": "who's there?" }
];
* Mattermost archive.addMessages(messages);
* Matrix ```
* Slack
* ... See the inline source code documentation (JSDoc) for usage details and function
arguments. For a real-world integration example, see
[hubot-remotestorage-logger](https://github.com/67P/hubot-remotestorage-logger/).
## Support, bugs, feedback, questions
Come and chat with us: https://wiki.kosmos.org/Main_Page#Chat

2
dist/build.js vendored

File diff suppressed because one or more lines are too long

2
dist/build.js.map vendored

File diff suppressed because one or more lines are too long

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "remotestorage-module-chat-messages", "name": "remotestorage-module-chat-messages",
"version": "1.0.1", "version": "2.0.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "remotestorage-module-chat-messages", "name": "remotestorage-module-chat-messages",
"version": "1.0.1", "version": "2.0.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": {
@@ -12,9 +12,10 @@
}, },
"author": "Kosmos Contributors <mail@kosmos.org> (https://kosmos.org)", "author": "Kosmos Contributors <mail@kosmos.org> (https://kosmos.org)",
"license": "MIT", "license": "MIT",
"homepage": "https://gitea.kosmos.org/kosmos/rs-module-chat-messages",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/67P/remotestorage-module-chat-messages.git" "url": "https://gitea.kosmos.org/kosmos/rs-module-chat-messages.git"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.14.8", "@babel/core": "^7.14.8",

View File

@@ -20,7 +20,7 @@ const ChatMessages = function (privateClient, publicClient) {
* *
* @example * @example
* { * {
* "@context": "https://kosmos.org/ns/v1", * "@context": "https://kosmos.org/ns/v2",
* "@id": "chat-messages/irc.libera.chat/channels/kosmos/", * "@id": "chat-messages/irc.libera.chat/channels/kosmos/",
* "@type": "ChatChannel", * "@type": "ChatChannel",
* "service": { * "service": {
@@ -48,8 +48,8 @@ const ChatMessages = function (privateClient, publicClient) {
"properties": { "properties": {
"@context": { "@context": {
"type": "string", "type": "string",
"default": "https://kosmos.org/ns/v1", "default": "https://kosmos.org/ns/v2",
"enum": ["https://kosmos.org/ns/v1"] "enum": ["https://kosmos.org/ns/v2"]
}, },
"@id": { "@id": {
"type": "string", "type": "string",
@@ -141,8 +141,8 @@ const ChatMessages = function (privateClient, publicClient) {
"required": [] "required": []
}; };
privateClient.declareType("daily-archive", "https://kosmos.org/ns/v1", archiveSchema); privateClient.declareType("daily-archive", "https://kosmos.org/ns/v2", archiveSchema);
publicClient.declareType("daily-archive", "https://kosmos.org/ns/v1", archiveSchema); publicClient.declareType("daily-archive", "https://kosmos.org/ns/v2", archiveSchema);
/** /**
* A daily archive stores chat messages by calendar day. * A daily archive stores chat messages by calendar day.
@@ -158,7 +158,7 @@ const ChatMessages = function (privateClient, publicClient) {
* @param {string} options.channelName - Name of room/channel (e.g. "#kosmos") * @param {string} options.channelName - Name of room/channel (e.g. "#kosmos")
* @param {string} [options.channelType] - Type of channel ("room" or "person") * @param {string} [options.channelType] - Type of channel ("room" or "person")
* @param {date} options.date - Date of archive day * @param {date} options.date - Date of archive day
* @param {boolean} options.isPublic - Store logs in public folder (defaults to false) * @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.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.next] - Date of next log file as `YYYY/MM/DD`. looked up automatically when not given
* *
@@ -360,7 +360,7 @@ const ChatMessages = function (privateClient, publicClient) {
* @private * @private
*/ */
_updateDocument (archive, messages) { _updateDocument (archive, messages) {
console.debug('[chat-messages] Updating archive document', archive); console.debug('[chat-messages] Updating archive document');
if (Array.isArray(messages)) { if (Array.isArray(messages)) {
messages.forEach(function(message) { messages.forEach(function(message) {
@@ -545,7 +545,7 @@ const ChatMessages = function (privateClient, publicClient) {
* @private * @private
*/ */
_sync (obj) { _sync (obj) {
console.debug('[chat-messages] Writing archive object', obj); console.debug(`[chat-messages] Writing archive object with ${obj.today.messages.length} messages`);
return this.client.storeObject('daily-archive', this.path, obj).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');

View File

@@ -9,7 +9,9 @@ module.exports = {
filename: 'build.js', filename: 'build.js',
library: 'ChatMessages', library: 'ChatMessages',
libraryTarget: 'umd', libraryTarget: 'umd',
libraryExport: 'default' libraryExport: 'default',
umdNamedDefine: true,
globalObject: 'this'
}, },
mode: isProd ? 'production' : 'development', mode: isProd ? 'production' : 'development',
devtool: isProd ? 'source-map' : 'eval-source-map', devtool: isProd ? 'source-map' : 'eval-source-map',