github.com/haalcala/mattermost-server-change-repo/v5@v5.33.2/model/command_args.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  	"io"
     9  
    10  	goi18n "github.com/mattermost/go-i18n/i18n"
    11  )
    12  
    13  type CommandArgs struct {
    14  	UserId          string               `json:"user_id"`
    15  	ChannelId       string               `json:"channel_id"`
    16  	TeamId          string               `json:"team_id"`
    17  	RootId          string               `json:"root_id"`
    18  	ParentId        string               `json:"parent_id"`
    19  	TriggerId       string               `json:"trigger_id,omitempty"`
    20  	Command         string               `json:"command"`
    21  	SiteURL         string               `json:"-"`
    22  	T               goi18n.TranslateFunc `json:"-"`
    23  	UserMentions    UserMentionMap       `json:"-"`
    24  	ChannelMentions ChannelMentionMap    `json:"-"`
    25  
    26  	// DO NOT USE Session field is deprecated. MM-26398
    27  	Session Session `json:"-"`
    28  }
    29  
    30  func (o *CommandArgs) ToJson() string {
    31  	b, _ := json.Marshal(o)
    32  	return string(b)
    33  }
    34  
    35  func CommandArgsFromJson(data io.Reader) *CommandArgs {
    36  	var o *CommandArgs
    37  	json.NewDecoder(data).Decode(&o)
    38  	return o
    39  }
    40  
    41  // AddUserMention adds or overrides an entry in UserMentions with name username
    42  // and identifier userId
    43  func (o *CommandArgs) AddUserMention(username, userId string) {
    44  	if o.UserMentions == nil {
    45  		o.UserMentions = make(UserMentionMap)
    46  	}
    47  
    48  	o.UserMentions[username] = userId
    49  }
    50  
    51  // AddChannelMention adds or overrides an entry in ChannelMentions with name
    52  // channelName and identifier channelId
    53  func (o *CommandArgs) AddChannelMention(channelName, channelId string) {
    54  	if o.ChannelMentions == nil {
    55  		o.ChannelMentions = make(ChannelMentionMap)
    56  	}
    57  
    58  	o.ChannelMentions[channelName] = channelId
    59  }