-
Notifications
You must be signed in to change notification settings - Fork 42
/
chatPane.js
132 lines (114 loc) · 4.29 KB
/
chatPane.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* Chat Pane
**
** Plan is to support a finte number of chat graph shapes
** and investigate the interop between them.
*/
const UI = require('solid-ui')
const ns = UI.ns
const kb = UI.store
module.exports = {
icon: UI.icons.iconBase + 'noun_346319.svg',
name: 'chat',
/* AN RRSAgent IRC log:
<irc://localhost:6667/&mit>
a foaf:ChatChannel
foaf:chatEventList
[ rdf:_100
<#T19-10-58>
rdf:_101
<#T19-10-58-1>
rdf:_102
..
<#T19-28-47-1>
dc:creator
[ a wn:Person; foaf:nick "timbl" ]
dc:date
"2016-03-15T19:28:47Z"
dc:description
"timbl has joined &mit"
a foaf:chatEvent.
*/
label: function (subject) {
var n = UI.store.each(subject, ns.wf('message')).length
if (n > 0) return 'Chat (' + n + ')' // Show how many in hover text
if (kb.holds(subject, ns.rdf('type'), ns.meeting('Chat'))) { // subject is the file
return 'Meeting chat'
}
if (kb.holds(undefined, ns.rdf('type'), ns.foaf('ChatChannel'), subject)) { // subject is the file
return 'IRC log' // contains anything of this type
}
return null // Suppress pane otherwise
},
mintClass: ns.meeting('Chat'),
mintNew: function (newPaneOptions) {
var updater = kb.updater
if (newPaneOptions.me && !newPaneOptions.me.uri) throw new Error('chat mintNew: Invalid userid ' + newPaneOptions.me)
var newInstance = newPaneOptions.newInstance = newPaneOptions.newInstance || kb.sym(newPaneOptions.newBase + 'index.ttl#this')
var newChatDoc = newInstance.doc()
kb.add(newInstance, ns.rdf('type'), ns.meeting('Chat'), newChatDoc)
kb.add(newInstance, ns.dc('title'), 'Chat', newChatDoc)
kb.add(newInstance, ns.dc('created'), new Date(), newChatDoc)
if (newPaneOptions.me) {
kb.add(newInstance, ns.dc('author'), newPaneOptions.me, newChatDoc)
}
return new Promise(function (resolve, reject) {
updater.put(
newChatDoc,
kb.statementsMatching(undefined, undefined, undefined, newChatDoc),
'text/turtle',
function (uri2, ok, message) {
if (ok) {
resolve(newPaneOptions)
} else {
reject(new Error('FAILED to save new tool at: ' + uri2 + ' : ' +
message))
};
})
})
},
render: function (subject, dom) {
var complain = function complain (message, color) {
var pre = dom.createElement('pre')
pre.setAttribute('style', 'background-color: ' + color || '#eed' + ';')
div.appendChild(pre)
pre.appendChild(dom.createTextNode(message))
}
var div = dom.createElement('div')
div.setAttribute('class', 'chatPane')
let options = {} // Like newestFirst
var messageStore
if (kb.holds(subject, ns.rdf('type'), ns.meeting('Chat'))) { // subject may be the file
messageStore = subject.doc()
} else if (kb.any(subject, UI.ns.wf('message'))) {
messageStore = UI.store.any(subject, UI.ns.wf('message')).doc()
} else if (kb.holds(undefined, ns.rdf('type'), ns.foaf('ChatChannel'), subject) ||
kb.holds(subject, ns.rdf('type'), ns.foaf('ChatChannel'))) { // subject is the file
var ircLogQuery = function () {
var query = new $rdf.Query('IRC log entries')
var v = []
var vv = ['chan', 'msg', 'date', 'list', 'pred', 'creator', 'content']
vv.map(function (x) {
query.vars.push(v[x] = $rdf.variable(x))
})
query.pat.add(v['chan'], ns.foaf('chatEventList'), v['list']) // chatEventList
query.pat.add(v['list'], v['pred'], v['msg']) //
query.pat.add(v['msg'], ns.dc('date'), v['date'])
query.pat.add(v['msg'], ns.dc('creator'), v['creator'])
query.pat.add(v['msg'], ns.dc('description'), v['content'])
return query
}
messageStore = subject.doc()
options.query = ircLogQuery()
} else {
complain('Unknown chat type')
}
// var context = {dom, div}
// UI.authn.logIn(context).then( context => { // The widget itself sees to login
div.appendChild(UI.messageArea(dom, kb, subject, messageStore, options))
kb.updater.addDownstreamChangeListener(messageStore, function () {
UI.widgets.refreshTree(div)
}) // Live update
// })
return div
}
}