13 Commits

7 changed files with 46 additions and 25 deletions

View File

@@ -4,19 +4,37 @@
Stores chat messages in daily archive documents.
Please feel free to open GitHub issues for questions, feature requests,
protocol proposals, and whatever else you like.
## Usage
## 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
* XMPP
const archive = new remoteStorage.chatMessages.DailyArchive({
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
* Matrix
* Slack
* ...
archive.addMessages(messages);
```
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",
"version": "1.0.1",
"version": "2.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "remotestorage-module-chat-messages",
"version": "1.0.1",
"version": "2.0.0",
"description": "Stores chat messages in daily archive files",
"main": "./dist/build.js",
"scripts": {
@@ -12,9 +12,10 @@
},
"author": "Kosmos Contributors <mail@kosmos.org> (https://kosmos.org)",
"license": "MIT",
"homepage": "https://gitea.kosmos.org/kosmos/rs-module-chat-messages",
"repository": {
"type": "git",
"url": "https://github.com/67P/remotestorage-module-chat-messages.git"
"url": "https://gitea.kosmos.org/kosmos/rs-module-chat-messages.git"
},
"devDependencies": {
"@babel/core": "^7.14.8",

View File

@@ -20,7 +20,7 @@ const ChatMessages = function (privateClient, publicClient) {
*
* @example
* {
* "@context": "https://kosmos.org/ns/v1",
* "@context": "https://kosmos.org/ns/v2",
* "@id": "chat-messages/irc.libera.chat/channels/kosmos/",
* "@type": "ChatChannel",
* "service": {
@@ -48,8 +48,8 @@ const ChatMessages = function (privateClient, publicClient) {
"properties": {
"@context": {
"type": "string",
"default": "https://kosmos.org/ns/v1",
"enum": ["https://kosmos.org/ns/v1"]
"default": "https://kosmos.org/ns/v2",
"enum": ["https://kosmos.org/ns/v2"]
},
"@id": {
"type": "string",
@@ -141,8 +141,8 @@ const ChatMessages = function (privateClient, publicClient) {
"required": []
};
privateClient.declareType("daily-archive", "https://kosmos.org/ns/v1", archiveSchema);
publicClient.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/v2", archiveSchema);
/**
* 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.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 {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
*
@@ -360,7 +360,7 @@ const ChatMessages = function (privateClient, publicClient) {
* @private
*/
_updateDocument (archive, messages) {
console.debug('[chat-messages] Updating archive document', archive);
console.debug('[chat-messages] Updating archive document');
if (Array.isArray(messages)) {
messages.forEach(function(message) {
@@ -545,7 +545,7 @@ const ChatMessages = function (privateClient, publicClient) {
* @private
*/
_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(){
console.debug('[chat-messages] Archive written to remote storage');

View File

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