solid-panes 3.7.3-3425a37d → 3.7.3-346708d2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/RDFXMLPane.js +58 -0
- package/dist/RDFXMLPane.js.map +1 -0
- package/dist/argument/argumentPane.js +61 -0
- package/dist/argument/argumentPane.js.map +1 -0
- package/dist/attach/attachPane.js +394 -0
- package/dist/attach/attachPane.js.map +1 -0
- package/dist/audio/audioPane.js +182 -0
- package/dist/audio/audioPane.js.map +1 -0
- package/dist/classInstancePane.js +92 -0
- package/dist/classInstancePane.js.map +1 -0
- package/dist/dashboard/basicPreferences.js +121 -129
- package/dist/dashboard/basicPreferences.js.map +1 -1
- package/dist/dashboard/dashboardPane.js +60 -54
- package/dist/dashboard/dashboardPane.js.map +1 -1
- package/dist/dashboard/homepage.js +45 -54
- package/dist/dashboard/homepage.js.map +1 -1
- package/dist/dataContentPane.js +259 -0
- package/dist/dataContentPane.js.map +1 -0
- package/dist/defaultPane.js +75 -0
- package/dist/defaultPane.js.map +1 -0
- package/dist/dokieli/dokieliPane.js +169 -0
- package/dist/dokieli/dokieliPane.js.map +1 -0
- package/dist/dokieli/new.js +28 -0
- package/dist/dokieli/new.js.map +1 -0
- package/dist/form/pane.js +185 -0
- package/dist/form/pane.js.map +1 -0
- package/dist/global.d.js +2 -0
- package/dist/global.d.js.map +1 -0
- package/dist/home/homePane.js +60 -55
- package/dist/home/homePane.js.map +1 -1
- package/dist/humanReadablePane.js +135 -0
- package/dist/humanReadablePane.js.map +1 -0
- package/dist/imagePane.js +70 -0
- package/dist/imagePane.js.map +1 -0
- package/dist/index.js +86 -25
- package/dist/index.js.map +1 -1
- package/dist/internal/internalPane.js +168 -179
- package/dist/internal/internalPane.js.map +1 -1
- package/dist/mainPage/footer.js +13 -7
- package/dist/mainPage/footer.js.map +1 -1
- package/dist/mainPage/header.js +59 -58
- package/dist/mainPage/header.js.map +1 -1
- package/dist/mainPage/index.js +19 -24
- package/dist/mainPage/index.js.map +1 -1
- package/dist/microblogPane/microblogPane.js +1031 -0
- package/dist/microblogPane/microblogPane.js.map +1 -0
- package/dist/n3Pane.js +56 -0
- package/dist/n3Pane.js.map +1 -0
- package/dist/outline/context.js +17 -11
- package/dist/outline/context.js.map +1 -1
- package/dist/outline/manager.js +1997 -0
- package/dist/outline/manager.js.map +1 -0
- package/dist/outline/outlineIcons.js +127 -0
- package/dist/outline/outlineIcons.js.map +1 -0
- package/dist/outline/propertyViews.js +39 -28
- package/dist/outline/propertyViews.js.map +1 -1
- package/dist/outline/queryByExample.js +285 -0
- package/dist/outline/queryByExample.js.map +1 -0
- package/dist/outline/userInput.js +1819 -0
- package/dist/outline/userInput.js.map +1 -0
- package/dist/outline/viewAsImage.js +13 -5
- package/dist/outline/viewAsImage.js.map +1 -1
- package/dist/outline/viewAsMbox.js +20 -11
- package/dist/outline/viewAsMbox.js.map +1 -1
- package/dist/pad/padPane.js +395 -404
- package/dist/pad/padPane.js.map +1 -1
- package/dist/playlist/playlistPane.js +124 -0
- package/dist/playlist/playlistPane.js.map +1 -0
- package/dist/registerPanes.js +146 -0
- package/dist/registerPanes.js.map +1 -0
- package/dist/schedule/schedulePane.js +888 -0
- package/dist/schedule/schedulePane.js.map +1 -0
- package/dist/sharing/sharingPane.js +36 -32
- package/dist/sharing/sharingPane.js.map +1 -1
- package/dist/slideshow/slideshowPane.js +80 -0
- package/dist/slideshow/slideshowPane.js.map +1 -0
- package/dist/socialPane.js +430 -0
- package/dist/socialPane.js.map +1 -0
- package/dist/tabbed/tabbedPane.js +54 -51
- package/dist/tabbed/tabbedPane.js.map +1 -1
- package/dist/tableViewPane.js +57 -0
- package/dist/tableViewPane.js.map +1 -0
- package/dist/transaction/pane.js +478 -0
- package/dist/transaction/pane.js.map +1 -0
- package/dist/transaction/period.js +324 -0
- package/dist/transaction/period.js.map +1 -0
- package/dist/trip/tripPane.js +175 -0
- package/dist/trip/tripPane.js.map +1 -0
- package/dist/trustedApplications/trustedApplications.dom.js +134 -146
- package/dist/trustedApplications/trustedApplications.dom.js.map +1 -1
- package/dist/trustedApplications/trustedApplications.utils.js +20 -20
- package/dist/trustedApplications/trustedApplications.utils.js.map +1 -1
- package/dist/trustedApplications/trustedApplications.view.js +51 -57
- package/dist/trustedApplications/trustedApplications.view.js.map +1 -1
- package/dist/types.js +5 -1
- package/dist/types.js.map +1 -1
- package/dist/ui/pane.js +147 -0
- package/dist/ui/pane.js.map +1 -0
- package/dist/versionInfo.js +35 -29
- package/dist/versionInfo.js.map +1 -1
- package/dist/video/videoPane.js +43 -0
- package/dist/video/videoPane.js.map +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,1031 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _solidLogic = require("solid-logic");
|
|
8
|
+
var UI = _interopRequireWildcard(require("solid-ui"));
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
/*
|
|
11
|
+
Microblog pane
|
|
12
|
+
Charles McKenzie <charles2@mit.edu>
|
|
13
|
+
*/
|
|
14
|
+
/* global alert */
|
|
15
|
+
var _default = exports.default = {
|
|
16
|
+
icon: UI.icons.originalIconBase + 'microblog/microblog.png',
|
|
17
|
+
name: 'microblogPane',
|
|
18
|
+
label: function (subject) {
|
|
19
|
+
if (_solidLogic.store.whether(subject, UI.ns.rdf('type'), UI.ns.foaf('Person'))) {
|
|
20
|
+
return 'Microblog';
|
|
21
|
+
} else {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
render: function (s, doc) {
|
|
26
|
+
//* **********************************************
|
|
27
|
+
// NAMESPACES SECTION
|
|
28
|
+
//* **********************************************
|
|
29
|
+
const SIOC = UI.rdf.Namespace('http://rdfs.org/sioc/ns#');
|
|
30
|
+
const SIOCt = UI.rdf.Namespace('http://rdfs.org/sioc/types#');
|
|
31
|
+
const FOAF = UI.rdf.Namespace('http://xmlns.com/foaf/0.1/');
|
|
32
|
+
const terms = UI.rdf.Namespace('http://purl.org/dc/terms/');
|
|
33
|
+
const RDF = UI.ns.rdf;
|
|
34
|
+
const kb = _solidLogic.store;
|
|
35
|
+
const charCount = 140;
|
|
36
|
+
const sf = _solidLogic.store.fetcher;
|
|
37
|
+
//* **********************************************
|
|
38
|
+
// BACK END
|
|
39
|
+
//* **********************************************
|
|
40
|
+
const sparqlUpdater = kb.updater;
|
|
41
|
+
// ----------------------------------------------
|
|
42
|
+
// FOLLOW LIST
|
|
43
|
+
// store the URIs of followed users for
|
|
44
|
+
// dereferencing the @replies
|
|
45
|
+
// ----------------------------------------------
|
|
46
|
+
const FollowList = function (user) {
|
|
47
|
+
this.userlist = {};
|
|
48
|
+
this.uris = {};
|
|
49
|
+
const myFollows = kb.each(kb.sym(user), SIOC('follows'));
|
|
50
|
+
for (const mf in myFollows) {
|
|
51
|
+
this.add(kb.any(myFollows[mf], SIOC('id')), myFollows[mf].uri);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
FollowList.prototype.add = function (user, uri) {
|
|
55
|
+
// add a user to the follows store
|
|
56
|
+
if (this.userlist[user]) {
|
|
57
|
+
if (!(uri in this.uris)) {
|
|
58
|
+
this.userlist[user].push(uri);
|
|
59
|
+
this.uris[uri] = '';
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
this.userlist[user] = [uri];
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
FollowList.prototype.selectUser = function (user) {
|
|
66
|
+
// check if a user is in the follows list.
|
|
67
|
+
if (this.userlist[user]) {
|
|
68
|
+
return [this.userlist[user].length === 1, this.userlist[user]];
|
|
69
|
+
} else {
|
|
70
|
+
// user does not follow any users with this nick
|
|
71
|
+
return [false, []];
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
// ----------------------------------------------
|
|
75
|
+
// FAVORITES
|
|
76
|
+
// controls the list of favorites.
|
|
77
|
+
// constructor expects a user as uri.
|
|
78
|
+
// ----------------------------------------------
|
|
79
|
+
const Favorites = function (user) {
|
|
80
|
+
this.favorites = {};
|
|
81
|
+
this.favoritesURI = '';
|
|
82
|
+
if (!user) {
|
|
83
|
+
// TODO is this even useful?
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.user = user.split('#')[0];
|
|
87
|
+
const created = kb.each(kb.sym(user), SIOC('creator_of'));
|
|
88
|
+
for (const c in created) {
|
|
89
|
+
if (kb.whether(created[c], RDF('type'), SIOCt('FavouriteThings'))) {
|
|
90
|
+
this.favoritesURI = created[c];
|
|
91
|
+
const favs = kb.each(created[c], SIOC('container_of'));
|
|
92
|
+
for (const f in favs) {
|
|
93
|
+
this.favorites[favs[f]] = '';
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
Favorites.prototype.favorited = function (post) {
|
|
100
|
+
/* Favorited- returns true if the post is a favorite
|
|
101
|
+
false otherwise */
|
|
102
|
+
return kb.sym(post) in this.favorites;
|
|
103
|
+
};
|
|
104
|
+
Favorites.prototype.add = function (post, callback) {
|
|
105
|
+
const batch = new UI.rdf.Statement(this.favoritesURI, SIOC('container_of'), kb.sym(post), kb.sym(this.user));
|
|
106
|
+
sparqlUpdater.insert_statement(batch, function (a, success, c) {
|
|
107
|
+
if (success) {
|
|
108
|
+
kb.add(batch.subject, batch.predicate, batch.object, batch.why);
|
|
109
|
+
}
|
|
110
|
+
callback(a, success, c);
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
Favorites.prototype.remove = function (post, callback) {
|
|
114
|
+
const batch = new UI.rdf.Statement(this.favoritesURI, SIOC('container_of'), kb.sym(post), kb.sym(this.user));
|
|
115
|
+
sparqlUpdater.delete_statement(batch, function (a, success, c) {
|
|
116
|
+
if (success) {
|
|
117
|
+
kb.add(batch.subject, batch.predicate, batch.object, batch.why);
|
|
118
|
+
}
|
|
119
|
+
callback(a, success, c);
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
// ----------------------------------------------
|
|
123
|
+
// MICROBLOG
|
|
124
|
+
// store the uri's of followed users for
|
|
125
|
+
// dereferencing the @replies.
|
|
126
|
+
// ----------------------------------------------
|
|
127
|
+
const Microblog = function (kb) {
|
|
128
|
+
this.kb = kb;
|
|
129
|
+
|
|
130
|
+
// attempt to fetch user account from local preferences if just
|
|
131
|
+
// in case the user's foaf was not writable. add it to the store
|
|
132
|
+
// this will probably need to change.
|
|
133
|
+
const theUser = _solidLogic.authn.currentUser();
|
|
134
|
+
if (theUser) {
|
|
135
|
+
let theAccount = UI.preferences.get('acct');
|
|
136
|
+
if (theAccount) {
|
|
137
|
+
theAccount = kb.sym(theAccount);
|
|
138
|
+
}
|
|
139
|
+
if (theUser && theAccount) {
|
|
140
|
+
kb.add(theUser, FOAF('holdsAccount'), theAccount, theUser.uri.split('#')[0]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
Microblog.prototype.getUser = function (uri) {
|
|
145
|
+
const User = {};
|
|
146
|
+
User.name = kb.any(uri, SIOC('name')) ? kb.any(uri, SIOC('name')) : '';
|
|
147
|
+
User.avatar = kb.any(uri, SIOC('avatar')) ? kb.any(uri, SIOC('avatar')) : '';
|
|
148
|
+
User.id = kb.any(uri, SIOC('id'));
|
|
149
|
+
User.sym = uri;
|
|
150
|
+
return User;
|
|
151
|
+
};
|
|
152
|
+
Microblog.prototype.getPost = function (uri) {
|
|
153
|
+
const Post = {};
|
|
154
|
+
// date ----------
|
|
155
|
+
let postLink = new Date(kb.anyValue(uri, terms('created')));
|
|
156
|
+
let h = postLink.getHours();
|
|
157
|
+
const a = h > 12 ? ' PM' : ' AM';
|
|
158
|
+
h = h > 12 ? h - 12 : h;
|
|
159
|
+
let m = postLink.getMinutes();
|
|
160
|
+
m = m < 10 ? '0' + m : m;
|
|
161
|
+
const mo = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
162
|
+
const da = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
163
|
+
const ds = da[postLink.getDay()] + ' ' + postLink.getDate() + ' ' + mo[postLink.getMonth()] + ' ' + postLink.getFullYear();
|
|
164
|
+
postLink = h + ':' + m + a + ' on ' + ds;
|
|
165
|
+
Post.date = postLink;
|
|
166
|
+
// ---------
|
|
167
|
+
Post.mentions = '';
|
|
168
|
+
Post.message = String(kb.any(uri, SIOC('content')));
|
|
169
|
+
Post.creator = kb.any(uri, SIOC('has_creator'));
|
|
170
|
+
Post.uri = '';
|
|
171
|
+
return Post;
|
|
172
|
+
};
|
|
173
|
+
Microblog.prototype.gen_random_uri = function (base) {
|
|
174
|
+
// generate random uri
|
|
175
|
+
const uriNonce = base + '#n' + Math.floor(Math.random() * 10e9);
|
|
176
|
+
return kb.sym(uriNonce);
|
|
177
|
+
};
|
|
178
|
+
Microblog.prototype.statusUpdate = function (statusMsg, callback, replyTo, meta) {
|
|
179
|
+
const myUserURI = this.getMyURI();
|
|
180
|
+
const myUser = kb.sym(myUserURI.split('#')[0]);
|
|
181
|
+
const newPost = this.gen_random_uri(myUser.uri);
|
|
182
|
+
const microlist = kb.each(kb.sym(myUserURI), SIOC('creator_of'));
|
|
183
|
+
let micro;
|
|
184
|
+
for (const microlistelement in microlist) {
|
|
185
|
+
if (kb.whether(microlist[microlistelement], RDF('type'), SIOCt('Microblog')) && !kb.whether(microlist[microlistelement], SIOC('topic'), kb.sym(this.getMyURI()))) {
|
|
186
|
+
micro = microlist[microlistelement];
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// generate new post
|
|
192
|
+
const batch = [new UI.rdf.Statement(newPost, RDF('type'), SIOCt('MicroblogPost'), myUser), new UI.rdf.Statement(newPost, SIOC('has_creator'), kb.sym(myUserURI), myUser), new UI.rdf.Statement(newPost, SIOC('content'), statusMsg, myUser), new UI.rdf.Statement(newPost, terms('created'), new Date(), myUser), new UI.rdf.Statement(micro, SIOC('container_of'), newPost, myUser)];
|
|
193
|
+
|
|
194
|
+
// message replies
|
|
195
|
+
if (replyTo) {
|
|
196
|
+
batch.push(new UI.rdf.Statement(newPost, SIOC('reply_of'), kb.sym(replyTo), myUser));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// @replies, #hashtags, !groupReplies
|
|
200
|
+
for (const r in meta.recipients) {
|
|
201
|
+
batch.push(new UI.rdf.Statement(newPost, SIOC('topic'), kb.sym(meta.recipients[r]), myUser));
|
|
202
|
+
batch.push(new UI.rdf.Statement(kb.any(), SIOC('container_of'), newPost, myUser));
|
|
203
|
+
const mblogs = kb.each(kb.sym(meta.recipients[r]), SIOC('creator_of'));
|
|
204
|
+
for (const mbl in mblogs) {
|
|
205
|
+
if (kb.whether(mblogs[mbl], SIOC('topic'), kb.sym(meta.recipients[r]))) {
|
|
206
|
+
const replyBatch = new UI.rdf.Statement(mblogs[mbl], SIOC('container_of'), newPost, kb.sym(meta.recipients[r].split('#')[0]));
|
|
207
|
+
sparqlUpdater.insert_statement(replyBatch);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
sparqlUpdater.insert_statement(batch, function (a, b, c) {
|
|
212
|
+
callback(a, b, c, batch);
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
Microblog.prototype.getMyURI = function () {
|
|
216
|
+
const me = _solidLogic.authn.currentUser();
|
|
217
|
+
console.log(me);
|
|
218
|
+
const myMicroblog = kb.any(kb.sym(me), FOAF('holdsAccount'));
|
|
219
|
+
console.log('\n\n' + myMicroblog);
|
|
220
|
+
return myMicroblog ? myMicroblog.uri : false;
|
|
221
|
+
};
|
|
222
|
+
Microblog.prototype.generateNewMB = function (id, name, avatar, loc) {
|
|
223
|
+
const host = loc + '/' + id;
|
|
224
|
+
const rememberMicroblog = function () {
|
|
225
|
+
UI.preferences.set('acct', host + '#' + id);
|
|
226
|
+
};
|
|
227
|
+
const cbgenUserMB = function (a, success, c, d) {
|
|
228
|
+
if (success) {
|
|
229
|
+
alert('Microblog generated at ' + host + '#' + id + 'please add <b>' + host + '</b> to your foaf.');
|
|
230
|
+
// mbCancelNewMB() @@TBD
|
|
231
|
+
// assume the foaf is not writable and store the microblog to the
|
|
232
|
+
// preferences for later retrieval.
|
|
233
|
+
// this will probably need to change.
|
|
234
|
+
rememberMicroblog();
|
|
235
|
+
for (const triple in d) {
|
|
236
|
+
kb.add(d[triple].subject, d[triple].predicate, d[triple].object, d[triple].why);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
const genUserMB = [
|
|
241
|
+
// user
|
|
242
|
+
new UI.rdf.Statement(kb.sym(host + '#' + id), RDF('type'), SIOC('User'), kb.sym(host)), new UI.rdf.Statement(kb.sym(host + '#' + id), SIOC('creator_of'), kb.sym(host + '#mb'), kb.sym(host)), new UI.rdf.Statement(kb.sym(host + '#' + id), SIOC('creator_of'), kb.sym(host + '#mbn'), kb.sym(host)), new UI.rdf.Statement(kb.sym(host + '#' + id), SIOC('creator_of'), kb.sym(host + '#fav'), kb.sym(host)), new UI.rdf.Statement(kb.sym(host + '#' + id), SIOC('name'), name, kb.sym(host)), new UI.rdf.Statement(kb.sym(host + '#' + id), SIOC('id'), id, kb.sym(host)), new UI.rdf.Statement(kb.sym(host + '#' + id), RDF('label'), id, kb.sym(host)), new UI.rdf.Statement(s, FOAF('holdsAccount'), kb.sym(host + '#' + id), kb.sym(host)),
|
|
243
|
+
// microblog
|
|
244
|
+
new UI.rdf.Statement(kb.sym(host + '#mb'), RDF('type'), SIOCt('Microblog'), kb.sym(host)), new UI.rdf.Statement(kb.sym(host + '#mb'), SIOC('has_creator'), kb.sym(host + '#' + id), kb.sym(host)),
|
|
245
|
+
// notification microblog
|
|
246
|
+
new UI.rdf.Statement(kb.sym(host + '#mbn'), RDF('type'), SIOCt('Microblog'), kb.sym(host)), new UI.rdf.Statement(kb.sym(host + '#mbn'), SIOC('topic'), kb.sym(host + '#' + id), kb.sym(host)), new UI.rdf.Statement(kb.sym(host + '#mbn'), SIOC('has_creator'), kb.sym(host + '#' + id), kb.sym(host)),
|
|
247
|
+
// favorites container
|
|
248
|
+
new UI.rdf.Statement(kb.sym(host + '#fav'), RDF('type'), SIOCt('FavouriteThings'), kb.sym(host)), new UI.rdf.Statement(kb.sym(host + '#fav'), SIOC('has_creator'), kb.sym(host + '#' + id), kb.sym(host))];
|
|
249
|
+
if (avatar) {
|
|
250
|
+
// avatar optional
|
|
251
|
+
genUserMB.push(new UI.rdf.Statement(kb.sym(host + '#' + id), SIOC('avatar'), kb.sym(avatar), kb.sym(host)));
|
|
252
|
+
}
|
|
253
|
+
sparqlUpdater.insert_statement(genUserMB, cbgenUserMB);
|
|
254
|
+
};
|
|
255
|
+
const mb = new Microblog(kb);
|
|
256
|
+
const myFavorites = new Favorites(mb.getMyURI());
|
|
257
|
+
const myFollowList = new FollowList(mb.getMyURI());
|
|
258
|
+
|
|
259
|
+
//* **********************************************
|
|
260
|
+
// FRONT END FUNCTIONALITY
|
|
261
|
+
//* **********************************************
|
|
262
|
+
// ----------------------------------------------
|
|
263
|
+
// PANE
|
|
264
|
+
// User Interface for the Microblog Pane
|
|
265
|
+
// ----------------------------------------------
|
|
266
|
+
const Pane = function (s, doc, microblogPane) {
|
|
267
|
+
const TabManager = function (doc) {
|
|
268
|
+
this.tablist = {};
|
|
269
|
+
this.doc = doc;
|
|
270
|
+
this.tabView = doc.createElement('ul');
|
|
271
|
+
this.tabView.className = 'tabslist';
|
|
272
|
+
};
|
|
273
|
+
TabManager.prototype.create = function (id, caption, view, isDefault) {
|
|
274
|
+
const tab = this.doc.createElement('li');
|
|
275
|
+
tab.innerHTML = caption;
|
|
276
|
+
if (isDefault) {
|
|
277
|
+
tab.className = 'active';
|
|
278
|
+
}
|
|
279
|
+
tab.id = id;
|
|
280
|
+
const change = this.change;
|
|
281
|
+
const tablist = this.tablist;
|
|
282
|
+
tab.addEventListener('click', function (evt) {
|
|
283
|
+
change(evt.target.id, tablist, doc);
|
|
284
|
+
}, false);
|
|
285
|
+
this.tablist[id] = {
|
|
286
|
+
view: view.id,
|
|
287
|
+
tab
|
|
288
|
+
};
|
|
289
|
+
this.tabView.appendChild(tab);
|
|
290
|
+
};
|
|
291
|
+
TabManager.prototype.getTabView = function () {
|
|
292
|
+
return this.tabView;
|
|
293
|
+
};
|
|
294
|
+
TabManager.prototype.change = function (id, tablist, doc) {
|
|
295
|
+
for (const tab in tablist) {
|
|
296
|
+
if (tab === id) {
|
|
297
|
+
tablist[id].tab.className = 'active';
|
|
298
|
+
doc.getElementById(tablist[id].view).className += ' active';
|
|
299
|
+
} else {
|
|
300
|
+
const view = doc.getElementById(tablist[tab].view);
|
|
301
|
+
view.className = view.className.replace(/\w*active\w*/, '');
|
|
302
|
+
tablist[tab].tab.className = tablist[id].tab.className.replace(/\w*active\w*/, '');
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
this.microblogPane = microblogPane;
|
|
307
|
+
const accounts = kb.each(s, FOAF('holdsAccount'));
|
|
308
|
+
let account;
|
|
309
|
+
for (const a in accounts) {
|
|
310
|
+
if (kb.whether(accounts[a], RDF('type'), SIOC('User')) && kb.whether(kb.any(accounts[a], SIOC('creator_of')), RDF('type'), SIOCt('Microblog'))) {
|
|
311
|
+
account = accounts[a];
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
this.Ifollow = kb.whether(kb.sym(mb.getMyURI()), SIOC('follows'), account);
|
|
316
|
+
const resourceType = kb.any(s, RDF('type'));
|
|
317
|
+
if (resourceType.uri === SIOCt('Microblog').uri || resourceType.uri === SIOCt('MicroblogPost').uri) {
|
|
318
|
+
this.thisIsMe = kb.any(s, SIOC('has_creator')).uri === mb.getMyURI();
|
|
319
|
+
} else if (resourceType.uri === SIOC('User').uri) {
|
|
320
|
+
this.thisIsMe = s.uri === mb.getMyURI();
|
|
321
|
+
} else if (resourceType.uri === FOAF('Person').uri) {
|
|
322
|
+
const me = _solidLogic.authn.currentUser();
|
|
323
|
+
const meUri = me && me.uri;
|
|
324
|
+
this.thisIsMe = s.uri === meUri;
|
|
325
|
+
} else {
|
|
326
|
+
this.thisIsMe = false;
|
|
327
|
+
}
|
|
328
|
+
this.Tab = new TabManager(doc);
|
|
329
|
+
};
|
|
330
|
+
Pane.prototype.notify = function (messageString) {
|
|
331
|
+
const xmsg = doc.createElement('li');
|
|
332
|
+
xmsg.className = 'notify';
|
|
333
|
+
xmsg.innerHTML = messageString;
|
|
334
|
+
doc.getElementById('notify-container').appendChild(xmsg);
|
|
335
|
+
setTimeout(function () {
|
|
336
|
+
doc.getElementById('notify-container').removeChild(xmsg);
|
|
337
|
+
// delete xmsg;
|
|
338
|
+
}, 4000);
|
|
339
|
+
};
|
|
340
|
+
Pane.prototype.header = function (s, doc) {
|
|
341
|
+
const that = this;
|
|
342
|
+
function lsFollowUser() {
|
|
343
|
+
const myUser = kb.sym(mb.getMyURI());
|
|
344
|
+
// var Ifollow = that.Ifollow
|
|
345
|
+
const username = that.creator.name;
|
|
346
|
+
const mbconfirmFollow = function (uri, success, _msg) {
|
|
347
|
+
if (success === true) {
|
|
348
|
+
if (!that.Ifollow) {
|
|
349
|
+
// prevent duplicate entries from being added to kb (because that was happening)
|
|
350
|
+
if (!kb.whether(followMe.subject, followMe.predicate, followMe.object, followMe.why)) {
|
|
351
|
+
kb.add(followMe.subject, followMe.predicate, followMe.object, followMe.why);
|
|
352
|
+
}
|
|
353
|
+
} else {
|
|
354
|
+
kb.removeMany(followMe.subject, followMe.predicate, followMe.object, followMe.why);
|
|
355
|
+
}
|
|
356
|
+
console.log(that.Ifollow);
|
|
357
|
+
that.Ifollow = !that.Ifollow;
|
|
358
|
+
xfollowButton.disabled = false;
|
|
359
|
+
console.log(that.Ifollow);
|
|
360
|
+
const followButtonLabel = that.Ifollow ? 'Unfollow ' : 'Follow ';
|
|
361
|
+
const doFollow = that.Ifollow ? 'now follow ' : 'no longer follow ';
|
|
362
|
+
xfollowButton.value = followButtonLabel + username;
|
|
363
|
+
that.notify('You ' + doFollow + username + '.');
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
const followMe = new UI.rdf.Statement(myUser, SIOC('follows'), that.creator.sym, myUser);
|
|
367
|
+
xfollowButton.disabled = true;
|
|
368
|
+
xfollowButton.value = 'Updating...';
|
|
369
|
+
if (!that.Ifollow) {
|
|
370
|
+
sparqlUpdater.insert_statement(followMe, mbconfirmFollow);
|
|
371
|
+
} else {
|
|
372
|
+
sparqlUpdater.delete_statement(followMe, mbconfirmFollow);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const notify = function (messageString) {
|
|
376
|
+
const xmsg = doc.createElement('li');
|
|
377
|
+
xmsg.className = 'notify';
|
|
378
|
+
xmsg.innerHTML = messageString;
|
|
379
|
+
doc.getElementById('notify-container').appendChild(xmsg);
|
|
380
|
+
setTimeout(function () {
|
|
381
|
+
doc.getElementById('notify-container').removeChild(xmsg);
|
|
382
|
+
// delete xmsg;
|
|
383
|
+
}, 4000);
|
|
384
|
+
};
|
|
385
|
+
const mbCancelNewMB = function (_evt) {
|
|
386
|
+
xupdateContainer.removeChild(xupdateContainer.childNodes[xupdateContainer.childNodes.length - 1]);
|
|
387
|
+
xcreateNewMB.disabled = false;
|
|
388
|
+
};
|
|
389
|
+
const lsCreateNewMB = function (_evt) {
|
|
390
|
+
// disable the create new microblog button.
|
|
391
|
+
// then prefills the information.
|
|
392
|
+
xcreateNewMB.disabled = true;
|
|
393
|
+
const xcmb = doc.createElement('div');
|
|
394
|
+
const xcmbName = doc.createElement('input');
|
|
395
|
+
if (kb.whether(s, FOAF('name'))) {
|
|
396
|
+
// handle use of FOAF:NAME
|
|
397
|
+
xcmbName.value = kb.any(s, FOAF('name'));
|
|
398
|
+
} else {
|
|
399
|
+
// handle use of family and given name
|
|
400
|
+
xcmbName.value = kb.any(s, FOAF('givenname')) ? kb.any(s, FOAF('givenname')) + ' ' : '';
|
|
401
|
+
xcmbName.value += kb.any(s, FOAF('family_name')) ? kb.any(s, FOAF('givenname')) : '';
|
|
402
|
+
xcmbName.value = kb.any(s, FOAF('givenname')) + ' ' + kb.any(s, FOAF('family_name'));
|
|
403
|
+
}
|
|
404
|
+
const xcmbId = doc.createElement('input');
|
|
405
|
+
xcmbId.value = kb.any(s, FOAF('nick')) ? kb.any(s, FOAF('nick')) : '';
|
|
406
|
+
const xcmbAvatar = doc.createElement('input');
|
|
407
|
+
if (kb.whether(s, FOAF('img'))) {
|
|
408
|
+
// handle use of img
|
|
409
|
+
xcmbAvatar.value = kb.any(s, FOAF('img')).uri;
|
|
410
|
+
} else {
|
|
411
|
+
// otherwise try depiction
|
|
412
|
+
xcmbAvatar.value = kb.any(s, FOAF('depiction')) ? kb.any(s, FOAF('depiction')).uri : '';
|
|
413
|
+
}
|
|
414
|
+
let workspace;
|
|
415
|
+
// = kb.any(s,WORKSPACE) //TODO - ADD URI FOR WORKSPACE DEFINITION
|
|
416
|
+
const xcmbWritable = doc.createElement('input');
|
|
417
|
+
xcmbWritable.value = workspace || 'http://dig.csail.mit.edu/2007/wiki/sandbox'; // @@@
|
|
418
|
+
xcmb.innerHTML = `
|
|
419
|
+
<form class ="createNewMB" id="createNewMB">
|
|
420
|
+
<p id="xcmbname"><span class="">Name: </span></p>
|
|
421
|
+
<p id="xcmbid">Id: </p>
|
|
422
|
+
<p id="xcmbavatar">Avatar: </p>
|
|
423
|
+
<p id="xcmbwritable">Host my microblog at: </p>
|
|
424
|
+
<input type="button" id="mbCancel" value="Cancel" />
|
|
425
|
+
<input type="submit" id="mbCreate" value="Create!" />
|
|
426
|
+
</form>
|
|
427
|
+
`;
|
|
428
|
+
xupdateContainer.appendChild(xcmb);
|
|
429
|
+
doc.getElementById('xcmbname').appendChild(xcmbName);
|
|
430
|
+
doc.getElementById('xcmbid').appendChild(xcmbId);
|
|
431
|
+
doc.getElementById('xcmbavatar').appendChild(xcmbAvatar);
|
|
432
|
+
doc.getElementById('xcmbwritable').appendChild(xcmbWritable);
|
|
433
|
+
doc.getElementById('mbCancel').addEventListener('click', mbCancelNewMB, false);
|
|
434
|
+
doc.getElementById('createNewMB').addEventListener('submit', function () {
|
|
435
|
+
mb.generateNewMB(xcmbId.value, xcmbName.value, xcmbAvatar.value, xcmbWritable.value);
|
|
436
|
+
}, false);
|
|
437
|
+
xcmbName.focus();
|
|
438
|
+
};
|
|
439
|
+
const mbSubmitPost = function () {
|
|
440
|
+
const meta = {
|
|
441
|
+
recipients: []
|
|
442
|
+
};
|
|
443
|
+
// user has selected a microblog to post to
|
|
444
|
+
if (mb.getMyURI()) {
|
|
445
|
+
// let myUser = kb.sym(mb.getMyURI())
|
|
446
|
+
// submission callback
|
|
447
|
+
const cbconfirmSubmit = function (uri, success, responseText, d) {
|
|
448
|
+
if (success === true) {
|
|
449
|
+
for (const triple in d) {
|
|
450
|
+
kb.add(d[triple].subject, d[triple].predicate, d[triple].object, d[triple].why);
|
|
451
|
+
}
|
|
452
|
+
xupdateSubmit.disabled = false;
|
|
453
|
+
xupdateStatus.value = '';
|
|
454
|
+
mbLetterCount();
|
|
455
|
+
notify('Microblog Updated.');
|
|
456
|
+
if (that.thisIsMe) {
|
|
457
|
+
doc.getElementById('postNotificationList').insertBefore(that.generatePost(d[0].subject), doc.getElementById('postNotificationList').childNodes[0]);
|
|
458
|
+
}
|
|
459
|
+
} else {
|
|
460
|
+
notify('There was a problem submitting your post.');
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
const words = xupdateStatus.value.split(' ');
|
|
464
|
+
const mbUpdateWithReplies = function () {
|
|
465
|
+
xupdateSubmit.disabled = true;
|
|
466
|
+
xupdateSubmit.value = 'Updating...';
|
|
467
|
+
mb.statusUpdate(xupdateStatus.value, cbconfirmSubmit, xinReplyToContainer.value, meta);
|
|
468
|
+
};
|
|
469
|
+
for (const word in words) {
|
|
470
|
+
if (words[word].match(/@\w+/)) {
|
|
471
|
+
const atUser = words[word].replace(/\W/g, '');
|
|
472
|
+
const recipient = myFollowList.selectUser(atUser);
|
|
473
|
+
if (recipient[0] === true) {
|
|
474
|
+
meta.recipients.push(recipient[1][0]);
|
|
475
|
+
} else if (recipient[1].length > 1) {
|
|
476
|
+
// if multiple users allow the user to choose
|
|
477
|
+
const xrecipients = doc.createElement('select');
|
|
478
|
+
const xrecipientsSubmit = doc.createElement('input');
|
|
479
|
+
xrecipientsSubmit.type = 'button';
|
|
480
|
+
xrecipientsSubmit.value = 'Continue';
|
|
481
|
+
xrecipientsSubmit.addEventListener('click', function () {
|
|
482
|
+
meta.recipients.push(recipient[1][xrecipients.value]);
|
|
483
|
+
mbUpdateWithReplies();
|
|
484
|
+
xrecipients.parentNode.removeChild(xrecipientsSubmit);
|
|
485
|
+
xrecipients.parentNode.removeChild(xrecipients);
|
|
486
|
+
}, false);
|
|
487
|
+
const recipChoice = function (recip, c) {
|
|
488
|
+
const name = kb.any(kb.sym(recip), SIOC('name'));
|
|
489
|
+
const choice = doc.createElement('option');
|
|
490
|
+
choice.value = c;
|
|
491
|
+
choice.innerHTML = name;
|
|
492
|
+
return choice;
|
|
493
|
+
};
|
|
494
|
+
for (const r in recipient[1]) {
|
|
495
|
+
xrecipients.appendChild(recipChoice(recipient[1][r], r));
|
|
496
|
+
}
|
|
497
|
+
xupdateContainer.appendChild(xrecipients);
|
|
498
|
+
xupdateContainer.appendChild(xrecipientsSubmit);
|
|
499
|
+
return;
|
|
500
|
+
} else {
|
|
501
|
+
// no users known or self reference.
|
|
502
|
+
if (String(kb.any(kb.sym(mb.getMyURI()), SIOC('id'))).toLowerCase() === atUser.toLowerCase()) {
|
|
503
|
+
meta.recipients.push(mb.getMyURI());
|
|
504
|
+
} else {
|
|
505
|
+
notify('You do not follow ' + atUser + '. Try following ' + atUser + ' before mentioning them.');
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
/* else if(words[word].match(/\#\w+/)){
|
|
511
|
+
//hashtag
|
|
512
|
+
} else if(words[word].match(/\!\w+/)){
|
|
513
|
+
//usergroup
|
|
514
|
+
} */
|
|
515
|
+
}
|
|
516
|
+
mbUpdateWithReplies();
|
|
517
|
+
} else {
|
|
518
|
+
notify('Please set your microblog first.');
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
const mbLetterCount = function () {
|
|
522
|
+
xupdateStatusCounter.innerHTML = charCount - xupdateStatus.value.length;
|
|
523
|
+
xupdateStatusCounter.style.color = charCount - xupdateStatus.value.length < 0 ? '#c33' : '';
|
|
524
|
+
if (xupdateStatus.value.length === 0) {
|
|
525
|
+
xinReplyToContainer.value = '';
|
|
526
|
+
xupdateSubmit.value = 'Send';
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
// reply viewer
|
|
530
|
+
const xviewReply = doc.createElement('ul');
|
|
531
|
+
xviewReply.className = 'replyView';
|
|
532
|
+
xviewReply.addEventListener('click', function () {
|
|
533
|
+
xviewReply.className = 'replyView';
|
|
534
|
+
}, false);
|
|
535
|
+
this.xviewReply = xviewReply;
|
|
536
|
+
const headerContainer = doc.createElement('div');
|
|
537
|
+
headerContainer.className = 'header-container';
|
|
538
|
+
|
|
539
|
+
// ---create status update box---
|
|
540
|
+
const xnotify = doc.createElement('ul');
|
|
541
|
+
xnotify.id = 'notify-container';
|
|
542
|
+
xnotify.className = 'notify-container';
|
|
543
|
+
this.xnotify = xnotify;
|
|
544
|
+
const xupdateContainer = doc.createElement('form');
|
|
545
|
+
xupdateContainer.className = 'update-container';
|
|
546
|
+
xupdateContainer.innerHTML = '<h3>What are you up to?</h3>';
|
|
547
|
+
let xinReplyToContainer;
|
|
548
|
+
let xupdateStatus;
|
|
549
|
+
let xupdateStatusCounter;
|
|
550
|
+
let xupdateSubmit;
|
|
551
|
+
let xcreateNewMB;
|
|
552
|
+
if (mb.getMyURI()) {
|
|
553
|
+
xinReplyToContainer = doc.createElement('input');
|
|
554
|
+
xinReplyToContainer.id = 'xinReplyToContainer';
|
|
555
|
+
xinReplyToContainer.type = 'hidden';
|
|
556
|
+
xupdateStatus = doc.createElement('textarea');
|
|
557
|
+
xupdateStatus.id = 'xupdateStatus';
|
|
558
|
+
xupdateStatusCounter = doc.createElement('span');
|
|
559
|
+
xupdateStatusCounter.appendChild(doc.createTextNode(charCount));
|
|
560
|
+
xupdateStatus.cols = 30;
|
|
561
|
+
xupdateStatus.addEventListener('keyup', mbLetterCount, false);
|
|
562
|
+
xupdateStatus.addEventListener('focus', mbLetterCount, false);
|
|
563
|
+
xupdateSubmit = doc.createElement('input');
|
|
564
|
+
xupdateSubmit.id = 'xupdateSubmit';
|
|
565
|
+
xupdateSubmit.type = 'submit';
|
|
566
|
+
xupdateSubmit.value = 'Send';
|
|
567
|
+
xupdateContainer.appendChild(xinReplyToContainer);
|
|
568
|
+
xupdateContainer.appendChild(xupdateStatusCounter);
|
|
569
|
+
xupdateContainer.appendChild(xupdateStatus);
|
|
570
|
+
xupdateContainer.appendChild(xupdateSubmit);
|
|
571
|
+
xupdateContainer.addEventListener('submit', mbSubmitPost, false);
|
|
572
|
+
} else {
|
|
573
|
+
const xnewUser = doc.createTextNode('Hi, it looks like you don\'t have a microblog, ' + ' would you like to create one? ');
|
|
574
|
+
xcreateNewMB = doc.createElement('input');
|
|
575
|
+
xcreateNewMB.type = 'button';
|
|
576
|
+
xcreateNewMB.value = 'Create a new Microblog';
|
|
577
|
+
xcreateNewMB.addEventListener('click', lsCreateNewMB, false);
|
|
578
|
+
xupdateContainer.appendChild(xnewUser);
|
|
579
|
+
xupdateContainer.appendChild(xcreateNewMB);
|
|
580
|
+
}
|
|
581
|
+
headerContainer.appendChild(xupdateContainer);
|
|
582
|
+
const subheaderContainer = doc.createElement('div');
|
|
583
|
+
subheaderContainer.className = 'subheader-container';
|
|
584
|
+
|
|
585
|
+
// user header
|
|
586
|
+
// this.creator
|
|
587
|
+
const creators = kb.each(s, FOAF('holdsAccount'));
|
|
588
|
+
let creator;
|
|
589
|
+
for (const c in creators) {
|
|
590
|
+
if (kb.whether(creators[c], RDF('type'), SIOC('User')) && kb.whether(kb.any(creators[c], SIOC('creator_of')), RDF('type'), SIOCt('Microblog'))) {
|
|
591
|
+
creator = creators[c];
|
|
592
|
+
// var mb = kb.sym(creator.uri.split("#")[0]);
|
|
593
|
+
// store.fetcher.refresh(mb);
|
|
594
|
+
break;
|
|
595
|
+
// TODO add support for more than one microblog in same foaf
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
let xfollowButton;
|
|
599
|
+
if (creator) {
|
|
600
|
+
this.creator = mb.getUser(creator);
|
|
601
|
+
// ---display avatar, if available ---
|
|
602
|
+
if (this.creator.avatar !== '') {
|
|
603
|
+
const avatar = doc.createElement('img');
|
|
604
|
+
avatar.src = this.creator.avatar.uri;
|
|
605
|
+
subheaderContainer.appendChild(avatar);
|
|
606
|
+
}
|
|
607
|
+
// ---generate name ---
|
|
608
|
+
const userName = doc.createElement('h1');
|
|
609
|
+
userName.className = 'fn';
|
|
610
|
+
userName.appendChild(doc.createTextNode(this.creator.name + ' (' + this.creator.id + ')'));
|
|
611
|
+
subheaderContainer.appendChild(userName);
|
|
612
|
+
// ---display follow button---
|
|
613
|
+
if (!this.thisIsMe && mb.getMyURI()) {
|
|
614
|
+
xfollowButton = doc.createElement('input');
|
|
615
|
+
xfollowButton.setAttribute('type', 'button');
|
|
616
|
+
const followButtonLabel = this.Ifollow ? 'Unfollow ' : 'Follow ';
|
|
617
|
+
xfollowButton.value = followButtonLabel + this.creator.name;
|
|
618
|
+
xfollowButton.addEventListener('click', lsFollowUser, false);
|
|
619
|
+
subheaderContainer.appendChild(xfollowButton);
|
|
620
|
+
}
|
|
621
|
+
// user header end
|
|
622
|
+
// header tabs
|
|
623
|
+
const xtabsList = this.Tab.getTabView();
|
|
624
|
+
headerContainer.appendChild(subheaderContainer);
|
|
625
|
+
headerContainer.appendChild(xtabsList);
|
|
626
|
+
}
|
|
627
|
+
return headerContainer;
|
|
628
|
+
};
|
|
629
|
+
Pane.prototype.generatePost = function (post, _me) {
|
|
630
|
+
/*
|
|
631
|
+
generatePost - Creates and formats microblog posts
|
|
632
|
+
post - symbol of the uri the post in question
|
|
633
|
+
*/
|
|
634
|
+
const that = this;
|
|
635
|
+
const viewPost = function (uris) {
|
|
636
|
+
const xviewReply = that.xviewReply;
|
|
637
|
+
for (let i = 0; i < xviewReply.childNodes.length; i++) {
|
|
638
|
+
xviewReply.removeChild(xviewReply.childNodes[0]);
|
|
639
|
+
}
|
|
640
|
+
const xcloseContainer = doc.createElement('li');
|
|
641
|
+
xcloseContainer.className = 'closeContainer';
|
|
642
|
+
const xcloseButton = doc.createElement('span');
|
|
643
|
+
xcloseButton.innerHTML = '×';
|
|
644
|
+
xcloseButton.className = 'closeButton';
|
|
645
|
+
xcloseContainer.appendChild(xcloseButton);
|
|
646
|
+
xviewReply.appendChild(xcloseContainer);
|
|
647
|
+
for (const uri in uris) {
|
|
648
|
+
xviewReply.appendChild(that.generatePost(kb.sym(uris[uri]), this.thisIsMe, 'view'));
|
|
649
|
+
}
|
|
650
|
+
xviewReply.className = 'replyView-active';
|
|
651
|
+
that.microblogPane.appendChild(xviewReply);
|
|
652
|
+
};
|
|
653
|
+
// container for post
|
|
654
|
+
const xpost = doc.createElement('li');
|
|
655
|
+
xpost.className = 'post';
|
|
656
|
+
xpost.setAttribute('id', String(post.uri).split('#')[1]);
|
|
657
|
+
const Post = mb.getPost(post);
|
|
658
|
+
// username text
|
|
659
|
+
// var uname = kb.any(kb.any(post, SIOC('has_creator')), SIOC('id'))
|
|
660
|
+
const uholdsaccount = kb.any(undefined, FOAF('holdsAccount'), kb.any(post, SIOC('has_creator')));
|
|
661
|
+
const xuname = doc.createElement('a');
|
|
662
|
+
xuname.href = uholdsaccount.uri;
|
|
663
|
+
xuname.className = 'userLink';
|
|
664
|
+
const xunameText = doc.createTextNode(mb.getUser(Post.creator).id);
|
|
665
|
+
xuname.appendChild(xunameText);
|
|
666
|
+
// user image
|
|
667
|
+
const xuavatar = doc.createElement('img');
|
|
668
|
+
xuavatar.src = mb.getUser(Post.creator).avatar.uri;
|
|
669
|
+
xuavatar.className = 'postAvatar';
|
|
670
|
+
// post content
|
|
671
|
+
const xpostContent = doc.createElement('blockquote');
|
|
672
|
+
let postText = Post.message;
|
|
673
|
+
// post date
|
|
674
|
+
const xpostLink = doc.createElement('a');
|
|
675
|
+
xpostLink.className = 'postLink';
|
|
676
|
+
xpostLink.addEventListener('click', function () {
|
|
677
|
+
viewPost([post.uri]);
|
|
678
|
+
}, false);
|
|
679
|
+
xpostLink.id = 'post_' + String(post.uri).split('#')[1];
|
|
680
|
+
xpostLink.setAttribute('content', post.uri);
|
|
681
|
+
xpostLink.setAttribute('property', 'permalink');
|
|
682
|
+
const postLink = doc.createTextNode(Post.date ? Post.date : 'post date unknown');
|
|
683
|
+
xpostLink.appendChild(postLink);
|
|
684
|
+
|
|
685
|
+
// LINK META DATA (MENTIONS, HASHTAGS, GROUPS)
|
|
686
|
+
const mentions = kb.each(post, SIOC('topic'));
|
|
687
|
+
const tags = {};
|
|
688
|
+
for (const mention in mentions) {
|
|
689
|
+
sf.lookUpThing(mentions[mention]);
|
|
690
|
+
const id = kb.any(mentions[mention], SIOC('id'));
|
|
691
|
+
tags['@' + id] = mentions[mention];
|
|
692
|
+
}
|
|
693
|
+
const postTags = postText.match(/(@|#|!)\w+/g);
|
|
694
|
+
const postFunction = function () {
|
|
695
|
+
const p = postTags.pop();
|
|
696
|
+
return tags[p] ? kb.any(undefined, FOAF('holdsAccount'), tags[p]).uri : p;
|
|
697
|
+
};
|
|
698
|
+
for (const t in tags) {
|
|
699
|
+
const person = t.replace(/@/, '');
|
|
700
|
+
const replacePerson = RegExp('(@|!|#)(' + person + ')');
|
|
701
|
+
postText = postText.replace(replacePerson, '$1<a href="' + postFunction() + '">$2</a>');
|
|
702
|
+
}
|
|
703
|
+
xpostContent.innerHTML = postText;
|
|
704
|
+
|
|
705
|
+
// in reply to logic
|
|
706
|
+
// This has the potential to support a post that replies to many messages.
|
|
707
|
+
const inReplyTo = kb.each(post, SIOC('reply_of'));
|
|
708
|
+
const xreplyTo = doc.createElement('span');
|
|
709
|
+
let theReply;
|
|
710
|
+
for (const reply in inReplyTo) {
|
|
711
|
+
theReply = String(inReplyTo[reply]).replace(/<|>/g, '');
|
|
712
|
+
const genReplyTo = function () {
|
|
713
|
+
const reply = doc.createElement('a');
|
|
714
|
+
reply.innerHTML = ', <b>in reply to</b>';
|
|
715
|
+
reply.addEventListener('click', function () {
|
|
716
|
+
viewPost([post.uri, theReply]);
|
|
717
|
+
return false;
|
|
718
|
+
}, false);
|
|
719
|
+
return reply;
|
|
720
|
+
};
|
|
721
|
+
xreplyTo.appendChild(genReplyTo());
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// END LINK META DATA
|
|
725
|
+
// add the reply to and delete buttons to the interface
|
|
726
|
+
const mbReplyTo = function () {
|
|
727
|
+
const id = mb.getUser(Post.creator).id;
|
|
728
|
+
const xupdateStatus = doc.getElementById('xupdateStatus');
|
|
729
|
+
const xinReplyToContainer = doc.getElementById('xinReplyToContainer');
|
|
730
|
+
const xupdateSubmit = doc.getElementById('xupdateSubmit');
|
|
731
|
+
xupdateStatus.value = '@' + id + ' ';
|
|
732
|
+
xupdateStatus.focus();
|
|
733
|
+
xinReplyToContainer.value = post.uri;
|
|
734
|
+
xupdateSubmit.value = 'Reply';
|
|
735
|
+
};
|
|
736
|
+
let xconfirmDeletionDialog;
|
|
737
|
+
const mbDeletePost = function (evt) {
|
|
738
|
+
const lsconfirmNo = function () {
|
|
739
|
+
doc.getElementById('notify-container').removeChild(xconfirmDeletionDialog);
|
|
740
|
+
evt.target.disabled = false;
|
|
741
|
+
};
|
|
742
|
+
const lsconfirmYes = function () {
|
|
743
|
+
reallyDelete();
|
|
744
|
+
doc.getElementById('notify-container').removeChild(xconfirmDeletionDialog);
|
|
745
|
+
};
|
|
746
|
+
evt.target.disabled = true;
|
|
747
|
+
xconfirmDeletionDialog = doc.createElement('li');
|
|
748
|
+
xconfirmDeletionDialog.className = 'notify conf';
|
|
749
|
+
xconfirmDeletionDialog.innerHTML += '<p>Are you sure you want to delete this post?</p>';
|
|
750
|
+
xconfirmDeletionDialog.addEventListener('keyup', function (evt) {
|
|
751
|
+
if (evt.keyCode === 27) {
|
|
752
|
+
lsconfirmNo();
|
|
753
|
+
}
|
|
754
|
+
}, false);
|
|
755
|
+
const confirmyes = doc.createElement('input');
|
|
756
|
+
confirmyes.type = 'button';
|
|
757
|
+
confirmyes.className = 'confirm';
|
|
758
|
+
confirmyes.value = 'Delete';
|
|
759
|
+
confirmyes.addEventListener('click', lsconfirmYes, false);
|
|
760
|
+
const confirmno = doc.createElement('input');
|
|
761
|
+
confirmno.type = 'button';
|
|
762
|
+
confirmno.className = 'confirm';
|
|
763
|
+
confirmno.value = 'Cancel';
|
|
764
|
+
confirmno.addEventListener('click', lsconfirmNo, false);
|
|
765
|
+
xconfirmDeletionDialog.appendChild(confirmno);
|
|
766
|
+
xconfirmDeletionDialog.appendChild(confirmyes);
|
|
767
|
+
doc.getElementById('notify-container').appendChild(xconfirmDeletionDialog);
|
|
768
|
+
confirmno.focus();
|
|
769
|
+
const reallyDelete = function () {
|
|
770
|
+
// callback after deletion
|
|
771
|
+
const mbconfirmDeletePost = function (a, success) {
|
|
772
|
+
if (success) {
|
|
773
|
+
that.notify('Post deleted.');
|
|
774
|
+
// update the ui to reflect model changes.
|
|
775
|
+
const deleteThisNode = evt.target.parentNode;
|
|
776
|
+
deleteThisNode.parentNode.removeChild(deleteThisNode);
|
|
777
|
+
kb.removeMany(deleteMe);
|
|
778
|
+
} else {
|
|
779
|
+
that.notify('Oops, there was a problem, please try again');
|
|
780
|
+
evt.target.disabled = true;
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
// delete references to post
|
|
784
|
+
const deleteContainerOf = function (a, success) {
|
|
785
|
+
if (success) {
|
|
786
|
+
const deleteContainer = kb.statementsMatching(undefined, SIOC('container_of'), kb.sym(doc.getElementById('post_' + evt.target.parentNode.id).getAttribute('content')));
|
|
787
|
+
sparqlUpdater.batch_delete_statement(deleteContainer, mbconfirmDeletePost);
|
|
788
|
+
} else {
|
|
789
|
+
that.notify('Oops, there was a problem, please try again');
|
|
790
|
+
evt.target.disabled = false;
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
// delete attributes of post
|
|
794
|
+
evt.target.disabled = true;
|
|
795
|
+
const deleteMe = kb.statementsMatching(kb.sym(doc.getElementById('post_' + evt.target.parentNode.id).getAttribute('content')));
|
|
796
|
+
sparqlUpdater.batch_delete_statement(deleteMe, deleteContainerOf);
|
|
797
|
+
};
|
|
798
|
+
};
|
|
799
|
+
let themaker;
|
|
800
|
+
let xreplyButton;
|
|
801
|
+
let xdeleteButton;
|
|
802
|
+
if (mb.getMyURI()) {
|
|
803
|
+
// If the microblog in question does not belong to the user,
|
|
804
|
+
// display the delete post and reply to post buttons.
|
|
805
|
+
themaker = kb.any(post, SIOC('has_creator'));
|
|
806
|
+
if (mb.getMyURI() !== themaker.uri) {
|
|
807
|
+
xreplyButton = doc.createElement('input');
|
|
808
|
+
xreplyButton.type = 'button';
|
|
809
|
+
xreplyButton.value = 'reply';
|
|
810
|
+
xreplyButton.className = 'reply';
|
|
811
|
+
xreplyButton.addEventListener('click', mbReplyTo, false);
|
|
812
|
+
} else {
|
|
813
|
+
xdeleteButton = doc.createElement('input');
|
|
814
|
+
xdeleteButton.type = 'button';
|
|
815
|
+
xdeleteButton.value = 'Delete';
|
|
816
|
+
xdeleteButton.className = 'reply';
|
|
817
|
+
xdeleteButton.addEventListener('click', mbDeletePost, false);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
const mbFavorite = function (evt) {
|
|
821
|
+
const nid = evt.target.parentNode.id;
|
|
822
|
+
const favpost = doc.getElementById('post_' + nid).getAttribute('content');
|
|
823
|
+
xfavorite.className += ' ing';
|
|
824
|
+
const cbFavorite = function (a, success, _c, _d) {
|
|
825
|
+
if (success) {
|
|
826
|
+
xfavorite.className = xfavorite.className.split(' ')[1] === 'ed' ? 'favorit' : 'favorit ed';
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
if (!myFavorites.favorited(favpost)) {
|
|
830
|
+
myFavorites.add(favpost, cbFavorite);
|
|
831
|
+
} else {
|
|
832
|
+
myFavorites.remove(favpost, cbFavorite);
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
const xfavorite = doc.createElement('a');
|
|
836
|
+
xfavorite.innerHTML = '★';
|
|
837
|
+
xfavorite.addEventListener('click', mbFavorite, false);
|
|
838
|
+
if (myFavorites.favorited(post.uri)) {
|
|
839
|
+
xfavorite.className = 'favorit ed';
|
|
840
|
+
} else {
|
|
841
|
+
xfavorite.className = 'favorit';
|
|
842
|
+
}
|
|
843
|
+
// build
|
|
844
|
+
xpost.appendChild(xuavatar);
|
|
845
|
+
xpost.appendChild(xpostContent);
|
|
846
|
+
if (mb.getMyURI()) {
|
|
847
|
+
xpost.appendChild(xfavorite);
|
|
848
|
+
if (mb.getMyURI() !== themaker.uri) {
|
|
849
|
+
xpost.appendChild(xreplyButton);
|
|
850
|
+
} else {
|
|
851
|
+
xpost.appendChild(xdeleteButton);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
xpost.appendChild(xuname);
|
|
855
|
+
xpost.appendChild(xpostLink);
|
|
856
|
+
if (inReplyTo !== '') {
|
|
857
|
+
xpost.appendChild(xreplyTo);
|
|
858
|
+
}
|
|
859
|
+
return xpost;
|
|
860
|
+
};
|
|
861
|
+
Pane.prototype.generatePostList = function (gmbPosts) {
|
|
862
|
+
/*
|
|
863
|
+
generatePostList - Generate the posts and
|
|
864
|
+
display their results on the interface.
|
|
865
|
+
*/
|
|
866
|
+
const postList = doc.createElement('ul');
|
|
867
|
+
const postlist = {};
|
|
868
|
+
const datelist = [];
|
|
869
|
+
for (const post in gmbPosts) {
|
|
870
|
+
const postDate = kb.any(gmbPosts[post], terms('created'));
|
|
871
|
+
if (postDate) {
|
|
872
|
+
datelist.push(postDate);
|
|
873
|
+
postlist[postDate] = this.generatePost(gmbPosts[post], this.thisIsMe);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
datelist.sort().reverse();
|
|
877
|
+
for (const d in datelist) {
|
|
878
|
+
postList.appendChild(postlist[datelist[d]]);
|
|
879
|
+
}
|
|
880
|
+
return postList;
|
|
881
|
+
};
|
|
882
|
+
Pane.prototype.followsView = function () {
|
|
883
|
+
const getFollowed = function (user) {
|
|
884
|
+
let userid = kb.any(user, SIOC('id'));
|
|
885
|
+
const follow = doc.createElement('li');
|
|
886
|
+
follow.className = 'follow';
|
|
887
|
+
userid = userid || user.uri;
|
|
888
|
+
let fol = kb.any(undefined, FOAF('holdsAccount'), user);
|
|
889
|
+
fol = fol ? fol.uri : user.uri;
|
|
890
|
+
follow.innerHTML = '<a href="' + fol + '">' + userid + '</a>';
|
|
891
|
+
return follow;
|
|
892
|
+
};
|
|
893
|
+
const xfollows = doc.createElement('div');
|
|
894
|
+
xfollows.id = 'xfollows';
|
|
895
|
+
xfollows.className = 'followlist-container view-container';
|
|
896
|
+
if (this.creator && kb.whether(this.creator.sym, SIOC('follows'))) {
|
|
897
|
+
const creatorFollows = kb.each(this.creator.sym, SIOC('follows'));
|
|
898
|
+
const xfollowsList = doc.createElement('ul');
|
|
899
|
+
for (const thisPerson in creatorFollows) {
|
|
900
|
+
xfollowsList.appendChild(getFollowed(creatorFollows[thisPerson]));
|
|
901
|
+
}
|
|
902
|
+
xfollows.appendChild(xfollowsList);
|
|
903
|
+
}
|
|
904
|
+
this.Tab.create('tab-follows', 'Follows', xfollows, false);
|
|
905
|
+
return xfollows;
|
|
906
|
+
};
|
|
907
|
+
Pane.prototype.streamView = function (s, doc) {
|
|
908
|
+
const postContainer = doc.createElement('div');
|
|
909
|
+
postContainer.id = 'postContainer';
|
|
910
|
+
postContainer.className = 'post-container view-container active';
|
|
911
|
+
let mbPosts = [];
|
|
912
|
+
if (kb.whether(s, FOAF('name')) && kb.whether(s, FOAF('holdsAccount'))) {
|
|
913
|
+
sf.lookUpThing(kb.any(s, FOAF('holdsAccount')));
|
|
914
|
+
const follows = kb.each(kb.any(s, FOAF('holdsAccount')), SIOC('follows'));
|
|
915
|
+
for (const f in follows) {
|
|
916
|
+
sf.lookUpThing(follows[f]);
|
|
917
|
+
// look up people user follows
|
|
918
|
+
const smicroblogs = kb.each(follows[f], SIOC('creator_of'));
|
|
919
|
+
// get the follows microblogs
|
|
920
|
+
for (const smb in smicroblogs) {
|
|
921
|
+
sf.lookUpThing(smicroblogs[smb]);
|
|
922
|
+
if (kb.whether(smicroblogs[smb], SIOC('topic'), follows[f])) {
|
|
923
|
+
continue;
|
|
924
|
+
} else {
|
|
925
|
+
mbPosts = mbPosts.concat(kb.each(smicroblogs[smb], SIOC('container_of')));
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
if (mbPosts.length > 0) {
|
|
931
|
+
const postList = this.generatePostList(mbPosts);
|
|
932
|
+
// generate stream
|
|
933
|
+
postList.id = 'postList';
|
|
934
|
+
postList.className = 'postList';
|
|
935
|
+
postContainer.appendChild(postList);
|
|
936
|
+
}
|
|
937
|
+
this.Tab.create('tab-stream', 'By Follows', postContainer, true);
|
|
938
|
+
return postContainer;
|
|
939
|
+
};
|
|
940
|
+
Pane.prototype.notificationsView = function (s, doc) {
|
|
941
|
+
const postNotificationContainer = doc.createElement('div');
|
|
942
|
+
postNotificationContainer.id = 'postNotificationContainer';
|
|
943
|
+
postNotificationContainer.className = 'notification-container view-container';
|
|
944
|
+
const postMentionContainer = doc.createElement('div');
|
|
945
|
+
postMentionContainer.id = 'postMentionContainer';
|
|
946
|
+
postMentionContainer.className = 'mention-container view-container';
|
|
947
|
+
let mbnPosts = [];
|
|
948
|
+
let mbmPosts = [];
|
|
949
|
+
// get mbs that I am the creator of.
|
|
950
|
+
const theUser = kb.any(s, FOAF('holdsAccount'));
|
|
951
|
+
const user = kb.any(theUser, SIOC('id'));
|
|
952
|
+
const microblogs = kb.each(theUser, SIOC('creator_of'));
|
|
953
|
+
for (const mbm in microblogs) {
|
|
954
|
+
sf.lookUpThing(microblogs[mbm]);
|
|
955
|
+
if (kb.whether(microblogs[mbm], SIOC('topic'), theUser)) {
|
|
956
|
+
mbmPosts = mbmPosts.concat(kb.each(microblogs[mbm], SIOC('container_of')));
|
|
957
|
+
} else {
|
|
958
|
+
if (kb.whether(microblogs[mbm], RDF('type'), SIOCt('Microblog'))) {
|
|
959
|
+
mbnPosts = mbnPosts.concat(kb.each(microblogs[mbm], SIOC('container_of')));
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
const postNotificationList = this.generatePostList(mbnPosts);
|
|
964
|
+
postNotificationList.id = 'postNotificationList';
|
|
965
|
+
postNotificationList.className = 'postList';
|
|
966
|
+
postNotificationContainer.appendChild(postNotificationList);
|
|
967
|
+
const postMentionList = this.generatePostList(mbmPosts);
|
|
968
|
+
postMentionList.id = 'postMentionList';
|
|
969
|
+
postMentionList.className = 'postList';
|
|
970
|
+
postMentionContainer.appendChild(postMentionList);
|
|
971
|
+
this.postMentionContainer = postMentionContainer;
|
|
972
|
+
this.postNotificationContainer = postNotificationContainer;
|
|
973
|
+
this.Tab.create('tab-by-user', 'By ' + user, postNotificationContainer, false);
|
|
974
|
+
this.Tab.create('tab-at-user', '@' + user, postMentionContainer, false);
|
|
975
|
+
};
|
|
976
|
+
Pane.prototype.build = function () {
|
|
977
|
+
const microblogPane = this.microblogPane;
|
|
978
|
+
this.headerContainer = this.header(s, doc);
|
|
979
|
+
this.postContainer = this.streamView(s, doc);
|
|
980
|
+
this.notificationsView(s, doc);
|
|
981
|
+
this.xfollows = this.followsView();
|
|
982
|
+
microblogPane.className = 'ppane';
|
|
983
|
+
microblogPane.appendChild(this.xviewReply);
|
|
984
|
+
microblogPane.appendChild(this.xnotify);
|
|
985
|
+
microblogPane.appendChild(this.headerContainer);
|
|
986
|
+
if (this.xfollows !== undefined) {
|
|
987
|
+
microblogPane.appendChild(this.xfollows);
|
|
988
|
+
}
|
|
989
|
+
microblogPane.appendChild(this.postContainer);
|
|
990
|
+
microblogPane.appendChild(this.postNotificationContainer);
|
|
991
|
+
microblogPane.appendChild(this.postMentionContainer);
|
|
992
|
+
};
|
|
993
|
+
const microblogpane = doc.createElement('div');
|
|
994
|
+
// var getusersfollows = function(uri){
|
|
995
|
+
// var follows = new Object();
|
|
996
|
+
// var followsa = {follows:0, matches:0};
|
|
997
|
+
// var accounts = kb.each(s, FOAF("holdsAccount"));
|
|
998
|
+
// //get all of the accounts that a person holds
|
|
999
|
+
// for (var acct in accounts){
|
|
1000
|
+
// var account = accounts[acct].uri;
|
|
1001
|
+
// var act = kb.each(kb.sym(account),SIOC("follows"));
|
|
1002
|
+
// for (var a in act){
|
|
1003
|
+
// var thisuri = act[a].uri.split("#")[0];
|
|
1004
|
+
// if (!follows[thisuri]){followsa.follows+=1;}
|
|
1005
|
+
// follows[thisuri] =true;
|
|
1006
|
+
// }
|
|
1007
|
+
// }
|
|
1008
|
+
//
|
|
1009
|
+
// var buildPaneUI = function(uri){
|
|
1010
|
+
// followsa.matches = (follows[uri]) ? followsa.matches+1: followsa.matches;
|
|
1011
|
+
// console.log(follows.toSource());
|
|
1012
|
+
// if(followsa.follows == followsa.matches ){
|
|
1013
|
+
const ppane = new Pane(s, doc, microblogpane);
|
|
1014
|
+
ppane.build();
|
|
1015
|
+
// return false;
|
|
1016
|
+
// }
|
|
1017
|
+
// else{
|
|
1018
|
+
// return true;
|
|
1019
|
+
// }
|
|
1020
|
+
// }
|
|
1021
|
+
// sf.addCallback('done',buildPaneUI);
|
|
1022
|
+
// sf.addCallback('fail',buildPaneUI);
|
|
1023
|
+
// //fetch each of the followers
|
|
1024
|
+
// for (var f in follows){
|
|
1025
|
+
// sf.refresh(kb.sym(f));
|
|
1026
|
+
// }
|
|
1027
|
+
// }(s);
|
|
1028
|
+
return microblogpane;
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
//# sourceMappingURL=microblogPane.js.map
|