github.com/masterhung0112/hk_server/v5@v5.0.0-20220302090640-ec71aef15e1c/services/sharedchannel/msg.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package sharedchannel
     5  
     6  import (
     7  	"encoding/json"
     8  
     9  	"github.com/masterhung0112/hk_server/v5/model"
    10  )
    11  
    12  // syncMsg represents a change in content (post add/edit/delete, reaction add/remove, users).
    13  // It is sent to remote clusters as the payload of a `RemoteClusterMsg`.
    14  type syncMsg struct {
    15  	Id        string                 `json:"id"`
    16  	ChannelId string                 `json:"channel_id"`
    17  	Users     map[string]*model.User `json:"users,omitempty"`
    18  	Posts     []*model.Post          `json:"posts,omitempty"`
    19  	Reactions []*model.Reaction      `json:"reactions,omitempty"`
    20  }
    21  
    22  func newSyncMsg(channelID string) *syncMsg {
    23  	return &syncMsg{
    24  		Id:        model.NewId(),
    25  		ChannelId: channelID,
    26  	}
    27  }
    28  
    29  func (sm *syncMsg) ToJSON() ([]byte, error) {
    30  	b, err := json.Marshal(sm)
    31  	if err != nil {
    32  		return nil, err
    33  	}
    34  	return b, nil
    35  }
    36  
    37  func (sm *syncMsg) String() string {
    38  	json, err := sm.ToJSON()
    39  	if err != nil {
    40  		return ""
    41  	}
    42  	return string(json)
    43  }