Skip to content

Commit

Permalink
Added new version.
Browse files Browse the repository at this point in the history
  • Loading branch information
petersirka committed Jul 31, 2018
1 parent c80d66a commit 207c02c
Show file tree
Hide file tree
Showing 52 changed files with 518 additions and 74 deletions.
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
======= 3.0.0

- added secret messages
- added `unread` channel/user
- added themes
- added auto-suggestion for users
- improve bots
- updated versions of scripts and styles
2 changes: 1 addition & 1 deletion config
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name : Messenger
version : 2.0.0
version : 3.0.0
author : Peter Širka
url : https://messenger.totaljs.com

Expand Down
5 changes: 4 additions & 1 deletion controllers/api.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ function json_blacklist() {
self.user.blacklist = {};
for (var i = 0, length = self.body.length; i < length; i++) {
var id = self.body[i];
id.isUID() && (self.user.blacklist[id] = true);
if (id.isUID()) {
self.user.blacklist[id] = true;
self.user.unread[id] && (delete self.user.unread[id]);
}
}
OPERATION('users.save', NOOP);
}
Expand Down
28 changes: 24 additions & 4 deletions controllers/chat.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ function messages() {
client.send(MSG_UNREAD);
break;

case 'setunread':
client.user.unread[message.id] = 1;
MSG_UNREAD.unread = client.user.unread;
MSG_UNREAD.lastmessages = client.user.lastmessages;
MSG_UNREAD.recent = undefined;
client.send(MSG_UNREAD);
break;

// Changed group (outside of channels and users)
case 'nochat':
client.threadtype = undefined;
Expand Down Expand Up @@ -162,6 +170,11 @@ F.global.sendmessage = function(client, message) {
message.mobile = client.req ? client.req.mobile : false;
message.robot = client.send ? false : true;

if (message.secret)
message.dateexpired = F.datetime.add('1 day');
else
message.secret = undefined;

if (!message.type)
message.type = 'message';

Expand Down Expand Up @@ -190,8 +203,14 @@ F.global.sendmessage = function(client, message) {
return true;
}

// ROBOT
if (!client.send && n.threadtype === 'user' && ((n.user.id === message.idto && n.user.threadid === client.threadid) || (n.user.id === client.threadid && n.user.threadid === message.idto))) {
is = false;
return true;
}

// !client.send (the messages is from "robot")
return ((!client.send && n.user.id === client.threadid) || (n.user.id === iduser)) && n.threadid === client.threadid;
return n.user.id === iduser && n.threadid === client.threadid;
});

if (is) {
Expand Down Expand Up @@ -259,7 +278,8 @@ F.global.sendmessage = function(client, message) {
}

// Saves message into the DB
var dbname = client.threadtype === 'channel' ? client.threadtype + client.threadid : 'user' + F.global.merge(client.threadid, iduser);
var dbname = client.threadtype === 'channel' ? client.threadtype + client.threadid : 'user' + F.global.merge(client.threadid, message.idto || iduser);

message.type = undefined;
message.idowner = client.threadid;
message.search = message.body.keywords(true, true).join(' ');
Expand All @@ -271,7 +291,7 @@ F.global.sendmessage = function(client, message) {
// Edited
tmp = { body: message.body, edited: true, dateupdated: message.datecreated };
db.modify(tmp).where('id', id).where('iduser', iduser);
dbBackup.modify(tmp).where('id', id).where('iduser', iduser);
!message.secret && dbBackup.modify(tmp).where('id', id).where('iduser', iduser);
} else {

// New
Expand All @@ -282,7 +302,7 @@ F.global.sendmessage = function(client, message) {

db.insert(message);
db.counter.hit('all').hit(client.user.id);
dbBackup.insert(message);
!message.secret && dbBackup.insert(message);
message.files && message.files.length && NOSQL(dbname + '-files').insert(message);
OPERATION('messages.cleaner', dbname, NOOP);
}
Expand Down
Empty file modified controllers/default.js
100644 → 100755
Empty file.
Empty file modified databases/channels.json
100644 → 100755
Empty file.
Empty file modified databases/users.json
100644 → 100755
Empty file.
Empty file modified debug.js
100644 → 100755
Empty file.
Empty file modified definitions/auth.js
100644 → 100755
Empty file.
Empty file modified definitions/convertors.js
100644 → 100755
Empty file.
Empty file modified definitions/globals.js
100644 → 100755
Empty file.
Empty file modified definitions/helpers.js
100644 → 100755
Empty file.
Empty file modified definitions/localization.js
100644 → 100755
Empty file.
Empty file modified definitions/merge.js
100644 → 100755
Empty file.
7 changes: 6 additions & 1 deletion definitions/operations.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ NEWOPERATION('users.load', function(error, value, callback) {

!user.lastmessages && (user.lastmessages = {});
!user.blacklist && (user.blacklist = {});
!user.theme && (user.theme = 'dark');

// Cleaner for unhandled assignment
delete user.recent[''];
Expand Down Expand Up @@ -119,7 +120,7 @@ NEWOPERATION('messages.cleaner', function(error, value, callback) {
db.count().callback(function(err, count) {
if (count > max) {
count = count - max;
db.remove().prepare((doc, index) => index < count);
db.remove().prepare((doc, index) => index < count || doc.dateexpired < F.datetime);
}
});
}, 30000);
Expand All @@ -137,6 +138,8 @@ NEWOPERATION('send', function(error, value, callback) {
// value.body = 'MESSAGE in MARKDOWN';
// value.users = [Array of ID users]; (OPTIONAL)
// value.files = [{ name: String, url: String }]; (OPTIONAL)
// value.idto = IDUSER; (OPTIONAL, can rewrite a private database between two users. Only for robots)
// value.secret = Boolean;

SEND_CLIENT.user = F.global.users.findItem('id', value.iduser);

Expand All @@ -154,6 +157,8 @@ NEWOPERATION('send', function(error, value, callback) {
SEND_MESSAGE.body = value.body;
SEND_MESSAGE.users = value.users || null;
SEND_MESSAGE.files = value.files || null;
SEND_MESSAGE.idto = value.idto;
SEND_MESSAGE.secret = value.secret;

F.global.sendmessage(SEND_CLIENT, SEND_MESSAGE);
callback(SUCCESS(true));
Expand Down
Empty file modified definitions/scheduler.js
100644 → 100755
Empty file.
96 changes: 96 additions & 0 deletions flow/messengersender.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const TRIGGER = 'getMessengerData';
const MESSAGE = {};

exports.id = 'messengersender';
exports.title = 'Messenger: Sender';
exports.version = '1.0.0';
exports.author = 'Peter Širka';
exports.group = 'Notifications';
exports.color = '#8CC152';
exports.input = 1;
exports.options = { from: '' };
exports.icon = 'commenting-o';
exports.readme = `# Total.js Messenger: Sender
This component can send message.
- input has to be a Markdown content`;

exports.html = `<div class="padding">
<div data-jc="dropdown" data-jc-path="from" data-source="messengerdata.users" data-empty="" class="m" data-required="true">@(Who is the sender?)</div>
<div data-jc="dropdown" data-jc-path="location" data-source="messengerdata.channels" data-empty="@(Current location)" class="m">@(Location)</div>
</div>
<script>TRIGGER('{0}', 'messengerdata');</script>`.format(TRIGGER);

exports.install = function(instance) {

var can;

instance.reconfigure = function() {
can = F.global.sendmessage ? true : false;

if (!can) {
instance.status('Messenger not found', 'red');
return;
}

var user = null;
if (instance.options.from) {
switch (instance.options.from) {
case '$sender':
instance.status('From: sender');
break;
case '$target':
instance.status('From: recipient');
break;
default:
var user = F.global.users.findItem('id', instance.options.from);
user && instance.status('From: ' + user.name);
break;
}
} else
instance.status('Not configured', 'red');
};

instance.on('data', function(response) {

if (!can)
return;

var data = response.data;
if (data == null)
return;

var client = response.get('client');
if (!instance.options.location) {
// if (!client || (instance.options.from === '$target' && client.threadtype === 'channel') || (instance.options.from !== '$sender' && instance.options.from !== '$target' && client.threadtype === 'user' && client.threadid !== instance.options.from))
if (!client || (instance.options.from === '$target' && client.threadtype === 'channel'))
return;
}

MESSAGE.idtarget = instance.options.location ? instance.options.location : instance.options.from === '$target' ? client.user.id : client.threadid;
MESSAGE.target = instance.options.location ? 'channel' : client.threadtype;
MESSAGE.iduser = instance.options.from === '$sender' ? client.user.id : instance.options.from === '$target' ? client.threadid : instance.options.from;
MESSAGE.body = typeof(data) === 'object' ? ('```json\n' + JSON.stringify(data, null, ' ') + '\n```') : data.toString();
MESSAGE.idto = MESSAGE.target !== 'channel' && !instance.options.location ? client.user.id : null;
OPERATION('send', MESSAGE, NOOP);
});

instance.on('options', instance.reconfigure);
setTimeout(instance.reconfigure, 1000);
};

FLOW.trigger(TRIGGER, function(next) {
var response = {};
response.users = [];
response.channels = [];
response.users.push({ id: '$sender', name: 'From: sender' });
response.users.push({ id: '$target', name: 'From: recipient' });
F.global.users && F.global.users.forEach(item => response.users.push({ id: item.id, name: item.name }));
F.global.channels && F.global.channels.forEach(item => response.channels.push({ id: item.id, name: item.name }));
next(response);
});

exports.uninstall = function() {
FLOW.trigger(TRIGGER, null);
};
2 changes: 2 additions & 0 deletions models/account.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ NEWSCHEMA('Account').make(function(schema) {
schema.define('password', 'String(30)');
schema.define('picture', 'String(30)');
schema.define('notifications', Boolean);
schema.define('theme', 'String(20)');

schema.setSave(function(error, model, options, callback, controller) {

Expand All @@ -17,6 +18,7 @@ NEWSCHEMA('Account').make(function(schema) {
user.picture = model.picture;
user.notifications = model.notifications;
user.status = model.status;
user.theme = model.theme;
model.password && !model.password.startsWith('****') && (user.password = model.password.sha1());
OPERATION('users.save', NOOP);
notify && F.global.refresh && F.global.refresh();
Expand Down
Empty file modified models/channels.js
100644 → 100755
Empty file.
Empty file modified models/favorites.js
100644 → 100755
Empty file.
Empty file modified models/login.js
100644 → 100755
Empty file.
9 changes: 8 additions & 1 deletion models/messages.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ NEWSCHEMA('Message').make(function(schema) {
if (!controller.query.max)
controller.query.max = 15;

db.find().sort('datecreated', true).page((controller.query.page || 1) - 1, controller.query.max + count).callback(function(err, response) {
var filter = db.find();
filter.or();
filter.where('dateexpired', undefined);
filter.where('dateexpired', '>', F.datetime);
filter.end();
filter.sort('datecreated', true);
filter.page((controller.query.page || 1) - 1, controller.query.max + count);
filter.callback(function(err, response) {

// Sets the first message as read message
if (controller.query.page === 1 && id && response.length)
Expand Down
Empty file modified models/tasks.js
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions models/users.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ NEWSCHEMA('User').make(function(schema) {
tmp.online = false;
tmp.linker = model.name.slug();
tmp.sa = model.sa;
tmp.theme = 'dark';
F.global.users.push(tmp);
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "messenger",
"name": "Messenger",
"description": "Total.js Messenger is a small alternative to Slack.",
"version": "2.0.0",
"version": "3.0.0",
"main": "release.js",
"dependencies": {
"total.js": "latest"
Expand Down
Empty file modified public/css/bootstrap.min.css
100644 → 100755
Empty file.
Loading

0 comments on commit 207c02c

Please sign in to comment.