aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--interface/ui.go4
-rw-r--r--matrix/matrix.go7
-rw-r--r--ui/view-main.go29
3 files changed, 21 insertions, 19 deletions
diff --git a/interface/ui.go b/interface/ui.go
index baa34bc..add3ee7 100644
--- a/interface/ui.go
+++ b/interface/ui.go
@@ -49,8 +49,8 @@ type GomuksUI interface {
type MainView interface {
GetRoom(roomID string) RoomView
- AddRoom(roomID string)
- RemoveRoom(roomID string)
+ AddRoom(room *rooms.Room)
+ RemoveRoom(room *rooms.Room)
SetRooms(rooms map[string]*rooms.Room)
SaveAllHistory()
diff --git a/matrix/matrix.go b/matrix/matrix.go
index 2b0832b..4ed2dd9 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -283,11 +283,14 @@ func (c *Container) processOwnMembershipChange(evt *gomatrix.Event) {
if membership == prevMembership {
return
}
+ room := c.GetRoom(evt.RoomID)
switch membership {
case "join":
- c.ui.MainView().AddRoom(evt.RoomID)
+ c.ui.MainView().AddRoom(room)
+ room.HasLeft = false
case "leave":
- c.ui.MainView().RemoveRoom(evt.RoomID)
+ c.ui.MainView().RemoveRoom(room)
+ room.HasLeft = true
case "invite":
// TODO handle
debug.Printf("%s invited the user to %s", evt.Sender, evt.RoomID)
diff --git a/ui/view-main.go b/ui/view-main.go
index 34bccc7..fee07b8 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -155,7 +155,7 @@ func (view *MainView) HandleCommand(roomView *RoomView, command string, args []s
err := view.matrix.LeaveRoom(roomView.Room.ID)
debug.Print("Leave room error:", err)
if err == nil {
- view.RemoveRoom(roomView.Room.ID)
+ view.RemoveRoom(roomView.Room)
}
case "/join":
if len(args) == 0 {
@@ -165,7 +165,7 @@ func (view *MainView) HandleCommand(roomView *RoomView, command string, args []s
room, err := view.matrix.JoinRoom(args[0])
debug.Print("Join room error:", err)
if err == nil {
- view.AddRoom(room.ID)
+ view.AddRoom(room)
}
default:
roomView.AddServiceMessage("Unknown command.")
@@ -327,7 +327,7 @@ func (view *MainView) addRoomPage(room *rooms.Room) {
func (view *MainView) GetRoom(roomID string) ifc.RoomView {
room, ok := view.rooms[roomID]
if !ok {
- view.AddRoom(roomID)
+ view.AddRoom(room.Room)
room, ok := view.rooms[roomID]
if !ok {
return nil
@@ -337,13 +337,12 @@ func (view *MainView) GetRoom(roomID string) ifc.RoomView {
return room
}
-func (view *MainView) AddRoom(roomID string) {
- if view.roomList.Contains(roomID) {
- debug.Print("Add aborted", roomID)
+func (view *MainView) AddRoom(room *rooms.Room) {
+ if view.roomList.Contains(room.ID) {
+ debug.Print("Add aborted", room.ID)
return
}
- debug.Print("Adding", roomID)
- room := view.matrix.GetRoom(roomID)
+ debug.Print("Adding", room.ID)
view.roomList.Add(room)
view.addRoomPage(room)
if !view.roomList.HasSelected() {
@@ -351,19 +350,19 @@ func (view *MainView) AddRoom(roomID string) {
}
}
-func (view *MainView) RemoveRoom(roomID string) {
- roomView := view.GetRoom(roomID)
+func (view *MainView) RemoveRoom(room *rooms.Room) {
+ roomView := view.GetRoom(room.ID)
if roomView == nil {
- debug.Print("Remove aborted", roomID)
+ debug.Print("Remove aborted", room.ID)
return
}
- debug.Print("Removing", roomID)
+ debug.Print("Removing", room.ID)
- view.roomList.Remove(roomView.MxRoom())
+ view.roomList.Remove(room)
view.SwitchRoom(view.roomList.Selected())
- view.roomView.RemovePage(roomID)
- delete(view.rooms, roomID)
+ view.roomView.RemovePage(room.ID)
+ delete(view.rooms, room.ID)
view.parent.Render()
}