mirror of
https://github.com/mattermost/mattermost.git
synced 2026-04-21 06:07:03 -04:00
40 lines
997 B
Go
40 lines
997 B
Go
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||
|
|
// See LICENSE.txt for license information.
|
||
|
|
|
||
|
|
package model
|
||
|
|
|
||
|
|
import "errors"
|
||
|
|
|
||
|
|
type TemporaryPost struct {
|
||
|
|
ID string `json:"id"`
|
||
|
|
Type string `json:"type"`
|
||
|
|
ExpireAt int64 `json:"expire_at"`
|
||
|
|
Message string `json:"message"`
|
||
|
|
FileIDs StringArray `json:"file_ids"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (o *TemporaryPost) IsValid() error {
|
||
|
|
if o.ID == "" {
|
||
|
|
return errors.New("id is required")
|
||
|
|
}
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// CreateTemporaryPost creates a temporary post from a post object. The post is modified in place.
|
||
|
|
// It returns the temporary post and the post object with the message and file ids removed.
|
||
|
|
func CreateTemporaryPost(post *Post, expireAt int64) (*TemporaryPost, *Post, error) {
|
||
|
|
temporaryPost := &TemporaryPost{
|
||
|
|
ID: post.Id,
|
||
|
|
Type: post.Type,
|
||
|
|
ExpireAt: expireAt,
|
||
|
|
Message: post.Message,
|
||
|
|
FileIDs: post.FileIds,
|
||
|
|
}
|
||
|
|
|
||
|
|
post.FileIds = []string{}
|
||
|
|
post.Message = ""
|
||
|
|
|
||
|
|
return temporaryPost, post, nil
|
||
|
|
}
|