Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
post back to original user for complete reminder. Fixes Issue #139
Browse files Browse the repository at this point in the history
  • Loading branch information
scottleedavis committed Aug 6, 2019
1 parent 2dec8a4 commit f7807f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
20 changes: 10 additions & 10 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (p *Plugin) handleComplete(w http.ResponseWriter, r *http.Request) {

request := model.PostActionIntegrationRequestFromJson(r.Body)

reminder := p.GetReminder(request.UserId, request.Context["reminder_id"].(string))
reminder := p.GetReminder(request.Context["orig_user_id"].(string), request.Context["reminder_id"].(string))
user, uErr := p.API.GetUser(request.UserId)
if uErr != nil {
p.API.LogError(uErr.Error())
Expand All @@ -202,7 +202,7 @@ func (p *Plugin) handleComplete(w http.ResponseWriter, r *http.Request) {
}

reminder.Completed = time.Now().UTC()
p.UpdateReminder(request.UserId, reminder)
p.UpdateReminder(request.Context["orig_user_id"].(string), reminder)

if post, pErr := p.API.GetPost(request.PostId); pErr != nil {
p.API.LogError("unable to get post " + pErr.Error())
Expand Down Expand Up @@ -269,7 +269,7 @@ func (p *Plugin) handleDelete(w http.ResponseWriter, r *http.Request) {

request := model.PostActionIntegrationRequestFromJson(r.Body)

reminder := p.GetReminder(request.UserId, request.Context["reminder_id"].(string))
reminder := p.GetReminder(request.Context["orig_user_id"].(string), request.Context["reminder_id"].(string))
user, uErr := p.API.GetUser(request.UserId)
if uErr != nil {
p.API.LogError(uErr.Error())
Expand All @@ -283,7 +283,7 @@ func (p *Plugin) handleDelete(w http.ResponseWriter, r *http.Request) {
}

message := reminder.Message
p.DeleteReminder(request.UserId, reminder)
p.DeleteReminder(request.Context["orig_user_id"].(string), reminder)

if post, pErr := p.API.GetPost(request.PostId); pErr != nil {
p.API.LogError(pErr.Error())
Expand Down Expand Up @@ -337,7 +337,7 @@ func (p *Plugin) handleSnooze(w http.ResponseWriter, r *http.Request) {

request := model.PostActionIntegrationRequestFromJson(r.Body)

reminder := p.GetReminder(request.UserId, request.Context["reminder_id"].(string))
reminder := p.GetReminder(request.Context["orig_user_id"].(string), request.Context["reminder_id"].(string))
user, uErr := p.API.GetUser(request.UserId)
if uErr != nil {
p.API.LogError(uErr.Error())
Expand Down Expand Up @@ -366,7 +366,7 @@ func (p *Plugin) handleSnooze(w http.ResponseWriter, r *http.Request) {
if occurrence.Id == request.Context["occurrence_id"].(string) {
occurrence.Snoozed = time.Now().UTC().Round(time.Second).Add(time.Minute * time.Duration(20))
reminder.Occurrences[i] = occurrence
p.UpdateReminder(request.UserId, reminder)
p.UpdateReminder(request.Context["orig_user_id"].(string), reminder)
p.upsertSnoozedOccurrence(&occurrence)
post.Message = T("action.snooze.20min", snoozeParameters)
break
Expand All @@ -377,7 +377,7 @@ func (p *Plugin) handleSnooze(w http.ResponseWriter, r *http.Request) {
if occurrence.Id == request.Context["occurrence_id"].(string) {
occurrence.Snoozed = time.Now().UTC().Round(time.Second).Add(time.Hour * time.Duration(1))
reminder.Occurrences[i] = occurrence
p.UpdateReminder(request.UserId, reminder)
p.UpdateReminder(request.Context["orig_user_id"].(string), reminder)
p.upsertSnoozedOccurrence(&occurrence)
post.Message = T("action.snooze.1hr", snoozeParameters)
break
Expand All @@ -388,7 +388,7 @@ func (p *Plugin) handleSnooze(w http.ResponseWriter, r *http.Request) {
if occurrence.Id == request.Context["occurrence_id"].(string) {
occurrence.Snoozed = time.Now().UTC().Round(time.Second).Add(time.Hour * time.Duration(3))
reminder.Occurrences[i] = occurrence
p.UpdateReminder(request.UserId, reminder)
p.UpdateReminder(request.Context["orig_user_id"].(string), reminder)
p.upsertSnoozedOccurrence(&occurrence)
post.Message = T("action.snooze.3hr", snoozeParameters)
break
Expand All @@ -406,7 +406,7 @@ func (p *Plugin) handleSnooze(w http.ResponseWriter, r *http.Request) {
tt := time.Now().In(location).Add(time.Hour * time.Duration(24))
occurrence.Snoozed = time.Date(tt.Year(), tt.Month(), tt.Day(), 9, 0, 0, 0, location).UTC()
reminder.Occurrences[i] = occurrence
p.UpdateReminder(request.UserId, reminder)
p.UpdateReminder(request.Context["orig_user_id"].(string), reminder)
p.upsertSnoozedOccurrence(&occurrence)
post.Message = T("action.snooze.tomorrow", snoozeParameters)
break
Expand Down Expand Up @@ -436,7 +436,7 @@ func (p *Plugin) handleSnooze(w http.ResponseWriter, r *http.Request) {
tt := time.Now().In(location).Add(time.Hour * time.Duration(24))
occurrence.Snoozed = time.Date(tt.Year(), tt.Month(), tt.Day(), 9, 0, 0, 0, location).AddDate(0, 0, day).UTC()
reminder.Occurrences[i] = occurrence
p.UpdateReminder(request.UserId, reminder)
p.UpdateReminder(request.Context["orig_user_id"].(string), reminder)
p.upsertSnoozedOccurrence(&occurrence)
post.Message = T("action.snooze.nextweek", snoozeParameters)
break
Expand Down
3 changes: 3 additions & 0 deletions server/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func TestHandleComplete(t *testing.T) {
UserId: "userID1",
PostId: "postID1",
Context: model.StringInterface{
"orig_user_id": "foobar",
"reminder_id": model.NewId(),
"occurrence_id": model.NewId(),
},
Expand Down Expand Up @@ -291,6 +292,7 @@ func TestHandleDelete(t *testing.T) {
UserId: "userID1",
PostId: "postID1",
Context: model.StringInterface{
"orig_user_id": "foobar",
"reminder_id": model.NewId(),
"occurrence_id": model.NewId(),
},
Expand Down Expand Up @@ -472,6 +474,7 @@ func TestHandleSnooze(t *testing.T) {
UserId: "userID1",
PostId: "postID1",
Context: model.StringInterface{
"orig_user_id": "foobar",
"reminder_id": model.NewId(),
"occurrence_id": model.NewId(),
"selected_option": test.SnoozeTime,
Expand Down
5 changes: 4 additions & 1 deletion server/reminder.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (p *Plugin) TriggerReminders() {
Id: model.NewId(),
Integration: &model.PostActionIntegration{
Context: model.StringInterface{
"orig_user_id": user.Id,
"reminder_id": reminder.Id,
"occurrence_id": occurrence.Id,
"action": "complete",
Expand All @@ -153,6 +154,7 @@ func (p *Plugin) TriggerReminders() {
{
Integration: &model.PostActionIntegration{
Context: model.StringInterface{
"orig_user_id": user.Id,
"reminder_id": reminder.Id,
"occurrence_id": occurrence.Id,
"action": "delete",
Expand All @@ -165,6 +167,7 @@ func (p *Plugin) TriggerReminders() {
{
Integration: &model.PostActionIntegration{
Context: model.StringInterface{
"orig_user_id": user.Id,
"reminder_id": reminder.Id,
"occurrence_id": occurrence.Id,
"action": "snooze",
Expand Down Expand Up @@ -341,7 +344,7 @@ func (p *Plugin) GetReminders(username string) []Reminder {
err := json.Unmarshal(bytes, &reminders)

if err != nil {
p.API.LogError("new reminder " + user.Username)
p.API.LogError("no reminders for " + user.Username)
}
return reminders
}
Expand Down

0 comments on commit f7807f6

Please sign in to comment.