// mmc -- Mattermost client // Copyright (C) 2023 Sergey Matveev // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . package mmc import ( "strings" "time" "github.com/mattermost/mattermost-server/v6/model" "go.cypherpunks.ru/recfile" ) const ( OutRec = "out.rec" OutRecLock = "out.rec.lock" Last = "last" ) var SleepTime = 250 * time.Millisecond type Post struct { P *model.Post E string } func PostToRec(w *recfile.Writer, users map[string]*model.User, post Post) error { _, err := w.RecordStart() if err != nil { return err } created := time.Unix(post.P.CreateAt/1000, 0) user := users[post.P.UserId] sender := "unknown" if user != nil { sender = user.Username } fields := []recfile.Field{ {Name: "Id", Value: post.P.Id}, {Name: "Created", Value: created.Format("2006-01-02 15:04:05")}, {Name: "Sender", Value: sender}, } if post.E != model.WebsocketEventPosted { fields = append(fields, recfile.Field{Name: "Event", Value: post.E}) } if post.P.RootId != "" { fields = append(fields, recfile.Field{Name: "RootId", Value: post.P.RootId}) } if post.P.Metadata != nil { for _, fi := range post.P.Metadata.Files { fields = append(fields, recfile.Field{Name: "File", Value: fi.Id}) } } if _, err = w.WriteFields(fields...); err != nil { return err } _, err = w.WriteFieldMultiline("Text", strings.Split(post.P.Message, "\n")) return err }