MCPcopy
hub / github.com/42wim/matterbridge / handleUploadFile

Method handleUploadFile

bridge/xmpp/xmpp.go:364–399  ·  view source on GitHub ↗

handleUploadFile handles native upload of files

(msg *config.Message)

Source from the content-addressed store, hash-verified

362
363// handleUploadFile handles native upload of files
364func (b *Bxmpp) handleUploadFile(msg *config.Message) error {
365 var urlDesc string
366
367 for _, file := range msg.Extra["file"] {
368 fileInfo := file.(config.FileInfo)
369 if fileInfo.Comment != "" {
370 msg.Text += fileInfo.Comment + ": "
371 }
372 if fileInfo.URL != "" {
373 msg.Text = fileInfo.URL
374 if fileInfo.Comment != "" {
375 msg.Text = fileInfo.Comment + ": " + fileInfo.URL
376 urlDesc = fileInfo.Comment
377 }
378 }
379 if _, err := b.xc.Send(xmpp.Chat{
380 Type: "groupchat",
381 Remote: msg.Channel + "@" + b.GetString("Muc"),
382 Text: msg.Username + msg.Text,
383 }); err != nil {
384 return err
385 }
386
387 if fileInfo.URL != "" {
388 if _, err := b.xc.SendOOB(xmpp.Chat{
389 Type: "groupchat",
390 Remote: msg.Channel + "@" + b.GetString("Muc"),
391 Ooburl: fileInfo.URL,
392 Oobdesc: urlDesc,
393 }); err != nil {
394 b.Log.WithError(err).Warn("Failed to send share URL.")
395 }
396 }
397 }
398 return nil
399}
400
401func (b *Bxmpp) parseNick(remote string) string {
402 s := strings.Split(remote, "@")

Callers 1

SendMethod · 0.95

Calls 2

SendMethod · 0.65
GetStringMethod · 0.65

Tested by

no test coverage detected