aboutsummaryrefslogtreecommitdiff
path: root/interface
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-04-14 18:09:02 +0300
committerGitHub <noreply@github.com>2018-04-14 18:09:02 +0300
commit53cdfb64c1773b63fb9432a1525b4ac4acb154fc (patch)
tree1c1aa180313abe8179d0b07591348e222b60483e /interface
parent14a84295d72a24a8bce8a71c240ab2b155ed5a1f (diff)
parentd060d10615434c557373ee00ba009cc8b583e881 (diff)
Merge pull request #18 from tulir/ui-refactor
Refactor UI to use interfaces and add advanced message rendering
Diffstat (limited to 'interface')
-rw-r--r--interface/matrix.go2
-rw-r--r--interface/ui.go80
2 files changed, 75 insertions, 7 deletions
diff --git a/interface/matrix.go b/interface/matrix.go
index f811dff..3a1ec14 100644
--- a/interface/matrix.go
+++ b/interface/matrix.go
@@ -34,4 +34,6 @@ type MatrixContainer interface {
LeaveRoom(roomID string) error
GetHistory(roomID, prevBatch string, limit int) ([]gomatrix.Event, string, error)
GetRoom(roomID string) *rooms.Room
+ Download(mxcURL string) ([]byte, string, string, error)
+ GetCachePath(homeserver, fileID string) string
}
diff --git a/interface/ui.go b/interface/ui.go
index c0ddf53..e6071fc 100644
--- a/interface/ui.go
+++ b/interface/ui.go
@@ -17,11 +17,12 @@
package ifc
import (
+ "time"
+
+ "maunium.net/go/tcell"
"maunium.net/go/gomatrix"
"maunium.net/go/gomuks/matrix/pushrules"
"maunium.net/go/gomuks/matrix/rooms"
- "maunium.net/go/gomuks/ui/types"
- "maunium.net/go/gomuks/ui/widget"
"maunium.net/go/tview"
)
@@ -42,7 +43,7 @@ type GomuksUI interface {
}
type MainView interface {
- GetRoom(roomID string) *widget.RoomView
+ GetRoom(roomID string) RoomView
HasRoom(roomID string) bool
AddRoom(roomID string)
RemoveRoom(roomID string)
@@ -50,11 +51,76 @@ type MainView interface {
SaveAllHistory()
SetTyping(roomID string, users []string)
- AddServiceMessage(roomID *widget.RoomView, message string)
- ProcessMessageEvent(roomView *widget.RoomView, evt *gomatrix.Event) *types.Message
- ProcessMembershipEvent(roomView *widget.RoomView, evt *gomatrix.Event) *types.Message
- NotifyMessage(room *rooms.Room, message *types.Message, should pushrules.PushActionArrayShould)
+ ParseEvent(roomView RoomView, evt *gomatrix.Event) Message
+ //ProcessMessageEvent(roomView RoomView, evt *gomatrix.Event) Message
+ //ProcessMembershipEvent(roomView RoomView, evt *gomatrix.Event) Message
+ NotifyMessage(room *rooms.Room, message Message, should pushrules.PushActionArrayShould)
}
type LoginView interface {
}
+
+type MessageDirection int
+
+const (
+ AppendMessage MessageDirection = iota
+ PrependMessage
+ IgnoreMessage
+)
+
+type RoomView interface {
+ MxRoom() *rooms.Room
+ SaveHistory(dir string) error
+ LoadHistory(gmx Gomuks, dir string) (int, error)
+
+ SetStatus(status string)
+ SetTyping(users []string)
+ UpdateUserList()
+
+ NewMessage(id, sender, msgtype, text string, timestamp time.Time) Message
+ NewTempMessage(msgtype, text string) Message
+ AddMessage(message Message, direction MessageDirection)
+ AddServiceMessage(message string)
+}
+
+type MessageMeta interface {
+ Sender() string
+ SenderColor() tcell.Color
+ TextColor() tcell.Color
+ TimestampColor() tcell.Color
+ Timestamp() time.Time
+ FormatTime() string
+ FormatDate() string
+ CopyFrom(from MessageMeta)
+}
+
+// MessageState is an enum to specify if a Message is being sent, failed to send or was successfully sent.
+type MessageState int
+
+// Allowed MessageStates.
+const (
+ MessageStateSending MessageState = iota
+ MessageStateDefault
+ MessageStateFailed
+)
+
+type Message interface {
+ MessageMeta
+
+ SetIsHighlight(isHighlight bool)
+ IsHighlight() bool
+
+ SetIsService(isService bool)
+ IsService() bool
+
+ SetID(id string)
+ ID() string
+
+ SetType(msgtype string)
+ Type() string
+
+ NotificationContent() string
+
+ SetState(state MessageState)
+ State() MessageState
+}