github.com/jlevesy/mattermost-server@v5.3.2-0.20181003190404-7468f35cb0c8+incompatible/app/auto_responder.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package app 5 6 import ( 7 "github.com/mattermost/mattermost-server/mlog" 8 "github.com/mattermost/mattermost-server/model" 9 ) 10 11 func (a *App) SendAutoResponse(channel *model.Channel, receiver *model.User, rootId string) { 12 if receiver == nil || receiver.NotifyProps == nil { 13 return 14 } 15 16 active := receiver.NotifyProps["auto_responder_active"] == "true" 17 message := receiver.NotifyProps["auto_responder_message"] 18 19 if active && message != "" { 20 autoResponderPost := &model.Post{ 21 ChannelId: channel.Id, 22 Message: message, 23 RootId: rootId, 24 ParentId: rootId, 25 Type: model.POST_AUTO_RESPONDER, 26 UserId: receiver.Id, 27 } 28 29 if _, err := a.CreatePost(autoResponderPost, channel, false); err != nil { 30 mlog.Error(err.Error()) 31 } 32 } 33 } 34 35 func (a *App) SetAutoResponderStatus(user *model.User, oldNotifyProps model.StringMap) { 36 active := user.NotifyProps["auto_responder_active"] == "true" 37 oldActive := oldNotifyProps["auto_responder_active"] == "true" 38 39 autoResponderEnabled := !oldActive && active 40 autoResponderDisabled := oldActive && !active 41 42 if autoResponderEnabled { 43 a.SetStatusOutOfOffice(user.Id) 44 } else if autoResponderDisabled { 45 a.SetStatusOnline(user.Id, true) 46 } 47 } 48 49 func (a *App) DisableAutoResponder(userId string, asAdmin bool) *model.AppError { 50 user, err := a.GetUser(userId) 51 if err != nil { 52 return err 53 } 54 55 active := user.NotifyProps["auto_responder_active"] == "true" 56 57 if active { 58 patch := &model.UserPatch{} 59 patch.NotifyProps = user.NotifyProps 60 patch.NotifyProps["auto_responder_active"] = "false" 61 62 _, err := a.PatchUser(userId, patch, asAdmin) 63 if err != nil { 64 return err 65 } 66 } 67 68 return nil 69 }