git ssb

16+

Dominic / patchbay



Commit 39a3fdd490156a44a50029332ebf5c046b40274a

improve the follow module

mix irving committed on 1/25/2017, 8:07:55 AM
Parent: d3dcc2d7640822834366e1c87af9581a92ef545e

Files changed

modules_basic/feed.jschanged
modules_basic/follow.jschanged
modules_basic/follow.mcssadded
modules_basic/feed.jsView
@@ -46,9 +46,9 @@
4646 u.next(api.sbot_user_feed, {
4747 id: id, reverse: true,
4848 limit: 50, live: false
4949 }, ['value', 'sequence']),
50- pull.through(console.log.bind(console)),
50 + // pull.through(console.log.bind(console)),
5151 Scroller(div, content, api.message_render, false, false)
5252 )
5353
5454 return div
modules_basic/follow.jsView
@@ -1,5 +1,6 @@
1-var h = require('hyperscript')
1 +const fs = require('fs')
2 +const h = require('../h')
23
34 //render a message when someone follows someone,
45 //so you see new users
56 function isRelated(value, name) {
@@ -17,74 +18,92 @@
1718 exports.gives = {
1819 message_content: true,
1920 message_content_mini: true,
2021 avatar_action: true,
22 + mcss: true
2123 }
2224
2325 exports.create = function (api) {
24- var exports = {}
25- exports.message_content =
26- exports.message_content_mini = function (msg) {
27- var content = msg.value.content
28- if(content.type == 'contact' && content.contact) {
29- var relation = isRelated(content.following, 'follows')
30- if(content.blocking) relation = 'blocks'
26 + return {
27 + message_content_mini,
28 + message_content,
29 + avatar_action,
30 + mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8')
31 + }
32 +
33 + function message_content_mini (msg) {
34 + const { type, contact, following, blocking } = msg.value.content
35 + if(type == 'contact' && contact) {
36 + var relation = isRelated(following, 'follows')
37 + if(blocking) relation = 'blocks'
3138 return [
32- relation, ' ',
33- api.avatar_link(content.contact, api.avatar_name(content.contact), '')
39 + relation,
40 + ' ',
41 + api.avatar_link(contact, api.avatar_name(contact), '')
3442 ]
3543 }
3644 }
3745
38- exports.message_content = function (msg) {
39-
40- var content = msg.value.content
41- if(content.type == 'contact' && content.contact) {
42- var relation = isRelated(content.following, 'follows')
43- if(content.blocking) relation = 'blocks'
44- return h('div.contact', relation, api.avatar(msg.value.content.contact, 'thumbnail'))
46 + function message_content (msg) {
47 + const { type, contact, following, blocking } = msg.value.content
48 + if(type == 'contact' && contact) {
49 + var relation = isRelated(following, 'follows')
50 + if(blocking) relation = 'blocks'
51 + return h('div.contact', [
52 + relation,
53 + api.avatar(contact, 'thumbnail')
54 + ])
4555 }
4656 }
4757
48- exports.avatar_action = function (id) {
58 + function avatar_action (id) {
4959 var follows_you, you_follow
5060
5161 var self_id = require('../keys').id
52- api.follower_of(self_id, id, function (err, f) {
62 + api.follower_of(self_id, id, (err, f) => {
5363 you_follow = f
5464 update()
5565 })
56- api.follower_of(id, self_id, function (err, f) {
66 + api.follower_of(id, self_id, (err, f) => {
5767 follows_you = f
5868 update()
5969 })
6070
61- var state = h('label')
62- var label = h('span')
71 + var followBtn = h('button', { 'ev-click': toggleFollow }, 'loading')
72 + var state = h('label', 'loading')
6373
6474 function update () {
6575 state.textContent = (
66- follows_you && you_follow ? 'friend'
76 + follows_you && you_follow ? 'you are friends'
6777 : follows_you ? 'follows you'
6878 : you_follow ? 'you follow'
6979 : ''
7080 )
81 +
82 + if (you_follow === undefined) return
83 + followBtn.textContent = you_follow ? 'unfollow' : 'follow'
84 + }
7185
72- label.textContent = you_follow ? 'unfollow' : 'follow'
86 + return h('Follow', [
87 + followBtn,
88 + state
89 + ])
90 +
91 + function toggleFollow () {
92 + if (followBtn.textContent === 'loading') return
93 + const msg = {
94 + type: 'contact',
95 + contact: id,
96 + following: !you_follow
97 + }
98 +
99 + api.message_confirm(msg, (err, msg) => {
100 + if (err) return console.error(err)
101 +
102 + you_follow = msg.value.content.following
103 + update()
104 + })
73105 }
74-
75- return h('div', state,
76- h('a', {href:'#', onclick: function () {
77- api.message_confirm({
78- type: 'contact',
79- contact: id,
80- following: !you_follow
81- }, function (err, msg) {
82- if (err) return console.error(err)
83- you_follow = msg.value.content.following
84- update()
85- })
86- }}, h('br'), label)
87- )
106 +
88107 }
89108 return exports
90109 }
modules_basic/follow.mcssView
@@ -1,0 +1,11 @@
1 +Follow {
2 + button {
3 + width: 6rem
4 + margin: 0 .5rem 0 0
5 + }
6 +
7 + label {
8 + $textSubtle
9 + }
10 +}
11 +

Built with git-ssb-web