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

Commit

Permalink
Snoozed reminders in list functioning again. Issue #154
Browse files Browse the repository at this point in the history
  • Loading branch information
scottleedavis committed Aug 20, 2019
1 parent bd64bae commit 468bbbc
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 72 deletions.
137 changes: 66 additions & 71 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,93 +513,88 @@ func (p *Plugin) handleSnoozeList(w http.ResponseWriter, r *http.Request) {
}
}

if _, pErr := p.API.GetPost(request.PostId); pErr != nil {
p.API.LogError(pErr.Error())
writePostActionIntegrationResponseError(w, &model.PostActionIntegrationResponse{})
} else {
switch request.Context["selected_option"].(string) {
case "20min":
for i, occurrence := range reminder.Occurrences {
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.upsertSnoozedOccurrence(&occurrence)
break
}
switch request.Context["selected_option"].(string) {
case "20min":
for i, occurrence := range reminder.Occurrences {
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.upsertSnoozedOccurrence(&occurrence)
break
}
case "1hr":
for i, occurrence := range reminder.Occurrences {
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.upsertSnoozedOccurrence(&occurrence)
break
}
}
case "1hr":
for i, occurrence := range reminder.Occurrences {
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.upsertSnoozedOccurrence(&occurrence)
break
}
case "3hrs":
for i, occurrence := range reminder.Occurrences {
if occurrence.Id == request.Context["occurrence_id"].(string) {
occurrence.Snoozed = time.Now().UTC().Round(time.Second).Add(time.Hour * time.Duration(3))
}
case "3hrs":
for i, occurrence := range reminder.Occurrences {
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.upsertSnoozedOccurrence(&occurrence)
break
}
}
case "tomorrow":
for i, occurrence := range reminder.Occurrences {
if occurrence.Id == request.Context["occurrence_id"].(string) {

if user, uErr := p.API.GetUser(request.UserId); uErr != nil {
p.API.LogError(uErr.Error())
return
} else {
location := p.location(user)
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.upsertSnoozedOccurrence(&occurrence)
break
}
}
case "tomorrow":
for i, occurrence := range reminder.Occurrences {
if occurrence.Id == request.Context["occurrence_id"].(string) {

if user, uErr := p.API.GetUser(request.UserId); uErr != nil {
p.API.LogError(uErr.Error())
return
} else {
location := p.location(user)
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.upsertSnoozedOccurrence(&occurrence)
break
}
}
}
case "nextweek":
for i, occurrence := range reminder.Occurrences {
if occurrence.Id == request.Context["occurrence_id"].(string) {
}
case "nextweek":
for i, occurrence := range reminder.Occurrences {
if occurrence.Id == request.Context["occurrence_id"].(string) {

if user, uErr := p.API.GetUser(request.UserId); uErr != nil {
p.API.LogError(uErr.Error())
return
} else {
location := p.location(user)
if user, uErr := p.API.GetUser(request.UserId); uErr != nil {
p.API.LogError(uErr.Error())
return
} else {
location := p.location(user)

todayWeekDayNum := int(time.Now().In(location).Weekday())
weekDayNum := 1
day := 0
todayWeekDayNum := int(time.Now().In(location).Weekday())
weekDayNum := 1
day := 0

if weekDayNum < todayWeekDayNum {
day = 7 - (todayWeekDayNum - weekDayNum)
} else if weekDayNum >= todayWeekDayNum {
day = 7 + (weekDayNum - todayWeekDayNum)
}

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.upsertSnoozedOccurrence(&occurrence)
break
if weekDayNum < todayWeekDayNum {
day = 7 - (todayWeekDayNum - weekDayNum)
} else if weekDayNum >= todayWeekDayNum {
day = 7 + (weekDayNum - todayWeekDayNum)
}

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.upsertSnoozedOccurrence(&occurrence)
break
}
}
}

p.UpdateListReminders(request.UserId, request.PostId, request.ChannelId, int(request.Context["offset"].(float64)))
writePostActionIntegrationResponseOk(w, &model.PostActionIntegrationResponse{})
}

p.UpdateListReminders(request.UserId, request.PostId, request.ChannelId, int(request.Context["offset"].(float64)))
writePostActionIntegrationResponseOk(w, &model.PostActionIntegrationResponse{})
}

func (p *Plugin) handleCloseList(w http.ResponseWriter, r *http.Request) {
Expand Down
1 change: 0 additions & 1 deletion server/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,6 @@ func TestHandleSnoozeList(t *testing.T) {
api.On("LogDebug", mock.Anything, mock.Anything, mock.Anything).Maybe()
api.On("LogError", mock.Anything, mock.Anything, mock.Anything).Maybe()
api.On("LogInfo", mock.Anything).Maybe()
api.On("GetPost", mock.Anything).Return(post, nil)
api.On("GetUser", mock.Anything).Return(user, nil)
api.On("GetUserByUsername", mock.Anything).Return(user, nil)
api.On("KVGet", user.Username).Return(stringReminders, nil)
Expand Down

0 comments on commit 468bbbc

Please sign in to comment.