Mailspring/internal_packages/inbox-activity-bar/lib/activity-bar-store.coffee
Ben Gotow eb2e1b81b5 fix(friday): Bugs and initial pass at the Today view without content (see summary)
Summary:
Load unread counts from database again, not tags

fix(multiselect-list): Clear selection on esc

fix(onboarding): Make target=_blank links work in onboarding pages

fix(workspace): Items in header and footer regions are in a single column

fix(layout): Critical issue for things not 100% height

fix(activity-bar): Show in dev mode so you know you're in dev mode

fix(quoted-text): Support for #divRplyFwdMsg quoted text marker

Test Plan: Run specs

Reviewers: evan

Reviewed By: evan

Differential Revision: https://review.inboxapp.com/D1484
2015-05-08 16:36:48 -07:00

80 lines
2.2 KiB
CoffeeScript

Reflux = require 'reflux'
{Actions} = require 'inbox-exports'
qs = require 'querystring'
ActivityBarStore = Reflux.createStore
init: ->
@_setStoreDefaults()
@_registerListeners()
########### PUBLIC #####################################################
curlHistory: -> @_curlHistory
longPollState: -> @_longPollState
longPollHistory: -> @_longPollHistory
visible: -> @_visible
########### PRIVATE ####################################################
_setStoreDefaults: ->
@_curlHistory = []
@_longPollHistory = []
@_longPollState = 'Unknown'
@_visible = atom.inDevMode()
_registerListeners: ->
@listenTo Actions.didMakeAPIRequest, @_onAPIRequest
@listenTo Actions.longPollReceivedRawDeltas, @_onLongPollDeltas
@listenTo Actions.longPollStateChanged, @_onLongPollStateChange
@listenTo Actions.clearDeveloperConsole, @_onClear
@listenTo Actions.showDeveloperConsole, @_onShow
@listenTo Actions.logout, @_onClear
_onShow: ->
@_visible = true
@trigger(@)
_onClear: ->
@_curlHistory = []
@_longPollHistory = []
@trigger(@)
_onLongPollDeltas: (deltas) ->
# Add a local timestamp to deltas so we can display it
now = new Date()
delta.timestamp = now for delta in deltas
# Incoming deltas are [oldest...newest]. Append them to the beginning
# of our internal history which is [newest...oldest]
@_longPollHistory.unshift(deltas.reverse()...)
if @_longPollHistory.length > 1000
@_longPollHistory.splice(1000, @_longPollHistory.length - 1000)
@trigger(@)
_onLongPollStateChange: (state) ->
@_longPollState = state
@trigger(@)
_onAPIRequest: ({request, response}) ->
url = request.url
if request.auth
url = url.replace('://', "://#{request.auth.user}:#{request.auth.pass}@")
if request.qs
url += "?#{qs.stringify(request.qs)}"
postBody = ""
postBody = JSON.stringify(request.body).replace(/'/g, '\\u0027') if request.body
data = ""
data = "-d '#{postBody}'" unless request.method == 'GET'
item =
command: "curl -X #{request.method} #{data} #{url}"
statusCode: response?.statusCode || 0
@_curlHistory.unshift(item)
@trigger(@)
module.exports = ActivityBarStore