git ssb

2+

ev / mvd



Commit 584349aaa5ca0d0cff1e326a204f1c0f396301ca

add follow/unfollow button and follow/following counts

Ev Bogue committed on 6/13/2018, 10:22:35 PM
Parent: bb8598896fc1966615e1f1d1c5b6d90fad9be52e

Files changed

render.jschanged
tools.jschanged
views.jschanged
render.jsView
@@ -42,9 +42,8 @@
4242
4343 pull(
4444 sbot.get(msg.value.content.repo, function (err, data) {
4545 if (err) throw err
46- console.log(data)
4746 if (data.content.name) {
4847 actualname = h('p', 'pushed to ', h('a', {href: '#' + msg.value.content.repo}, '%' + data.content.name))
4948 reponame.parentNode.replaceChild(actualname, reponame)
5049 }
@@ -91,9 +90,8 @@
9190 pull(
9291 sbot.query({query: [{$filter: {value: {content: {type: 'edit', original: msg.key}}}}], limit: 100, live: true}),
9392 pull.drain(function (update) {
9493 if (update.sync) {
95- //console.log('Waiting for new edits.')
9694 } else {
9795 var newMessage = h('div', tools.markdown(update.value.content.text))
9896 var latest = h('div.message__body',
9997 tools.timestamp(update, {edited: true}),
@@ -144,10 +142,8 @@
144142 message.replaceChild(compose, message.lastElementChild)
145143 }
146144 }))
147145
148- buttons.appendChild(tools.done(msg.key))
149-
150146 buttons.appendChild(tools.star(msg))
151147 message.appendChild(buttons)
152148 return message
153149
tools.jsView
@@ -12,8 +12,139 @@
1212 var config = require('./config')()
1313
1414 var id = require('./keys').id
1515
16 +module.exports.getFollowing = function (src) {
17 + var followingCount = 0
18 +
19 + var following = h('div.following', 'Following: ')
20 +
21 + following.appendChild(h('span#followingcount', '0'))
22 + following.appendChild(h('br'))
23 +
24 + pull(
25 + sbot.query({query: [{$filter: { value: { author: src, content: {type: 'contact'}}}}], live: true}),
26 + pull.drain(function (msg) {
27 + if (msg.value) {
28 + if (msg.value.content.following == true) {
29 + followingcount = document.getElementById('followingcount')
30 + followingCount++
31 + followingcount.textContent = followingCount
32 + var gotIt = document.getElementById('following:' + msg.value.content.contact.substring(0, 44))
33 + if (gotIt == null) {
34 + following.appendChild(h('a#following:'+ msg.value.content.contact.substring(0, 44), {href: '#' + msg.value.content.contact}, h('span.avatar--small', avatar.image(msg.value.content.contact))))
35 + }
36 + }
37 + if (msg.value.content.following == false) {
38 + followingcount = document.getElementById('followingcount')
39 + followingCount--
40 + followingcount.textContent = followingCount
41 + var gotIt = document.getElementById('following:' + msg.value.content.contact.substring(0, 44))
42 + console.log(gotIt)
43 + if (gotIt != null) {
44 + console.log('removing' + gotIt)
45 + gotIt.outerHTML = ''
46 + }
47 + }
48 + }
49 + })
50 + )
51 +
52 + return following
53 +
54 +}
55 +
56 +module.exports.getFollowers = function (src) {
57 + var followerCount = 0
58 +
59 + var followers = h('div.followers', 'Followers: ')
60 +
61 + followers.appendChild(h('span#followercount', '0'))
62 + followers.appendChild(h('br'))
63 +
64 + pull(
65 + sbot.query({query: [{$filter: { value: { content: {type: 'contact', contact: src}}}}], live: true}),
66 + pull.drain(function (msg) {
67 + if (msg.value) {
68 + if (msg.value.content.following == true) {
69 + followcount = document.getElementById('followercount')
70 + followerCount++
71 + followcount.textContent = followerCount
72 + var gotIt = document.getElementById('followers:' + msg.value.author.substring(0, 44))
73 + if (gotIt == null) {
74 + followers.appendChild(h('a#followers:'+ msg.value.author.substring(0, 44), {href: '#' + msg.value.author}, h('span.avatar--small', avatar.image(msg.value.author))))
75 + }
76 + }
77 + if (msg.value.content.following == false) {
78 + followcount = document.getElementById('followercount')
79 + followerCount--
80 + followcount.textContent = followerCount
81 + var gotIt = document.getElementById('followers:' + msg.value.author.substring(0, 44))
82 + console.log(gotIt)
83 + if (gotIt != null) {
84 + console.log('removing' + gotIt)
85 + gotIt.outerHTML = ''
86 + }
87 + }
88 + }
89 + })
90 + )
91 +
92 + return followers
93 +}
94 +
95 +module.exports.follow = function (src) {
96 + var button = h('span.button')
97 +
98 + var followButton = h('button.btn', 'Follow ' + avatar.name(src).textContent, {
99 + onclick: function () {
100 + var content = {
101 + type: 'contact',
102 + contact: src,
103 + following: true
104 + }
105 + sbot.publish(content, function (err, publish) {
106 + if (err) throw err
107 + console.log(publish)
108 + })
109 + }
110 + })
111 +
112 + var unfollowButton = h('button.btn', 'Unfollow ' + avatar.name(src).textContent, {
113 + onclick: function () {
114 + var content = {
115 + type: 'contact',
116 + contact: src,
117 + following: false
118 + }
119 + sbot.publish(content, function (err, publish) {
120 + if (err) throw err
121 + console.log(publish)
122 + })
123 + }
124 + })
125 +
126 + pull(
127 + sbot.query({query: [{$filter: { value: { author: id, content: {type: 'contact', contact: src}}}}], live: true}),
128 + pull.drain(function (msg) {
129 + if (msg.value) {
130 + if (msg.value.content.following == true) {
131 + button.removeChild(button.firstChild)
132 + button.appendChild(unfollowButton)
133 + }
134 + if (msg.value.content.following == false) {
135 + button.removeChild(button.firstChild)
136 + button.appendChild(followButton)
137 + }
138 + }
139 + })
140 + )
141 +
142 + button.appendChild(followButton)
143 +
144 + return button
145 +}
146 +
16147 module.exports.box = function (content) {
17148 return ssbKeys.box(content, content.recps.map(function (e) {
18149 return ref.isFeed(e) ? e : e.link
19150 }))
@@ -28,29 +159,8 @@
28159 if(cb) cb(err, msg)
29160 })
30161 }
31162
32-module.exports.done = function (src) {
33- var content = {
34- type: 'done',
35- vote: {'link': src}
36- }
37-
38- var done = h('button.btn.right', 'Done ', h('img.emoji', {src: config.emojiUrl + 'v.png'}), {
39- onclick: function () {
40- content.done = true
41- content.mentions = [id]
42- content.recps = [id]
43- exports.publish(content, function (err, published) {
44- if (err) throw err
45- })
46- }
47- })
48-
49- return done
50-
51-}
52-
53163 module.exports.mute = function (src) {
54164 if (!localStorage[src])
55165 var cache = {mute: false}
56166 else
views.jsView
@@ -112,10 +112,8 @@
112112 profile.firstChild.appendChild(avatars)
113113 profile.firstChild.appendChild(buttons)
114114 buttons.appendChild(tools.mute(src))
115115
116- console.log(name)
117-
118116 var writeMessage = h('button.btn', 'Public message ' + name.textContent, {
119117 onclick: function () {
120118 opts = {}
121119 opts.type = 'post'
@@ -137,8 +135,13 @@
137135 })
138136
139137 buttons.appendChild(writeMessage)
140138 buttons.appendChild(writePrivate)
139 + buttons.appendChild(tools.follow(src))
140 +
141 + profile.firstChild.appendChild(tools.getFollowing(src))
142 + profile.firstChild.appendChild(tools.getFollowers(src))
143 +
141144 }
142145
143146 var msgThread = function (src) {
144147

Built with git-ssb-web