Skip to content

Commit

Permalink
fix backoff time
Browse files Browse the repository at this point in the history
  • Loading branch information
fedecarroz committed Oct 17, 2024
1 parent a445eac commit 77f5db7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
12 changes: 6 additions & 6 deletions functions/src/functions/quiz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import { parseGroupRef, parseQuestionListRef } from "../utils/firestoreHelpers";
import { serializedErrorResponse, serializedExceptionResponse, serializedSuccessResponse } from "../utils/responseHelper";
import { generateUniqueRandomStrings } from "../utils/stringHelpers";

const timePerQuestion = 60 * 1000;
const backoffTime = 30 * 1000;

export const createQuiz = functions.https.onCall(async (data, context) => {
const { questionList, type, talkId, sponsorId, title, isOpen } = data;
const { questionList, type, title, isOpen } = data;

if (!context.auth) {
return serializedErrorResponse("unauthenticated", "User must be authenticated.");
Expand Down Expand Up @@ -69,12 +72,10 @@ export const createQuiz = functions.https.onCall(async (data, context) => {
const quizDoc = await quizRef.add({
questionList: questionListRef,
type: type,
talkId: talkId ?? "",
sponsorId: sponsorId ?? "",
title: title ?? "",
maxScore: maxScore,
isOpen: isOpen ?? false,
timerDuration: 1000 * 60 * 3, // 3 minutes
timerDuration: timePerQuestion * questionList.length,
creatorUid: context.auth.uid,
});

Expand Down Expand Up @@ -263,10 +264,9 @@ export const submitQuiz = functions.https.onCall(async (data, context) => {
}

if (
startTimeData.startTimestamp + quizData.timerDuration - 10000 <
startTimeData.startTimestamp + quizData.timerDuration - backoffTime <
Date.now()
) {
// 10 seconds buffer for network latency
return serializedErrorResponse("quiz-time-up", "Quiz time is up.");
}

Expand Down
8 changes: 3 additions & 5 deletions lib/data/models/quiz.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ class Quiz extends Equatable {
}

factory Quiz.fromMap(Map<String, dynamic> map) {
const backOffTime = 30000;
final timerDuration = map['timerDuration'] != null
? (map['timerDuration'] as int) - backOffTime
: 0;
return Quiz(
quizId: map['quizId'] as String? ?? '',
title: map['title'] as String? ?? '',
Expand All @@ -49,7 +45,9 @@ class Quiz extends Equatable {
map['questionList'] ?? [],
).map((x) => Question.fromMap(x)),
),
timerDuration: Duration(milliseconds: timerDuration),
timerDuration: Duration(
milliseconds: (map['timerDuration'] as int?) ?? 0,
),
);
}

Expand Down

0 comments on commit 77f5db7

Please sign in to comment.