2015-12-05 14:09:25 +08:00
|
|
|
{ComposerExtension} = require 'nylas-exports'
|
2015-10-03 07:06:56 +08:00
|
|
|
request = require 'request'
|
|
|
|
|
2015-12-05 14:09:25 +08:00
|
|
|
class AvailabilityComposerExtension extends ComposerExtension
|
2015-10-03 07:06:56 +08:00
|
|
|
|
2015-12-05 14:09:25 +08:00
|
|
|
# When subclassing the ComposerExtension, you can add your own custom logic
|
2015-10-03 07:06:56 +08:00
|
|
|
# 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
|
2015-11-24 16:09:59 +08:00
|
|
|
matches = (/data-quick-schedule="(.*)?" style/).exec body
|
2015-10-03 07:06:56 +08:00
|
|
|
if matches?
|
2015-11-20 10:16:38 +08:00
|
|
|
json = atob(matches[1])
|
2015-10-03 07:06:56 +08:00
|
|
|
data = JSON.parse(json)
|
|
|
|
data.attendees = []
|
|
|
|
data.attendees = participants.map (p) ->
|
2015-11-20 10:16:38 +08:00
|
|
|
name: p.name, email: p.email, isSender: p.isMe()
|
2015-11-24 16:30:29 +08:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2015-12-05 14:09:25 +08:00
|
|
|
module.exports = AvailabilityComposerExtension
|