UNPKG

chat-pane

Version:

Solid-compatible Panes: Chat

146 lines (139 loc) 6.8 kB
"use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.shortChatPane = void 0; var _solidLogic = require("solid-logic"); var UI = _interopRequireWildcard(require("solid-ui")); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } /* Chat Pane ** ** Plan is to support a finte number of chat graph shapes ** and investigate the interop between them. */ /* global $rdf */ var ns = UI.ns; var shortChatPane = exports.shortChatPane = { icon: UI.icons.iconBase + 'noun_346319.svg', name: 'chat', /* * As part of the work on merging the existing chat views (aka panes) into one view * https://github.com/solid/chat-pane/issues/17 * we want to dis-incentivize the use of Small Chat until we've gotten the work done * by making it difficult to create new data resources that uses the Small Chat view * but we still want existing resources to be viewed by the Small Chat view */ audience: [ns.solid('PowerUser')], /* 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 label(subject, context) { var kb = context.session.store; var n = kb.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 mintNew(context, newPaneOptions) { // This deprecates the creation of short Chats after 2023-04-03. // The mintNew function will be removed/commented out in a few months. if (!confirm('short Chat is deprecated in favor of long Chat.' + '\nEmbedded chat for comments and existing short Chats will work.' + '\nYou can report any issues at https://github.com/SolidOS/chat-pane ?' + '\n\nDo you really want to create a new deprecated short Chat?')) return; var kb = context.session.store; 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 render(subject, context) { var kb = context.session.store; var dom = context.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'); var 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 = _solidLogic.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 ircLogQuery() { 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; } }; //# sourceMappingURL=shortChatPane.js.map