-
Notifications
You must be signed in to change notification settings - Fork 102
/
background.go
executable file
·79 lines (68 loc) · 2.69 KB
/
background.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// AUTOGENERATED - DO NOT EDIT
package tdlib
import (
"encoding/json"
)
// Background Describes a chat background
type Background struct {
tdCommon
ID JSONInt64 `json:"id"` // Unique background identifier
IsDefault bool `json:"is_default"` // True, if this is one of default backgrounds
IsDark bool `json:"is_dark"` // True, if the background is dark and is recommended to be used with dark theme
Name string `json:"name"` // Unique background name
Document *Document `json:"document"` // Document with the background; may be null. Null only for filled backgrounds
Type BackgroundType `json:"type"` // Type of the background
}
// MessageType return the string telegram-type of Background
func (background *Background) MessageType() string {
return "background"
}
// NewBackground creates a new Background
//
// @param iD Unique background identifier
// @param isDefault True, if this is one of default backgrounds
// @param isDark True, if the background is dark and is recommended to be used with dark theme
// @param name Unique background name
// @param document Document with the background; may be null. Null only for filled backgrounds
// @param typeParam Type of the background
func NewBackground(iD JSONInt64, isDefault bool, isDark bool, name string, document *Document, typeParam BackgroundType) *Background {
backgroundTemp := Background{
tdCommon: tdCommon{Type: "background"},
ID: iD,
IsDefault: isDefault,
IsDark: isDark,
Name: name,
Document: document,
Type: typeParam,
}
return &backgroundTemp
}
// UnmarshalJSON unmarshal to json
func (background *Background) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
tempObj := struct {
tdCommon
ID JSONInt64 `json:"id"` // Unique background identifier
IsDefault bool `json:"is_default"` // True, if this is one of default backgrounds
IsDark bool `json:"is_dark"` // True, if the background is dark and is recommended to be used with dark theme
Name string `json:"name"` // Unique background name
Document *Document `json:"document"` // Document with the background; may be null. Null only for filled backgrounds
}{}
err = json.Unmarshal(b, &tempObj)
if err != nil {
return err
}
background.tdCommon = tempObj.tdCommon
background.ID = tempObj.ID
background.IsDefault = tempObj.IsDefault
background.IsDark = tempObj.IsDark
background.Name = tempObj.Name
background.Document = tempObj.Document
fieldType, _ := unmarshalBackgroundType(objMap["type"])
background.Type = fieldType
return nil
}