Exemplo n.º 1
0
func (c Rooms) Show(roomkey string) revel.Result {
	if !isLogin(c.Controller) {
		c.Flash.Error("Please login first")
		return c.Redirect(Sessions.New)
	}

	currentUser := CurrentUser(c.Controller)

	room := model.FindRoomByRoomKey(roomkey)
	activeRoom := ChatServer.GetActiveRoom(roomkey)
	activeRoom.AddUserToRecent(currentUser)
	log.Println(currentUser.Email)

	// user list
	users := activeRoom.UserList()

	// room list
	rooms := model.FindRoomByUserId(currentUser.Id)
	// user avatar
	userAvatar := currentUser.AvatarUrl()
	// gem latest message
	latestMessages := room.LatestMessage()
	log.Println("latest message len is:", len(latestMessages))

	return c.Render(room, users, userAvatar, rooms, latestMessages)
}
Exemplo n.º 2
0
func (c Rooms) Edit(roomkey string) revel.Result {

	if !isLogin(c.Controller) {
		c.Flash.Error("Please login first")
		return c.Redirect(Application.Index)
	}

	room := model.FindRoomByRoomKey(roomkey)

	return c.Render(room)
}
Exemplo n.º 3
0
func (c Rooms) Update(roomkey string, updateroom *form.UpdateRoom) revel.Result {

	if !isLogin(c.Controller) {
		c.Flash.Error("Please login first")
		return c.Redirect(Application.Index)
	}

	room := model.FindRoomByRoomKey(roomkey)

	if err := room.Update(updateroom); err != nil {
		c.Flash.Error(err.Error())
		return c.Redirect("/r/%s/edit", room.RoomKey)
	}

	c.Flash.Success("update success")
	return c.Redirect("/r/%s/edit", room.RoomKey)
}