mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* Posts * Add missing translation * Fix internal store marshaling * [MM-22051] Remove To/From JSON (Channels) (#18116) * Channels * Channel members * ChannelSearch * Channel categories, list, sidebar, stats, view * Fix conversions * [MM-22051] Remove To/From JSON (Users) (#18121) * User related structs * Fix return * Team related structures (#18127) * [MM-22051] Remove To/From JSON (Status, Bot, Reaction, Thread, FileInfo) (#18130) * Status * Bot * Reaction * Thread * FileInfo * Some fixes * Translations update from Weblate (#18143) * Translated using Weblate (German) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2309 of 2309 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ Update translation files Updated by "Cleanup translation files" hook in Weblate. Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ * Translated using Weblate (German) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/de/ * Translated using Weblate (Turkish) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/tr/ * Translated using Weblate (Hungarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/hu/ * Translated using Weblate (English (Australia)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/en_AU/ * Translated using Weblate (Bulgarian) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/bg/ * Translated using Weblate (Japanese) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/ja/ * Translated using Weblate (Chinese (Simplified)) Currently translated at 100.0% (2301 of 2301 strings) Translation: mattermost-languages-shipped/mattermost-server Translate-URL: https://translate.mattermost.com/projects/mattermost/mattermost-server_master/zh_Hans/ Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> * [MM-22051] Remove To/From JSON methods from model (#18138) * Scheme * Role * Session * Config * Status * Fix logic * Emoji * GuestsInvite * Group * Command * ClusterInfo * License * Job * System * Plugin * Command2 * IncomingWebhook * OutgoingWebhook * Fix tests * Update traslation * Some fixes * Add missing return * Simplify * Make Config.ToJSONFiltered() return []byte * Make Busy.ToJSON() return []byte * Include error in log * Split logic * [MM-22051] Remove To/From JSON (final) (#18150) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * [MM-23280] Fix linting for ToJSON/FromJSON (#18153) * SwitchRequest * PluginEventData * Permalink * PushNotification * SuggestCommand * PluginsResponse * WebSocketMessage * RemoteCluster * SharedChannel * PluginStatuses * InitialLoad * ClusterDiscovery * ClusterStats * MfaSecret * GroupSyncable * SAML * WebSocketRequest * TypingRequest * SecurityBulletin * OAuthApp * IntegrationAction * DataRetention * Preference * FileInfoList * Compliance * Preferences * FileInfoSearchResults * TermsOfService * InstallMarketplacePluginRequest * GitLabUser * UploadSessions * Remove unused helpers * Fix tests * Fix linting for ToJSON/FromJSON * Fix conversions Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: JtheBAB <srast@bioc.uzh.ch> Co-authored-by: Kaya Zeren <kayazeren@gmail.com> Co-authored-by: Tóth Csaba // Online ERP Hungary Kft <csaba.toth@online-erp.hu> Co-authored-by: Matthew Williams <Matthew.Williams@outlook.com.au> Co-authored-by: Nikolai Zahariev <nikolaiz@yahoo.com> Co-authored-by: kaakaa <stooner.hoe@gmail.com> Co-authored-by: aeomin <lin@aeomin.net> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
178 lines
3.2 KiB
Go
178 lines
3.2 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"sort"
|
|
)
|
|
|
|
type PostList struct {
|
|
Order []string `json:"order"`
|
|
Posts map[string]*Post `json:"posts"`
|
|
NextPostId string `json:"next_post_id"`
|
|
PrevPostId string `json:"prev_post_id"`
|
|
}
|
|
|
|
func NewPostList() *PostList {
|
|
return &PostList{
|
|
Order: make([]string, 0),
|
|
Posts: make(map[string]*Post),
|
|
NextPostId: "",
|
|
PrevPostId: "",
|
|
}
|
|
}
|
|
|
|
func (o *PostList) Clone() *PostList {
|
|
orderCopy := make([]string, len(o.Order))
|
|
postsCopy := make(map[string]*Post)
|
|
for i, v := range o.Order {
|
|
orderCopy[i] = v
|
|
}
|
|
for k, v := range o.Posts {
|
|
postsCopy[k] = v.Clone()
|
|
}
|
|
return &PostList{
|
|
Order: orderCopy,
|
|
Posts: postsCopy,
|
|
NextPostId: o.NextPostId,
|
|
PrevPostId: o.PrevPostId,
|
|
}
|
|
}
|
|
|
|
func (o *PostList) ToSlice() []*Post {
|
|
var posts []*Post
|
|
|
|
if l := len(o.Posts); l > 0 {
|
|
posts = make([]*Post, 0, l)
|
|
}
|
|
|
|
for _, id := range o.Order {
|
|
posts = append(posts, o.Posts[id])
|
|
}
|
|
return posts
|
|
}
|
|
|
|
func (o *PostList) WithRewrittenImageURLs(f func(string) string) *PostList {
|
|
copy := *o
|
|
copy.Posts = make(map[string]*Post)
|
|
for id, post := range o.Posts {
|
|
copy.Posts[id] = post.WithRewrittenImageURLs(f)
|
|
}
|
|
return ©
|
|
}
|
|
|
|
func (o *PostList) StripActionIntegrations() {
|
|
posts := o.Posts
|
|
o.Posts = make(map[string]*Post)
|
|
for id, post := range posts {
|
|
pcopy := post.Clone()
|
|
pcopy.StripActionIntegrations()
|
|
o.Posts[id] = pcopy
|
|
}
|
|
}
|
|
|
|
func (o *PostList) ToJSON() (string, error) {
|
|
copy := *o
|
|
copy.StripActionIntegrations()
|
|
b, err := json.Marshal(©)
|
|
return string(b), err
|
|
}
|
|
|
|
func (o *PostList) MakeNonNil() {
|
|
if o.Order == nil {
|
|
o.Order = make([]string, 0)
|
|
}
|
|
|
|
if o.Posts == nil {
|
|
o.Posts = make(map[string]*Post)
|
|
}
|
|
|
|
for _, v := range o.Posts {
|
|
v.MakeNonNil()
|
|
}
|
|
}
|
|
|
|
func (o *PostList) AddOrder(id string) {
|
|
|
|
if o.Order == nil {
|
|
o.Order = make([]string, 0, 128)
|
|
}
|
|
|
|
o.Order = append(o.Order, id)
|
|
}
|
|
|
|
func (o *PostList) AddPost(post *Post) {
|
|
|
|
if o.Posts == nil {
|
|
o.Posts = make(map[string]*Post)
|
|
}
|
|
|
|
o.Posts[post.Id] = post
|
|
}
|
|
|
|
func (o *PostList) UniqueOrder() {
|
|
keys := make(map[string]bool)
|
|
order := []string{}
|
|
for _, postId := range o.Order {
|
|
if _, value := keys[postId]; !value {
|
|
keys[postId] = true
|
|
order = append(order, postId)
|
|
}
|
|
}
|
|
|
|
o.Order = order
|
|
}
|
|
|
|
func (o *PostList) Extend(other *PostList) {
|
|
for postId := range other.Posts {
|
|
o.AddPost(other.Posts[postId])
|
|
}
|
|
|
|
for _, postId := range other.Order {
|
|
o.AddOrder(postId)
|
|
}
|
|
|
|
o.UniqueOrder()
|
|
}
|
|
|
|
func (o *PostList) SortByCreateAt() {
|
|
sort.Slice(o.Order, func(i, j int) bool {
|
|
return o.Posts[o.Order[i]].CreateAt > o.Posts[o.Order[j]].CreateAt
|
|
})
|
|
}
|
|
|
|
func (o *PostList) Etag() string {
|
|
|
|
id := "0"
|
|
var t int64 = 0
|
|
|
|
for _, v := range o.Posts {
|
|
if v.UpdateAt > t {
|
|
t = v.UpdateAt
|
|
id = v.Id
|
|
} else if v.UpdateAt == t && v.Id > id {
|
|
t = v.UpdateAt
|
|
id = v.Id
|
|
}
|
|
}
|
|
|
|
orderId := ""
|
|
if len(o.Order) > 0 {
|
|
orderId = o.Order[0]
|
|
}
|
|
|
|
return Etag(orderId, id, t)
|
|
}
|
|
|
|
func (o *PostList) IsChannelId(channelId string) bool {
|
|
for _, v := range o.Posts {
|
|
if v.ChannelId != channelId {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|