// ListHandler returns all available rooms func ListHandler(w http.ResponseWriter, r *http.Request) { au, _ := auth.GetAuthenticatedUserKey(r) rooms, err := roomMemberRepo.ListRoomsForUser(au, 20) render.Check(err, w) joinable, err := roomMemberRepo.ListJoinableRoomsForUser(au, 20) render.Check(err, w) render.Render(w, r, "home", map[string]interface{}{ "request": r, "rooms": rooms, "joinable": joinable, }) }
func roomHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) hash := vars["hash"] userHash, _ := auth.GetAuthenticatedUserKey(r) room, err := roomRepo.Load(hash) render.Check(err, w) // If this is a private one-on-one room check whether the logged // in user is part of that room. If not, then they shouldn't be // able to view this room. if room.Kind == rooms.OneOnOne { _, err := roomMemberRepo.Load(room.Hash, userHash) if err != nil { render.Redirect(w, r, "/") return } } messages, err := messageRepo.List(hash, 20) render.Check(err, w) members, err := roomMemberRepo.ListMembers(room.Hash) render.Check(err, w) isMember, _ := roomMemberRepo.Load(room.Hash, userHash) render.Render(w, r, "room", map[string]interface{}{ "request": r, "room": room, "messages": messages, "members": members, "isMember": isMember, }) }