Update ui AddRoom and RemoveRoom parameters
This commit is contained in:
parent
c600ce68a2
commit
986c84b768
@ -49,8 +49,8 @@ type GomuksUI interface {
|
|||||||
|
|
||||||
type MainView interface {
|
type MainView interface {
|
||||||
GetRoom(roomID string) RoomView
|
GetRoom(roomID string) RoomView
|
||||||
AddRoom(roomID string)
|
AddRoom(room *rooms.Room)
|
||||||
RemoveRoom(roomID string)
|
RemoveRoom(room *rooms.Room)
|
||||||
SetRooms(rooms map[string]*rooms.Room)
|
SetRooms(rooms map[string]*rooms.Room)
|
||||||
SaveAllHistory()
|
SaveAllHistory()
|
||||||
|
|
||||||
|
@ -283,11 +283,14 @@ func (c *Container) processOwnMembershipChange(evt *gomatrix.Event) {
|
|||||||
if membership == prevMembership {
|
if membership == prevMembership {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
room := c.GetRoom(evt.RoomID)
|
||||||
switch membership {
|
switch membership {
|
||||||
case "join":
|
case "join":
|
||||||
c.ui.MainView().AddRoom(evt.RoomID)
|
c.ui.MainView().AddRoom(room)
|
||||||
|
room.HasLeft = false
|
||||||
case "leave":
|
case "leave":
|
||||||
c.ui.MainView().RemoveRoom(evt.RoomID)
|
c.ui.MainView().RemoveRoom(room)
|
||||||
|
room.HasLeft = true
|
||||||
case "invite":
|
case "invite":
|
||||||
// TODO handle
|
// TODO handle
|
||||||
debug.Printf("%s invited the user to %s", evt.Sender, evt.RoomID)
|
debug.Printf("%s invited the user to %s", evt.Sender, evt.RoomID)
|
||||||
|
@ -155,7 +155,7 @@ func (view *MainView) HandleCommand(roomView *RoomView, command string, args []s
|
|||||||
err := view.matrix.LeaveRoom(roomView.Room.ID)
|
err := view.matrix.LeaveRoom(roomView.Room.ID)
|
||||||
debug.Print("Leave room error:", err)
|
debug.Print("Leave room error:", err)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
view.RemoveRoom(roomView.Room.ID)
|
view.RemoveRoom(roomView.Room)
|
||||||
}
|
}
|
||||||
case "/join":
|
case "/join":
|
||||||
if len(args) == 0 {
|
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])
|
room, err := view.matrix.JoinRoom(args[0])
|
||||||
debug.Print("Join room error:", err)
|
debug.Print("Join room error:", err)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
view.AddRoom(room.ID)
|
view.AddRoom(room)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
roomView.AddServiceMessage("Unknown command.")
|
roomView.AddServiceMessage("Unknown command.")
|
||||||
@ -327,7 +327,7 @@ func (view *MainView) addRoomPage(room *rooms.Room) {
|
|||||||
func (view *MainView) GetRoom(roomID string) ifc.RoomView {
|
func (view *MainView) GetRoom(roomID string) ifc.RoomView {
|
||||||
room, ok := view.rooms[roomID]
|
room, ok := view.rooms[roomID]
|
||||||
if !ok {
|
if !ok {
|
||||||
view.AddRoom(roomID)
|
view.AddRoom(room.Room)
|
||||||
room, ok := view.rooms[roomID]
|
room, ok := view.rooms[roomID]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
@ -337,13 +337,12 @@ func (view *MainView) GetRoom(roomID string) ifc.RoomView {
|
|||||||
return room
|
return room
|
||||||
}
|
}
|
||||||
|
|
||||||
func (view *MainView) AddRoom(roomID string) {
|
func (view *MainView) AddRoom(room *rooms.Room) {
|
||||||
if view.roomList.Contains(roomID) {
|
if view.roomList.Contains(room.ID) {
|
||||||
debug.Print("Add aborted", roomID)
|
debug.Print("Add aborted", room.ID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
debug.Print("Adding", roomID)
|
debug.Print("Adding", room.ID)
|
||||||
room := view.matrix.GetRoom(roomID)
|
|
||||||
view.roomList.Add(room)
|
view.roomList.Add(room)
|
||||||
view.addRoomPage(room)
|
view.addRoomPage(room)
|
||||||
if !view.roomList.HasSelected() {
|
if !view.roomList.HasSelected() {
|
||||||
@ -351,19 +350,19 @@ func (view *MainView) AddRoom(roomID string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (view *MainView) RemoveRoom(roomID string) {
|
func (view *MainView) RemoveRoom(room *rooms.Room) {
|
||||||
roomView := view.GetRoom(roomID)
|
roomView := view.GetRoom(room.ID)
|
||||||
if roomView == nil {
|
if roomView == nil {
|
||||||
debug.Print("Remove aborted", roomID)
|
debug.Print("Remove aborted", room.ID)
|
||||||
return
|
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.SwitchRoom(view.roomList.Selected())
|
||||||
|
|
||||||
view.roomView.RemovePage(roomID)
|
view.roomView.RemovePage(room.ID)
|
||||||
delete(view.rooms, roomID)
|
delete(view.rooms, room.ID)
|
||||||
|
|
||||||
view.parent.Render()
|
view.parent.Render()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user