mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 12:40:08 +08:00
cd1ee3f672
Summary: - Rewrites composer extension adpater to support all versions of the ComposerExtension API we've ever declared. This will allow old plugins (or plugins that haven't been reinstalled after update) to keep functioning without breaking N1 - Adds specs Test Plan: - Unit tests Reviewers: evan, bengotow Reviewed By: bengotow Differential Revision: https://phab.nylas.com/D2399
25 lines
1 KiB
CoffeeScript
25 lines
1 KiB
CoffeeScript
{ComposerExtension} = require 'nylas-exports'
|
|
request = require 'request'
|
|
|
|
class AvailabilityComposerExtension extends ComposerExtension
|
|
|
|
# When subclassing the ComposerExtension, 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
|
|
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()
|
|
serverUrl = "https://quickschedule.herokuapp.com/register-events"
|
|
request.post {url: serverUrl, body: JSON.stringify(data)}, (error, resp, data) =>
|
|
console.log(error,resp,data)
|
|
|
|
|
|
module.exports = AvailabilityComposerExtension
|