diff --git a/mattermost/server/bathroom-linux-amd64 b/mattermost/server/bathroom-linux-amd64 index 4a5b7d9..542b2a5 100755 --- a/mattermost/server/bathroom-linux-amd64 +++ b/mattermost/server/bathroom-linux-amd64 Binary files differ diff --git a/mattermost/server/bathroom-linux-amd64 b/mattermost/server/bathroom-linux-amd64 index 4a5b7d9..542b2a5 100755 --- a/mattermost/server/bathroom-linux-amd64 +++ b/mattermost/server/bathroom-linux-amd64 Binary files differ diff --git a/mattermost/server/bathroom.go b/mattermost/server/bathroom.go index 5be0d1c..a540998 100644 --- a/mattermost/server/bathroom.go +++ b/mattermost/server/bathroom.go @@ -56,6 +56,16 @@ return "", errors.New(fmt.Sprintf("Invalid status %d", status)) } +type UserOptions struct { + ShowWidget bool `json:"show_widget"` +} + +func defaultUserOptions() *UserOptions { + return &UserOptions { + ShowWidget: true, + } +} + type DoorRequest struct { ip string time int64 @@ -247,9 +257,9 @@ } func (p *BathroomMonitorPlugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) { - auth, ok := r.Header["Mattermost-User-Id"] + auth, authOk := r.Header["Mattermost-User-Id"] var authUser string = "" - if ok && len(auth) > 0 { + if authOk && len(auth) > 0 { authUser = auth[0] } p.log(fmt.Sprintf("Requested path: %s %s AUTH: %s", r.URL.Path, c.IpAddress, authUser)) @@ -258,7 +268,20 @@ p.configLock.Lock() defer p.configLock.Unlock() - bytes, err := json.Marshal(p.config.settingsJson) + retMap := make(map[string]interface{}) + for k, v := range p.config.settingsJson { + retMap[k] = v + } + + userOptions := defaultUserOptions() + + if authOk { + p.Helpers.KVGetJSON("settings_" + authUser, userOptions) + } + + retMap["user"] = userOptions + + bytes, err := json.Marshal(retMap) if err == nil { fmt.Fprint(w, string(bytes)) } else { @@ -643,8 +666,18 @@ } } +func (p *BathroomMonitorPlugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) { + userOptions := defaultUserOptions() + +} func (p *BathroomMonitorPlugin) OnActivate() error { + p.API.RegisterCommand(&model.Command { + Trigger: "bathrooms", + AutoComplete: true, + AutoCompleteDesc: "Turns the bathroom widget \"on\" or \"off\" (\"status\" or no option prints bathroom statuses)", + AutoCompleteHint: "(on|off|status)", + }) if p.bot == nil { botUser, err := p.Helpers.EnsureBot(&model.Bot{Username:"bathroom-bot", DisplayName:"Bathroom Bot", Description:"Tracks Bathroom Status"}); if err == nil {