git ssb

2+

ev / mvd



Commit 98a2107f7a6f0dc6ea2ca1a3e86d1b830cfb74ff

add ability to publish avatar images

Ev Bogue committed on 6/30/2018, 2:08:10 PM
Parent: e123126e7f263e8ab6840196d1ed0666c79c1bcc

Files changed

package-lock.jsonchanged
package.jsonchanged
views.jschanged
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 205304 bytes
New file size: 205908 bytes
package.jsonView
@@ -16,12 +16,14 @@
1616 },
1717 "author": "Ev Bogue <ev@evbogue.com>",
1818 "license": "MIT",
1919 "dependencies": {
20 + "dataurl-": "^0.1.0",
2021 "decent-ws": "1.0.4",
2122 "deep-extend": "^0.6.0",
2223 "emoji-server": "^1.0.0",
2324 "human-time": "0.0.1",
25 + "hyperfile": "^2.0.0",
2426 "hyperloadmore": "^1.1.0",
2527 "hyperscript": "^2.0.2",
2628 "hyperscroll": "^1.0.0",
2729 "muxrpcli": "^1.1.0",
views.jsView
@@ -1,8 +1,10 @@
11 var pull = require('pull-stream')
22 var human = require('human-time')
33 var sbot = require('./scuttlebot')
44 var hyperscroll = require('hyperscroll')
5 +var hyperfile = require('hyperfile')
6 +var dataurl = require('dataurl-')
57 var More = require('pull-more')
68 var stream = require('hyperloadmore/stream')
79 var h = require('hyperscript')
810 var render = require('./render')
@@ -139,13 +141,14 @@
139141 screen.firstChild.insertBefore(profile, screen.firstChild.firstChild)
140142 } else {
141143 screen.firstChild.appendChild(profile)
142144 }
145 +
143146 var name = avatar.name(src)
144147
145148 var editname = h('span',
146149 avatar.name(src),
147- h('button.btn', 'Edit', {
150 + h('button.btn', 'New name', {
148151 onclick: function () {
149152 var nameput = h('input', {placeholder: name.textContent})
150153 var nameedit =
151154 h('span', nameput,
@@ -171,12 +174,73 @@
171174 }
172175 })
173176 )
174177
178 + var editimage = h('span',
179 + h('button.btn', 'New image', {
180 + onclick: function () {
181 + var upload =
182 + h('span',
183 + hyperfile.asDataURL(function (data) {
184 + if(data) {
185 + //img.src = data
186 + var _data = dataurl.parse(data)
187 + pull(
188 + pull.once(_data.data),
189 + sbot.addblob(function (err, hash) {
190 + if(err) return alert(err.stack)
191 + selected = {
192 + link: hash,
193 + size: _data.data.length,
194 + type: _data.mimetype,
195 + width: 512,
196 + height: 512
197 + }
198 + })
199 + )
200 + }
201 + }),
202 + h('button.btn', 'Preview image', {
203 + onclick: function() {
204 + if (selected) {
205 + console.log(selected)
206 + var oldImage = document.getElementById('profileImage')
207 + var newImage = h('span.avatar--medium', h('img', {src: config.blobsUrl + selected.link}))
208 + var publish = h('button.btn', 'Publish image', {
209 + onclick: function () {
210 + sbot.publish({
211 + type: 'about',
212 + about: src,
213 + image: selected
214 + }, function (err, published) {
215 + console.log(published)
216 + })
217 + }
218 + })
219 + upload.parentNode.replaceChild(publish, upload)
220 + oldImage.parentNode.replaceChild(newImage, oldImage)
221 + }
222 + /*if(selected) {
223 + api.message_confirm({
224 + type: 'about',
225 + about: id,
226 + image: selected
227 + })
228 + } else { alert('select an image before hitting preview')}*/
229 + }
230 + })
231 + )
232 + editimage.parentNode.replaceChild(upload, editimage)
233 + }
234 + })
235 + )
236 +
175237 var avatars = h('div.avatars',
176238 h('a', {href: '#' + src},
177- h('span.avatar--medium', avatar.image(src)),
178- editname
239 + h('span.avatar--medium#profileImage', avatar.image(src)),
240 + editname,
241 + h('br'),
242 + editimage
179243 )
180244 )
181245
182246 pull(

Built with git-ssb-web