Enha: sse update on actions
This commit is contained in:
		| @@ -35,24 +35,23 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { | ||||
| 		abortWithError(w, err.Error()) | ||||
| 		return | ||||
| 	} | ||||
| 	session, ok := ctx.Value(models.CtxSessionKey).(*models.Session) | ||||
| 	if !ok { | ||||
| 		// trying to get color without a session -> error | ||||
| 		http.Redirect(w, r, "/", 302) | ||||
| 		return | ||||
| 	} | ||||
| 	state, err := loadState(session.Username) | ||||
| 	fi, err := getFullInfoByCtx(ctx) | ||||
| 	if err != nil { | ||||
| 		abortWithError(w, err.Error()) | ||||
| 		return | ||||
| 	} | ||||
| 	// TODO: whos move it is? | ||||
| 	if state.Role != "guesser" { | ||||
| 	if fi.State.Role != "guesser" { | ||||
| 		err = errors.New("need to guesser to open the card") | ||||
| 		abortWithError(w, err.Error()) | ||||
| 		return | ||||
| 	} | ||||
| 	log.Debug("got state", "state", state) | ||||
| 	// whos move it is? | ||||
| 	if fi.State.Team != models.UserTeam(fi.Room.TeamTurn) { | ||||
| 		err = errors.New("not your team's move") | ||||
| 		abortWithError(w, err.Error()) | ||||
| 		return | ||||
| 	} | ||||
| 	log.Debug("got state", "state", fi) | ||||
| 	// TODO: update room score | ||||
| 	color, exists := roundWords[word] | ||||
| 	log.Debug("got show-color request", "word", word, "color", color) | ||||
| @@ -65,5 +64,11 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { | ||||
| 		Color:    models.StrToWordColor(color), | ||||
| 		Revealed: true, | ||||
| 	} | ||||
| 	fi.Room.RevealSpecificWord(word) | ||||
| 	if err := saveFullInfo(fi); err != nil { | ||||
| 		abortWithError(w, err.Error()) | ||||
| 		return | ||||
| 	} | ||||
| 	notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "") | ||||
| 	tmpl.ExecuteTemplate(w, "cardword", cardword) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder