<commit_before>var nest = require('depnest')
var { h, when, send, computed } = require('mutant')

exports.gives = nest('contact.html.followToggle')
exports.needs = nest({
  'intl.sync.i18n': 'first',
  'keys.sync.id': 'first',
  'contact.async.follow': 'first',
  'contact.async.unfollow': 'first',
  'contact.async.block': 'first',
  'contact.async.unblock': 'first',
  'contact.obs.following': 'first',
  'contact.obs.followers': 'first',
  'contact.obs.blockers': 'first'
})

exports.create = function (api) {
  var i18n = api.intl.sync.i18n
  return nest('contact.html.followToggle', function (id, opts) {
    var yourId = api.keys.sync.id()

    var yourFollows = api.contact.obs.following(yourId)
    var rawFollowers = api.contact.obs.followers(id)
    var rawFollowing = api.contact.obs.following(id)

    var friends = computed([rawFollowing, rawFollowers], (following, followers) => {
      return Array.from(following).filter(follow => followers.includes(follow))
    })

    var following = computed([rawFollowing, friends], (following, friends) => {
      return Array.from(following).filter(follow => !friends.includes(follow))
    })

    var isFriends = computed([friends], function (friends) {
      return friends.includes(yourId)
    })

    var followsYou = computed([following], function (followsYou) {
      return followsYou.includes(yourId)
    })

    var youFollow = computed([yourFollows], function (youFollow) {
      return youFollow.includes(id)
    })

    var blockers = api.contact.obs.blockers(id)
    var youBlock = computed(blockers, function (blockers) {
      return blockers.includes(yourId)
    })

    var showBlockButton = computed([opts && opts.block], (block) => block !== false)

    if (id !== yourId) {
      return when(youBlock, [
        h('a.ToggleButton.-unblocking', {
          'href': '#',
          'title': i18n('Click to unblock'),
          'ev-click': send(api.contact.async.unblock, id)
        }, i18n('Blocked'))
      ], [
        when(youFollow,
          h('a.ToggleButton.-unsubscribe', {
            'href': '#',
            'title': i18n('Click to unfollow'),
            'ev-click': send(api.contact.async.unfollow, id)
          }, when(isFriends, i18n('Friends'), i18n('Following'))),
          h('a.ToggleButton.-subscribe', {
            'href': '#',
            'ev-click': send(api.contact.async.follow, id)
          }, when(followsYou, i18n('Follow Back'), i18n('Follow')))
        ),
        when(showBlockButton, h('a.ToggleButton.-blocking', {
          'href': '#',
          'title': i18n('Click to block syncing with this person and hide their posts'),
          'ev-click': send(api.contact.async.block, id)
        }, i18n('Block')))
      ])
    } else {
      return []
    }
  })
}<commit_msg>quick hack to add a block confirm dialog<commit_after>var nest = require('depnest')
var { h, when, send, computed } = require('mutant')

exports.gives = nest('contact.html.followToggle')
exports.needs = nest({
  'intl.sync.i18n': 'first',
  'keys.sync.id': 'first',
  'message.async.publish': 'first',
  'contact.async.follow': 'first',
  'contact.async.unfollow': 'first',
  'contact.async.block': 'first',
  'contact.async.unblock': 'first',
  'contact.obs.following': 'first',
  'contact.obs.followers': 'first',
  'contact.obs.blockers': 'first'
})

exports.create = function (api) {
  var i18n = api.intl.sync.i18n
  return nest('contact.html.followToggle', function (id, opts) {
    var yourId = api.keys.sync.id()

    var yourFollows = api.contact.obs.following(yourId)
    var rawFollowers = api.contact.obs.followers(id)
    var rawFollowing = api.contact.obs.following(id)

    var friends = computed([rawFollowing, rawFollowers], (following, followers) => {
      return Array.from(following).filter(follow => followers.includes(follow))
    })

    var following = computed([rawFollowing, friends], (following, friends) => {
      return Array.from(following).filter(follow => !friends.includes(follow))
    })

    var isFriends = computed([friends], function (friends) {
      return friends.includes(yourId)
    })

    var followsYou = computed([following], function (followsYou) {
      return followsYou.includes(yourId)
    })

    var youFollow = computed([yourFollows], function (youFollow) {
      return youFollow.includes(id)
    })

    var blockers = api.contact.obs.blockers(id)
    var youBlock = computed(blockers, function (blockers) {
      return blockers.includes(yourId)
    })

    var showBlockButton = computed([opts && opts.block], (block) => block !== false)

    if (id !== yourId) {
      return when(youBlock, [
        h('a.ToggleButton.-unblocking', {
          'href': '#',
          'title': i18n('Click to unblock'),
          'ev-click': send(api.contact.async.unblock, id)
        }, i18n('Blocked'))
      ], [
        when(youFollow,
          h('a.ToggleButton.-unsubscribe', {
            'href': '#',
            'title': i18n('Click to unfollow'),
            'ev-click': send(api.contact.async.unfollow, id)
          }, when(isFriends, i18n('Friends'), i18n('Following'))),
          h('a.ToggleButton.-subscribe', {
            'href': '#',
            'ev-click': send(api.contact.async.follow, id)
          }, when(followsYou, i18n('Follow Back'), i18n('Follow')))
        ),
        when(showBlockButton, h('a.ToggleButton.-blocking', {
          'href': '#',
          'title': i18n('Click to block syncing with this person and hide their posts'),
          'ev-click': send(block, id)
        }, i18n('Block')))
      ])
    } else {
      return []
    }
  })

  function block (id) {
    // displays message confirm
    api.message.async.publish({
      type: 'contact',
      contact: id,
      blocking: true
    })
  }
}
{'fraction_non_alphanumeric': 0.16614691614691615, 'fraction_numerical': 0.008316008316008316, 'mean_word_length': 2.9165535956580735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7373147', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1784, 'n_words': 358}