Mailspring/examples/N1-Send-Availability/docs/availability-draft-extension.coffee
Drew Regitsky 92820fc3d2 fix(examples): revamp/fix Send-Availability, change URL to live Heroku link
Summary:
Several fixes and updates the the Send Availability example package. Switches from
using `electron-safe-ipc` to using `protocol.RegisterStringProtocol` to communicate
with the child window. Changes the URLs in the package from localhost to our live
demo backend.

Test Plan: manual

Reviewers: bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D2271
2015-11-19 18:16:38 -08:00

28 lines
1.1 KiB
CoffeeScript

{DraftStoreExtension} = require 'nylas-exports'
request = require 'request'
class AvailabilityDraftExtension extends DraftStoreExtension
# When subclassing the DraftStoreExtension, you can add your own custom logic
# to execute before a draft is sent in the @finalizeSessionBeforeSending
# method. Here, we're registering the events before we send the draft.
@finalizeSessionBeforeSending: (session) ->
body = session.draft().body
participants = session.draft().participants()
sender = session.draft().from
matches = (/data-send-availability="(.*)?" style/).exec body
if matches?
json = atob(matches[1])
data = JSON.parse(json)
data.attendees = []
data.attendees = participants.map (p) ->
name: p.name, email: p.email, isSender: p.isMe()
console.log "Sending request!\n",JSON.stringify data
serverUrl = "https://sendavail.herokuapp.com/register-events"
request.post {url: serverUrl, body: JSON.stringify(data)}, (error, resp, data) =>
console.log(error,resp,data)
module.exports = AvailabilityDraftExtension