aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/command-processor.go2
-rw-r--r--ui/commands.go25
-rw-r--r--ui/messages/filemessage.go59
-rw-r--r--ui/messages/parser.go6
-rw-r--r--ui/room-view.go17
5 files changed, 72 insertions, 37 deletions
diff --git a/ui/command-processor.go b/ui/command-processor.go
index e9485c4..94b07b8 100644
--- a/ui/command-processor.go
+++ b/ui/command-processor.go
@@ -135,6 +135,8 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor {
"hprof": cmdHeapProfile,
"cprof": cmdCPUProfile,
"trace": cmdTrace,
+
+ "fingerprint": cmdFingerprint,
},
}
}
diff --git a/ui/commands.go b/ui/commands.go
index ed853a2..fc86e85 100644
--- a/ui/commands.go
+++ b/ui/commands.go
@@ -250,7 +250,7 @@ func cmdTag(cmd *Command) {
err = cmd.Matrix.Client().AddTag(cmd.Room.MxRoom().ID, cmd.Args[0], order)
}
if err != nil {
- cmd.Reply("Failed to add tag:", err)
+ cmd.Reply("Failed to add tag: %v", err)
}
}
@@ -261,7 +261,7 @@ func cmdUntag(cmd *Command) {
}
err := cmd.Matrix.Client().RemoveTag(cmd.Room.MxRoom().ID, cmd.Args[0])
if err != nil {
- cmd.Reply("Failed to remove tag:", err)
+ cmd.Reply("Failed to remove tag: %v", err)
}
}
@@ -271,13 +271,24 @@ func cmdRoomNick(cmd *Command) {
member.Displayname = strings.Join(cmd.Args, " ")
_, err := cmd.Matrix.Client().SendStateEvent(room.ID, event.StateMember, string(room.SessionUserID), member)
if err != nil {
- cmd.Reply("Failed to set room nick:", err)
+ cmd.Reply("Failed to set room nick: %v", err)
+ }
+}
+
+func cmdFingerprint(cmd *Command) {
+ c := cmd.Matrix.Crypto()
+ if c == nil {
+ cmd.Reply("Encryption support is not enabled")
+ } else {
+ cmd.Reply("Device ID: %s\nFingerprint: %s", cmd.Matrix.Client().DeviceID, c.Fingerprint())
}
}
func cmdHeapProfile(cmd *Command) {
- runtime.GC()
- dbg.FreeOSMemory()
+ if len(cmd.Args) == 0 || cmd.Args[0] != "nogc" {
+ runtime.GC()
+ dbg.FreeOSMemory()
+ }
memProfile, err := os.Create("gomuks.heap.prof")
if err != nil {
debug.Print("Failed to open gomuks.heap.prof:", err)
@@ -451,7 +462,7 @@ func cmdCreateRoom(cmd *Command) {
}
room, err := cmd.Matrix.CreateRoom(req)
if err != nil {
- cmd.Reply("Failed to create room:", err)
+ cmd.Reply("Failed to create room: %v", err)
return
}
cmd.MainView.SwitchRoom("", room)
@@ -476,7 +487,7 @@ func cmdPrivateMessage(cmd *Command) {
}
room, err := cmd.Matrix.CreateRoom(req)
if err != nil {
- cmd.Reply("Failed to create room:", err)
+ cmd.Reply("Failed to create room: %v", err)
return
}
cmd.MainView.SwitchRoom("", room)
diff --git a/ui/messages/filemessage.go b/ui/messages/filemessage.go
index 7422146..3d5e554 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.ParseOrIgnore(),
+ File: file,
+ Thumbnail: content.GetInfo().ThumbnailURL.ParseOrIgnore(),
+ 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..4a214f1 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"
@@ -82,7 +82,7 @@ func directParseEvent(matrix ifc.MatrixContainer, room *rooms.Room, evt *muksevt
}
return ParseMessage(matrix, room, evt, displayname)
case *event.EncryptedEventContent:
- return NewExpandedTextMessage(evt, displayname, tstring.NewStyleTString("Encrypted messages are not yet supported", tcell.StyleDefault.Italic(true)))
+ return NewExpandedTextMessage(evt, displayname, tstring.NewStyleTString("Decryption failed or gomuks not built with encryption support", tcell.StyleDefault.Italic(true)))
case *event.TopicEventContent, *event.RoomNameEventContent, *event.CanonicalAliasEventContent:
return ParseStateEvent(evt, displayname)
case *event.MemberEventContent:
diff --git a/ui/room-view.go b/ui/room-view.go
index 0cdc7f1..dbdaccc 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -27,6 +27,7 @@ import (
"github.com/mattn/go-runewidth"
"github.com/zyedidia/clipboard"
+ "maunium.net/go/mautrix/crypto/attachment"
"maunium.net/go/mauview"
"maunium.net/go/tcell"
@@ -123,6 +124,10 @@ func NewRoomView(parent *MainView, room *rooms.Room) *RoomView {
SetPressKeyUpAtStartFunc(view.EditPrevious).
SetPressKeyDownAtEndFunc(view.EditNext)
+ if room.Encrypted {
+ view.input.SetPlaceholder("Send an encrypted message...")
+ }
+
view.topic.
SetTextColor(tcell.ColorWhite).
SetBackgroundColor(tcell.ColorDarkGreen)
@@ -203,12 +208,12 @@ func (view *RoomView) OnSelect(message *messages.UIMessage) {
} else if view.selectReason == SelectDownload {
path = msg.Body
}
- go view.Download(msg.URL, path, view.selectReason == SelectOpen)
+ go view.Download(msg.URL, msg.File, path, view.selectReason == SelectOpen)
}
case SelectCopy:
msg, ok := message.Renderer.(*messages.TextMessage)
if ok {
- go view.CopyToClipboard(msg.PlainText(),view.selectContent)
+ go view.CopyToClipboard(msg.PlainText(), view.selectContent)
}
}
view.selecting = false
@@ -631,8 +636,8 @@ func (view *RoomView) InputSubmit(text string) {
}
func (view *RoomView) CopyToClipboard(text string, register string) {
- if (register == "clipboard" || register == "primary") {
- err := clipboard.WriteAll(text,register)
+ if register == "clipboard" || register == "primary" {
+ err := clipboard.WriteAll(text, register)
if err != nil {
view.AddServiceMessage(fmt.Sprintf("Clipboard unsupported: %v", err))
view.parent.parent.Render()
@@ -643,8 +648,8 @@ func (view *RoomView) CopyToClipboard(text string, register string) {
}
}
-func (view *RoomView) Download(url id.ContentURI, filename string, openFile bool) {
- path, err := view.parent.matrix.DownloadToDisk(url, filename)
+func (view *RoomView) Download(url id.ContentURI, file *attachment.EncryptedFile, filename string, openFile bool) {
+ path, err := view.parent.matrix.DownloadToDisk(url, file, filename)
if err != nil {
view.AddServiceMessage(fmt.Sprintf("Failed to download media: %v", err))
view.parent.parent.Render()