aboutsummaryrefslogtreecommitdiff
path: root/ui/messages
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2020-04-29 02:45:54 +0300
committerTulir Asokan <tulir@maunium.net>2020-04-29 02:45:54 +0300
commita9dff6da7391297b64bb5be473b76c3c590f34a1 (patch)
tree6fe83bffeba6f09066fd87d2457571ae3ab3e5f4 /ui/messages
parentfa04323daffb8bf783ba438065a5ce47b2994bea (diff)
Add support for encrypted files
Diffstat (limited to 'ui/messages')
-rw-r--r--ui/messages/filemessage.go59
-rw-r--r--ui/messages/parser.go4
2 files changed, 40 insertions, 23 deletions
diff --git a/ui/messages/filemessage.go b/ui/messages/filemessage.go
index 7422146..d2455ab 100644
--- a/ui/messages/filemessage.go
+++ b/ui/messages/filemessage.go
@@ -22,7 +22,7 @@ import (
"image"
"image/color"
- "maunium.net/go/gomuks/matrix/muksevt"
+ "maunium.net/go/mautrix/crypto/attachment"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
"maunium.net/go/mauview"
@@ -32,14 +32,19 @@ import (
"maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/interface"
"maunium.net/go/gomuks/lib/ansimage"
+ "maunium.net/go/gomuks/matrix/muksevt"
"maunium.net/go/gomuks/ui/messages/tstring"
)
type FileMessage struct {
- Type event.MessageType
- Body string
- URL id.ContentURI
- Thumbnail id.ContentURI
+ Type event.MessageType
+ Body string
+
+ URL id.ContentURI
+ File *attachment.EncryptedFile
+ Thumbnail id.ContentURI
+ ThumbnailFile *attachment.EncryptedFile
+
imageData []byte
buffer []tstring.TString
@@ -49,14 +54,23 @@ type FileMessage struct {
// NewFileMessage creates a new FileMessage object with the provided values and the default state.
func NewFileMessage(matrix ifc.MatrixContainer, evt *muksevt.Event, displayname string) *UIMessage {
content := evt.Content.AsMessage()
- url, _ := content.URL.Parse()
- thumbnail, _ := content.GetInfo().ThumbnailURL.Parse()
+ var file, thumbnailFile *attachment.EncryptedFile
+ if content.File != nil {
+ file = &content.File.EncryptedFile
+ content.URL = content.File.URL
+ }
+ if content.GetInfo().ThumbnailFile != nil {
+ thumbnailFile = &content.Info.ThumbnailFile.EncryptedFile
+ content.Info.ThumbnailURL = content.Info.ThumbnailFile.URL
+ }
return newUIMessage(evt, displayname, &FileMessage{
- Type: content.MsgType,
- Body: content.Body,
- URL: url,
- Thumbnail: thumbnail,
- matrix: matrix,
+ Type: content.MsgType,
+ Body: content.Body,
+ URL: content.URL,
+ File: file,
+ Thumbnail: content.GetInfo().ThumbnailURL,
+ ThumbnailFile: thumbnailFile,
+ matrix: matrix,
})
}
@@ -96,17 +110,20 @@ func (msg *FileMessage) String() string {
}
func (msg *FileMessage) DownloadPreview() {
- url := msg.Thumbnail
- if url.IsEmpty() {
- if msg.Type == event.MsgImage && !msg.URL.IsEmpty() {
- msg.Thumbnail = msg.URL
- url = msg.Thumbnail
- } else {
- return
- }
+ var url id.ContentURI
+ var file *attachment.EncryptedFile
+ if !msg.Thumbnail.IsEmpty() {
+ url = msg.Thumbnail
+ file = msg.ThumbnailFile
+ } else if msg.Type == event.MsgImage && !msg.URL.IsEmpty() {
+ msg.Thumbnail = msg.URL
+ url = msg.URL
+ file = msg.File
+ } else {
+ return
}
debug.Print("Loading file:", url)
- data, err := msg.matrix.Download(url)
+ data, err := msg.matrix.Download(url, file)
if err != nil {
debug.Printf("Failed to download file %s: %v", url, err)
return
diff --git a/ui/messages/parser.go b/ui/messages/parser.go
index 9e44647..8cc6209 100644
--- a/ui/messages/parser.go
+++ b/ui/messages/parser.go
@@ -20,13 +20,13 @@ import (
"fmt"
"strings"
- "maunium.net/go/gomuks/debug"
- "maunium.net/go/gomuks/matrix/muksevt"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
"maunium.net/go/tcell"
+ "maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/interface"
+ "maunium.net/go/gomuks/matrix/muksevt"
"maunium.net/go/gomuks/matrix/rooms"
"maunium.net/go/gomuks/ui/messages/html"
"maunium.net/go/gomuks/ui/messages/tstring"