chat-pane
Version:
Solid-compatible Panes: Chat
507 lines (495 loc) • 34.1 kB
JavaScript
"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.longChatPane = void 0;
var _solidLogic = require("solid-logic");
var UI = _interopRequireWildcard(require("solid-ui"));
var $rdf = _interopRequireWildcard(require("rdflib"));
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; }
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } /* Long Chat Pane
**
** A long chat consists a of a series of chat files saved by date.
*/
var ns = UI.ns;
var mainClass = ns.meeting('LongChat'); // @@ something from SIOC?
var CHAT_LOCATION_IN_CONTAINER = 'index.ttl#this';
// const menuIcon = 'noun_897914.svg'
var SPANNER_ICON = 'noun_344563.svg';
// resize: horizontal; min-width: 20em;
var SIDEBAR_COMPONENT_STYLE = UI.style.sidebarComponentStyle || ' padding: 0.5em; width: 100%;';
var SIDEBAR_STYLE = UI.style.sidebarStyle || 'overflow-x: auto; overflow-y: auto; border-radius: 1em; border: 0.1em solid white;';
// was purple border
var longChatPane = exports.longChatPane = {
CHAT_LOCATION_IN_CONTAINER: CHAT_LOCATION_IN_CONTAINER,
// noun_704.svg Canoe noun_346319.svg = 1 Chat noun_1689339.svg = three chat
icon: UI.icons.iconBase + 'noun_1689339.svg',
name: 'long chat',
label: function label(subject, context) {
var kb = context.session.store;
if (kb.holds(subject, ns.rdf('type'), ns.meeting('LongChat'))) {
// subject is the object
return 'Chat channnel';
}
if (kb.holds(subject, ns.rdf('type'), ns.sioc('Thread'))) {
// subject is the object
return 'Thread';
}
// Looks like a message -- might not havre any class declared
if (kb.any(subject, ns.sioc('content')) && kb.any(subject, ns.dct('created'))) {
return 'message';
}
return null; // Suppress pane otherwise
},
mintClass: mainClass,
mintNew: function mintNew(context, newPaneOptions) {
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 + CHAT_LOCATION_IN_CONTAINER);
var newChatDoc = newInstance.doc();
kb.add(newInstance, ns.rdf('type'), ns.meeting('LongChat'), newChatDoc);
kb.add(newInstance, ns.dc('title'), 'Chat channel', newChatDoc);
kb.add(newInstance, ns.dc('created'), new Date(), newChatDoc);
if (newPaneOptions.me) {
kb.add(newInstance, ns.dc('author'), newPaneOptions.me, newChatDoc);
}
var aclBody = function aclBody(me, resource, AppendWrite) {
return "\n @prefix : <#>.\n @prefix acl: <http://www.w3.org/ns/auth/acl#>.\n @prefix foaf: <http://xmlns.com/foaf/0.1/>.\n @prefix lon: <./".concat(resource, ">.\n\n :ControlReadWrite\n a acl:Authorization;\n acl:accessTo lon:;\n acl:agent <").concat(me.uri, ">;\n acl:default lon:;\n acl:mode acl:Control, acl:Read, acl:Write.\n :Read\n a acl:Authorization;\n acl:accessTo lon:;\n acl:agentClass foaf:Agent;\n acl:default lon:;\n acl:mode acl:Read.\n :Read").concat(AppendWrite, "\n a acl:Authorization;\n acl:accessTo lon:;\n acl:agentClass acl:AuthenticatedAgent;\n acl:default lon:;\n acl:mode acl:Read, acl:").concat(AppendWrite, ".");
};
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 chat channel at: ' + uri2 + ' : ' + message));
}
})
// newChat container authenticated users Append only
.then(function (result) {
return new Promise(function (resolve, reject) {
if (newPaneOptions.me) {
kb.fetcher.webOperation('PUT', newPaneOptions.newBase + '.acl', {
data: aclBody(newPaneOptions.me, '', 'Append'),
contentType: 'text/turtle'
});
kb.fetcher.webOperation('PUT', newPaneOptions.newBase + 'index.ttl.acl', {
data: aclBody(newPaneOptions.me, 'index.ttl', 'Write'),
contentType: 'text/turtle'
});
}
resolve(newPaneOptions);
});
});
});
},
render: function render(subject, context, paneOptions) {
var dom = context.dom;
var kb = context.session.store;
/* Preferences
**
** Things like whether to color text by author webid, to expand image URLs inline,
** expanded inline image height. ...
** In general, preferences can be set per user, per user/app combo, per instance,
** and per instance/user combo. Per instance? not sure about unless it is valuable
** for everyone to be seeing the same thing.
*/
// const DCT = $rdf.Namespace('http://purl.org/dc/terms/')
var preferencesFormText = "\n @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.\n @prefix solid: <http://www.w3.org/ns/solid/terms#>.\n @prefix ui: <http://www.w3.org/ns/ui#>.\n @prefix : <#>.\n\n :this\n <http://purl.org/dc/elements/1.1/title> \"Chat preferences\" ;\n a ui:Form ;\n ui:parts ( :colorizeByAuthor :expandImagesInline :newestFirst :inlineImageHeightEms\n :shiftEnterSendsMessage :authorDateOnLeft :showDeletedMessages).\n\n :colorizeByAuthor a ui:TristateField; ui:property solid:colorizeByAuthor;\n ui:label \"Color user input by user\".\n\n :expandImagesInline a ui:TristateField; ui:property solid:expandImagesInline;\n ui:label \"Expand image URLs inline\".\n\n :newestFirst a ui:TristateField; ui:property solid:newestFirst;\n ui:label \"Newest messages at the top\".\n\n :inlineImageHeightEms a ui:IntegerField; ui:property solid:inlineImageHeightEms;\n ui:label \"Inline image height (lines)\".\n\n :shiftEnterSendsMessage a ui:TristateField; ui:property solid:shiftEnterSendsMessage;\n ui:label \"Shift-Enter sends message\".\n\n :authorDateOnLeft a ui:TristateField; ui:property solid:authorDateOnLeft;\n ui:label \"Author & date of message on left\".\n\n :showDeletedMessages a ui:TristateField; ui:property solid:showDeletedMessages;\n ui:label \"Show placeholders for deleted messages\".\n";
var preferencesForm = kb.sym('https://solid.github.io/solid-panes/longCharPane/preferencesForm.ttl#this');
var preferencesFormDoc = preferencesForm.doc();
if (!kb.holds(undefined, undefined, undefined, preferencesFormDoc)) {
// If not loaded already
$rdf.parse(preferencesFormText, kb, preferencesFormDoc.uri, 'text/turtle'); // Load form directly
}
var preferenceProperties = kb.statementsMatching(null, ns.ui.property, null, preferencesFormDoc).map(function (st) {
return st.object;
});
// Preferences Menu
//
// Build a menu a the side (@@ reactive: on top?)
function renderPreferencesSidebar(_x) {
return _renderPreferencesSidebar.apply(this, arguments);
} // @@ Split out into solid-ui
function _renderPreferencesSidebar() {
_renderPreferencesSidebar = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(context) {
var dom, noun, preferencesArea, menuTable, registrationArea, statusArea, me;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
// const noun = 'chat room'
dom = context.dom, noun = context.noun;
preferencesArea = dom.createElement('div');
preferencesArea.appendChild(panelCloseButton(preferencesArea));
// @@ style below fix .. just make it onviious while testing
preferencesArea.style = SIDEBAR_COMPONENT_STYLE;
preferencesArea.style.minWidth = '25em'; // bit bigger
preferencesArea.style.maxHeight = triptychHeight;
menuTable = preferencesArea.appendChild(dom.createElement('table'));
registrationArea = menuTable.appendChild(dom.createElement('tr'));
statusArea = menuTable.appendChild(dom.createElement('tr'));
me = _solidLogic.authn.currentUser();
if (!me) {
_context.next = 15;
break;
}
_context.next = 13;
return UI.login.registrationControl({
noun: noun,
me: me,
statusArea: statusArea,
dom: dom,
div: registrationArea
}, chatChannel, mainClass);
case 13:
console.log('Registration control finsished.');
preferencesArea.appendChild(UI.preferences.renderPreferencesForm(chatChannel, mainClass, preferencesForm, {
noun: noun,
me: me,
statusArea: statusArea,
div: preferencesArea,
dom: dom,
kb: kb
}));
case 15:
return _context.abrupt("return", preferencesArea);
case 16:
case "end":
return _context.stop();
}
}, _callee);
}));
return _renderPreferencesSidebar.apply(this, arguments);
}
function panelCloseButton(panel) {
function removePanel() {
panel.parentNode.removeChild(panel);
}
var button = UI.widgets.button(context.dom, UI.icons.iconBase + 'noun_1180156.svg', 'close', removePanel);
button.style["float"] = 'right';
button.style.margin = '0.7em';
delete button.style.backgroundColor; // do not want white
return button;
}
function preferencesButtonPressed(_x2) {
return _preferencesButtonPressed.apply(this, arguments);
} // preferencesButtonPressed
// All my chats
//
/* Build a other chats list drawer the side
*/
function _preferencesButtonPressed() {
_preferencesButtonPressed = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_event) {
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
if (preferencesArea) {
_context2.next = 4;
break;
}
_context2.next = 3;
return renderPreferencesSidebar({
dom: dom,
noun: 'chat room'
});
case 3:
preferencesArea = _context2.sent;
case 4:
if (paneRight.contains(preferencesArea)) {
// Close menu (hide or delete??)
preferencesArea.parentNode.removeChild(preferencesArea);
preferencesArea = null;
} else {
paneRight.appendChild(preferencesArea);
}
case 5:
case "end":
return _context2.stop();
}
}, _callee2);
}));
return _preferencesButtonPressed.apply(this, arguments);
}
function renderCreationControl(refreshTarget, noun) {
var creationDiv = dom.createElement('div');
var me = _solidLogic.authn.currentUser();
var creationContext = {
// folder: subject,
div: creationDiv,
dom: dom,
noun: noun,
statusArea: creationDiv,
me: me,
refreshTarget: refreshTarget
};
var chatPane = context.session.paneRegistry.byName('chat');
var relevantPanes = [chatPane];
UI.create.newThingUI(creationContext, context, relevantPanes); // Have to pass panes down newUI
return creationDiv;
}
function renderInstances(_x3, _x4) {
return _renderInstances.apply(this, arguments);
}
function _renderInstances() {
_renderInstances = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(theClass, noun) {
var instancesDiv, context;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
instancesDiv = dom.createElement('div');
context = {
dom: dom,
div: instancesDiv,
noun: noun
};
_context3.next = 4;
return UI.login.registrationList(context, {
"public": true,
"private": true,
type: theClass
});
case 4:
instancesDiv.appendChild(renderCreationControl(instancesDiv, noun));
return _context3.abrupt("return", instancesDiv);
case 6:
case "end":
return _context3.stop();
}
}, _callee3);
}));
return _renderInstances.apply(this, arguments);
}
var otherChatsArea = null;
function otherChatsHandler(_x5) {
return _otherChatsHandler.apply(this, arguments);
} // otherChatsHandler
// People in the chat
//
/* Build a participants list drawer the side
*/
function _otherChatsHandler() {
_otherChatsHandler = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_event) {
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
if (otherChatsArea) {
_context4.next = 10;
break;
}
// Lazy build when needed
// Expand
otherChatsArea = dom.createElement('div');
otherChatsArea.style = SIDEBAR_COMPONENT_STYLE;
otherChatsArea.style.maxHeight = triptychHeight;
otherChatsArea.appendChild(panelCloseButton(otherChatsArea));
_context4.t0 = otherChatsArea;
_context4.next = 8;
return renderInstances(ns.meeting('LongChat'), 'chat');
case 8:
_context4.t1 = _context4.sent;
_context4.t0.appendChild.call(_context4.t0, _context4.t1);
case 10:
// Toggle visibility with button clicks
if (paneLeft.contains(otherChatsArea)) {
otherChatsArea.parentNode.removeChild(otherChatsArea);
} else {
paneLeft.appendChild(otherChatsArea);
}
case 11:
case "end":
return _context4.stop();
}
}, _callee4);
}));
return _otherChatsHandler.apply(this, arguments);
}
var participantsArea;
function participantsHandler(_event) {
if (!participantsArea) {
// Expand
participantsArea = dom.createElement('div');
participantsArea.style = SIDEBAR_COMPONENT_STYLE;
participantsArea.style.maxHeight = triptychHeight;
participantsArea.appendChild(panelCloseButton(participantsArea));
// Record my participation and display participants
var me = _solidLogic.authn.currentUser();
if (!me) alert('Should be logeed in for partipants panel');
UI.pad.manageParticipation(dom, participantsArea, chatChannel.doc(), chatChannel, me, {});
}
// Toggle appearance in sidebar with clicks
// Note also it can remove itself using the X button
if (paneLeft.contains(participantsArea)) {
// Close participants (hide or delete??)
participantsArea.parentNode.removeChild(participantsArea);
participantsArea = null;
} else {
paneLeft.appendChild(participantsArea);
}
} // participantsHandler
var chatChannel = subject;
var selectedMessage = null;
var thread = null;
if (kb.holds(subject, ns.rdf('type'), ns.meeting('LongChat'))) {
// subject is the chatChannel
console.log('@@@ Chat channnel');
// Looks like a message -- might not havre any class declared
} else if (kb.holds(subject, ns.rdf('type'), ns.sioc('Thread'))) {
// subject is the chatChannel
console.log('Thread is subject ' + subject.uri);
thread = subject;
var rootMessage = kb.the(null, ns.sioc('has_reply'), thread, thread.doc());
if (!rootMessage) throw new Error('Thread has no root message ' + thread);
chatChannel = kb.any(null, ns.wf('message'), rootMessage);
if (!chatChannel) throw new Error('Thread root has no link to chatChannel');
} else if (
// Looks like a message -- might not havre any class declared
kb.any(subject, ns.sioc('content')) && kb.any(subject, ns.dct('created'))) {
console.log('message is subject ' + subject.uri);
selectedMessage = subject;
chatChannel = kb.any(null, ns.wf('message'), selectedMessage);
if (!chatChannel) throw new Error('Message has no link to chatChannel');
}
var div = dom.createElement('div');
// Three large columns for particpant, chat, Preferences. formula below just as a note
// const windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
var triptychHeight = '20cm'; // @@ need to be able to set to window!
var triptych = div.appendChild(dom.createElement('table'));
triptych.style.maxHeight = '12"'; // Screen max
var paneRow = triptych.appendChild(dom.createElement('tr'));
var paneLeft = paneRow.appendChild(dom.createElement('td'));
var paneMiddle = paneRow.appendChild(dom.createElement('td'));
var paneThread = paneRow.appendChild(dom.createElement('td'));
var paneRight = paneRow.appendChild(dom.createElement('td'));
var paneBottom = triptych.appendChild(dom.createElement('tr'));
paneLeft.style = SIDEBAR_STYLE;
paneLeft.style.paddingRight = '1em';
paneThread.style = SIDEBAR_STYLE;
paneThread.style.paddingLeft = '1em';
paneRight.style = SIDEBAR_STYLE;
paneRight.style.paddingLeft = '1em';
paneBottom.appendChild(dom.createElement('td'));
var buttonCell = paneBottom.appendChild(dom.createElement('td'));
paneBottom.appendChild(dom.createElement('td'));
// Button to bring up participants drawer on left
var participantsIcon = 'noun_339237.svg';
var participantsButton = UI.widgets.button(dom, UI.icons.iconBase + participantsIcon, 'participants ...'); // wider var
buttonCell.appendChild(participantsButton);
participantsButton.addEventListener('click', participantsHandler);
// Button to bring up otherChats drawer on left
var otherChatsIcon = 'noun_1689339.svg'; // long chat icon -- not ideal for a set of chats @@
var otherChatsButton = UI.widgets.button(dom, UI.icons.iconBase + otherChatsIcon, 'List of other chats ...'); // wider var
buttonCell.appendChild(otherChatsButton);
otherChatsButton.addEventListener('click', otherChatsHandler);
var preferencesArea = null;
var menuButton = UI.widgets.button(dom, UI.icons.iconBase + SPANNER_ICON, 'Setting ...'); // wider var
buttonCell.appendChild(menuButton);
menuButton.style["float"] = 'right';
menuButton.addEventListener('click', preferencesButtonPressed);
div.setAttribute('class', 'chatPane');
var options = {
infinite: true
};
var participantsHandlerContext = {
noun: 'chat room',
div: div,
dom: dom
};
participantsHandlerContext.me = _solidLogic.authn.currentUser(); // If already logged on
function showThread(_x6, _x7) {
return _showThread.apply(this, arguments);
}
function _showThread() {
_showThread = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(thread, options) {
var newOptions, chatControl;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
console.log('@@@@ showThread thread ' + thread);
newOptions = {}; // @@@ inherit
newOptions.thread = thread;
newOptions.includeRemoveButton = true;
newOptions.authorDateOnLeft = options.authorDateOnLeft;
newOptions.newestFirst = options.newestFirst;
paneThread.innerHTML = '';
console.log('Options for showThread message Area', newOptions);
_context5.next = 10;
return UI.infiniteMessageArea(dom, kb, chatChannel, newOptions);
case 10:
chatControl = _context5.sent;
chatControl.style.resize = 'both';
chatControl.style.overflow = 'auto';
chatControl.style.maxHeight = triptychHeight;
paneThread.appendChild(chatControl);
case 15:
case "end":
return _context5.stop();
}
}, _callee5);
}));
return _showThread.apply(this, arguments);
}
function buildPane() {
return _buildPane.apply(this, arguments);
}
function _buildPane() {
_buildPane = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
var prefMap, propuri, chatControl;
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
_context6.prev = 0;
_context6.next = 3;
return UI.preferences.getPreferencesForClass(chatChannel, mainClass, preferenceProperties, participantsHandlerContext);
case 3:
prefMap = _context6.sent;
_context6.next = 9;
break;
case 6:
_context6.prev = 6;
_context6.t0 = _context6["catch"](0);
UI.widgets.complain(participantsHandlerContext, _context6.t0);
case 9:
for (propuri in prefMap) {
options[propuri.split('#')[1]] = prefMap[propuri];
}
if (selectedMessage) {
options.selectedMessage = selectedMessage;
}
if (paneOptions.solo) {
// This is the top pane, title, scrollbar etc are ours
options.solo = true;
}
if (thread) {
// Rendereing a thread as first class object
options.thread = thread;
} else {
// either show thread *or* allow new threads. Threads don't nest but they could
options.showThread = showThread;
}
_context6.next = 15;
return UI.infiniteMessageArea(dom, kb, chatChannel, options);
case 15:
chatControl = _context6.sent;
chatControl.style.resize = 'both';
chatControl.style.overflow = 'auto';
chatControl.style.maxHeight = triptychHeight;
paneMiddle.appendChild(chatControl);
case 20:
case "end":
return _context6.stop();
}
}, _callee6, null, [[0, 6]]);
}));
return _buildPane.apply(this, arguments);
}
buildPane().then(console.log('async - chat pane built'));
return div;
}
};
//# sourceMappingURL=longChatPane.js.map