diff options
author | Tulir Asokan <tulir@maunium.net> | 2018-03-22 19:51:20 +0200 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2018-03-22 19:54:31 +0200 |
commit | 702a75a8c0355737e3e62735b59fe30bee7e42f4 (patch) | |
tree | 538b2acd579eabf893fd1f63bc7093b65b620f28 /ui/view-main.go | |
parent | 232f7fe1be917bf91f6342946f6d001948b8559e (diff) |
Save history to disk. Fixes #1
Diffstat (limited to 'ui/view-main.go')
-rw-r--r-- | ui/view-main.go | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/ui/view-main.go b/ui/view-main.go index 0c3b0a4..36ffe28 100644 --- a/ui/view-main.go +++ b/ui/view-main.go @@ -162,7 +162,7 @@ func (view *MainView) HandleCommand(room, command string, args []string) { case "/quit": view.gmx.Stop() case "/clearcache": - view.config.Session.Clear() + view.config.Clear() view.gmx.Stop() case "/panic": panic("This is a test panic.") @@ -239,6 +239,15 @@ func (view *MainView) Focus(delegate func(p tview.Primitive)) { } } +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) + } + } +} + func (view *MainView) addRoom(index int, room string) { roomStore := view.matrix.GetRoom(room) @@ -254,7 +263,13 @@ func (view *MainView) addRoom(index int, room string) { view.rooms[room] = roomView view.roomView.AddPage(room, roomView, true, false) roomView.UpdateUserList() - go view.LoadInitialHistory(room) + + count, err := roomView.LoadHistory(view.config.HistoryDir) + if err != nil { + debug.Printf("Failed to load history of %s: %v", roomView.Room.GetTitle(), err) + } else if count <= 0 { + go view.LoadInitialHistory(room) + } } } @@ -377,6 +392,11 @@ func (view *MainView) LoadHistory(room string, initial bool) { room.AddMessage(message, widget.PrependMessage) } } + err = roomView.SaveHistory(view.config.HistoryDir) + if err != nil { + debug.Printf("%Failed to save history of %s: %v", roomView.Room.GetTitle(), err) + } + view.config.Session.Save() view.parent.Render() } |