TimelineContent set timeline notification
(code string, title string, ts *time.Time, items []*MsgTimeItem)
| 53 | |
| 54 | // TimelineContent set timeline notification |
| 55 | func (m *Message) TimelineContent(code string, title string, ts *time.Time, items []*MsgTimeItem) *Message { |
| 56 | tis := []*pb.TimeItem{} |
| 57 | for _, item := range items { |
| 58 | ti := &pb.TimeItem{Name: item.Name} |
| 59 | switch v := item.Value.(type) { |
| 60 | case int: |
| 61 | ti.ValueType = pb.ValueType_ValueTypeInteger |
| 62 | ti.IntegerValue = int64(v) |
| 63 | case int64: |
| 64 | ti.ValueType = pb.ValueType_ValueTypeInteger |
| 65 | ti.IntegerValue = v |
| 66 | case float64: |
| 67 | ti.ValueType = pb.ValueType_ValueTypeDouble |
| 68 | ti.DoubleValue = v |
| 69 | default: |
| 70 | continue |
| 71 | } |
| 72 | tis = append(tis, ti) |
| 73 | } |
| 74 | if ts == nil { |
| 75 | var t = time.Now() |
| 76 | ts = &t |
| 77 | } |
| 78 | ctx := &pb.MsgContent{ |
| 79 | Type: pb.MsgType_Timeline, |
| 80 | Title: title, |
| 81 | TimeContent: &pb.TimeContent{ |
| 82 | Code: code, |
| 83 | Timestamp: uint64(ts.UTC().UnixNano() / 1e6), |
| 84 | TimeItems: tis, |
| 85 | }, |
| 86 | } |
| 87 | m.Content, _ = proto.Marshal(ctx) |
| 88 | m.isTimeline = true |
| 89 | return m |
| 90 | } |
| 91 | |
| 92 | // TextContent set text notification |
| 93 | func (m *Message) TextContent(text string, title string, copytext string, autocopy string) *Message { |