summaryrefslogtreecommitdiffstats
path: root/api/import.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-07-07 09:16:13 -0400
committerChristopher Speller <crspeller@gmail.com>2015-08-19 08:52:49 -0400
commitd78ebab108942058a100e0f607771c4addafb698 (patch)
treee15ea58c83979e003556e063460368f509a5ebd5 /api/import.go
parent7004a348b59d5572e8c84eb1c8138bf45cbd0d3e (diff)
downloadchat-d78ebab108942058a100e0f607771c4addafb698.tar.gz
chat-d78ebab108942058a100e0f607771c4addafb698.tar.bz2
chat-d78ebab108942058a100e0f607771c4addafb698.zip
Implemention of slack import feature.
Diffstat (limited to 'api/import.go')
-rw-r--r--api/import.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/api/import.go b/api/import.go
new file mode 100644
index 000000000..e3f314d20
--- /dev/null
+++ b/api/import.go
@@ -0,0 +1,57 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package api
+
+import (
+ l4g "code.google.com/p/log4go"
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/utils"
+)
+
+//
+// Import functions are sutible for entering posts and users into the database without
+// some of the usual checks. (IsValid is still run)
+//
+
+func ImportPost(post *model.Post) {
+ post.Hashtags, _ = model.ParseHashtags(post.Message)
+
+ if result := <-Srv.Store.Post().Save(post); result.Err != nil {
+ l4g.Debug("Error saving post. user=" + post.UserId + ", message=" + post.Message)
+ }
+}
+
+func ImportUser(user *model.User) *model.User {
+ user.MakeNonNil()
+ if len(user.Props["theme"]) == 0 {
+ user.AddProp("theme", utils.Cfg.TeamSettings.DefaultThemeColor)
+ }
+
+ if result := <-Srv.Store.User().Save(user); result.Err != nil {
+ l4g.Error("Error saving user. err=%v", result.Err)
+ return nil
+ } else {
+ ruser := result.Data.(*model.User)
+
+ if err := JoinDefaultChannels(ruser, ""); err != nil {
+ l4g.Error("Encountered an issue joining default channels user_id=%s, team_id=%s, err=%v", ruser.Id, ruser.TeamId, err)
+ }
+
+ if cresult := <-Srv.Store.User().VerifyEmail(ruser.Id); cresult.Err != nil {
+ l4g.Error("Failed to set email verified err=%v", cresult.Err)
+ }
+
+ return ruser
+ }
+}
+
+func ImportChannel(channel *model.Channel) *model.Channel {
+ if result := <-Srv.Store.Channel().Save(channel); result.Err != nil {
+ return nil
+ } else {
+ sc := result.Data.(*model.Channel)
+
+ return sc
+ }
+}