| 201 | } |
| 202 | |
| 203 | func (c *Core) makeTextContent(msg *model.Message, text string, title string, copytext string, autocopy string, actions []string) (*model.Message, error) { |
| 204 | var fname string |
| 205 | if len(copytext) > 1000 { |
| 206 | return nil, ErrTooLargeContent |
| 207 | } |
| 208 | l := len(title) + len(text) |
| 209 | if len(actions) > 4 { |
| 210 | actions = actions[:4] |
| 211 | } |
| 212 | for _, act := range actions { |
| 213 | l += len(act) |
| 214 | } |
| 215 | if l < 2000 { |
| 216 | if len(actions) > 0 { |
| 217 | return c.makeActionContent(msg, text, title, actions) |
| 218 | } |
| 219 | return msg.TextContent(text, title, copytext, autocopy), nil |
| 220 | } |
| 221 | if !c.logic.CanFileStore() { |
| 222 | return nil, ErrTooLargeContent |
| 223 | } |
| 224 | txts := []string{} |
| 225 | if len(title) > 0 { |
| 226 | txts = append(txts, title) |
| 227 | fname = title |
| 228 | } |
| 229 | if len(text) > 0 { |
| 230 | txts = append(txts, text) |
| 231 | } |
| 232 | data := []byte(strings.Join(txts, "\n\n")) |
| 233 | path, err := c.logic.SaveFile("files", data) |
| 234 | if err != nil { |
| 235 | return nil, err |
| 236 | } |
| 237 | if len(title) > 100 { |
| 238 | fname = string([]rune(title)[:100]) |
| 239 | title = fname + "⋯" |
| 240 | } |
| 241 | if len(fname) > 0 { |
| 242 | fname = strings.ReplaceAll(filepath.Base(fname), ".", "") |
| 243 | } |
| 244 | if len(fname) <= 0 { |
| 245 | fname = "text" |
| 246 | } |
| 247 | return msg.TextFileContent(path, fname+".txt", title, string([]rune(text)[:100])+"⋯", len(data), actions), nil |
| 248 | } |
| 249 | |
| 250 | func (c *Core) makeActionContent(msg *model.Message, text string, title string, actions []string) (*model.Message, error) { |
| 251 | return msg.ActionContent(text, title, actions), nil |