aboutsummaryrefslogtreecommitdiff
path: root/ui/messages
diff options
context:
space:
mode:
Diffstat (limited to 'ui/messages')
-rw-r--r--ui/messages/base.go4
-rw-r--r--ui/messages/expandedtextmessage.go7
-rw-r--r--ui/messages/imagemessage.go11
-rw-r--r--ui/messages/message.go3
-rw-r--r--ui/messages/textbase.go9
-rw-r--r--ui/messages/textmessage.go7
6 files changed, 23 insertions, 18 deletions
diff --git a/ui/messages/base.go b/ui/messages/base.go
index ae37431..02bbddb 100644
--- a/ui/messages/base.go
+++ b/ui/messages/base.go
@@ -24,6 +24,7 @@ import (
"maunium.net/go/gomuks/ui/messages/tstring"
"maunium.net/go/gomuks/ui/widget"
"maunium.net/go/tcell"
+ "maunium.net/go/gomuks/config"
)
func init() {
@@ -43,7 +44,7 @@ type BaseMessage struct {
buffer []tstring.TString
plainBuffer []tstring.TString
prevBufferWidth int
- prevBareMode bool
+ prevPrefs config.UserPreferences
}
func newBaseMessage(id, sender, displayname, msgtype string, timestamp time.Time) BaseMessage {
@@ -55,7 +56,6 @@ func newBaseMessage(id, sender, displayname, msgtype string, timestamp time.Time
MsgType: msgtype,
MsgID: id,
prevBufferWidth: 0,
- prevBareMode: false,
MsgState: ifc.MessageStateDefault,
MsgIsHighlight: false,
MsgIsService: false,
diff --git a/ui/messages/expandedtextmessage.go b/ui/messages/expandedtextmessage.go
index 6534b04..33e5514 100644
--- a/ui/messages/expandedtextmessage.go
+++ b/ui/messages/expandedtextmessage.go
@@ -21,6 +21,7 @@ import (
"time"
"maunium.net/go/gomuks/ui/messages/tstring"
+ "maunium.net/go/gomuks/config"
)
func init() {
@@ -52,11 +53,11 @@ func (msg *ExpandedTextMessage) PlainText() string {
return msg.MsgText.String()
}
-func (msg *ExpandedTextMessage) CalculateBuffer(bare bool, width int) {
- msg.calculateBufferWithText(bare, msg.MsgText, width)
+func (msg *ExpandedTextMessage) CalculateBuffer(prefs config.UserPreferences, width int) {
+ msg.calculateBufferWithText(prefs, msg.MsgText, width)
}
// RecalculateBuffer calculates the buffer again with the previously provided width.
func (msg *ExpandedTextMessage) RecalculateBuffer() {
- msg.CalculateBuffer(msg.prevBareMode, msg.prevBufferWidth)
+ msg.CalculateBuffer(msg.prevPrefs, msg.prevBufferWidth)
}
diff --git a/ui/messages/imagemessage.go b/ui/messages/imagemessage.go
index 3f50193..671148b 100644
--- a/ui/messages/imagemessage.go
+++ b/ui/messages/imagemessage.go
@@ -29,6 +29,7 @@ import (
"maunium.net/go/gomuks/lib/ansimage"
"maunium.net/go/gomuks/ui/messages/tstring"
"maunium.net/go/tcell"
+ "maunium.net/go/gomuks/config"
)
func init() {
@@ -92,13 +93,13 @@ func (msg *ImageMessage) Path() string {
// CalculateBuffer generates the internal buffer for this message that consists
// of the text of this message split into lines at most as wide as the width
// parameter.
-func (msg *ImageMessage) CalculateBuffer(bare bool, width int) {
+func (msg *ImageMessage) CalculateBuffer(prefs config.UserPreferences, width int) {
if width < 2 {
return
}
- if bare {
- msg.calculateBufferWithText(bare, tstring.NewTString(msg.PlainText()), width)
+ if prefs.BareMessageView || prefs.DisableImages {
+ msg.calculateBufferWithText(prefs, tstring.NewTString(msg.PlainText()), width)
return
}
@@ -111,10 +112,10 @@ func (msg *ImageMessage) CalculateBuffer(bare bool, width int) {
msg.buffer = image.Render()
msg.prevBufferWidth = width
- msg.prevBareMode = false
+ msg.prevPrefs = prefs
}
// RecalculateBuffer calculates the buffer again with the previously provided width.
func (msg *ImageMessage) RecalculateBuffer() {
- msg.CalculateBuffer(msg.prevBareMode, msg.prevBufferWidth)
+ msg.CalculateBuffer(msg.prevPrefs, msg.prevBufferWidth)
}
diff --git a/ui/messages/message.go b/ui/messages/message.go
index 0de2835..3f1e694 100644
--- a/ui/messages/message.go
+++ b/ui/messages/message.go
@@ -19,13 +19,14 @@ package messages
import (
"maunium.net/go/gomuks/interface"
"maunium.net/go/gomuks/ui/messages/tstring"
+ "maunium.net/go/gomuks/config"
)
// UIMessage is a wrapper for the content and metadata of a Matrix message intended to be displayed.
type UIMessage interface {
ifc.Message
- CalculateBuffer(bare bool, width int)
+ CalculateBuffer(preferences config.UserPreferences, width int)
RecalculateBuffer()
Buffer() []tstring.TString
Height() int
diff --git a/ui/messages/textbase.go b/ui/messages/textbase.go
index 9f34683..e00ebc4 100644
--- a/ui/messages/textbase.go
+++ b/ui/messages/textbase.go
@@ -20,6 +20,7 @@ import (
"regexp"
"maunium.net/go/gomuks/ui/messages/tstring"
"fmt"
+ "maunium.net/go/gomuks/config"
)
// Regular expressions used to split lines when calculating the buffer.
@@ -50,14 +51,14 @@ func matchBoundaryPattern(bare bool, extract tstring.TString) tstring.TString {
// CalculateBuffer generates the internal buffer for this message that consists
// of the text of this message split into lines at most as wide as the width
// parameter.
-func (msg *BaseMessage) calculateBufferWithText(bare bool, text tstring.TString, width int) {
+func (msg *BaseMessage) calculateBufferWithText(prefs config.UserPreferences, text tstring.TString, width int) {
if width < 2 {
return
}
msg.buffer = []tstring.TString{}
- if bare {
+ if prefs.BareMessageView {
newText := tstring.NewTString(msg.FormatTime())
if len(msg.Sender()) > 0 {
newText = newText.AppendTString(tstring.NewColorTString(fmt.Sprintf(" <%s> ", msg.Sender()), msg.SenderColor()))
@@ -84,12 +85,12 @@ func (msg *BaseMessage) calculateBufferWithText(bare bool, text tstring.TString,
if spaces := spacePattern.FindStringIndex(str[len(extract):].String()); spaces != nil && spaces[0] == 0 {
extract = str[:len(extract)+spaces[1]]
}
- extract = matchBoundaryPattern(bare, extract)
+ extract = matchBoundaryPattern(prefs.BareMessageView, extract)
}
msg.buffer = append(msg.buffer, extract)
str = str[len(extract):]
}
}
msg.prevBufferWidth = width
- msg.prevBareMode = bare
+ msg.prevPrefs = prefs
}
diff --git a/ui/messages/textmessage.go b/ui/messages/textmessage.go
index 20dcbfc..add8588 100644
--- a/ui/messages/textmessage.go
+++ b/ui/messages/textmessage.go
@@ -23,6 +23,7 @@ import (
"maunium.net/go/gomuks/interface"
"maunium.net/go/gomuks/ui/messages/tstring"
+ "maunium.net/go/gomuks/config"
)
func init() {
@@ -84,11 +85,11 @@ func (msg *TextMessage) PlainText() string {
return msg.MsgText
}
-func (msg *TextMessage) CalculateBuffer(bare bool, width int) {
- msg.calculateBufferWithText(bare, msg.getCache(), width)
+func (msg *TextMessage) CalculateBuffer(prefs config.UserPreferences, width int) {
+ msg.calculateBufferWithText(prefs, msg.getCache(), width)
}
// RecalculateBuffer calculates the buffer again with the previously provided width.
func (msg *TextMessage) RecalculateBuffer() {
- msg.CalculateBuffer(msg.prevBareMode, msg.prevBufferWidth)
+ msg.CalculateBuffer(msg.prevPrefs, msg.prevBufferWidth)
}