Release 1.0.3 (#14446)
* [FIX] New day separator overlapping above system message (#14362)
* Improve German translations (#14351)
* Use the plural for discussions-section in side panel
* Formal and informal translations for 1.0
* fix german typos
* [FIX] Main thread title on replies (#14372)
* fix
* fix test
* fix setting
* Update tests/pageobjects/main-content.page.js
Co-Authored-By: ggazzo <guilhermegazzo@gmail.com>
* Update app/ui-utils/client/lib/RoomHistoryManager.js
Co-Authored-By: ggazzo <guilhermegazzo@gmail.com>
* [FIX] Bell was too small on threads (#14394)
* [FIX] Messages on threads disappearing (#14393)
* fix subscription-changed updating all messages(#14391)
* Fix: Message body was not being updated when user disabled nrr message (#14390)
* [NEW] Allow change Discussion's properties (#14389)
* [FIX] Unnecessary meteor.defer on openRoom (#14396)
* [FIX] more message actions to threads context(follow, unfollow, copy, delete) (#14387)
* added more message actions to threads context
* more actions
* change token name (#14379)
* [FIX] Pressing Enter in User Search field at channel causes reload (#14388)
* Prevent default on enter in User search
* Prevent form submission in membersList
* If using subpath make sure streams use that also for multi-instance. Fixes #13200 (#14376)
* Revert "[IMPROVE] Use SessionId for credential token in SAML request (#13791)" (#14345)
This reverts commit 3967a74f5b.
* Add fallback to mongo version that doesn't require clusterMonitor role (#14403)
* [FIX] Users actions in administration were returning error (#14400)
* Fix actions collapse into popup in userInfo
* Refactor userActions
* [FIX] Error 400 on send a reply to an old thread (#14402)
* fix error 400 on send a reply to an old thread
* ignoring properly hidden messages
* [FIX] Messages on thread panel were receiving wrong context/subscription (#14404)
* [FIX] preview pdf its not working (#14419)
* [FIX] renderMessageBody was caching messages in wrong scenarios #14420
* LingoHub Update 🚀 (#14426)
Manual push by LingoHub User: Diego Sampaio.
Project: Rocket.Chat
Made with ❤️ by https://lingohub.com
* [FIX] Mentions message missing 'jump to message' action (#14430)
* fixed context
* threads context
* [FIX] Escape unrecognized slash command message (#14432)
* Add missing german translations (#14386)
* [FIX] IE11 support (#14422)
* Add symlinks to ES6 node_modules imports
* Add URL polyfill for IE11
* Fix thread replies for IE11
* [IMPROVE] allow users to skip activeUsers to be ready (#14431)
* allow users to skip activeUsers to be ready
* Update main.js
* Update app/ui-master/client/main.js
Co-Authored-By: ggazzo <guilhermegazzo@gmail.com>
* [IMPROVE] Don't use regex to find users (#14397)
* Don't use regex to find users
* Invert logic on model methods
* Escape username regex
* Find users in batch
* Use only normalizeMessagesForUser
* Don't ignore username case to get owners on graphql
* Fixes on DAU and MAU aggregations (#14418)
* Fixes on SAU and MAU aggregations
* Report new data from DAU/MAU
* Run tests agains a mongodb container in CI
* Try to run CI correctly
* Fix drop database
* Parse desktop app User Agent correctly
* Fix aggregation of past sessions
* Return past month today
* Fix bug
* Add migration
* Fixed migration
* Migration improvements
* Fix crowd sync by using correct logging method (#14405)
* Fix room names in user info dialogs (#14415)
* Fix discussion name being invalid (#14442)
Closes #14378
* Fix i18n files keys sort (#14433)
* Add script to normalize i18n files
* Fix i18n files
* Set as official script
* Update package-lock.json
* fix (#14443)
* Update threads.css
* Bump version to 1.0.3
* regen changelog
pull/14653/head
1.0.3
parent
abf67ce985
commit
f19473c626
@ -0,0 +1,28 @@ |
||||
/** |
||||
* This script will: |
||||
* |
||||
* - remove any duplicated i18n key on the same file; |
||||
* - re-order all keys based on source i18n file (en.i18n.json) |
||||
* - remove all keys not present in source i18n file |
||||
*/ |
||||
|
||||
const fg = require('fast-glob'); |
||||
const fs = require('fs'); |
||||
|
||||
const fixFiles = (path, source, newlineAtEnd = false) => { |
||||
const sourceFile = JSON.parse(fs.readFileSync(`${ path }${ source }`, 'utf8')); |
||||
const sourceKeys = Object.keys(sourceFile); |
||||
|
||||
fg([`${ path }/**/*.i18n.json`]).then((entries) => { |
||||
entries.forEach((file) => { |
||||
console.log(file); |
||||
|
||||
const json = JSON.parse(fs.readFileSync(file, 'utf8')); |
||||
|
||||
fs.writeFileSync(file, `${ JSON.stringify(json, sourceKeys, 2) }${ newlineAtEnd ? '\n' : '' }`); |
||||
}); |
||||
}); |
||||
}; |
||||
|
||||
fixFiles('./packages/rocketchat-i18n', '/i18n/en.i18n.json'); |
||||
fixFiles('./packages/rocketchat-livechat/.app/i18n', '/en.i18n.json'); |
||||
@ -1,9 +1,10 @@ |
||||
import { composeMessageObjectWithUser } from '../../../utils'; |
||||
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser'; |
||||
import { API } from '../api'; |
||||
|
||||
API.helperMethods.set('composeRoomWithLastMessage', function _composeRoomWithLastMessage(room, userId) { |
||||
if (room.lastMessage) { |
||||
room.lastMessage = composeMessageObjectWithUser(room.lastMessage, userId); |
||||
const [lastMessage] = normalizeMessagesForUser([room.lastMessage], userId); |
||||
room.lastMessage = lastMessage; |
||||
} |
||||
return room; |
||||
}); |
||||
|
||||
@ -0,0 +1,7 @@ |
||||
import mock from 'mock-require'; |
||||
|
||||
mock('./_Base', { |
||||
Base: class Base { |
||||
tryEnsureIndex() {} |
||||
}, |
||||
}); |
||||
@ -0,0 +1,821 @@ |
||||
/* eslint-env mocha */ |
||||
|
||||
import assert from 'assert'; |
||||
import './Sessions.mocks.js'; |
||||
const mongoUnit = require('mongo-unit'); |
||||
const { MongoClient } = require('mongodb'); |
||||
const { aggregates } = require('./Sessions'); |
||||
|
||||
const sessions_dates = []; |
||||
const baseDate = new Date(2018, 6, 1); |
||||
|
||||
for (let index = 0; index < 365; index++) { |
||||
sessions_dates.push({ |
||||
_id: `${ baseDate.getFullYear() }-${ baseDate.getMonth() + 1 }-${ baseDate.getDate() }`, |
||||
year: baseDate.getFullYear(), |
||||
month: baseDate.getMonth() + 1, |
||||
day: baseDate.getDate(), |
||||
}); |
||||
baseDate.setDate(baseDate.getDate() + 1); |
||||
} |
||||
|
||||
const DATA = { |
||||
sessions: [{ |
||||
_id : 'fNFyFcjszvoN6Grip2', |
||||
day : 30, |
||||
instanceId : 'HvbqxukP8E65LAGMY', |
||||
month : 4, |
||||
sessionId : 'kiA4xX33AyzPgpBNs2', |
||||
year : 2019, |
||||
_updatedAt : new Date('2019-04-30T16:33:24.311Z'), |
||||
createdAt : new Date('2019-04-30T00:11:34.047Z'), |
||||
device : { |
||||
type : 'browser', |
||||
name : 'Firefox', |
||||
longVersion : '66.0.3', |
||||
os : { |
||||
name : 'Linux', |
||||
version : '12', |
||||
}, |
||||
version : '66.0.3', |
||||
}, |
||||
host : 'localhost:3000', |
||||
ip : '127.0.0.1', |
||||
loginAt : new Date('2019-04-30T00:11:34.047Z'), |
||||
type : 'session', |
||||
userId : 'xPZXw9xqM3kKshsse', |
||||
lastActivityAt : new Date('2019-04-30T00:16:20.349Z'), |
||||
closedAt : new Date('2019-04-30T00:16:20.349Z'), |
||||
}, { |
||||
_id : 'fNFyFcjszvoN6Grip', |
||||
day : 2, |
||||
instanceId : 'HvbqxukP8E65LAGMY', |
||||
month : 5, |
||||
sessionId : 'kiA4xX33AyzPgpBNs', |
||||
year : 2019, |
||||
_updatedAt : new Date('2019-05-06T16:33:24.311Z'), |
||||
createdAt : new Date('2019-05-03T00:11:34.047Z'), |
||||
device : { |
||||
type : 'browser', |
||||
name : 'Firefox', |
||||
longVersion : '66.0.3', |
||||
os : { |
||||
name : 'Linux', |
||||
version : '12', |
||||
}, |
||||
version : '66.0.3', |
||||
}, |
||||
host : 'localhost:3000', |
||||
ip : '127.0.0.1', |
||||
loginAt : new Date('2019-05-03T00:11:34.047Z'), |
||||
type : 'session', |
||||
userId : 'xPZXw9xqM3kKshsse', |
||||
lastActivityAt : new Date('2019-05-03T00:16:20.349Z'), |
||||
closedAt : new Date('2019-05-03T00:16:20.349Z'), |
||||
}, { |
||||
_id : 'oZMkfR3gFB6kuKDK2', |
||||
day : 2, |
||||
instanceId : 'HvbqxukP8E65LAGMY', |
||||
month : 5, |
||||
sessionId : 'i8uJFekr9np4x88kS', |
||||
year : 2019, |
||||
_updatedAt : new Date('2019-05-06T16:33:24.311Z'), |
||||
createdAt : new Date('2019-05-03T00:16:21.847Z'), |
||||
device : { |
||||
type : 'browser', |
||||
name : 'Chrome', |
||||
longVersion : '73.0.3683.103', |
||||
os : { |
||||
name : 'Mac OS', |
||||
version : '10.14.1', |
||||
}, |
||||
version : '73.0.3683', |
||||
}, |
||||
host : 'localhost:3000', |
||||
ip : '127.0.0.1', |
||||
loginAt : new Date('2019-05-03T00:16:21.846Z'), |
||||
type : 'session', |
||||
userId : 'xPZXw9xqM3kKshsse', |
||||
lastActivityAt : new Date('2019-05-03T00:17:21.081Z'), |
||||
closedAt : new Date('2019-05-03T00:17:21.081Z'), |
||||
}, { |
||||
_id : 'ABXKoXKTZpPpzLjKd', |
||||
day : 2, |
||||
instanceId : 'HvbqxukP8E65LAGMY', |
||||
month : 5, |
||||
sessionId : 'T8MB28cpx2ZjfEDXr', |
||||
year : 2019, |
||||
_updatedAt : new Date('2019-05-06T16:33:24.311Z'), |
||||
createdAt : new Date('2019-05-03T00:17:22.375Z'), |
||||
device : { |
||||
type : 'browser', |
||||
name : 'Chrome', |
||||
longVersion : '73.0.3683.103', |
||||
os : { |
||||
name : 'Mac OS', |
||||
version : '10.14.1', |
||||
}, |
||||
version : '73.0.3683', |
||||
}, |
||||
host : 'localhost:3000', |
||||
ip : '127.0.0.1', |
||||
loginAt : new Date('2019-05-03T00:17:22.375Z'), |
||||
type : 'session', |
||||
userId : 'xPZXw9xqM3kKshsse', |
||||
lastActivityAt : new Date('2019-05-03T01:48:31.695Z'), |
||||
closedAt : new Date('2019-05-03T01:48:31.695Z'), |
||||
}, { |
||||
_id : 's4ucvvcfBjnTEtYEb', |
||||
day : 2, |
||||
instanceId : 'HvbqxukP8E65LAGMY', |
||||
month : 5, |
||||
sessionId : '8mHbJJypgeRG27TYF', |
||||
year : 2019, |
||||
_updatedAt : new Date('2019-05-06T16:33:24.311Z'), |
||||
createdAt : new Date('2019-05-03T01:48:43.521Z'), |
||||
device : { |
||||
type : 'browser', |
||||
name : 'Chrome', |
||||
longVersion : '73.0.3683.103', |
||||
os : { |
||||
name : 'Mac OS', |
||||
version : '10.14.1', |
||||
}, |
||||
version : '73.0.3683', |
||||
}, |
||||
host : 'localhost:3000', |
||||
ip : '127.0.0.1', |
||||
loginAt : new Date('2019-05-03T01:48:43.521Z'), |
||||
type : 'session', |
||||
userId : 'xPZXw9xqM3kKshsse', |
||||
closedAt : new Date('2019-05-03T01:48:43.761Z'), |
||||
lastActivityAt : new Date('2019-05-03T01:48:43.761Z'), |
||||
}, { |
||||
_id : 'MDs9SzQKmwaDmXL8s', |
||||
day : 2, |
||||
instanceId : 'HvbqxukP8E65LAGMY', |
||||
month : 5, |
||||
sessionId : 'GmoBDPKy9RW2eXdCG', |
||||
year : 2019, |
||||
_updatedAt : new Date('2019-05-06T16:33:24.311Z'), |
||||
createdAt : new Date('2019-05-03T01:48:45.064Z'), |
||||
device : { |
||||
type : 'browser', |
||||
name : 'Chrome', |
||||
longVersion : '73.0.3683.103', |
||||
os : { |
||||
name : 'Mac OS', |
||||
version : '10.14.1', |
||||
}, |
||||
version : '73.0.3683', |
||||
}, |
||||
host : 'localhost:3000', |
||||
ip : '127.0.0.1', |
||||
loginAt : new Date('2019-05-03T01:48:45.064Z'), |
||||
type : 'session', |
||||
userId : 'xPZXw9xqM3kKshsse', |
||||
}, { |
||||
_id : 'CJwfxASo62FHDgqog', |
||||
day : 2, |
||||
instanceId : 'Nmwo2ttFeWZSrowNh', |
||||
month : 5, |
||||
sessionId : 'LMrrL4sbpNMLWYomA', |
||||
year : 2019, |
||||
_updatedAt : new Date('2019-05-06T16:33:24.311Z'), |
||||
createdAt : new Date('2019-05-03T01:50:31.098Z'), |
||||
device : { |
||||
type : 'browser', |
||||
name : 'Chrome', |
||||
longVersion : '73.0.3683.103', |
||||
os : { |
||||
name : 'Mac OS', |
||||
version : '10.14.1', |
||||
}, |
||||
version : '73.0.3683', |
||||
}, |
||||
host : 'localhost:3000', |
||||
ip : '127.0.0.1', |
||||
loginAt : new Date('2019-05-03T01:50:31.092Z'), |
||||
type : 'session', |
||||
userId : 'xPZXw9xqM3kKshsse', |
||||
closedAt : new Date('2019-05-03T01:50:31.355Z'), |
||||
lastActivityAt : new Date('2019-05-03T01:50:31.355Z'), |
||||
}, { |
||||
_id : 'iGAcPobWfTQtN6s4K', |
||||
day : 1, |
||||
instanceId : 'Nmwo2ttFeWZSrowNh', |
||||
month : 5, |
||||
sessionId : 'AsbjZRLNQMqfbyYFS', |
||||
year : 2019, |
||||
_updatedAt : new Date('2019-05-06T16:33:24.311Z'), |
||||
createdAt : new Date('2019-05-03T01:50:32.765Z'), |
||||
device : { |
||||
type : 'browser', |
||||
name : 'Chrome', |
||||
longVersion : '73.0.3683.103', |
||||
os : { |
||||
name : 'Mac OS', |
||||
version : '10.14.1', |
||||
}, |
||||
version : '73.0.3683', |
||||
}, |
||||
host : 'localhost:3000', |
||||
ip : '127.0.0.1', |
||||
loginAt : new Date('2019-05-03T01:50:32.765Z'), |
||||
type : 'session', |
||||
userId : 'xPZXw9xqM3kKshsse2', |
||||
lastActivityAt : new Date('2019-05-03T02:59:59.999Z'), |
||||
}], |
||||
sessions_dates, |
||||
}; // require('./fixtures/testData.json')
|
||||
|
||||
describe.only('Sessions Aggregates', () => { |
||||
let db; |
||||
|
||||
if (!process.env.MONGO_URL) { |
||||
before(function() { |
||||
this.timeout(120000); |
||||
return mongoUnit.start({ version: '3.2.22' }) |
||||
.then((testMongoUrl) => process.env.MONGO_URL = testMongoUrl); |
||||
}); |
||||
|
||||
after(() => { mongoUnit.stop(); }); |
||||
} |
||||
|
||||
before(function() { |
||||
return MongoClient.connect(process.env.MONGO_URL) |
||||
.then((client) => db = client.db('test')); |
||||
}); |
||||
|
||||
before(() => db.dropDatabase().then(() => { |
||||
const sessions = db.collection('sessions'); |
||||
const sessions_dates = db.collection('sessions_dates'); |
||||
return Promise.all([ |
||||
sessions.insertMany(DATA.sessions), |
||||
sessions_dates.insertMany(DATA.sessions_dates), |
||||
]); |
||||
})); |
||||
|
||||
after(() => { db.close(); }); |
||||
|
||||
it('should have sessions_dates data saved', () => { |
||||
const collection = db.collection('sessions_dates'); |
||||
return collection.find().toArray() |
||||
.then((docs) => assert.equal(docs.length, DATA.sessions_dates.length)); |
||||
}); |
||||
|
||||
it('should match sessions between 2018-12-11 and 2019-1-10', () => { |
||||
const collection = db.collection('sessions_dates'); |
||||
const $match = aggregates.getMatchOfLastMonthToday({ year: 2019, month: 1, day: 10 }); |
||||
|
||||
assert.deepEqual($match, { |
||||
$and: [{ |
||||
$or: [ |
||||
{ year: { $gt: 2018 } }, |
||||
{ year: 2018, month: { $gt: 12 } }, |
||||
{ year: 2018, month: 12, day: { $gte: 11 } }, |
||||
], |
||||
}, { |
||||
$or: [ |
||||
{ year: { $lt: 2019 } }, |
||||
{ year: 2019, month: { $lt: 1 } }, |
||||
{ year: 2019, month: 1, day: { $lte: 10 } }, |
||||
], |
||||
}], |
||||
}); |
||||
|
||||
return collection.aggregate([{ |
||||
$match, |
||||
}]).toArray() |
||||
.then((docs) => { |
||||
assert.equal(docs.length, 31); |
||||
assert.deepEqual(docs, [ |
||||
{ _id: '2018-12-11', year: 2018, month: 12, day: 11 }, |
||||
{ _id: '2018-12-12', year: 2018, month: 12, day: 12 }, |
||||
{ _id: '2018-12-13', year: 2018, month: 12, day: 13 }, |
||||
{ _id: '2018-12-14', year: 2018, month: 12, day: 14 }, |
||||
{ _id: '2018-12-15', year: 2018, month: 12, day: 15 }, |
||||
{ _id: '2018-12-16', year: 2018, month: 12, day: 16 }, |
||||
{ _id: '2018-12-17', year: 2018, month: 12, day: 17 }, |
||||
{ _id: '2018-12-18', year: 2018, month: 12, day: 18 }, |
||||
{ _id: '2018-12-19', year: 2018, month: 12, day: 19 }, |
||||
{ _id: '2018-12-20', year: 2018, month: 12, day: 20 }, |
||||
{ _id: '2018-12-21', year: 2018, month: 12, day: 21 }, |
||||
{ _id: '2018-12-22', year: 2018, month: 12, day: 22 }, |
||||
{ _id: '2018-12-23', year: 2018, month: 12, day: 23 }, |
||||
{ _id: '2018-12-24', year: 2018, month: 12, day: 24 }, |
||||
{ _id: '2018-12-25', year: 2018, month: 12, day: 25 }, |
||||
{ _id: '2018-12-26', year: 2018, month: 12, day: 26 }, |
||||
{ _id: '2018-12-27', year: 2018, month: 12, day: 27 }, |
||||
{ _id: '2018-12-28', year: 2018, month: 12, day: 28 }, |
||||
{ _id: '2018-12-29', year: 2018, month: 12, day: 29 }, |
||||
{ _id: '2018-12-30', year: 2018, month: 12, day: 30 }, |
||||
{ _id: '2018-12-31', year: 2018, month: 12, day: 31 }, |
||||
{ _id: '2019-1-1', year: 2019, month: 1, day: 1 }, |
||||
{ _id: '2019-1-2', year: 2019, month: 1, day: 2 }, |
||||
{ _id: '2019-1-3', year: 2019, month: 1, day: 3 }, |
||||
{ _id: '2019-1-4', year: 2019, month: 1, day: 4 }, |
||||
{ _id: '2019-1-5', year: 2019, month: 1, day: 5 }, |
||||
{ _id: '2019-1-6', year: 2019, month: 1, day: 6 }, |
||||
{ _id: '2019-1-7', year: 2019, month: 1, day: 7 }, |
||||
{ _id: '2019-1-8', year: 2019, month: 1, day: 8 }, |
||||
{ _id: '2019-1-9', year: 2019, month: 1, day: 9 }, |
||||
{ _id: '2019-1-10', year: 2019, month: 1, day: 10 }, |
||||
]); |
||||
}); |
||||
}); |
||||
|
||||
it('should match sessions between 2019-1-11 and 2019-2-10', () => { |
||||
const collection = db.collection('sessions_dates'); |
||||
const $match = aggregates.getMatchOfLastMonthToday({ year: 2019, month: 2, day: 10 }); |
||||
|
||||
assert.deepEqual($match, { |
||||
year: 2019, |
||||
$and: [{ |
||||
$or: [ |
||||
{ month: { $gt: 1 } }, |
||||
{ month: 1, day: { $gte: 11 } }, |
||||
], |
||||
}, { |
||||
$or: [ |
||||
{ month: { $lt: 2 } }, |
||||
{ month: 2, day: { $lte: 10 } }, |
||||
], |
||||
}], |
||||
}); |
||||
|
||||
return collection.aggregate([{ |
||||
$match, |
||||
}]).toArray() |
||||
.then((docs) => { |
||||
assert.equal(docs.length, 31); |
||||
assert.deepEqual(docs, [ |
||||
{ _id: '2019-1-11', year: 2019, month: 1, day: 11 }, |
||||
{ _id: '2019-1-12', year: 2019, month: 1, day: 12 }, |
||||
{ _id: '2019-1-13', year: 2019, month: 1, day: 13 }, |
||||
{ _id: '2019-1-14', year: 2019, month: 1, day: 14 }, |
||||
{ _id: '2019-1-15', year: 2019, month: 1, day: 15 }, |
||||
{ _id: '2019-1-16', year: 2019, month: 1, day: 16 }, |
||||
{ _id: '2019-1-17', year: 2019, month: 1, day: 17 }, |
||||
{ _id: '2019-1-18', year: 2019, month: 1, day: 18 }, |
||||
{ _id: '2019-1-19', year: 2019, month: 1, day: 19 }, |
||||
{ _id: '2019-1-20', year: 2019, month: 1, day: 20 }, |
||||
{ _id: '2019-1-21', year: 2019, month: 1, day: 21 }, |
||||
{ _id: '2019-1-22', year: 2019, month: 1, day: 22 }, |
||||
{ _id: '2019-1-23', year: 2019, month: 1, day: 23 }, |
||||
{ _id: '2019-1-24', year: 2019, month: 1, day: 24 }, |
||||
{ _id: '2019-1-25', year: 2019, month: 1, day: 25 }, |
||||
{ _id: '2019-1-26', year: 2019, month: 1, day: 26 }, |
||||
{ _id: '2019-1-27', year: 2019, month: 1, day: 27 }, |
||||
{ _id: '2019-1-28', year: 2019, month: 1, day: 28 }, |
||||
{ _id: '2019-1-29', year: 2019, month: 1, day: 29 }, |
||||
{ _id: '2019-1-30', year: 2019, month: 1, day: 30 }, |
||||
{ _id: '2019-1-31', year: 2019, month: 1, day: 31 }, |
||||
{ _id: '2019-2-1', year: 2019, month: 2, day: 1 }, |
||||
{ _id: '2019-2-2', year: 2019, month: 2, day: 2 }, |
||||
{ _id: '2019-2-3', year: 2019, month: 2, day: 3 }, |
||||
{ _id: '2019-2-4', year: 2019, month: 2, day: 4 }, |
||||
{ _id: '2019-2-5', year: 2019, month: 2, day: 5 }, |
||||
{ _id: '2019-2-6', year: 2019, month: 2, day: 6 }, |
||||
{ _id: '2019-2-7', year: 2019, month: 2, day: 7 }, |
||||
{ _id: '2019-2-8', year: 2019, month: 2, day: 8 }, |
||||
{ _id: '2019-2-9', year: 2019, month: 2, day: 9 }, |
||||
{ _id: '2019-2-10', year: 2019, month: 2, day: 10 }, |
||||
]); |
||||
}); |
||||
}); |
||||
|
||||
it('should match sessions between 2019-5-1 and 2019-5-31', () => { |
||||
const collection = db.collection('sessions_dates'); |
||||
const $match = aggregates.getMatchOfLastMonthToday({ year: 2019, month: 5, day: 31 }); |
||||
|
||||
assert.deepEqual($match, { |
||||
year: 2019, |
||||
month: 5, |
||||
day: { $gte: 1, $lte: 31 }, |
||||
}); |
||||
|
||||
return collection.aggregate([{ |
||||
$match, |
||||
}]).toArray() |
||||
.then((docs) => { |
||||
assert.equal(docs.length, 31); |
||||
assert.deepEqual(docs, [ |
||||
{ _id: '2019-5-1', year: 2019, month: 5, day: 1 }, |
||||
{ _id: '2019-5-2', year: 2019, month: 5, day: 2 }, |
||||
{ _id: '2019-5-3', year: 2019, month: 5, day: 3 }, |
||||
{ _id: '2019-5-4', year: 2019, month: 5, day: 4 }, |
||||
{ _id: '2019-5-5', year: 2019, month: 5, day: 5 }, |
||||
{ _id: '2019-5-6', year: 2019, month: 5, day: 6 }, |
||||
{ _id: '2019-5-7', year: 2019, month: 5, day: 7 }, |
||||
{ _id: '2019-5-8', year: 2019, month: 5, day: 8 }, |
||||
{ _id: '2019-5-9', year: 2019, month: 5, day: 9 }, |
||||
{ _id: '2019-5-10', year: 2019, month: 5, day: 10 }, |
||||
{ _id: '2019-5-11', year: 2019, month: 5, day: 11 }, |
||||
{ _id: '2019-5-12', year: 2019, month: 5, day: 12 }, |
||||
{ _id: '2019-5-13', year: 2019, month: 5, day: 13 }, |
||||
{ _id: '2019-5-14', year: 2019, month: 5, day: 14 }, |
||||
{ _id: '2019-5-15', year: 2019, month: 5, day: 15 }, |
||||
{ _id: '2019-5-16', year: 2019, month: 5, day: 16 }, |
||||
{ _id: '2019-5-17', year: 2019, month: 5, day: 17 }, |
||||
{ _id: '2019-5-18', year: 2019, month: 5, day: 18 }, |
||||
{ _id: '2019-5-19', year: 2019, month: 5, day: 19 }, |
||||
{ _id: '2019-5-20', year: 2019, month: 5, day: 20 }, |
||||
{ _id: '2019-5-21', year: 2019, month: 5, day: 21 }, |
||||
{ _id: '2019-5-22', year: 2019, month: 5, day: 22 }, |
||||
{ _id: '2019-5-23', year: 2019, month: 5, day: 23 }, |
||||
{ _id: '2019-5-24', year: 2019, month: 5, day: 24 }, |
||||
{ _id: '2019-5-25', year: 2019, month: 5, day: 25 }, |
||||
{ _id: '2019-5-26', year: 2019, month: 5, day: 26 }, |
||||
{ _id: '2019-5-27', year: 2019, month: 5, day: 27 }, |
||||
{ _id: '2019-5-28', year: 2019, month: 5, day: 28 }, |
||||
{ _id: '2019-5-29', year: 2019, month: 5, day: 29 }, |
||||
{ _id: '2019-5-30', year: 2019, month: 5, day: 30 }, |
||||
{ _id: '2019-5-31', year: 2019, month: 5, day: 31 }, |
||||
]); |
||||
}); |
||||
}); |
||||
|
||||
it('should match sessions between 2019-4-1 and 2019-4-30', () => { |
||||
const collection = db.collection('sessions_dates'); |
||||
const $match = aggregates.getMatchOfLastMonthToday({ year: 2019, month: 4, day: 30 }); |
||||
|
||||
assert.deepEqual($match, { |
||||
year: 2019, |
||||
month: 4, |
||||
day: { $gte: 1, $lte: 30 }, |
||||
}); |
||||
|
||||
return collection.aggregate([{ |
||||
$match, |
||||
}]).toArray() |
||||
.then((docs) => { |
||||
assert.equal(docs.length, 30); |
||||
assert.deepEqual(docs, [ |
||||
{ _id: '2019-4-1', year: 2019, month: 4, day: 1 }, |
||||
{ _id: '2019-4-2', year: 2019, month: 4, day: 2 }, |
||||
{ _id: '2019-4-3', year: 2019, month: 4, day: 3 }, |
||||
{ _id: '2019-4-4', year: 2019, month: 4, day: 4 }, |
||||
{ _id: '2019-4-5', year: 2019, month: 4, day: 5 }, |
||||
{ _id: '2019-4-6', year: 2019, month: 4, day: 6 }, |
||||
{ _id: '2019-4-7', year: 2019, month: 4, day: 7 }, |
||||
{ _id: '2019-4-8', year: 2019, month: 4, day: 8 }, |
||||
{ _id: '2019-4-9', year: 2019, month: 4, day: 9 }, |
||||
{ _id: '2019-4-10', year: 2019, month: 4, day: 10 }, |
||||
{ _id: '2019-4-11', year: 2019, month: 4, day: 11 }, |
||||
{ _id: '2019-4-12', year: 2019, month: 4, day: 12 }, |
||||
{ _id: '2019-4-13', year: 2019, month: 4, day: 13 }, |
||||
{ _id: '2019-4-14', year: 2019, month: 4, day: 14 }, |
||||
{ _id: '2019-4-15', year: 2019, month: 4, day: 15 }, |
||||
{ _id: '2019-4-16', year: 2019, month: 4, day: 16 }, |
||||
{ _id: '2019-4-17', year: 2019, month: 4, day: 17 }, |
||||
{ _id: '2019-4-18', year: 2019, month: 4, day: 18 }, |
||||
{ _id: '2019-4-19', year: 2019, month: 4, day: 19 }, |
||||
{ _id: '2019-4-20', year: 2019, month: 4, day: 20 }, |
||||
{ _id: '2019-4-21', year: 2019, month: 4, day: 21 }, |
||||
{ _id: '2019-4-22', year: 2019, month: 4, day: 22 }, |
||||
{ _id: '2019-4-23', year: 2019, month: 4, day: 23 }, |
||||
{ _id: '2019-4-24', year: 2019, month: 4, day: 24 }, |
||||
{ _id: '2019-4-25', year: 2019, month: 4, day: 25 }, |
||||
{ _id: '2019-4-26', year: 2019, month: 4, day: 26 }, |
||||
{ _id: '2019-4-27', year: 2019, month: 4, day: 27 }, |
||||
{ _id: '2019-4-28', year: 2019, month: 4, day: 28 }, |
||||
{ _id: '2019-4-29', year: 2019, month: 4, day: 29 }, |
||||
{ _id: '2019-4-30', year: 2019, month: 4, day: 30 }, |
||||
]); |
||||
}); |
||||
}); |
||||
|
||||
it('should match sessions between 2019-2-1 and 2019-2-28', () => { |
||||
const collection = db.collection('sessions_dates'); |
||||
const $match = aggregates.getMatchOfLastMonthToday({ year: 2019, month: 2, day: 28 }); |
||||
|
||||
assert.deepEqual($match, { |
||||
year: 2019, |
||||
month: 2, |
||||
day: { $gte: 1, $lte: 28 }, |
||||
}); |
||||
|
||||
return collection.aggregate([{ |
||||
$match, |
||||
}]).toArray() |
||||
.then((docs) => { |
||||
assert.equal(docs.length, 28); |
||||
assert.deepEqual(docs, [ |
||||
{ _id: '2019-2-1', year: 2019, month: 2, day: 1 }, |
||||
{ _id: '2019-2-2', year: 2019, month: 2, day: 2 }, |
||||
{ _id: '2019-2-3', year: 2019, month: 2, day: 3 }, |
||||
{ _id: '2019-2-4', year: 2019, month: 2, day: 4 }, |
||||
{ _id: '2019-2-5', year: 2019, month: 2, day: 5 }, |
||||
{ _id: '2019-2-6', year: 2019, month: 2, day: 6 }, |
||||
{ _id: '2019-2-7', year: 2019, month: 2, day: 7 }, |
||||
{ _id: '2019-2-8', year: 2019, month: 2, day: 8 }, |
||||
{ _id: '2019-2-9', year: 2019, month: 2, day: 9 }, |
||||
{ _id: '2019-2-10', year: 2019, month: 2, day: 10 }, |
||||
{ _id: '2019-2-11', year: 2019, month: 2, day: 11 }, |
||||
{ _id: '2019-2-12', year: 2019, month: 2, day: 12 }, |
||||
{ _id: '2019-2-13', year: 2019, month: 2, day: 13 }, |
||||
{ _id: '2019-2-14', year: 2019, month: 2, day: 14 }, |
||||
{ _id: '2019-2-15', year: 2019, month: 2, day: 15 }, |
||||
{ _id: '2019-2-16', year: 2019, month: 2, day: 16 }, |
||||
{ _id: '2019-2-17', year: 2019, month: 2, day: 17 }, |
||||
{ _id: '2019-2-18', year: 2019, month: 2, day: 18 }, |
||||
{ _id: '2019-2-19', year: 2019, month: 2, day: 19 }, |
||||
{ _id: '2019-2-20', year: 2019, month: 2, day: 20 }, |
||||
{ _id: '2019-2-21', year: 2019, month: 2, day: 21 }, |
||||
{ _id: '2019-2-22', year: 2019, month: 2, day: 22 }, |
||||
{ _id: '2019-2-23', year: 2019, month: 2, day: 23 }, |
||||
{ _id: '2019-2-24', year: 2019, month: 2, day: 24 }, |
||||
{ _id: '2019-2-25', year: 2019, month: 2, day: 25 }, |
||||
{ _id: '2019-2-26', year: 2019, month: 2, day: 26 }, |
||||
{ _id: '2019-2-27', year: 2019, month: 2, day: 27 }, |
||||
{ _id: '2019-2-28', year: 2019, month: 2, day: 28 }, |
||||
]); |
||||
}); |
||||
}); |
||||
|
||||
it('should match sessions between 2019-1-28 and 2019-2-27', () => { |
||||
const collection = db.collection('sessions_dates'); |
||||
const $match = aggregates.getMatchOfLastMonthToday({ year: 2019, month: 2, day: 27 }); |
||||
|
||||
assert.deepEqual($match, { |
||||
year: 2019, |
||||
$and: [{ |
||||
$or: [ |
||||
{ month: { $gt: 1 } }, |
||||
{ month: 1, day: { $gte: 28 } }, |
||||
], |
||||
}, { |
||||
$or: [ |
||||
{ month: { $lt: 2 } }, |
||||
{ month: 2, day: { $lte: 27 } }, |
||||
], |
||||
}], |
||||
}); |
||||
|
||||
return collection.aggregate([{ |
||||
$match, |
||||
}]).toArray() |
||||
.then((docs) => { |
||||
assert.equal(docs.length, 31); |
||||
assert.deepEqual(docs, [ |
||||
{ _id: '2019-1-28', year: 2019, month: 1, day: 28 }, |
||||
{ _id: '2019-1-29', year: 2019, month: 1, day: 29 }, |
||||
{ _id: '2019-1-30', year: 2019, month: 1, day: 30 }, |
||||
{ _id: '2019-1-31', year: 2019, month: 1, day: 31 }, |
||||
{ _id: '2019-2-1', year: 2019, month: 2, day: 1 }, |
||||
{ _id: '2019-2-2', year: 2019, month: 2, day: 2 }, |
||||
{ _id: '2019-2-3', year: 2019, month: 2, day: 3 }, |
||||
{ _id: '2019-2-4', year: 2019, month: 2, day: 4 }, |
||||
{ _id: '2019-2-5', year: 2019, month: 2, day: 5 }, |
||||
{ _id: '2019-2-6', year: 2019, month: 2, day: 6 }, |
||||
{ _id: '2019-2-7', year: 2019, month: 2, day: 7 }, |
||||
{ _id: '2019-2-8', year: 2019, month: 2, day: 8 }, |
||||
{ _id: '2019-2-9', year: 2019, month: 2, day: 9 }, |
||||
{ _id: '2019-2-10', year: 2019, month: 2, day: 10 }, |
||||
{ _id: '2019-2-11', year: 2019, month: 2, day: 11 }, |
||||
{ _id: '2019-2-12', year: 2019, month: 2, day: 12 }, |
||||
{ _id: '2019-2-13', year: 2019, month: 2, day: 13 }, |
||||
{ _id: '2019-2-14', year: 2019, month: 2, day: 14 }, |
||||
{ _id: '2019-2-15', year: 2019, month: 2, day: 15 }, |
||||
{ _id: '2019-2-16', year: 2019, month: 2, day: 16 }, |
||||
{ _id: '2019-2-17', year: 2019, month: 2, day: 17 }, |
||||
{ _id: '2019-2-18', year: 2019, month: 2, day: 18 }, |
||||
{ _id: '2019-2-19', year: 2019, month: 2, day: 19 }, |
||||
{ _id: '2019-2-20', year: 2019, month: 2, day: 20 }, |
||||
{ _id: '2019-2-21', year: 2019, month: 2, day: 21 }, |
||||
{ _id: '2019-2-22', year: 2019, month: 2, day: 22 }, |
||||
{ _id: '2019-2-23', year: 2019, month: 2, day: 23 }, |
||||
{ _id: '2019-2-24', year: 2019, month: 2, day: 24 }, |
||||
{ _id: '2019-2-25', year: 2019, month: 2, day: 25 }, |
||||
{ _id: '2019-2-26', year: 2019, month: 2, day: 26 }, |
||||
{ _id: '2019-2-27', year: 2019, month: 2, day: 27 }, |
||||
]); |
||||
}); |
||||
}); |
||||
|
||||
it('should have sessions data saved', () => { |
||||
const collection = db.collection('sessions'); |
||||
return collection.find().toArray() |
||||
.then((docs) => assert.equal(docs.length, DATA.sessions.length)); |
||||
}); |
||||
|
||||
it('should generate daily sessions', () => { |
||||
const collection = db.collection('sessions'); |
||||
return aggregates.dailySessionsOfYesterday(collection, { year: 2019, month: 5, day: 2 }).toArray() |
||||
.then((docs) => { |
||||
docs.forEach((doc) => { |
||||
doc._id = `${ doc.userId }-${ doc.year }-${ doc.month }-${ doc.day }`; |
||||
}); |
||||
|
||||
assert.equal(docs.length, 3); |
||||
assert.deepEqual(docs, [{ |
||||
_id: 'xPZXw9xqM3kKshsse-2019-5-2', |
||||
time: 5814, |
||||
sessions: 3, |
||||
devices: [{ |
||||
sessions: 1, |
||||
time: 286, |
||||
device: { |
||||
type: 'browser', |
||||
name: 'Firefox', |
||||
longVersion: '66.0.3', |
||||
os: { |
||||
name: 'Linux', |
||||
version: '12', |
||||
}, |
||||
version: '66.0.3', |
||||
}, |
||||
}, { |
||||
sessions: 2, |
||||
time: 5528, |
||||
device: { |
||||
type: 'browser', |
||||
name: 'Chrome', |
||||
longVersion: '73.0.3683.103', |
||||
os: { |
||||
name: 'Mac OS', |
||||
version: '10.14.1', |
||||
}, |
||||
version: '73.0.3683', |
||||
}, |
||||
}], |
||||
type: 'user_daily', |
||||
_computedAt: docs[0]._computedAt, |
||||
day: 2, |
||||
month: 5, |
||||
year: 2019, |
||||
userId: 'xPZXw9xqM3kKshsse', |
||||
}, { |
||||
_id: 'xPZXw9xqM3kKshsse-2019-4-30', |
||||
day: 30, |
||||
devices: [{ |
||||
device: { |
||||
longVersion: '66.0.3', |
||||
name: 'Firefox', |
||||
os: { |
||||
name: 'Linux', |
||||
version: '12', |
||||
}, |
||||
type: 'browser', |
||||
version: '66.0.3', |
||||
}, |
||||
sessions: 1, |
||||
time: 286, |
||||
}], |
||||
month: 4, |
||||
sessions: 1, |
||||
time: 286, |
||||
type: 'user_daily', |
||||
_computedAt: docs[1]._computedAt, |
||||
userId: 'xPZXw9xqM3kKshsse', |
||||
year: 2019, |
||||
}, { |
||||
_id: 'xPZXw9xqM3kKshsse2-2019-5-1', |
||||
time: 4167, |
||||
sessions: 1, |
||||
devices: [{ |
||||
sessions: 1, |
||||
time: 4167, |
||||
device: { |
||||
type: 'browser', |
||||
name: 'Chrome', |
||||
longVersion: '73.0.3683.103', |
||||
os: { |
||||
name: 'Mac OS', |
||||
version: '10.14.1', |
||||
}, |
||||
version: '73.0.3683', |
||||
}, |
||||
}], |
||||
type: 'user_daily', |
||||
_computedAt: docs[2]._computedAt, |
||||
day: 1, |
||||
month: 5, |
||||
year: 2019, |
||||
userId: 'xPZXw9xqM3kKshsse2', |
||||
}]); |
||||
|
||||
return collection.insertMany(docs); |
||||
}); |
||||
}); |
||||
|
||||
it('should have 2 unique users for month 5 of 2019', () => { |
||||
const collection = db.collection('sessions'); |
||||
return aggregates.getUniqueUsersOfLastMonth(collection, { year: 2019, month: 5, day: 31 }) |
||||
.then((docs) => { |
||||
assert.equal(docs.length, 1); |
||||
assert.deepEqual(docs, [{ |
||||
count: 2, |
||||
sessions: 4, |
||||
time: 9981, |
||||
}]); |
||||
}); |
||||
}); |
||||
|
||||
it('should have 1 unique user for 1st of month 5 of 2019', () => { |
||||
const collection = db.collection('sessions'); |
||||
return aggregates.getUniqueUsersOfYesterday(collection, { year: 2019, month: 5, day: 1 }) |
||||
.then((docs) => { |
||||
assert.equal(docs.length, 1); |
||||
assert.deepEqual(docs, [{ |
||||
count: 1, |
||||
sessions: 1, |
||||
time: 4167, |
||||
}]); |
||||
}); |
||||
}); |
||||
|
||||
it('should have 1 unique user for 2nd of month 5 of 2019', () => { |
||||
const collection = db.collection('sessions'); |
||||
return aggregates.getUniqueUsersOfYesterday(collection, { year: 2019, month: 5, day: 2 }) |
||||
.then((docs) => { |
||||
assert.equal(docs.length, 1); |
||||
assert.deepEqual(docs, [{ |
||||
count: 1, |
||||
sessions: 3, |
||||
time: 5814, |
||||
}]); |
||||
}); |
||||
}); |
||||
|
||||
it('should have 2 unique devices for month 5 of 2019', () => { |
||||
const collection = db.collection('sessions'); |
||||
return aggregates.getUniqueDevicesOfLastMonth(collection, { year: 2019, month: 5, day: 31 }) |
||||
.then((docs) => { |
||||
assert.equal(docs.length, 2); |
||||
assert.deepEqual(docs, [{ |
||||
count: 3, |
||||
time: 9695, |
||||
type: 'browser', |
||||
name: 'Chrome', |
||||
version: '73.0.3683', |
||||
}, { |
||||
count: 1, |
||||
time: 286, |
||||
type: 'browser', |
||||
name: 'Firefox', |
||||
version: '66.0.3', |
||||
}]); |
||||
}); |
||||
}); |
||||
|
||||
it('should have 2 unique devices for 2nd of month 5 of 2019', () => { |
||||
const collection = db.collection('sessions'); |
||||
return aggregates.getUniqueDevicesOfYesterday(collection, { year: 2019, month: 5, day: 2 }) |
||||
.then((docs) => { |
||||
assert.equal(docs.length, 2); |
||||
assert.deepEqual(docs, [{ |
||||
count: 2, |
||||
time: 5528, |
||||
type: 'browser', |
||||
name: 'Chrome', |
||||
version: '73.0.3683', |
||||
}, { |
||||
count: 1, |
||||
time: 286, |
||||
type: 'browser', |
||||
name: 'Firefox', |
||||
version: '66.0.3', |
||||
}]); |
||||
}); |
||||
}); |
||||
|
||||
it('should have 2 unique OS for month 5 of 2019', () => { |
||||
const collection = db.collection('sessions'); |
||||
return aggregates.getUniqueOSOfLastMonth(collection, { year: 2019, month: 5, day: 31 }) |
||||
.then((docs) => { |
||||
assert.equal(docs.length, 2); |
||||
assert.deepEqual(docs, [{ |
||||
count: 3, |
||||
time: 9695, |
||||
name: 'Mac OS', |
||||
version: '10.14.1', |
||||
}, { |
||||
count: 1, |
||||
time: 286, |
||||
name: 'Linux', |
||||
version: '12', |
||||
}]); |
||||
}); |
||||
}); |
||||
|
||||
it('should have 2 unique OS for 2nd of month 5 of 2019', () => { |
||||
const collection = db.collection('sessions'); |
||||
return aggregates.getUniqueOSOfYesterday(collection, { year: 2019, month: 5, day: 2 }) |
||||
.then((docs) => { |
||||
assert.equal(docs.length, 2); |
||||
assert.deepEqual(docs, [{ |
||||
count: 2, |
||||
time: 5528, |
||||
name: 'Mac OS', |
||||
version: '10.14.1', |
||||
}, { |
||||
count: 1, |
||||
time: 286, |
||||
name: 'Linux', |
||||
version: '12', |
||||
}]); |
||||
}); |
||||
}); |
||||
}); |
||||
@ -0,0 +1,77 @@ |
||||
/* eslint-env mocha */ |
||||
|
||||
import { expect } from 'chai'; |
||||
import { UAParserMobile, UAParserDesktop } from './UAParserCustom'; |
||||
|
||||
const UAMobile = 'RC Mobile; iOS 12.2; v3.4.0 (250)'; |
||||
const UADesktop = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Rocket.Chat/2.15.2 Chrome/69.0.3497.128 Electron/4.1.4 Safari/537.36'; |
||||
const UAChrome = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36'; |
||||
|
||||
describe('UAParserCustom', () => { |
||||
|
||||
describe('UAParserMobile', () => { |
||||
|
||||
it('should identify mobile UA', () => { |
||||
expect(UAParserMobile.isMobileApp(UAMobile)).to.be.true; |
||||
}); |
||||
|
||||
it('should not identify desktop UA', () => { |
||||
expect(UAParserMobile.isMobileApp(UADesktop)).to.be.false; |
||||
}); |
||||
|
||||
it('should not identify chrome UA', () => { |
||||
expect(UAParserMobile.isMobileApp(UAChrome)).to.be.false; |
||||
}); |
||||
|
||||
it('should parse mobile UA', () => { |
||||
expect(UAParserMobile.uaObject(UAMobile)).to.be.deep.equal({ |
||||
device: { |
||||
type: 'mobile-app', |
||||
}, |
||||
app: { |
||||
name: 'RC Mobile', |
||||
version: '3.4.0', |
||||
bundle: '250', |
||||
}, |
||||
os: { |
||||
name: 'iOS', |
||||
version: '12.2', |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
}); |
||||
|
||||
describe('UAParserDesktop', () => { |
||||
|
||||
it('should not identify mobile UA', () => { |
||||
expect(UAParserDesktop.isDesktopApp(UAMobile)).to.be.false; |
||||
}); |
||||
|
||||
it('should identify desktop UA', () => { |
||||
expect(UAParserDesktop.isDesktopApp(UADesktop)).to.be.true; |
||||
}); |
||||
|
||||
it('should not identify chrome UA', () => { |
||||
expect(UAParserDesktop.isDesktopApp(UAChrome)).to.be.false; |
||||
}); |
||||
|
||||
it('should parse desktop UA', () => { |
||||
expect(UAParserDesktop.uaObject(UADesktop)).to.be.deep.equal({ |
||||
device: { |
||||
type: 'desktop-app', |
||||
}, |
||||
app: { |
||||
name: 'Rocket.Chat', |
||||
version: '2.15.2', |
||||
}, |
||||
os: { |
||||
name: 'Mac OS', |
||||
version: '10.14.1', |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
}); |
||||
|
||||
}); |
||||
@ -1,11 +1,35 @@ |
||||
import { callbacks } from '../../../callbacks'; |
||||
import s from 'underscore.string'; |
||||
|
||||
export const renderMessageBody = (message) => { |
||||
const generateKeyDefault = (...args) => args.map((item) => JSON.stringify(item)).join('-'); |
||||
|
||||
const mem = (fn, tm = 500, generateKey = generateKeyDefault) => { |
||||
const cache = {}; |
||||
const timeout = {}; |
||||
|
||||
const invalidateCache = (key) => delete cache[key]; |
||||
return (...args) => { |
||||
const key = generateKey(...args); |
||||
if (!key) { |
||||
return fn(...args); |
||||
} |
||||
if (!cache[key]) { |
||||
cache[key] = fn(...args); |
||||
} |
||||
if (timeout[key]) { |
||||
clearTimeout(timeout[key]); |
||||
} |
||||
timeout[key] = setTimeout(invalidateCache, tm, key); |
||||
return cache[key]; |
||||
}; |
||||
}; |
||||
|
||||
export const renderMessageBody = mem((message) => { |
||||
|
||||
message.html = s.trim(message.msg) ? s.escapeHTML(message.msg) : ''; |
||||
|
||||
const { tokens, html } = callbacks.run('renderMessage', message); |
||||
|
||||
return (Array.isArray(tokens) ? tokens.reverse() : []) |
||||
.reduce((html, { token, text }) => html.replace(token, () => text), html); |
||||
}; |
||||
}, 5000, ({ _id, _updatedAt }) => (_id && _updatedAt && _id + _updatedAt)); |
||||
|
||||
@ -1,3 +1,3 @@ |
||||
{ |
||||
"version": "1.0.2" |
||||
"version": "1.0.3" |
||||
} |
||||
|
||||
@ -0,0 +1,54 @@ |
||||
import { MongoInternals } from 'meteor/mongo'; |
||||
|
||||
function fallbackMongoInfo() { |
||||
let mongoVersion; |
||||
let mongoStorageEngine; |
||||
|
||||
const { mongo } = MongoInternals.defaultRemoteCollectionDriver(); |
||||
|
||||
const oplogEnabled = Boolean(mongo._oplogHandle && mongo._oplogHandle.onOplogEntry); |
||||
|
||||
try { |
||||
const { version } = Promise.await(mongo.db.command({ buildinfo: 1 })); |
||||
mongoVersion = version; |
||||
mongoStorageEngine = 'unknown'; |
||||
} catch (e) { |
||||
console.error('=== Error getting MongoDB info ==='); |
||||
console.error(e && e.toString()); |
||||
console.error('----------------------------------'); |
||||
console.error('Without mongodb version we can\'t ensure you are running a compatible version.'); |
||||
console.error('If you are running your mongodb with auth enabled and an user different from admin'); |
||||
console.error('you may need to grant permissions for this user to check cluster data.'); |
||||
console.error('You can do it via mongo shell running the following command replacing'); |
||||
console.error('the string YOUR_USER by the correct user\'s name:'); |
||||
console.error(''); |
||||
console.error(' db.runCommand({ grantRolesToUser: "YOUR_USER" , roles: [{role: "clusterMonitor", db: "admin"}]})'); |
||||
console.error(''); |
||||
console.error('=================================='); |
||||
} |
||||
|
||||
return { oplogEnabled, mongoVersion, mongoStorageEngine }; |
||||
} |
||||
|
||||
export function getMongoInfo() { |
||||
let mongoVersion; |
||||
let mongoStorageEngine; |
||||
|
||||
const { mongo } = MongoInternals.defaultRemoteCollectionDriver(); |
||||
|
||||
const oplogEnabled = Boolean(mongo._oplogHandle && mongo._oplogHandle.onOplogEntry); |
||||
|
||||
try { |
||||
const { version, storageEngine } = Promise.await(mongo.db.command({ serverStatus: 1 })); |
||||
|
||||
mongoVersion = version; |
||||
mongoStorageEngine = storageEngine.name; |
||||
|
||||
} catch (e) { |
||||
return fallbackMongoInfo(); |
||||
} |
||||
|
||||
return { oplogEnabled, mongoVersion, mongoStorageEngine }; |
||||
} |
||||
|
||||
|
||||
@ -1,34 +0,0 @@ |
||||
import { Users } from '../../../models'; |
||||
import { settings } from '../../../settings'; |
||||
import memoize from 'mem'; |
||||
|
||||
const maxAgeInMS = 1000; |
||||
|
||||
const getUserByUsername = (username) => Users.findOneByUsername(username, { fields: { name: 1 } }); |
||||
const getNameOfUser = memoize((username) => { |
||||
const user = getUserByUsername(username); |
||||
return user ? user.name : undefined; |
||||
}, { maxAge: maxAgeInMS }); |
||||
|
||||
export const composeMessageObjectWithUser = function(message, userId) { |
||||
if (message) { |
||||
if (message.starred && Array.isArray(message.starred)) { |
||||
message.starred = message.starred.filter((star) => star._id === userId); |
||||
} |
||||
if (settings.get('UI_Use_Real_Name')) { |
||||
if (message.u && message.u._id) { |
||||
message.u.name = getNameOfUser(message.u.username); |
||||
} |
||||
if (message.mentions && message.mentions.length) { |
||||
message.mentions.forEach((mention) => mention.name = getNameOfUser(mention.username)); |
||||
} |
||||
if (message.reactions && Object.keys(message.reactions).length) { |
||||
Object.keys(message.reactions).forEach((reaction) => { |
||||
const names = message.reactions[reaction].usernames.map(getNameOfUser); |
||||
message.reactions[reaction].names = names; |
||||
}); |
||||
} |
||||
} |
||||
} |
||||
return message; |
||||
}; |
||||
@ -0,0 +1,56 @@ |
||||
import { Users } from '../../../models/server'; |
||||
import { settings } from '../../../settings/server'; |
||||
|
||||
const filterStarred = (message, uid) => { |
||||
// only return starred field if user has it starred
|
||||
if (message.starred && Array.isArray(message.starred)) { |
||||
message.starred = message.starred.filter((star) => star._id === uid); |
||||
} |
||||
return message; |
||||
}; |
||||
|
||||
// TODO: we should let clients get user names on demand instead of doing this
|
||||
|
||||
export const normalizeMessagesForUser = (messages, uid) => { |
||||
// if not using real names, there is nothing else to do
|
||||
if (!settings.get('UI_Use_Real_Name')) { |
||||
return messages.map((message) => filterStarred(message, uid)); |
||||
} |
||||
|
||||
const usernames = new Set(); |
||||
|
||||
messages.forEach((message) => { |
||||
message = filterStarred(message, uid); |
||||
|
||||
usernames.add(message.u.username); |
||||
|
||||
(message.mentions || []).forEach(({ username }) => { usernames.add(username); }); |
||||
|
||||
Object.values(message.reactions || {}) |
||||
.forEach((reaction) => reaction.usernames.forEach((username) => usernames.add(username))); |
||||
}); |
||||
|
||||
const users = {}; |
||||
|
||||
Users.findUsersByUsernames([...usernames.values()], { |
||||
fields: { |
||||
username: 1, |
||||
name: 1, |
||||
}, |
||||
}).forEach((user) => { |
||||
users[user.username] = user.name; |
||||
}); |
||||
|
||||
messages.forEach((message) => { |
||||
message.u.name = users[message.u.username]; |
||||
|
||||
(message.mentions || []).forEach((mention) => { mention.name = users[mention.username]; }); |
||||
|
||||
Object.keys(message.reactions || {}).forEach((reaction) => { |
||||
const names = message.reactions[reaction].usernames.map((username) => users[username]); |
||||
message.reactions[reaction].names = names; |
||||
}); |
||||
}); |
||||
|
||||
return messages; |
||||
}; |
||||
@ -0,0 +1 @@ |
||||
../../node_modules/limax |
||||
@ -0,0 +1 @@ |
||||
../../node_modules/map-age-cleaner |
||||
@ -0,0 +1 @@ |
||||
../../node_modules/mem |
||||
@ -0,0 +1 @@ |
||||
../../node_modules/mimic-fn |
||||
@ -0,0 +1 @@ |
||||
../../node_modules/p-defer |
||||
@ -0,0 +1 @@ |
||||
../../node_modules/p-is-promise |
||||
@ -0,0 +1 @@ |
||||
../../node_modules/pinyin |
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue