コード例 #1
0
ファイル: rooms.go プロジェクト: supermouseno1/webchat
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)
}
コード例 #2
0
ファイル: rooms.go プロジェクト: supermouseno1/webchat
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)
}
コード例 #3
0
ファイル: rooms.go プロジェクト: supermouseno1/webchat
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)
}