// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. package model import ( "encoding/json" "io" "github.com/pkg/errors" ) type ProductNotices []ProductNotice func (r *ProductNotices) Marshal() ([]byte, error) { return json.Marshal(r) } func UnmarshalProductNotices(data []byte) (ProductNotices, error) { var r ProductNotices err := json.Unmarshal(data, &r) return r, err } // List of product notices. Order is important and is used to resolve priorities. // Each notice will only be show if conditions are met. type ProductNotice struct { Conditions Conditions `json:"conditions"` ID string `json:"id"` // Unique identifier for this notice. Can be a running number. Used for storing 'viewed'; state on the server. LocalizedMessages map[string]NoticeMessageInternal `json:"localizedMessages"` // Notice message data, organized by locale.; Example:; "localizedMessages": {; "en": { "title": "English", description: "English description"},; "frFR": { "title": "Frances", description: "French description"}; } Repeatable *bool `json:"repeatable,omitempty"` // Configurable flag if the notice should reappear after it’s seen and dismissed } func (n *ProductNotice) SysAdminOnly() bool { return n.Conditions.Audience != nil && *n.Conditions.Audience == NoticeAudienceSysadmin } func (n *ProductNotice) TeamAdminOnly() bool { return n.Conditions.Audience != nil && *n.Conditions.Audience == NoticeAudienceTeamAdmin } type Conditions struct { Audience *NoticeAudience `json:"audience,omitempty"` ClientType *NoticeClientType `json:"clientType,omitempty"` // Only show the notice on specific clients. Defaults to 'all' DesktopVersion []string `json:"desktopVersion,omitempty"` // What desktop client versions does this notice apply to.; Format: semver ranges (https://devhints.io/semver); Example: [">=1.2.3 < ~2.4.x"]; Example: ["= 2020-03-01T00:00:00Z" - show after specified date; "< 2020-03-01T00:00:00Z" - show before the specified date; "> 2020-03-01T00:00:00Z <= 2020-04-01T00:00:00Z" - show only between the specified dates InstanceType *NoticeInstanceType `json:"instanceType,omitempty"` MobileVersion []string `json:"mobileVersion,omitempty"` // What mobile client versions does this notice apply to.; Format: semver ranges (https://devhints.io/semver); Example: [">=1.2.3 < ~2.4.x"]; Example: ["=1.2.3 < ~2.4.x"]; Example: ["