aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/commands.go8
-rw-r--r--ui/message-view.go51
-rw-r--r--ui/messages/parser/parser.go2
-rw-r--r--ui/room-view.go8
-rw-r--r--ui/view-main.go33
5 files changed, 20 insertions, 82 deletions
diff --git a/ui/commands.go b/ui/commands.go
index bc07779..a8b1faa 100644
--- a/ui/commands.go
+++ b/ui/commands.go
@@ -113,10 +113,10 @@ func cmdHelp(cmd *Command) {
/join <room address> - Join a room.
/leave - Leave the current room.
-/invite <user id> - Invite a user.
-/kick <user id> [reason] - Kick a user.
-/ban <user id> [reason] - Ban a user.
-/unban <user id> - Unban a user.
+/invite <user id> - Invite a user.
+/kick <user id> [reason] - Kick a user.
+/ban <user id> [reason] - Ban a user.
+/unban <user id> - Unban a user.
/send <room id> <type> <json> - Send a custom event to the given room.
/msend <type> <json> - Send a custom event to the current room.
diff --git a/ui/message-view.go b/ui/message-view.go
index d90a3a7..91f4621 100644
--- a/ui/message-view.go
+++ b/ui/message-view.go
@@ -17,10 +17,8 @@
package ui
import (
- "encoding/gob"
"fmt"
"math"
- "os"
"strings"
"github.com/mattn/go-runewidth"
@@ -84,55 +82,6 @@ func NewMessageView(parent *RoomView) *MessageView {
}
}
-func (view *MessageView) SaveHistory(path string) error {
- file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0600)
- if err != nil {
- return err
- }
- defer file.Close()
-
- enc := gob.NewEncoder(file)
- err = enc.Encode(view.messages)
- if err != nil {
- return err
- }
-
- return nil
-}
-
-func (view *MessageView) LoadHistory(matrix ifc.MatrixContainer, path string) (int, error) {
- file, err := os.OpenFile(path, os.O_RDONLY, 0600)
- if err != nil {
- if os.IsNotExist(err) {
- return 0, nil
- }
- return -1, err
- }
- defer file.Close()
-
- var msgs []messages.UIMessage
-
- dec := gob.NewDecoder(file)
- err = dec.Decode(&msgs)
- if err != nil {
- return -1, err
- }
-
- view.messages = make([]messages.UIMessage, len(msgs))
- indexOffset := 0
- for index, message := range msgs {
- if message != nil {
- view.messages[index-indexOffset] = message
- view.updateWidestSender(message.Sender())
- message.RegisterMatrix(matrix)
- } else {
- indexOffset++
- }
- }
-
- return len(view.messages), nil
-}
-
func (view *MessageView) updateWidestSender(sender string) {
if len(sender) > view.widestSender {
view.widestSender = len(sender)
diff --git a/ui/messages/parser/parser.go b/ui/messages/parser/parser.go
index b36fde0..79e628a 100644
--- a/ui/messages/parser/parser.go
+++ b/ui/messages/parser/parser.go
@@ -106,7 +106,7 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *mautrix.Eve
if len(roomID) == 0 {
roomID = room.ID
}
- replyToEvt, _ := matrix.Client().GetEvent(roomID, evt.Content.GetReplyTo())
+ replyToEvt, _ := matrix.GetEvent(room, evt.Content.GetReplyTo())
if replyToEvt != nil {
replyToEvt.Content.RemoveReplyFallback()
if len(replyToEvt.Content.FormattedBody) == 0 {
diff --git a/ui/room-view.go b/ui/room-view.go
index bc9c0cc..1a1ae78 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -119,14 +119,6 @@ func (view *RoomView) logPath(dir string) string {
return filepath.Join(dir, fmt.Sprintf("%s.gmxlog", view.Room.ID))
}
-func (view *RoomView) SaveHistory(dir string) error {
- return view.MessageView().SaveHistory(view.logPath(dir))
-}
-
-func (view *RoomView) LoadHistory(matrix ifc.MatrixContainer, dir string) (int, error) {
- return view.MessageView().LoadHistory(matrix, view.logPath(dir))
-}
-
func (view *RoomView) SetInputSubmitFunc(fn func(room *RoomView, text string)) *RoomView {
view.inputSubmitFunc = fn
return view
diff --git a/ui/view-main.go b/ui/view-main.go
index f726af5..382d9c8 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -122,9 +122,12 @@ func (view *MainView) BumpFocus(roomView *RoomView) {
func (view *MainView) MarkRead(roomView *RoomView) {
if roomView != nil && roomView.Room.HasNewMessages() && roomView.MessageView().ScrollOffset == 0 {
msgList := roomView.MessageView().messages
- msg := msgList[len(msgList)-1]
- roomView.Room.MarkRead(msg.ID())
- view.matrix.MarkRead(roomView.Room.ID, msg.ID())
+ if len(msgList) > 0 {
+ msg := msgList[len(msgList)-1]
+ if roomView.Room.MarkRead(msg.ID()) {
+ view.matrix.MarkRead(roomView.Room.ID, msg.ID())
+ }
+ }
}
}
@@ -301,14 +304,8 @@ func (view *MainView) SwitchRoom(tag string, room *rooms.Room) {
view.MarkRead(roomView)
view.roomList.SetSelected(tag, room)
view.parent.Render()
-}
-
-func (view *MainView) SaveAllHistory() {
- for _, room := range view.rooms {
- err := room.SaveHistory(view.config.HistoryDir)
- if err != nil {
- debug.Printf("Failed to save history of %s: %v", room.Room.GetTitle(), err)
- }
+ if len(roomView.MessageView().messages) == 0 {
+ go view.LoadHistory(room.ID)
}
}
@@ -320,10 +317,11 @@ func (view *MainView) addRoomPage(room *rooms.Room) {
view.rooms[room.ID] = roomView
roomView.UpdateUserList()
- _, err := roomView.LoadHistory(view.matrix, view.config.HistoryDir)
+ // FIXME
+ /*_, err := roomView.LoadHistory(view.matrix, view.config.HistoryDir)
if err != nil {
debug.Printf("Failed to load history of %s: %v", roomView.Room.GetTitle(), err)
- }
+ }*/
}
}
@@ -465,24 +463,23 @@ func (view *MainView) LoadHistory(room string) {
return
}
- debug.Print("Fetching history for", room, "starting from", batch)
- history, prevBatch, err := view.matrix.GetHistory(roomView.Room.ID, batch, 50)
+ history, err := view.matrix.GetHistory(roomView.Room, 50)
if err != nil {
roomView.AddServiceMessage("Failed to fetch history")
debug.Print("Failed to fetch history for", roomView.Room.ID, err)
return
}
- roomView.Room.PrevBatch = prevBatch
for _, evt := range history {
message := view.ParseEvent(roomView, evt)
if message != nil {
roomView.AddMessage(message, ifc.PrependMessage)
}
}
- err = roomView.SaveHistory(view.config.HistoryDir)
+ // TODO?
+ /*err = roomView.SaveHistory(view.config.HistoryDir)
if err != nil {
debug.Printf("Failed to save history of %s: %v", roomView.Room.GetTitle(), err)
- }
+ }*/
view.config.PutRoom(roomView.Room)
view.parent.Render()
}