This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
2019-06-02 21:39:21 +02:00
|
|
|
package threema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"strconv"
|
|
|
|
|
2019-06-28 03:03:38 +02:00
|
|
|
"gosrc.io/xmpp/stanza"
|
2019-06-02 21:39:21 +02:00
|
|
|
)
|
|
|
|
|
2019-06-28 03:03:38 +02:00
|
|
|
func (a *Account) FileToXMPP(from string, msgID uint64, ext string, data []byte) (stanza.Message, error) {
|
2019-06-02 21:39:21 +02:00
|
|
|
msgIDStr := strconv.FormatUint(msgID, 10)
|
2019-06-28 03:03:38 +02:00
|
|
|
msg := stanza.Message{
|
|
|
|
Attrs: stanza.Attrs{
|
2019-06-02 21:39:21 +02:00
|
|
|
Id: msgIDStr,
|
|
|
|
From: from,
|
|
|
|
To: a.XMPP.String(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
url := fmt.Sprintf("%s/%d.%s", a.threema.httpUploadURL, msgID, ext)
|
|
|
|
path := fmt.Sprintf("%s/%d.%s", a.threema.httpUploadPath, msgID, ext)
|
|
|
|
if err := ioutil.WriteFile(path, data, 0644); err != nil {
|
|
|
|
msg.Body = "unable to save file on transport to forward"
|
|
|
|
return msg, err
|
|
|
|
}
|
|
|
|
msg.Body = url
|
2019-06-28 03:03:38 +02:00
|
|
|
msg.Extensions = append(msg.Extensions, stanza.OOB{URL: url})
|
2019-06-02 21:39:21 +02:00
|
|
|
return msg, nil
|
|
|
|
}
|