diff --git a/server/occurrence_test.go b/server/occurrence_test.go index 66d82e2..76f4a06 100755 --- a/server/occurrence_test.go +++ b/server/occurrence_test.go @@ -611,8 +611,7 @@ func TestFreeForm(t *testing.T) { times, err = p.freeFormEN("everyday at 3:23am", user) assert.Nil(t, err) if err == nil { - assert.True(t, times[0].In(location).Weekday().String() == time.Now().In(location).AddDate(0, 0, 1).Weekday().String() && - times[0].In(location).Hour() == 3 && times[0].In(location).Minute() == 23) + assert.True(t, times[0].In(location).Hour() == 3 && times[0].In(location).Minute() == 23) } times, err = p.freeFormEN("mondays", user) diff --git a/server/reminder.go b/server/reminder.go index 710893f..f1089cb 100755 --- a/server/reminder.go +++ b/server/reminder.go @@ -120,78 +120,134 @@ func (p *Plugin) TriggerReminders() { return } - interactivePost := model.Post{ - ChannelId: channel.Id, - PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()), - UserId: p.remindUserId, - Props: model.StringInterface{ - "attachments": []*model.SlackAttachment{ - { - Text: T("reminder.message", messageParameters), - Actions: []*model.PostAction{ - { - Id: model.NewId(), - Integration: &model.PostActionIntegration{ - Context: model.StringInterface{ - "reminder_id": reminder.Id, - "occurrence_id": occurrence.Id, - "action": "complete", - }, - URL: fmt.Sprintf("%s/plugins/%s/complete", siteURL, manifest.Id), - }, - Type: model.POST_ACTION_TYPE_BUTTON, - Name: T("button.complete"), - }, - { - Integration: &model.PostActionIntegration{ - Context: model.StringInterface{ - "reminder_id": reminder.Id, - "occurrence_id": occurrence.Id, - "action": "delete", + interactivePost := model.Post{} + + if occurrence.Repeat == "" { + + interactivePost = model.Post{ + ChannelId: channel.Id, + PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()), + UserId: p.remindUserId, + Props: model.StringInterface{ + "attachments": []*model.SlackAttachment{ + { + Text: T("reminder.message", messageParameters), + Actions: []*model.PostAction{ + { + Id: model.NewId(), + Integration: &model.PostActionIntegration{ + Context: model.StringInterface{ + "reminder_id": reminder.Id, + "occurrence_id": occurrence.Id, + "action": "complete", + }, + URL: fmt.Sprintf("%s/plugins/%s/complete", siteURL, manifest.Id), }, - URL: fmt.Sprintf("%s/plugins/%s/delete", siteURL, manifest.Id), + Type: model.POST_ACTION_TYPE_BUTTON, + Name: T("button.complete"), }, - Name: T("button.delete"), - Type: "action", - }, - { - Integration: &model.PostActionIntegration{ - Context: model.StringInterface{ - "reminder_id": reminder.Id, - "occurrence_id": occurrence.Id, - "action": "snooze", + { + Integration: &model.PostActionIntegration{ + Context: model.StringInterface{ + "reminder_id": reminder.Id, + "occurrence_id": occurrence.Id, + "action": "delete", + }, + URL: fmt.Sprintf("%s/plugins/%s/delete", siteURL, manifest.Id), }, - URL: fmt.Sprintf("%s/plugins/%s/snooze", siteURL, manifest.Id), + Name: T("button.delete"), + Type: "action", }, - Name: T("button.snooze"), - Type: "select", - Options: []*model.PostActionOptions{ - { - Text: T("button.snooze.20min"), - Value: "20min", + { + Integration: &model.PostActionIntegration{ + Context: model.StringInterface{ + "reminder_id": reminder.Id, + "occurrence_id": occurrence.Id, + "action": "snooze", + }, + URL: fmt.Sprintf("%s/plugins/%s/snooze", siteURL, manifest.Id), }, - { - Text: T("button.snooze.1hr"), - Value: "1hr", + Name: T("button.snooze"), + Type: "select", + Options: []*model.PostActionOptions{ + { + Text: T("button.snooze.20min"), + Value: "20min", + }, + { + Text: T("button.snooze.1hr"), + Value: "1hr", + }, + { + Text: T("button.snooze.3hr"), + Value: "3hrs", + }, + { + Text: T("button.snooze.tomorrow"), + Value: "tomorrow", + }, + { + Text: T("button.snooze.nextweek"), + Value: "nextweek", + }, }, - { - Text: T("button.snooze.3hr"), - Value: "3hrs", - }, - { - Text: T("button.snooze.tomorrow"), - Value: "tomorrow", + }, + }, + }, + }, + }, + } + + } else { + + interactivePost = model.Post{ + ChannelId: channel.Id, + PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()), + UserId: p.remindUserId, + Props: model.StringInterface{ + "attachments": []*model.SlackAttachment{ + { + Text: T("reminder.message", messageParameters), + Actions: []*model.PostAction{ + { + Integration: &model.PostActionIntegration{ + Context: model.StringInterface{ + "reminder_id": reminder.Id, + "occurrence_id": occurrence.Id, + "action": "snooze", + }, + URL: fmt.Sprintf("%s/plugins/%s/snooze", siteURL, manifest.Id), }, - { - Text: T("button.snooze.nextweek"), - Value: "nextweek", + Name: T("button.snooze"), + Type: "select", + Options: []*model.PostActionOptions{ + { + Text: T("button.snooze.20min"), + Value: "20min", + }, + { + Text: T("button.snooze.1hr"), + Value: "1hr", + }, + { + Text: T("button.snooze.3hr"), + Value: "3hrs", + }, + { + Text: T("button.snooze.tomorrow"), + Value: "tomorrow", + }, + { + Text: T("button.snooze.nextweek"), + Value: "nextweek", + }, }, }, }, }, }, }, - }, + } } if _, pErr := p.API.CreatePost(&interactivePost); pErr != nil { @@ -473,6 +529,29 @@ func (p *Plugin) rescheduleOccurrence(occurrence *Occurrence) { p.upsertOccurrence(occurrence) } + bytes, bErr := p.API.KVGet(user.Username) + if bErr != nil { + p.API.LogError("failed KVGet %s", bErr) + } + var reminders []Reminder + rsErr := json.Unmarshal(bytes, &reminders) + if rsErr != nil { + p.API.LogError("failed json Unmarshal %s", rsErr) + } + + reminder := p.findReminder(reminders, *occurrence) + + updatedOccurrences := []Occurrence{} + for _, o := range reminder.Occurrences { + if o.Id == occurrence.Id { + updatedOccurrences = append(updatedOccurrences, *occurrence) + } else { + updatedOccurrences = append(updatedOccurrences, o) + } + } + reminder.Occurrences = updatedOccurrences + p.UpdateReminder(user.Id, reminder) + } func (p *Plugin) rescheduleOccurrenceEN(occurrence *Occurrence) ([]time.Time, error) {