Files: 8dc25143a3f37f1618f7a92b3c46dec512b43bfd / modules / avatar-edit.js
2166 bytesRaw
1 | |
2 | var dataurl = require('dataurl-') |
3 | var hyperfile = require('hyperfile') |
4 | var hypercrop = require('hypercrop') |
5 | var hyperlightbox = require('hyperlightbox') |
6 | var h = require('hyperscript') |
7 | var pull = require('pull-stream') |
8 | var getAvatar = require('ssb-avatar') |
9 | var ref = require('ssb-ref') |
10 | var visualize = require('visualize-buffer') |
11 | var self_id = require('../keys').id |
12 | |
13 | exports.needs = { |
14 | message_confirm: 'first', |
15 | sbot_blobs_add: 'first', |
16 | blob_url: 'first', |
17 | sbot_links: 'first', |
18 | avatar_name: 'first' |
19 | } |
20 | |
21 | exports.gives = 'avatar_edit' |
22 | |
23 | exports.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