aboutsummaryrefslogtreecommitdiff
path: root/ui/messages
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-04-18 18:35:24 +0300
committerTulir Asokan <tulir@maunium.net>2018-04-18 18:35:54 +0300
commitb17ff318c26aecdcf2c6719ed5b0872be5254c44 (patch)
tree43f5f9aa3ce300c15376860727ff13d3716f3751 /ui/messages
parent3b2d5fa0349bf01217f6954813c669680cdd16d4 (diff)
Disconnect UI from main Gomuks struct. Fixes #21
Diffstat (limited to 'ui/messages')
-rw-r--r--ui/messages/base.go2
-rw-r--r--ui/messages/imagemessage.go18
-rw-r--r--ui/messages/message.go2
-rw-r--r--ui/messages/parser/parser.go10
4 files changed, 15 insertions, 17 deletions
diff --git a/ui/messages/base.go b/ui/messages/base.go
index 5322b34..cf698db 100644
--- a/ui/messages/base.go
+++ b/ui/messages/base.go
@@ -59,7 +59,7 @@ func newBaseMessage(id, sender, displayname, msgtype string, timestamp time.Time
}
}
-func (msg *BaseMessage) RegisterGomuks(gmx ifc.Gomuks) {}
+func (msg *BaseMessage) RegisterMatrix(matrix ifc.MatrixContainer) {}
// Sender gets the string that should be displayed as the sender of this message.
//
diff --git a/ui/messages/imagemessage.go b/ui/messages/imagemessage.go
index cd8c2fe..c9301c5 100644
--- a/ui/messages/imagemessage.go
+++ b/ui/messages/imagemessage.go
@@ -41,27 +41,26 @@ type ImageMessage struct {
FileID string
data []byte
- gmx ifc.Gomuks
+ matrix ifc.MatrixContainer
}
// NewImageMessage creates a new ImageMessage object with the provided values and the default state.
-func NewImageMessage(gmx ifc.Gomuks, id, sender, displayname, msgtype, homeserver, fileID string, data []byte, timestamp time.Time) UIMessage {
+func NewImageMessage(matrix ifc.MatrixContainer, id, sender, displayname, msgtype, homeserver, fileID string, data []byte, timestamp time.Time) UIMessage {
return &ImageMessage{
newBaseMessage(id, sender, displayname, msgtype, timestamp),
homeserver,
fileID,
data,
- gmx,
+ matrix,
}
}
-func (msg *ImageMessage) RegisterGomuks(gmx ifc.Gomuks) {
- msg.gmx = gmx
+func (msg *ImageMessage) RegisterMatrix(matrix ifc.MatrixContainer) {
+ msg.matrix = matrix
- debug.Print(len(msg.data), msg.data)
if len(msg.data) == 0 {
go func() {
- defer gmx.Recover()
+ defer debug.Recover()
msg.updateData()
}()
}
@@ -73,7 +72,7 @@ func (msg *ImageMessage) NotificationContent() string {
func (msg *ImageMessage) updateData() {
debug.Print("Loading image:", msg.Homeserver, msg.FileID)
- data, _, _, err := msg.gmx.Matrix().Download(fmt.Sprintf("mxc://%s/%s", msg.Homeserver, msg.FileID))
+ data, _, _, err := msg.matrix.Download(fmt.Sprintf("mxc://%s/%s", msg.Homeserver, msg.FileID))
if err != nil {
debug.Print("Failed to download image %s/%s: %v", msg.Homeserver, msg.FileID, err)
return
@@ -82,7 +81,7 @@ func (msg *ImageMessage) updateData() {
}
func (msg *ImageMessage) Path() string {
- return msg.gmx.Matrix().GetCachePath(msg.Homeserver, msg.FileID)
+ return msg.matrix.GetCachePath(msg.Homeserver, msg.FileID)
}
// CalculateBuffer generates the internal buffer for this message that consists
@@ -108,4 +107,3 @@ func (msg *ImageMessage) CalculateBuffer(width int) {
func (msg *ImageMessage) RecalculateBuffer() {
msg.CalculateBuffer(msg.prevBufferWidth)
}
-
diff --git a/ui/messages/message.go b/ui/messages/message.go
index 0d5c9e4..d3f2db4 100644
--- a/ui/messages/message.go
+++ b/ui/messages/message.go
@@ -32,7 +32,7 @@ type UIMessage interface {
SenderID() string
RealSender() string
- RegisterGomuks(gmx ifc.Gomuks)
+ RegisterMatrix(matrix ifc.MatrixContainer)
}
const DateFormat = "January _2, 2006"
diff --git a/ui/messages/parser/parser.go b/ui/messages/parser/parser.go
index fbb2bf5..9c833f5 100644
--- a/ui/messages/parser/parser.go
+++ b/ui/messages/parser/parser.go
@@ -30,10 +30,10 @@ import (
"maunium.net/go/tcell"
)
-func ParseEvent(gmx ifc.Gomuks, room *rooms.Room, evt *gomatrix.Event) messages.UIMessage {
+func ParseEvent(matrix ifc.MatrixContainer, room *rooms.Room, evt *gomatrix.Event) messages.UIMessage {
switch evt.Type {
case "m.room.message":
- return ParseMessage(gmx, room, evt)
+ return ParseMessage(matrix, room, evt)
case "m.room.member":
return ParseMembershipEvent(room, evt)
}
@@ -48,7 +48,7 @@ func unixToTime(unix int64) time.Time {
return timestamp
}
-func ParseMessage(gmx ifc.Gomuks, room *rooms.Room, evt *gomatrix.Event) messages.UIMessage {
+func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *gomatrix.Event) messages.UIMessage {
displayname := evt.Sender
member := room.GetMember(evt.Sender)
if member != nil {
@@ -68,11 +68,11 @@ func ParseMessage(gmx ifc.Gomuks, room *rooms.Room, evt *gomatrix.Event) message
}
case "m.image":
url, _ := evt.Content["url"].(string)
- data, hs, id, err := gmx.Matrix().Download(url)
+ data, hs, id, err := matrix.Download(url)
if err != nil {
debug.Printf("Failed to download %s: %v", url, err)
}
- return messages.NewImageMessage(gmx, evt.ID, evt.Sender, displayname, msgtype, hs, id, data, ts)
+ return messages.NewImageMessage(matrix, evt.ID, evt.Sender, displayname, msgtype, hs, id, data, ts)
}
return nil
}