<commit_before>const nest = require('depnest')
const { h } = require('mutant')
const pull = require('pull-stream')
const Scroller = require('pull-scroll')
const next = require('../../../junk/next-stepper')
const ref = require('ssb-ref')

exports.gives = nest({
  'app.html': {
    page: true,
    menuItem: true
  }
})

exports.needs = nest({
  'app.html': {
    filter: 'first',
    scroller: 'first'
  },
  'app.sync.goTo': 'first',
  'feed.pull.private': 'first',
  'feed.pull.rollup': 'first',
  'keys.sync.id': 'first',
  'message.html': {
    compose: 'first',
    render: 'first'
  }
})

exports.create = function (api) {
  const route = '/inbox'

  return nest({
    'app.html': {
      page: privatePage,
      menuItem: menuItem
    }
  })

  function menuItem () {
    return h('a', {
      style: { order: 2 },
      'ev-click': () => api.app.sync.goTo(route)
    }, route)
  }

  function privatePage (path) {
    if (path !== route) return

    const id = api.keys.sync.id()

    const composer = api.message.html.compose({
      meta: { type: 'post' },
      prepublish: meta => {
        meta.recps = [id, ...(meta.mentions || [])]
          .filter(m => ref.isFeed(typeof m === 'string' ? m : m.link))
        return meta
      },
      placeholder: 'Write a private message. \n\n@mention users in the first message to start a private thread.'}
    )
    const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw)
    const { container, content } = api.app.html.scroller({ prepend: [ composer, filterMenu ] })

    function draw () {
      resetFeed({ container, content })

      pull(
        next(api.feed.pull.private, {old: false, limit: 100}, ['value', 'timestamp']),
        filterDownThrough(),
        api.feed.pull.rollup(),
        Scroller(container, content, render, true, false)
      )

      pull(
        next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']),
        filterUpThrough(),
        api.feed.pull.rollup(),
        Scroller(container, content, render, false, false)
      )
    }
    draw()

    function render (msgRollup) {
      return api.message.html.render(msgRollup, { layout: 'inbox' })
    }

    return container
  }<commit_msg>show new inbox messages in a counter<commit_after>const nest = require('depnest')
const { h, Value } = require('mutant')
const pull = require('pull-stream')
const Scroller = require('pull-scroll')
const next = require('../../../junk/next-stepper')
const ref = require('ssb-ref')

exports.gives = nest({
  'app.html': {
    page: true,
    menuItem: true
  }
})

exports.needs = nest({
  'app.html': {
    filter: 'first',
    scroller: 'first'
  },
  'app.sync.goTo': 'first',
  'feed.pull.private': 'first',
  'feed.pull.rollup': 'first',
  'keys.sync.id': 'first',
  'message.html': {
    compose: 'first',
    render: 'first'
  }
})

exports.create = function (api) {
  const route = '/inbox'

  return nest({
    'app.html': {
      page: privatePage,
      menuItem: menuItem
    }
  })

  function menuItem () {
    return h('a', {
      style: { order: 2 },
      'ev-click': () => api.app.sync.goTo(route)
    }, route)
  }

  function privatePage (path) {
    if (path !== route) return

    const id = api.keys.sync.id()

    const composer = api.message.html.compose({
      meta: { type: 'post' },
      prepublish: meta => {
        meta.recps = [id, ...(meta.mentions || [])]
          .filter(m => ref.isFeed(typeof m === 'string' ? m : m.link))
        return meta
      },
      placeholder: 'Write a private message. \n\n@mention users in the first message to start a private thread.'}
    )
    const newMsgCount = Value(0)
    const newMsg = h('div', ['New Messages: ', newMsgCount])
    const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw)
    const { container, content } = api.app.html.scroller({ prepend: [ newMsg, composer, filterMenu ] })

    function draw () {
      resetFeed({ container, content })

      pull(
        next(api.feed.pull.private, {old: false, limit: 100}, ['value', 'timestamp']),
        filterDownThrough(),
        pull.drain(msg => newMsgCount.set(newMsgCount() + 1))
      )

      // pull(
      //   next(api.feed.pull.private, {old: false, limit: 100}, ['value', 'timestamp']),
      //   filterDownThrough(),
      //   api.feed.pull.rollup(),
      //   Scroller(container, content, render, true, false)
      // )

      pull(
        next(api.feed.pull.private, {reverse: true, limit: 100, live: false}, ['value', 'timestamp']),
        filterUpThrough(),
        api.feed.pull.rollup(),
        Scroller(container, content, render, false, false)
      )
    }
    draw()

    function render (msgRollup) {
      return api.message.html.render(msgRollup, { layout: 'inbox' })
    }

    return container
  }
{'fraction_non_alphanumeric': 0.1710121125025662, 'fraction_numerical': 0.00390063641962636, 'mean_word_length': 2.603550295857988, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '5248799', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1584, 'n_words': 375}