github.com/haalcala/mattermost-server-change-repo/v5@v5.33.2/model/thread.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"encoding/json"
     8  )
     9  
    10  type 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  
    18  type 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  
    29  type 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  
    36  type 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  
    59  func (o *ThreadResponse) ToJson() string {
    60  	b, _ := json.Marshal(o)
    61  	return string(b)
    62  }
    63  
    64  func (o *Threads) ToJson() string {
    65  	b, _ := json.Marshal(o)
    66  	return string(b)
    67  }
    68  
    69  func (o *Thread) ToJson() string {
    70  	b, _ := json.Marshal(o)
    71  	return string(b)
    72  }
    73  
    74  func ThreadFromJson(s string) (*Thread, error) {
    75  	var t Thread
    76  	err := json.Unmarshal([]byte(s), &t)
    77  	return &t, err
    78  }
    79  
    80  func (o *Thread) Etag() string {
    81  	return Etag(o.PostId, o.LastReplyAt)
    82  }
    83  
    84  type ThreadMembership struct {
    85  	PostId         string `json:"post_id"`
    86  	UserId         string `json:"user_id"`
    87  	Following      bool   `json:"following"`
    88  	LastViewed     int64  `json:"last_view_at"`
    89  	LastUpdated    int64  `json:"last_update_at"`
    90  	UnreadMentions int64  `json:"unread_mentions"`
    91  }
    92  
    93  func (o *ThreadMembership) ToJson() string {
    94  	b, _ := json.Marshal(o)
    95  	return string(b)
    96  }