Skip to content

Commit 0752c77

Browse files
committed
jabber: show only non-empty logs
1 parent 685916e commit 0752c77

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

handlers/courses/controller/groupMaterials.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var exec = require('child_process').exec;
1616
var glob = require('glob');
1717
var iprotect = require('iprotect');
1818
var moment = require('momentWithLocale');
19+
var stripTags = require('textUtil/stripTags');
1920

2021
// Group info for a participant, with user instructions on how to login
2122
exports.get = function*() {
@@ -52,12 +53,30 @@ exports.get = function*() {
5253
logs = [];
5354
}
5455

55-
logs = logs.sort().map(file => ({
56-
title: file,
57-
link: `/courses/groups/${group.slug}/logs/${file.replace(/\.html$/, '')}`
58-
}));
56+
logs = logs.sort();
5957

60-
this.locals.chatLogs = logs;
58+
let contents = yield logs.map(file => fs.readFile(config.jabberLogsRoot + '/' + group.webinarId + '/' + file, {encoding: 'utf8'}));
59+
60+
this.locals.chatLogs = [];
61+
for (let i = 0; i < logs.length; i++) {
62+
let log = logs[i];
63+
let content = contents[i]
64+
.match(/<body>([\s\S]*?)(<\/body>|$)/)[0]
65+
.replace(/<font[\s\S]*?<\/font>/gim, '')
66+
.replace(/<a[\s\S]*?<\/a>/gim, '')
67+
.replace(/<div[\s\S]*?<\/div>/gim, '')
68+
.replace(/<br.*?>/gim, '');
69+
content = stripTags(content);
70+
71+
content = content.replace(/\s+/gim, ' ');
72+
73+
if (content.length > 1000) {
74+
this.locals.chatLogs.push({
75+
title: log,
76+
link: `/courses/groups/${group.slug}/logs/${log.replace(/\.html$/, '')}`
77+
});
78+
}
79+
}
6180

6281

6382
this.body = this.render('groupMaterials');

0 commit comments

Comments
 (0)