1// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
2// See LICENSE.txt for license information.
3
4package model
5
6import (
7	"encoding/json"
8)
9
10type Thread struct {
11	PostId       string      `json:"id"`
12	ChannelId    string      `json:"channel_id"`
13	ReplyCount   int64       `json:"reply_count"`
14	LastReplyAt  int64       `json:"last_reply_at"`
15	Participants StringArray `json:"participants"`
16}
17
18type ThreadResponse struct {
19	PostId         string  `json:"id"`
20	ReplyCount     int64   `json:"reply_count"`
21	LastReplyAt    int64   `json:"last_reply_at"`
22	LastViewedAt   int64   `json:"last_viewed_at"`
23	Participants   []*User `json:"participants"`
24	Post           *Post   `json:"post"`
25	UnreadReplies  int64   `json:"unread_replies"`
26	UnreadMentions int64   `json:"unread_mentions"`
27}
28
29type Threads struct {
30	Total               int64             `json:"total"`
31	TotalUnreadThreads  int64             `json:"total_unread_threads"`
32	TotalUnreadMentions int64             `json:"total_unread_mentions"`
33	Threads             []*ThreadResponse `json:"threads"`
34}
35
36type GetUserThreadsOpts struct {
37	// PageSize specifies the size of the returned chunk of results. Default = 30
38	PageSize uint64
39
40	// Extended will enrich the response with participant details. Default = false
41	Extended bool
42
43	// Deleted will specify that even deleted threads should be returned (For mobile sync). Default = false
44	Deleted bool
45
46	// Since filters the threads based on their LastUpdateAt timestamp.
47	Since uint64
48
49	// Before specifies thread id as a cursor for pagination and will return `PageSize` threads before the cursor
50	Before string
51
52	// After specifies thread id as a cursor for pagination and will return `PageSize` threads after the cursor
53	After string
54
55	// Unread will make sure that only threads with unread replies are returned
56	Unread bool
57
58	// TotalsOnly will not fetch any threads and just fetch the total counts
59	TotalsOnly bool
60
61	// TeamOnly will only fetch threads and unreads for the specified team and excludes DMs/GMs
62	TeamOnly bool
63}
64
65func (o *ThreadResponse) ToJson() string {
66	b, _ := json.Marshal(o)
67	return string(b)
68}
69
70func ThreadResponseFromJson(s string) (*ThreadResponse, error) {
71	var t ThreadResponse
72	err := json.Unmarshal([]byte(s), &t)
73	return &t, err
74}
75
76func (o *Threads) ToJson() string {
77	b, _ := json.Marshal(o)
78	return string(b)
79}
80
81func (o *Thread) ToJson() string {
82	b, _ := json.Marshal(o)
83	return string(b)
84}
85
86func ThreadFromJson(s string) (*Thread, error) {
87	var t Thread
88	err := json.Unmarshal([]byte(s), &t)
89	return &t, err
90}
91
92func (o *Thread) Etag() string {
93	return Etag(o.PostId, o.LastReplyAt)
94}
95
96type ThreadMembership struct {
97	PostId         string `json:"post_id"`
98	UserId         string `json:"user_id"`
99	Following      bool   `json:"following"`
100	LastViewed     int64  `json:"last_view_at"`
101	LastUpdated    int64  `json:"last_update_at"`
102	UnreadMentions int64  `json:"unread_mentions"`
103}
104
105func (o *ThreadMembership) ToJson() string {
106	b, _ := json.Marshal(o)
107	return string(b)
108}
109