diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2015-10-13 18:23:53 -0400 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2015-10-13 18:23:53 -0400 |
commit | 56b02f2ebab6646b1d978b8f873d4949670967e2 (patch) | |
tree | 687fa2ccd73e1e122a56a3b9c9deedc18096bcbf /model/preference.go | |
parent | 998b5f7e11ac07a482e88f5d3ef4fd726cf0c99a (diff) | |
parent | 97b2f6ffe7fa09a2188163740865322582b00b59 (diff) | |
download | chat-56b02f2ebab6646b1d978b8f873d4949670967e2.tar.gz chat-56b02f2ebab6646b1d978b8f873d4949670967e2.tar.bz2 chat-56b02f2ebab6646b1d978b8f873d4949670967e2.zip |
Merge pull request #968 from hmhealey/plt322
PLT-322 Updated Direct Messages menu
Diffstat (limited to 'model/preference.go')
-rw-r--r-- | model/preference.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/model/preference.go b/model/preference.go new file mode 100644 index 000000000..44279f71a --- /dev/null +++ b/model/preference.go @@ -0,0 +1,60 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "encoding/json" + "io" +) + +const ( + PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW = "direct_channel_show" +) + +type Preference struct { + UserId string `json:"user_id"` + Category string `json:"category"` + Name string `json:"name"` + Value string `json:"value"` +} + +func (o *Preference) ToJson() string { + b, err := json.Marshal(o) + if err != nil { + return "" + } else { + return string(b) + } +} + +func PreferenceFromJson(data io.Reader) *Preference { + decoder := json.NewDecoder(data) + var o Preference + err := decoder.Decode(&o) + if err == nil { + return &o + } else { + return nil + } +} + +func (o *Preference) IsValid() *AppError { + if len(o.UserId) != 26 { + return NewAppError("Preference.IsValid", "Invalid user id", "user_id="+o.UserId) + } + + if len(o.Category) == 0 || len(o.Category) > 32 { + return NewAppError("Preference.IsValid", "Invalid category", "category="+o.Category) + } + + if len(o.Name) == 0 || len(o.Name) > 32 { + return NewAppError("Preference.IsValid", "Invalid name", "name="+o.Name) + } + + if len(o.Value) > 128 { + return NewAppError("Preference.IsValid", "Value is too long", "value="+o.Value) + } + + return nil +} |