aboutsummaryrefslogtreecommitdiff
path: root/views.js
diff options
context:
space:
mode:
authorJoop Kiefte <ikojba@gmail.com>2020-02-01 03:01:40 +0100
committerJoop Kiefte <ikojba@gmail.com>2020-02-01 03:01:40 +0100
commitd5aa1cc524d34f112298f0d4cac0d6ccfb8817b1 (patch)
tree401bf3520bdbb2fcc69259bc57717434586739c5 /views.js
parent908e4d9c762957876b8babee2b58c7ffd8c53a1e (diff)
parentd9325369c27eb5d96522d045004f32f1b01049f8 (diff)
Merge new contents and translate as much as possible TODO: translate settings.js
Diffstat (limited to 'views.js')
-rw-r--r--views.js346
1 files changed, 203 insertions, 143 deletions
diff --git a/views.js b/views.js
index 36bff70..e6ea28e 100644
--- a/views.js
+++ b/views.js
@@ -4,67 +4,163 @@ function threadPage (src, keys) {
})
}
+function getLoc (src) {
+ var loc = h('span')
+ bog().then(log => {
+ if (log) {
+ for (var i = 0; i < log.length; i++) {
+ if (((log[i].located === src) && (log[i].author === src)) || ((log[i].located === src.key) && (log[i].author === src.author))) {
+ // if you've identified someone as something else show that something else
+ return loc.textContent = log[i].loc
+ }
+ }
+ }
+ })
+ return loc
+}
+
function profilePage (src, keys) {
- var profile = h('div', {classList: 'profile'})
+ var timer = setInterval(function () {
+ if (window.location.hash.substring(1) != src) {
+ clearInterval(timer)
+ //console.log('stop syncing')
+ }
+ sync([src], keys)
+ //console.log('syncing ' + src)
+ }, 5000)
+
+ /*timer = function() {
+ if (src === window.location.hash.substring(1)) {
+ //if (interval < 10000) { interval = interval + 50 }
+ sync([src], keys)
+ setTimeout(timer, interval)
+ }
+ }
+
+ timer()*/
- scroller.appendChild(profile)
+ var msg = {}
+ msg.author = src
- if (src != keys.publicKey) {
- reply = { author: src }
- scroller.appendChild(composer(keys, reply))
- } else {
- scroller.appendChild(composer(keys))
+ var profileDiv = h('div')
+ var profile = h('div', {classList: 'profile'})
+ var banner = h('div', {classList: 'banner'})
+
+ function getDesc (src) {
+ var desc = h('span')
+ bog().then(log => {
+ if (log) {
+ for (var i = 0; i < log.length; i++) {
+ if ((log[i].descripted === src) && (log[i].author === src)) {
+ // if you've identified someone as something else show that something else
+ return desc.innerHTML = marked(log[i].description)
+ }
+ }
+ }
+ })
+ return desc
}
- var subs = [src]
+ function getBg (src, profile) {
+ bog().then(log => {
+ if (log) {
+ for (var i = 0; i < log.length; i++) {
+ if ((log[i].backgrounded === src) && (log[i].author === src)) {
+ // if you've identified someone as something else show that something else
+ banner.style.height = '300px'
+ return banner.style.background = 'fixed top/680px no-repeat url(' + log[i].background + ')'
+ }
+ }
+ }
+ })
+ }
- sync(subs, keys)
+ getBg(src, profile)
- profile.appendChild(h('a', {href: '#' + src}, [getName(src, keys)]))
- profile.appendChild(h('br'))
+ profileDiv.appendChild(banner)
+ profileDiv.appendChild(profile)
+ scroller.appendChild(profileDiv)
- var mentionsButton = h('button', {
- onclick: function () {
- location.href = '#?' + src
- }
- }, ['Mencioj'])
+ profile.appendChild(h('span', {classList: 'right'}, [getLoc(src)]))
+ profile.appendChild(h('div', [
+ h('a', {href: '#' + src}, [
+ getImage(src, keys, 'profileAvatar'),
+ getName(src, keys)
+ ]),
+ profile.appendChild(getDesc(src))
+ ]))
- profile.appendChild(identify(src, profile, keys))
- profile.appendChild(mentionsButton)
+ quickName(src).then(name => {
+ var mentionsButton = h('button', {
+ onclick: function () {
+ location.href = '#?' + src
+ }
+ }, ['Mencioj de '+ name])
+ profile.appendChild(mentionsButton)
+ var respond = h('button', {
+ onclick: function () {
+ scroller.insertBefore(composer(keys, msg, name), scroller.childNodes[1])
+ }
+ }, ['Respondi al ' + name])
+ profile.appendChild(respond)
- localforage.getItem('subscriptions').then(function (subs) {
- if (subs.includes(src)) {
- profile.appendChild(h('button', {
- onclick: function () {
- subs = subs.filter(a => a !== src)
- localforage.setItem('subscriptions', subs).then(function () { location.reload() })
+ profile.appendChild(h('button', {
+ onclick: function () {
+ localforage.removeItem(src).then(function () {
+ var home = true
+ regenerate(home)
+ })
+ }
+ }, ['Delete ' + name + '\'s feed']))
+
+ if (src != keys.publicKey) {
+ localforage.getItem('subscriptions').then(function (subs) {
+ if (subs.includes(src)) {
+ profile.appendChild(h('button', {
+ onclick: function () {
+ subs = subs.filter(a => a !== src)
+ localforage.setItem('subscriptions', subs).then(function () { location.hash = '' })
+ }
+ }, ['Unsubscribe from ' + name]))
+ } else {
+ profile.appendChild(h('button', {
+ onclick: function () {
+ subs.push(src)
+ localforage.setItem('subscriptions', subs).then(function () { location.hash = '' })
+ }
+ }, ['Subscribe to ' + name]))
}
- }, ['Ne plu sekvi']))
+ profile.appendChild(identify(src, profile, keys))
+ })
} else {
- profile.appendChild(h('button', {
- onclick: function () {
- subs.push(src)
- localforage.setItem('subscriptions', subs).then(function () { location.reload() })
- }
- }, ['Sekvi']))
+ profile.appendChild(identify(src, profile, keys))
}
+ //profile.appendChild(identify(src, profile, keys, name))
})
-
- profile.appendChild(h('button', {
- onclick: function () {
- localforage.removeItem(src).then(function () {
- var home = true
- regenerate(home)
- })
- }
- }, ['Forigi fluon']))
-
+
+
+ async function addPosts (posts, keys) {
+ posts.forEach(function (msg) {
+ if (msg.author === src) {
+ scroller.appendChild(render(msg, keys))
+ }
+ })
+ }
bog().then(log => {
+ var index = 0
if (log) {
- log.forEach(function (msg) {
- if (msg.author === src) {
- scroller.appendChild(render(msg, keys))
+ var posts = log.slice(index, index + 33)
+ addPosts(posts, keys).then(done => {
+ index = index + 33
+ window.onscroll = function(ev) {
+ //console.log(document.body.scrollHeight)
+ if (((window.innerHeight + window.scrollY) >= (document.body.scrollHeight - 2500)) && (window.location.hash.substring(1) === src)) {
+ posts = log.slice(index, index + 33)
+ index = index + 33
+ addPosts(posts, keys)
+ //console.log("Bottom of page")
+ }
}
})
}
@@ -74,12 +170,27 @@ function profilePage (src, keys) {
function searchPage (src, keys) {
var search = src.substring(1).replace("%20"," ").toUpperCase()
+ async function addPosts (posts, keys) {
+ posts.forEach(function (msg) {
+ if (msg.text) {
+ if (msg.text.toUpperCase().includes(search)) {
+ scroller.appendChild(render(msg, keys))
+ }
+ }
+ })
+ }
bog().then(log => {
+ var index = 0
if (log) {
- log.forEach(function (msg) {
- if (msg.text) {
- if (msg.text.toUpperCase().includes(search)) {
- scroller.appendChild(render(msg, keys))
+ var posts = log.slice(index, index + 33)
+ addPosts(posts, keys).then(done => {
+ index = index + 33
+ window.onscroll = function(ev) {
+ if (((window.innerHeight + window.scrollY) >= document.body.scrollHeight - 2500) && (window.location.hash.substring(1) === src)) {
+ posts = log.slice(index, index + 33)
+ index = index + 33
+ addPosts(posts, keys)
+ //console.log("Bottom of page")
}
}
})
@@ -89,114 +200,63 @@ function searchPage (src, keys) {
function publicPage (keys) {
- localforage.getItem('subscriptions').then(function (subs) {
+ localforage.getItem('log').then(log => {
+ log.sort((a, b) => a.timestamp - b.timestamp)
+ var reversed = log.reverse()
+ localforage.setItem('log', reversed)
+ })
+
+ localforage.getItem('subscriptions').then(subs => {
if (subs) {
- sync(subs, keys)
+ // the next two lines just fix a bug where the first sub was being set to null. Delete this code after March 2020.
+
+ subs.forEach(function (sub, index) {
+ var timer = setInterval(function () {
+ setTimeout(function () {
+ if (window.location.hash.substring(1) != '') {
+ clearInterval(timer)
+ //console.log('stop syncing')
+ }
+ sync([sub], keys)
+ //console.log('syncing ' + sub)
+ }, 1000 * index)
+ }, 2500)
+
+ if ((sub == null) || (sub == undefined)) {
+ var subs = [keys.publicKey]
+ localforage.setItem('subscriptions', subs)
+ }
+ })
} else {
var subs = [keys.publicKey]
+ console.log(subs)
localforage.setItem('subscriptions', subs)
- sync(subs, keys)
}
})
- var div = h('div')
-
- div.appendChild(h('button', {
- onclick: function () {
- localforage.clear().then(function () {location.reload()})
- }
- }, ['Forviŝi ĉion']))
-
- div.appendChild(h('button', {
- onclick: function () {
- regenerate()
- }
- }, ['Regeneri']))
+ scroller.appendChild(composer(keys))
- scroller.appendChild(div)
+ async function addPosts (posts, keys) {
+ posts.forEach(function (msg) {
+ scroller.appendChild(render(msg, keys))
+ })
+ }
- scroller.appendChild(composer(keys))
bog().then(log => {
+ var index = 0
if (log) {
- log.forEach(function (msg) {
- scroller.appendChild(render(msg, keys))
- })
- }
- })
-}
-
-function keyPage (keys) {
- var message = h('div', {classList: 'message'})
-
- message.appendChild(h('p', {innerHTML: marked('Jen via ŝlosilparo de ed25519-norma publika kaj privata ŝlosilo. Ĝi estas kreita per [TweetNaCl.js](https://tweetnacl.js.org/#/). Via publika ŝlosilo estas via identeco dum vi uzas [Interskri.be](https://interskri.be) (aŭ [Bogbook](http://bogbook.com/), la ĉefa projekto, se vi elektas tion), konservu vian ŝlosilon en sekura loko por ke vi povu uzadi la saman identecon.')}))
-
- message.appendChild(h('pre', {style: 'width: 80%'}, [h('code', [JSON.stringify(keys)])]))
-
- message.appendChild(h('button', {
- onclick: function () {
- localforage.removeItem('id', function () {
- location.hash = ''
- location.reload()
- })
- }
- }, ['Forigi ŝlosilon']))
-
- var textarea = h('textarea', {placeholder: 'Ĉi tie vi povas importi vian ekzistantan ed25519-ŝlosilparon'})
- message.appendChild(textarea)
- message.appendChild(h('button', {
- onclick: function () {
- if (textarea.value) {
- localforage.setItem('id', JSON.parse(textarea.value)).then(function () { location.reload() })
- }
- }
- }, ['Importi ŝlosilon']))
-
- scroller.appendChild(message)
-}
-
-function pubs () {
- var message = h('div', {classList: 'message'})
-
- message.appendChild(h('p', {innerHTML: marked('Jen la Bogbook-konigejoj al kiuj via foliumilo konektiĝas por kontroli pri novaj mesaĝoj de viaj sekvataj personoj, kiam vi afiŝas novajn aferojn kaj kiam vi surklakas fluojn.\n\nAldonu aŭ forigu ĉi tie konigejojn por decidi kien afiŝas la retejo. Se vi loke instalis kaj ruligas Bogbook, ĝi ankaŭ uzas tion kiel publikigo-celo. Atentu ke la kreinto de Bogbook ne ŝatas https, do ĉi tie malkiel en [Bogbook](http://bogbook.com) nur funkcias wss-konigejoj krom se via retumilo permesas konektiĝi de https al nesekuraj ws-konektoj. Vi povas loke instali kaj ruligi Bogbook [klonante la deponejon](https://git.kiefte.eu/lapingvino/bogbook-esperanto).')}))
-
- var add = h('input', {placeholder: 'Aldoni konigejon'})
-
- localforage.getItem('securepubs').then(function (servers) {
-
- message.appendChild(h('div', [
- add,
- h('button', {
- onclick: function () {
- if (add.value) {
- servers.push(add.value)
- localforage.setItem('securepubs', servers).then(function () { location.reload() })
+ var posts = log.slice(index, index + 25)
+ addPosts(posts, keys).then(done => {
+ index = index + 25
+ window.onscroll = function(ev) {
+ if (((window.innerHeight + window.scrollY) >= document.body.scrollHeight) && window.location.hash.substring(1) === '') {
+ posts = log.slice(index, index + 25)
+ index = index + 25
+ addPosts(posts, keys)
+ console.log("Bottom of page")
}
}
- }, ['Aldoni konigejon'])
- ]))
-
- servers.forEach(function (pub) {
- message.appendChild(h('p', [
- pub,
- h('button', {
- onclick: function () {
- var newServers = servers.filter(item => item !== pub)
- localforage.setItem('securepubs', newServers).then(function () { location.reload() })
- }
- }, ['Forigi'])
- ]))
- })
- })
-
- message.appendChild(h('button', {
- onclick: function () {
- localforage.removeItem('securepubs').then(function () {
- location.hash = ''
- location.reload()
})
}
- }, ['Restarigi konigejojn']))
-
- scroller.appendChild(message)
+ })
}
-