提交 8f409d60 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

debug message...

上级 ca040a43
......@@ -15,10 +15,17 @@ class Message {
constructor(rawObj) {
Message.counter++
this.logToFile(JSON.stringify(rawObj))
this.rawObj = rawObj = rawObj || {}
this.obj = this.parse(rawObj)
}
logToFile(data) {
require('fs').appendFile('message.log', data + '\n\n#############################\n\n', err => {
if (err) { log.error('Message', 'logToFile: ' + err) }
})
}
// Transform rawObj to local m
parse(rawObj) {
return {
......@@ -35,13 +42,15 @@ class Message {
}
}
toString() { return `Message#${Message.counter}(` + this.getFromString() + `: ${content})` }
toString() { return `Message#${Message.counter}(` + this.getFromString() + ':' + this.getContentString() + ')' }
getContentString() {
let content = this.unescapeHtml(this.stripHtml(this.obj.content))
if (content.length > 20) { content = content.substring(0,17) + '...' }
return content
}
getFromString() {
const name = this.obj.from.get('name')
const group = this.obj.group
let content = this.unescapeHtml(this.stripHtml(this.obj.content))
if (content.length > 20) { content = content.substring(0,17) + '...' }
return '<' + name + (group ? `@[${group}]` : '') + '>'
}
stripHtml(str) { return String(str).replace(/(<([^>]+)>)/ig,'') }
......
......@@ -30,6 +30,10 @@ test('Contact smoke testing', t => {
.then(r => {
t.equal(c.get('id') , UserName, 'UserName set')
t.equal(c.get('name') , NickName, 'NickName set')
const s = c.toString()
t.equal(typeof s, 'string', 'toString()')
})
.catch(e => t.fail('ready() rejected: ' + e))
.then(t.end) // test end
......
......@@ -20,6 +20,9 @@ false && test('Group constructor parser test', t => {
t.equal(m.get('id') , EXPECTED.id , 'id right')
t.equal(m.get('from').getId() , EXPECTED.from , 'from right')
const s = g.toString()
t.equal(typeof s, 'string', 'toString()')
t.end()
})
......
......@@ -20,6 +20,9 @@ test('Message constructor parser test', t => {
t.equal(m.get('id') , EXPECTED.id , 'id right')
t.equal(m.get('from').getId() , EXPECTED.from , 'from right')
const s = m.toString()
t.equal(typeof s, 'string', 'toString()')
t.end()
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册