git ssb

0+

ev / minbase



Tree: b62ecd6f843b26f37e70c7b6d65c71db35bbf922

Files: b62ecd6f843b26f37e70c7b6d65c71db35bbf922 / modules / avatar-edit.js

2166 bytesRaw
1'use strict'
2var dataurl = require('dataurl-')
3var hyperfile = require('hyperfile')
4var hypercrop = require('hypercrop')
5var hyperlightbox = require('hyperlightbox')
6var h = require('hyperscript')
7var pull = require('pull-stream')
8var getAvatar = require('ssb-avatar')
9var ref = require('ssb-ref')
10var visualize = require('visualize-buffer')
11var self_id = require('../keys').id
12
13exports.needs = {
14 message_confirm: 'first',
15 sbot_blobs_add: 'first',
16 blob_url: 'first',
17 sbot_links: 'first',
18 avatar_name: 'first'
19}
20
21exports.gives = 'avatar_edit'
22
23exports.create = function (api) {
24 return function (id) {
25 var img = visualize(new Buffer(id.substring(1), 'base64'), 256)
26 img.classList.add('avatar--profile')
27
28 var lb = hyperlightbox()
29 var name_input = h('input', {placeholder: 'New name'})
30 var name = api.avatar_name(id)
31
32 var img_input = h('input', {placeholder: 'New profile pic blob url'})
33
34 getAvatar({links: api.sbot_links}, self_id, id, function (err, avatar) {
35 if (err) return console.error(err)
36 if(ref.isBlob(avatar.image))
37 img.src = api.blob_url(avatar.image)
38 })
39
40 return h('div.row.profile',
41 lb,
42 img,
43 h('div.column.profile__info',
44 h('strong', name),
45 name_input,
46 h('button', 'Preview', {onclick: function () {
47 if(name_input.value) {
48 api.message_confirm({
49 type: 'about',
50 about: id,
51 name: name_input.value || undefined
52 })
53 }
54 }}),
55 img_input,
56 h('button', 'Preview', {onclick: function () {
57 if(img_input.value) {
58 if (ref.isBlobId(img_input.value)) {
59 api.message_confirm({
60 type: 'about',
61 about: id,
62 image: img_input.value || undefined
63 })
64 } else { alert('The link you uploaded is not a blob, please use a valid blob id. - Example: &G7v7pgTXYfr4bTF7FB/qLiScmFIIOccsTV3Pp6bURB0=.sha256. - To upload a blob: write a normal message, upload a file, and publish. Square photos are best for avatar images.')}
65 }
66 }})
67 )
68 )
69 }
70}
71

Built with git-ssb-web