mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-14 01:04:18 +08:00
fix(rsvp): Check that you are a participant, support aliases. Fixes #962
This commit is contained in:
parent
3160520017
commit
356365dc42
4 changed files with 28 additions and 31 deletions
|
@ -29,6 +29,7 @@ class EventHeader extends React.Component
|
|||
@setState({event})
|
||||
|
||||
componentDidMount: =>
|
||||
# TODO: This should use observables!
|
||||
@_unlisten = DatabaseStore.listen (change) =>
|
||||
if @state.event and change.objectClass is Event.name
|
||||
updated = _.find change.objects, (o) => o.id is @state.event.id
|
||||
|
@ -42,11 +43,6 @@ class EventHeader extends React.Component
|
|||
componentWillUnmount: =>
|
||||
@_unlisten?()
|
||||
|
||||
_myStatus: =>
|
||||
myEmail = AccountStore.current()?.me().email
|
||||
for p in @state.event.participants
|
||||
return p['status'] if p['email'] is myEmail
|
||||
return null
|
||||
|
||||
render: =>
|
||||
if @state.event?
|
||||
|
@ -74,12 +70,15 @@ class EventHeader extends React.Component
|
|||
<div></div>
|
||||
|
||||
_renderEventActions: =>
|
||||
me = @state.event.participantForMe()
|
||||
return false unless me
|
||||
|
||||
actions = [["yes", "Accept"], ["maybe", "Maybe"], ["no", "Decline"]]
|
||||
|
||||
<div className="event-actions">
|
||||
{actions.map ([status, label]) =>
|
||||
classes = "btn-rsvp "
|
||||
classes += status if @_myStatus() is status
|
||||
classes += status if me.status is status
|
||||
<div key={status} className={classes} onClick={=> @_rsvp(status)}>
|
||||
{label}
|
||||
</div>
|
||||
|
@ -87,7 +86,7 @@ class EventHeader extends React.Component
|
|||
</div>
|
||||
|
||||
_rsvp: (status) =>
|
||||
Actions.queueTask(new EventRSVPTask(@state.event, status))
|
||||
|
||||
me = @state.event.participantForMe()
|
||||
Actions.queueTask(new EventRSVPTask(@state.event, me.email, status))
|
||||
|
||||
module.exports = EventHeader
|
||||
|
|
|
@ -35,7 +35,7 @@ describe "EventRSVPTask", ->
|
|||
"email": @myEmail,
|
||||
"status": 'noreply'}
|
||||
]
|
||||
@task = new EventRSVPTask(@event, "no")
|
||||
@task = new EventRSVPTask(@event, @myEmail, "no")
|
||||
|
||||
describe "performLocal", ->
|
||||
it "should mark our status as no", ->
|
||||
|
@ -82,7 +82,7 @@ describe "EventRSVPTask", ->
|
|||
"email": @myEmail,
|
||||
"status": 'noreply'}
|
||||
]
|
||||
@task = new EventRSVPTask(@event, "no")
|
||||
@task = new EventRSVPTask(@event, @myEmail, "no")
|
||||
@task.performLocal()
|
||||
@task.performRemote()
|
||||
advanceClock()
|
||||
|
|
|
@ -48,4 +48,10 @@ class Event extends Model
|
|||
delete @when.object
|
||||
@
|
||||
|
||||
participantForMe: =>
|
||||
for p in @participants
|
||||
if (new Contact(email: p.email)).isMe()
|
||||
return p
|
||||
return null
|
||||
|
||||
module.exports = Event
|
||||
|
|
|
@ -9,24 +9,20 @@ NylasAPI = require '../nylas-api'
|
|||
|
||||
module.exports =
|
||||
class EventRSVPTask extends Task
|
||||
constructor: (calendar_event, @RSVPResponse) ->
|
||||
@myEmail = AccountStore.current()?.me().email.toLowerCase().trim()
|
||||
@event = calendar_event
|
||||
constructor: (@event, @RSVPEmail, @RSVPResponse) ->
|
||||
super
|
||||
|
||||
performLocal: ->
|
||||
DatabaseStore.inTransaction (t) =>
|
||||
t.find(Event, @event.id).then (e) =>
|
||||
e ?= @event
|
||||
@_previousParticipantsState = Utils.deepClone(e.participants)
|
||||
participants = []
|
||||
for p in e.participants
|
||||
if p['email'] == @myEmail
|
||||
p['status'] = @RSVPResponse
|
||||
participants.push p
|
||||
e.participants = participants
|
||||
@event = e
|
||||
t.persistModel(e)
|
||||
t.find(Event, @event.id).then (updated) =>
|
||||
@event = updated ? @event
|
||||
@_previousParticipantsState = Utils.deepClone(@event.participants)
|
||||
|
||||
for p in @event.participants
|
||||
if p.email is @RSVPEmail
|
||||
p.status = @RSVPResponse
|
||||
|
||||
t.persistModel(@event)
|
||||
|
||||
performRemote: ->
|
||||
NylasAPI.makeRequest
|
||||
|
@ -38,16 +34,12 @@ class EventRSVPTask extends Task
|
|||
status: @RSVPResponse
|
||||
}
|
||||
returnsModel: true
|
||||
.then =>
|
||||
return Promise.resolve(Task.Status.Success)
|
||||
.thenReturn(Task.Status.Success)
|
||||
.catch APIError, (err) =>
|
||||
##TODO event already accepted/declined/etc
|
||||
@event.participants = @_previousParticipantsState
|
||||
DatabaseStore.inTransaction (t) =>
|
||||
t.persistModel(@event).then ->
|
||||
return Promise.resolve(Task.Status.Failed)
|
||||
.catch (err) ->
|
||||
return Promise.resolve(Task.Status.Failed)
|
||||
t.persistModel(@event)
|
||||
.thenReturn(Task.Status.Failed)
|
||||
|
||||
onOtherError: -> Promise.resolve()
|
||||
onTimeoutError: -> Promise.resolve()
|
||||
|
|
Loading…
Reference in a new issue