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

Commit

Permalink
Maintain page when complete/delete/snooze on /remind list fixes Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
scottleedavis committed May 25, 2019
1 parent 1e61264 commit ee30671
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
8 changes: 4 additions & 4 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func (p *Plugin) handleCompleteList(w http.ResponseWriter, r *http.Request) {

reminder.Completed = time.Now().UTC()
p.UpdateReminder(request.UserId, reminder)
p.UpdateListReminders(request.UserId, request.PostId, request.ChannelId, 0)
p.UpdateListReminders(request.UserId, request.PostId, request.ChannelId, int(request.Context["offset"].(float64)))
writePostActionIntegrationResponseOk(w, &model.PostActionIntegrationResponse{})
}

Expand All @@ -457,14 +457,14 @@ func (p *Plugin) handleDeleteList(w http.ResponseWriter, r *http.Request) {
}

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

func (p *Plugin) handleDeleteCompleteList(w http.ResponseWriter, r *http.Request) {
request := model.PostActionIntegrationRequestFromJson(r.Body)
p.DeleteCompletedReminders(request.UserId)
p.UpdateListReminders(request.UserId, request.PostId, request.ChannelId, 0)
p.UpdateListReminders(request.UserId, request.PostId, request.ChannelId, int(request.Context["offset"].(float64)))
writePostActionIntegrationResponseOk(w, &model.PostActionIntegrationResponse{})
}

Expand Down Expand Up @@ -562,7 +562,7 @@ func (p *Plugin) handleSnoozeList(w http.ResponseWriter, r *http.Request) {
}
}

p.UpdateListReminders(request.UserId, request.PostId, request.ChannelId, 0)
p.UpdateListReminders(request.UserId, request.PostId, request.ChannelId, int(request.Context["offset"].(float64)))
writePostActionIntegrationResponseOk(w, &model.PostActionIntegrationResponse{})
}
}
Expand Down
13 changes: 12 additions & 1 deletion server/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ func TestHandleCompleteList(t *testing.T) {
Context: model.StringInterface{
"reminder_id": model.NewId(),
"occurrence_id": model.NewId(),
"offset": 0,
},
}

Expand Down Expand Up @@ -785,6 +786,7 @@ func TestHandleDeleteList(t *testing.T) {
Context: model.StringInterface{
"reminder_id": model.NewId(),
"occurrence_id": model.NewId(),
"offset": 0,
},
}

Expand Down Expand Up @@ -859,7 +861,15 @@ func TestHandleDeleteCompleteList(t *testing.T) {
p.router = p.InitAPI()
p.API = api

request := &model.PostActionIntegrationRequest{UserId: "userID1", PostId: "postID1"}
request := &model.PostActionIntegrationRequest{
UserId: "userID1",
PostId: "postID1",
Context: model.StringInterface{
"reminder_id": model.NewId(),
"occurrence_id": model.NewId(),
"offset": 0,
},
}

w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/delete/complete/list", bytes.NewReader(request.ToJson()))
Expand Down Expand Up @@ -959,6 +969,7 @@ func TestHandleSnoozeList(t *testing.T) {
"reminder_id": model.NewId(),
"occurrence_id": model.NewId(),
"selected_option": test.SnoozeTime,
"offset": 0,
},
}

Expand Down
21 changes: 16 additions & 5 deletions server/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func (p *Plugin) UpdateListReminders(userId string, postId string, channelId str
activeReminderCount := len(reminders) - completedReminderCount
if offset < 0 {
offset = 0
} else if offset >= activeReminderCount {
offset = 0
}
endOffset := offset + RemindersPerPage - 1
if endOffset >= activeReminderCount {
Expand Down Expand Up @@ -187,7 +189,7 @@ func (p *Plugin) pagedOccurrences(
if len(upcomingOccurrences) > 0 {
for _, o := range upcomingOccurrences {
if offsetCount >= offset && offsetCount <= endOffset {
attachments = append(attachments, p.addAttachment(user, o, reminders, "upcoming"))
attachments = append(attachments, p.addAttachment(user, o, reminders, "upcoming", offset))
}
offsetCount += 1
}
Expand All @@ -196,7 +198,7 @@ func (p *Plugin) pagedOccurrences(
if len(recurringOccurrences) > 0 {
for _, o := range recurringOccurrences {
if offsetCount >= offset && offsetCount <= endOffset {
attachments = append(attachments, p.addAttachment(user, o, reminders, "recurring"))
attachments = append(attachments, p.addAttachment(user, o, reminders, "recurring", offset))
}
offsetCount += 1
}
Expand All @@ -205,15 +207,15 @@ func (p *Plugin) pagedOccurrences(
if len(pastOccurrences) > 0 {
for _, o := range pastOccurrences {
if offsetCount >= offset && offsetCount <= endOffset {
attachments = append(attachments, p.addAttachment(user, o, reminders, "past"))
attachments = append(attachments, p.addAttachment(user, o, reminders, "past", offset))
}
offsetCount += 1
}
}
if len(channelOccurrences) > 0 {
for _, o := range channelOccurrences {
if offsetCount >= offset && offsetCount <= endOffset {
attachments = append(attachments, p.addAttachment(user, o, reminders, "channel"))
attachments = append(attachments, p.addAttachment(user, o, reminders, "channel", offset))
}
offsetCount += 1
}
Expand Down Expand Up @@ -337,6 +339,7 @@ func (p *Plugin) listControl(
Integration: &model.PostActionIntegration{
Context: model.StringInterface{
"action": "delete/complete/list",
"offset": offset,
},
URL: fmt.Sprintf("%s/plugins/%s/delete/complete/list", p.URL, manifest.Id),
},
Expand Down Expand Up @@ -364,7 +367,7 @@ func (p *Plugin) listControl(
})
}

func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminders []Reminder, gType string) *model.SlackAttachment {
func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminders []Reminder, gType string, offset int) *model.SlackAttachment {

location := p.location(user)
T, _ := p.translation(user)
Expand Down Expand Up @@ -409,6 +412,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder
"reminder_id": reminder.Id,
"occurrence_id": occurrence.Id,
"action": "complete/list",
"offset": offset,
},
URL: fmt.Sprintf("%s/plugins/%s/complete/list", p.URL, manifest.Id),
},
Expand All @@ -421,6 +425,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder
"reminder_id": reminder.Id,
"occurrence_id": occurrence.Id,
"action": "delete/list",
"offset": offset,
},
URL: fmt.Sprintf("%s/plugins/%s/delete/list", p.URL, manifest.Id),
},
Expand All @@ -445,6 +450,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder
"reminder_id": reminder.Id,
"occurrence_id": occurrence.Id,
"action": "delete/list",
"offset": offset,
},
URL: fmt.Sprintf("%s/plugins/%s/delete/list", p.URL, manifest.Id),
},
Expand All @@ -469,6 +475,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder
"reminder_id": reminder.Id,
"occurrence_id": occurrence.Id,
"action": "complete/list",
"offset": offset,
},
URL: fmt.Sprintf("%s/plugins/%s/complete/list", p.URL, manifest.Id),
},
Expand All @@ -481,6 +488,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder
"reminder_id": reminder.Id,
"occurrence_id": occurrence.Id,
"action": "delete/list",
"offset": offset,
},
URL: fmt.Sprintf("%s/plugins/%s/delete/list", p.URL, manifest.Id),
},
Expand All @@ -493,6 +501,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder
"reminder_id": reminder.Id,
"occurrence_id": occurrence.Id,
"action": "snooze/list",
"offset": offset,
},
URL: fmt.Sprintf("%s/plugins/%s/snooze/list", p.URL, manifest.Id),
},
Expand Down Expand Up @@ -539,6 +548,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder
"reminder_id": reminder.Id,
"occurrence_id": occurrence.Id,
"action": "complete/list",
"offset": offset,
},
URL: fmt.Sprintf("%s/plugins/%s/complete/list", p.URL, manifest.Id),
},
Expand All @@ -551,6 +561,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder
"reminder_id": reminder.Id,
"occurrence_id": occurrence.Id,
"action": "delete/list",
"offset": offset,
},
URL: fmt.Sprintf("%s/plugins/%s/delete/list", p.URL, manifest.Id),
},
Expand Down

0 comments on commit ee30671

Please sign in to comment.