summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2016-12-02 13:13:15 +0000
committerJoram Wilander <jwawilander@gmail.com>2016-12-02 08:13:15 -0500
commit275188ad040864823764deb8a71c1e85c9ef00b2 (patch)
treef4a26571daeaeb1b7edf67f9c05a162cdd7faa32 /api
parentc51afba71a8d4614f74709d5e9c432c2cff3fcf7 (diff)
downloadchat-275188ad040864823764deb8a71c1e85c9ef00b2.tar.gz
chat-275188ad040864823764deb8a71c1e85c9ef00b2.tar.bz2
chat-275188ad040864823764deb8a71c1e85c9ef00b2.zip
PLT-4839 Split too-long Slack messages on import. (#4679)
* PLT-4839 Split too-long Slack messages on import. This PR also takes the opportunity to make the max values for Post properties into constants for easier use elsewhere, as has previously been done for Channel properties. * Only count runes once.
Diffstat (limited to 'api')
-rw-r--r--api/import.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/api/import.go b/api/import.go
index 570444464..63dfb033d 100644
--- a/api/import.go
+++ b/api/import.go
@@ -7,6 +7,7 @@ import (
"bytes"
"io"
"regexp"
+ "unicode/utf8"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
@@ -19,10 +20,24 @@ import (
//
func ImportPost(post *model.Post) {
- post.Hashtags, _ = model.ParseHashtags(post.Message)
+ for messageRuneCount := utf8.RuneCountInString(post.Message); messageRuneCount > 0; messageRuneCount = utf8.RuneCountInString(post.Message) {
+ var remainder string
+ if messageRuneCount > model.POST_MESSAGE_MAX_RUNES {
+ remainder = string(([]rune(post.Message))[model.POST_MESSAGE_MAX_RUNES:])
+ post.Message = truncateRunes(post.Message, model.POST_MESSAGE_MAX_RUNES)
+ } else {
+ remainder = ""
+ }
+
+ post.Hashtags, _ = model.ParseHashtags(post.Message)
+
+ if result := <-Srv.Store.Post().Save(post); result.Err != nil {
+ l4g.Debug(utils.T("api.import.import_post.saving.debug"), post.UserId, post.Message)
+ }
- if result := <-Srv.Store.Post().Save(post); result.Err != nil {
- l4g.Debug(utils.T("api.import.import_post.saving.debug"), post.UserId, post.Message)
+ post.Id = ""
+ post.CreateAt++
+ post.Message = remainder
}
}