Mailspring/examples/N1-Quick-Schedule/docs/availability-draft-extension.coffee

28 lines
1.1 KiB
CoffeeScript
Raw Normal View History

2015-10-03 07:06:56 +08:00
{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-quick-schedule="(.*)?" style/).exec body
2015-10-03 07:06:56 +08:00
if matches?
json = atob(matches[1])
2015-10-03 07:06:56 +08:00
data = JSON.parse(json)
data.attendees = []
data.attendees = participants.map (p) ->
name: p.name, email: p.email, isSender: p.isMe()
2015-10-03 07:06:56 +08:00
console.log "Sending request!\n",JSON.stringify data
serverUrl = "https://quickschedule.herokuapp.com/register-events"
2015-10-03 07:06:56 +08:00
request.post {url: serverUrl, body: JSON.stringify(data)}, (error, resp, data) =>
console.log(error,resp,data)
module.exports = AvailabilityDraftExtension