summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api4/file.go1
-rw-r--r--app/import_functions.go8
-rw-r--r--app/import_functions_test.go54
3 files changed, 60 insertions, 3 deletions
diff --git a/api4/file.go b/api4/file.go
index f73a54fb4..cfb72cdcb 100644
--- a/api4/file.go
+++ b/api4/file.go
@@ -285,6 +285,7 @@ func getFilePreview(c *Context, w http.ResponseWriter, r *http.Request) {
if err != nil {
c.Err = err
c.Err.StatusCode = http.StatusNotFound
+ return
}
defer fileReader.Close()
diff --git a/app/import_functions.go b/app/import_functions.go
index f4ff5607f..e370099d9 100644
--- a/app/import_functions.go
+++ b/app/import_functions.go
@@ -763,7 +763,7 @@ func (a *App) ImportReply(data *ReplyImportData, post *model.Post, teamId string
var reply *model.Post
for _, r := range replies {
- if r.Message == *data.Message {
+ if r.Message == *data.Message && r.RootId == post.Id {
reply = r
break
}
@@ -784,7 +784,7 @@ func (a *App) ImportReply(data *ReplyImportData, post *model.Post, teamId string
if err != nil {
return err
}
- reply.FileIds = fileIds
+ reply.FileIds = append(reply.FileIds, fileIds...)
}
if reply.Id == "" {
@@ -820,6 +820,8 @@ func (a *App) ImportAttachment(data *AttachmentImportData, post *model.Post, tea
return nil, fileUploadError
}
+ a.HandleImages([]string{fileInfo.PreviewPath}, []string{fileInfo.ThumbnailPath}, [][]byte{buf.Bytes()})
+
mlog.Info(fmt.Sprintf("uploading file with name %s", file.Name()))
return fileInfo, nil
}
@@ -889,7 +891,7 @@ func (a *App) ImportPost(data *PostImportData, dryRun bool) *model.AppError {
if err != nil {
return err
}
- post.FileIds = fileIds
+ post.FileIds = append(post.FileIds, fileIds...)
}
if post.Id == "" {
diff --git a/app/import_functions_test.go b/app/import_functions_test.go
index e0859af45..fd8ae462e 100644
--- a/app/import_functions_test.go
+++ b/app/import_functions_test.go
@@ -1700,6 +1700,60 @@ func TestImportImportPost(t *testing.T) {
}
}
}
+
+ // Update post with replies.
+ data = &PostImportData{
+ Team: &teamName,
+ Channel: &channelName,
+ User: &user2.Username,
+ Message: ptrStr("Message with reply"),
+ CreateAt: &replyPostTime,
+ Replies: &[]ReplyImportData{{
+ User: &username,
+ Message: ptrStr("Message reply"),
+ CreateAt: &replyTime,
+ }},
+ }
+ if err := th.App.ImportPost(data, false); err != nil {
+ t.Fatalf("Expected success.")
+ }
+ AssertAllPostsCount(t, th.App, initialPostCount, 8, team.Id)
+
+ // Create new post with replies based on the previous one.
+ data = &PostImportData{
+ Team: &teamName,
+ Channel: &channelName,
+ User: &user2.Username,
+ Message: ptrStr("Message with reply 2"),
+ CreateAt: &replyPostTime,
+ Replies: &[]ReplyImportData{{
+ User: &username,
+ Message: ptrStr("Message reply"),
+ CreateAt: &replyTime,
+ }},
+ }
+ if err := th.App.ImportPost(data, false); err != nil {
+ t.Fatalf("Expected success.")
+ }
+ AssertAllPostsCount(t, th.App, initialPostCount, 10, team.Id)
+
+ // Create new reply for existing post with replies.
+ data = &PostImportData{
+ Team: &teamName,
+ Channel: &channelName,
+ User: &user2.Username,
+ Message: ptrStr("Message with reply"),
+ CreateAt: &replyPostTime,
+ Replies: &[]ReplyImportData{{
+ User: &username,
+ Message: ptrStr("Message reply 2"),
+ CreateAt: &replyTime,
+ }},
+ }
+ if err := th.App.ImportPost(data, false); err != nil {
+ t.Fatalf("Expected success.")
+ }
+ AssertAllPostsCount(t, th.App, initialPostCount, 11, team.Id)
}
func TestImportImportDirectChannel(t *testing.T) {