fix: address Neo review — fix cloud function partnerName scope, WheelCompleteScreen session ID, polling isActive, navigateTo reset
This commit is contained in:
parent
7926289153
commit
2b8e05b29b
|
|
@ -248,6 +248,10 @@ class DesireSyncViewModel @Inject constructor(
|
||||||
} else null
|
} else null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onNavigated() {
|
||||||
|
_uiState.update { it.copy(navigateTo = null) }
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val SESSION_SIZE = 10
|
private const val SESSION_SIZE = 10
|
||||||
private const val ADVANCE_DELAY_MS = 380L
|
private const val ADVANCE_DELAY_MS = 380L
|
||||||
|
|
@ -265,7 +269,10 @@ fun DesireSyncScreen(
|
||||||
val state by viewModel.uiState.collectAsState()
|
val state by viewModel.uiState.collectAsState()
|
||||||
|
|
||||||
LaunchedEffect(state.navigateTo) {
|
LaunchedEffect(state.navigateTo) {
|
||||||
state.navigateTo?.let { onNavigate(it) }
|
state.navigateTo?.let {
|
||||||
|
onNavigate(it)
|
||||||
|
viewModel.onNavigated()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
|
|
@ -37,6 +38,7 @@ import app.closer.domain.usecase.GameSessionManager
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.isActive
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
@ -63,7 +65,7 @@ class WaitingForPartnerViewModel @Inject constructor(
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
loadGameInfo()
|
loadGameInfo()
|
||||||
// Poll for partner's session completion
|
// Poll for partner's session completion
|
||||||
while (_uiState.value.navigateTo == null) {
|
while (isActive && _uiState.value.navigateTo == null) {
|
||||||
delay(5000) // Check every 5 seconds
|
delay(5000) // Check every 5 seconds
|
||||||
val userId = gameSessionManager.currentUserId ?: ""
|
val userId = gameSessionManager.currentUserId ?: ""
|
||||||
val couple = gameSessionManager.getCoupleForUser(userId)
|
val couple = gameSessionManager.getCoupleForUser(userId)
|
||||||
|
|
@ -110,6 +112,13 @@ fun WaitingForPartnerScreen(
|
||||||
) {
|
) {
|
||||||
val state by viewModel.uiState.collectAsState()
|
val state by viewModel.uiState.collectAsState()
|
||||||
|
|
||||||
|
LaunchedEffect(state.navigateTo) {
|
||||||
|
state.navigateTo?.let {
|
||||||
|
onNavigate(it)
|
||||||
|
viewModel.onNavigated()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
|
|
||||||
|
|
@ -235,6 +235,10 @@ class HowWellViewModel @Inject constructor(
|
||||||
load()
|
load()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onNavigated() {
|
||||||
|
_uiState.update { it.copy(navigateTo = null) }
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val SESSION_SIZE = 10
|
const val SESSION_SIZE = 10
|
||||||
private const val TAG = "HowWellViewModel"
|
private const val TAG = "HowWellViewModel"
|
||||||
|
|
@ -251,7 +255,10 @@ fun HowWellScreen(
|
||||||
val state by viewModel.uiState.collectAsState()
|
val state by viewModel.uiState.collectAsState()
|
||||||
|
|
||||||
LaunchedEffect(state.navigateTo) {
|
LaunchedEffect(state.navigateTo) {
|
||||||
state.navigateTo?.let { onNavigate(it) }
|
state.navigateTo?.let {
|
||||||
|
onNavigate(it)
|
||||||
|
viewModel.onNavigated()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,10 @@ class ThisOrThatViewModel @Inject constructor(
|
||||||
load()
|
load()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onNavigated() {
|
||||||
|
_uiState.update { it.copy(navigateTo = null) }
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val SESSION_SIZE = 10
|
const val SESSION_SIZE = 10
|
||||||
private const val TAG = "ThisOrThatViewModel"
|
private const val TAG = "ThisOrThatViewModel"
|
||||||
|
|
@ -178,7 +182,10 @@ fun ThisOrThatScreen(
|
||||||
val state by viewModel.uiState.collectAsState()
|
val state by viewModel.uiState.collectAsState()
|
||||||
|
|
||||||
LaunchedEffect(state.navigateTo) {
|
LaunchedEffect(state.navigateTo) {
|
||||||
state.navigateTo?.let { onNavigate(it) }
|
state.navigateTo?.let {
|
||||||
|
onNavigate(it)
|
||||||
|
viewModel.onNavigated()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ data class LocalWheelSession(
|
||||||
@Singleton
|
@Singleton
|
||||||
class LocalWheelSessionStore @Inject constructor() {
|
class LocalWheelSessionStore @Inject constructor() {
|
||||||
var activeSession: LocalWheelSession? = null
|
var activeSession: LocalWheelSession? = null
|
||||||
|
var sessionId: String? = null
|
||||||
var lastAnswered: Int = 0
|
var lastAnswered: Int = 0
|
||||||
var lastTotal: Int = 0
|
var lastTotal: Int = 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,7 @@ class SpinWheelViewModel @Inject constructor(
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sessionStore.sessionId = startResult
|
||||||
_uiState.update { it.copy(navigateTo = AppRoute.wheelSession(startResult)) }
|
_uiState.update { it.copy(navigateTo = AppRoute.wheelSession(startResult)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,8 @@ import app.closer.ui.theme.closerBackgroundBrush
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import app.closer.core.navigation.AppRoute
|
import app.closer.core.navigation.AppRoute
|
||||||
import app.closer.domain.model.QuestionSession
|
|
||||||
import app.closer.domain.repository.AuthRepository
|
import app.closer.domain.repository.AuthRepository
|
||||||
import app.closer.domain.repository.CoupleRepository
|
import app.closer.domain.repository.CoupleRepository
|
||||||
import app.closer.domain.repository.QuestionSessionRepository
|
|
||||||
import app.closer.domain.usecase.GameSessionManager
|
import app.closer.domain.usecase.GameSessionManager
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
@ -51,7 +49,6 @@ import app.closer.ui.theme.CloserPalette
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class WheelCompleteViewModel @Inject constructor(
|
class WheelCompleteViewModel @Inject constructor(
|
||||||
private val sessionStore: LocalWheelSessionStore,
|
private val sessionStore: LocalWheelSessionStore,
|
||||||
private val sessionRepository: QuestionSessionRepository,
|
|
||||||
private val authRepository: AuthRepository,
|
private val authRepository: AuthRepository,
|
||||||
private val coupleRepository: CoupleRepository,
|
private val coupleRepository: CoupleRepository,
|
||||||
private val gameSessionManager: GameSessionManager
|
private val gameSessionManager: GameSessionManager
|
||||||
|
|
@ -66,20 +63,12 @@ class WheelCompleteViewModel @Inject constructor(
|
||||||
|
|
||||||
private fun saveSession() {
|
private fun saveSession() {
|
||||||
val session = sessionStore.activeSession ?: return
|
val session = sessionStore.activeSession ?: return
|
||||||
|
val sessionId = sessionStore.sessionId ?: return
|
||||||
val uid = authRepository.currentUserId ?: return
|
val uid = authRepository.currentUserId ?: return
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val couple = coupleRepository.getCoupleForUser(uid) ?: return@launch
|
val couple = coupleRepository.getCoupleForUser(uid) ?: return@launch
|
||||||
val savedSession = QuestionSession(
|
|
||||||
coupleId = couple.id,
|
|
||||||
categoryId = session.categoryId,
|
|
||||||
questionIds = session.questions.map { it.id },
|
|
||||||
startedByUserId = uid,
|
|
||||||
completedAt = System.currentTimeMillis(),
|
|
||||||
status = "completed"
|
|
||||||
)
|
|
||||||
sessionRepository.saveSession(savedSession)
|
|
||||||
gameSessionManager.finishGame(
|
gameSessionManager.finishGame(
|
||||||
sessionId = savedSession.id,
|
sessionId = sessionId,
|
||||||
coupleId = couple.id,
|
coupleId = couple.id,
|
||||||
userId = uid
|
userId = uid
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,180 @@
|
||||||
|
"use strict";
|
||||||
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
|
}) : (function(o, m, k, k2) {
|
||||||
|
if (k2 === undefined) k2 = k;
|
||||||
|
o[k2] = m[k];
|
||||||
|
}));
|
||||||
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||||
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
|
}) : function(o, v) {
|
||||||
|
o["default"] = v;
|
||||||
|
});
|
||||||
|
var __importStar = (this && this.__importStar) || (function () {
|
||||||
|
var ownKeys = function(o) {
|
||||||
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||||
|
var ar = [];
|
||||||
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||||
|
return ar;
|
||||||
|
};
|
||||||
|
return ownKeys(o);
|
||||||
|
};
|
||||||
|
return function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||||
|
__setModuleDefault(result, mod);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.onGameSessionUpdate = void 0;
|
||||||
|
const functions = __importStar(require("firebase-functions"));
|
||||||
|
const admin = __importStar(require("firebase-admin"));
|
||||||
|
/**
|
||||||
|
* Firestore trigger that notifies partners when a game session is created or completed.
|
||||||
|
*
|
||||||
|
* Path: couples/{coupleId}/sessions/{sessionId}
|
||||||
|
* Condition: onWrite (create, update, delete)
|
||||||
|
*/
|
||||||
|
exports.onGameSessionUpdate = functions.firestore
|
||||||
|
.document('couples/{coupleId}/sessions/{sessionId}')
|
||||||
|
.onWrite(async (change, context) => {
|
||||||
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
||||||
|
const { coupleId, sessionId } = context.params;
|
||||||
|
const db = admin.firestore();
|
||||||
|
const messaging = admin.messaging();
|
||||||
|
// Get the session document
|
||||||
|
const sessionDoc = await db.collection('couples').doc(coupleId).collection('sessions').doc(sessionId).get();
|
||||||
|
const session = sessionDoc.data();
|
||||||
|
if (!session) {
|
||||||
|
console.log(`[onGameSessionUpdate] session ${sessionId} not found, skipping`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Get couple info
|
||||||
|
const coupleDoc = await db.collection('couples').doc(coupleId).get();
|
||||||
|
if (!coupleDoc.exists) {
|
||||||
|
console.warn(`[onGameSessionUpdate] couple ${coupleId} not found`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const coupleData = (_a = coupleDoc.data()) !== null && _a !== void 0 ? _a : {};
|
||||||
|
const userIds = ((_b = coupleData.userIds) !== null && _b !== void 0 ? _b : []);
|
||||||
|
if (userIds.length !== 2) {
|
||||||
|
console.warn(`[onGameSessionUpdate] invalid couple ${coupleId}: expected 2 users, got ${userIds.length}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const partnerA = userIds[0];
|
||||||
|
const partnerB = userIds[1];
|
||||||
|
// Get user display names for notifications
|
||||||
|
const userA = await db.collection('users').doc(partnerA).get();
|
||||||
|
const userB = await db.collection('users').doc(partnerB).get();
|
||||||
|
const partnerAName = (_d = (_c = userA.data()) === null || _c === void 0 ? void 0 : _c.displayName) !== null && _d !== void 0 ? _d : 'Partner A';
|
||||||
|
const partnerBName = (_f = (_e = userB.data()) === null || _e === void 0 ? void 0 : _e.displayName) !== null && _f !== void 0 ? _f : 'Partner B';
|
||||||
|
// Check if session was just created (status = "active")
|
||||||
|
const previousData = (_g = change.before.data()) !== null && _g !== void 0 ? _g : {};
|
||||||
|
const currentData = (_h = change.after.data()) !== null && _h !== void 0 ? _h : {};
|
||||||
|
const wasInactive = ((_j = previousData.status) !== null && _j !== void 0 ? _j : '') !== 'active';
|
||||||
|
const isActiveNow = currentData.status === 'active';
|
||||||
|
if (wasInactive && isActiveNow) {
|
||||||
|
// New session started - notify the other partner
|
||||||
|
const startedBy = currentData.startedByUserId;
|
||||||
|
const gameType = (_k = currentData.gameType) !== null && _k !== void 0 ? _k : 'wheel';
|
||||||
|
const partnerId = startedBy === partnerA ? partnerB : partnerA;
|
||||||
|
const partnerName = startedBy === partnerA ? partnerBName : partnerAName;
|
||||||
|
await notifyPartner(db, messaging, partnerId, partnerName, gameType, 'partner_started_game', `${partnerName} has started a game. Tap to join!`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Check if session was completed
|
||||||
|
const wasActive = ((_l = previousData.status) !== null && _l !== void 0 ? _l : '') === 'active';
|
||||||
|
const isCompletedNow = currentData.status === 'completed';
|
||||||
|
if (wasActive && isCompletedNow) {
|
||||||
|
const completedBy = currentData.startedByUserId;
|
||||||
|
const partnerId = completedBy === partnerA ? partnerB : partnerA;
|
||||||
|
const completingPartnerName = completedBy === partnerA ? partnerAName : partnerBName;
|
||||||
|
// Check if partner has also completed
|
||||||
|
const partnerCompletedAt = currentData.partnerCompletedAt;
|
||||||
|
if (partnerCompletedAt) {
|
||||||
|
// Both completed - notify both
|
||||||
|
await notifyPartner(db, messaging, partnerA, partnerAName, (_m = currentData.gameType) !== null && _m !== void 0 ? _m : 'wheel', 'partner_finished_game', `${partnerBName} has finished the game. Tap to see the results!`);
|
||||||
|
await notifyPartner(db, messaging, partnerB, partnerBName, (_o = currentData.gameType) !== null && _o !== void 0 ? _o : 'wheel', 'partner_finished_game', `${partnerAName} has finished the game. Tap to see the results!`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Only one completed - notify the other to continue
|
||||||
|
await notifyPartner(db, messaging, partnerId, completingPartnerName, (_p = currentData.gameType) !== null && _p !== void 0 ? _p : 'wheel', 'partner_finished_game', `${completingPartnerName} has finished. Tap to continue playing!`);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
/**
|
||||||
|
* Send notification to partner via FCM and write to notification_queue.
|
||||||
|
*/
|
||||||
|
async function notifyPartner(db, messaging, partnerId, partnerName, gameType, notificationType, body) {
|
||||||
|
var _a;
|
||||||
|
const notificationPayload = {
|
||||||
|
type: notificationType,
|
||||||
|
title: `${partnerName} is playing`,
|
||||||
|
body: body,
|
||||||
|
};
|
||||||
|
// Write an in-app notification record for the partner
|
||||||
|
await db
|
||||||
|
.collection('users')
|
||||||
|
.doc(partnerId)
|
||||||
|
.collection('notification_queue')
|
||||||
|
.add(Object.assign(Object.assign({}, notificationPayload), { read: false, createdAt: admin.firestore.FieldValue.serverTimestamp() }));
|
||||||
|
// Collect the partner's FCM tokens
|
||||||
|
const tokens = [];
|
||||||
|
const partnerUserDoc = await db.collection('users').doc(partnerId).get();
|
||||||
|
if (partnerUserDoc.exists) {
|
||||||
|
const legacyToken = (_a = partnerUserDoc.data()) === null || _a === void 0 ? void 0 : _a.fcmToken;
|
||||||
|
if (typeof legacyToken === 'string' && legacyToken.length > 0) {
|
||||||
|
tokens.push(legacyToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const tokenSnapshot = await db
|
||||||
|
.collection('users')
|
||||||
|
.doc(partnerId)
|
||||||
|
.collection('fcmTokens')
|
||||||
|
.get();
|
||||||
|
tokenSnapshot.docs.forEach((doc) => {
|
||||||
|
var _a;
|
||||||
|
const t = (_a = doc.data()) === null || _a === void 0 ? void 0 : _a.token;
|
||||||
|
if (typeof t === 'string' && t.length > 0 && !tokens.includes(t)) {
|
||||||
|
tokens.push(t);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (tokens.length === 0) {
|
||||||
|
console.log(`[notifyPartner] no FCM tokens for ${partnerId}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const fcmMessage = {
|
||||||
|
token: tokens[0],
|
||||||
|
notification: {
|
||||||
|
title: notificationPayload.title,
|
||||||
|
body: notificationPayload.body,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
type: notificationPayload.type,
|
||||||
|
gameType: gameType,
|
||||||
|
partnerId: partnerId,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const sendResults = await Promise.allSettled(tokens.map((token) => messaging.send(Object.assign(Object.assign({}, fcmMessage), { token }))));
|
||||||
|
const failures = [];
|
||||||
|
sendResults.forEach((result, index) => {
|
||||||
|
if (result.status === 'rejected') {
|
||||||
|
failures.push(`${tokens[index]}: ${String(result.reason)}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (failures.length > 0) {
|
||||||
|
console.error(`[notifyPartner] some notifications failed:`, failures);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log(`[notifyPartner] notified ${partnerId} (${notificationType})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//# sourceMappingURL=onGameSessionUpdate.js.map
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.health = exports.onCoupleLeave = exports.onAnswerWritten = exports.assignDailyQuestionCallable = exports.assignDailyQuestion = exports.createDateMatchOnMutualLove = exports.checkDeviceIntegrity = exports.sendPartnerAnsweredNotification = exports.sendDailyQuestionReminder = exports.syncEntitlement = exports.revenueCatWebhook = void 0;
|
exports.health = exports.onGameSessionUpdate = exports.onCoupleLeave = exports.onAnswerWritten = exports.assignDailyQuestionCallable = exports.assignDailyQuestion = exports.createDateMatchOnMutualLove = exports.checkDeviceIntegrity = exports.sendPartnerAnsweredNotification = exports.sendDailyQuestionReminder = exports.syncEntitlement = exports.revenueCatWebhook = void 0;
|
||||||
const functions = __importStar(require("firebase-functions"));
|
const functions = __importStar(require("firebase-functions"));
|
||||||
const admin = __importStar(require("firebase-admin"));
|
const admin = __importStar(require("firebase-admin"));
|
||||||
// Initialize the Admin SDK once for every function in this codebase.
|
// Initialize the Admin SDK once for every function in this codebase.
|
||||||
|
|
@ -60,6 +60,8 @@ var onAnswerWritten_1 = require("./questions/onAnswerWritten");
|
||||||
Object.defineProperty(exports, "onAnswerWritten", { enumerable: true, get: function () { return onAnswerWritten_1.onAnswerWritten; } });
|
Object.defineProperty(exports, "onAnswerWritten", { enumerable: true, get: function () { return onAnswerWritten_1.onAnswerWritten; } });
|
||||||
var onCoupleLeave_1 = require("./couples/onCoupleLeave");
|
var onCoupleLeave_1 = require("./couples/onCoupleLeave");
|
||||||
Object.defineProperty(exports, "onCoupleLeave", { enumerable: true, get: function () { return onCoupleLeave_1.onCoupleLeave; } });
|
Object.defineProperty(exports, "onCoupleLeave", { enumerable: true, get: function () { return onCoupleLeave_1.onCoupleLeave; } });
|
||||||
|
var onGameSessionUpdate_1 = require("./games/onGameSessionUpdate");
|
||||||
|
Object.defineProperty(exports, "onGameSessionUpdate", { enumerable: true, get: function () { return onGameSessionUpdate_1.onGameSessionUpdate; } });
|
||||||
/**
|
/**
|
||||||
* Basic health check callable.
|
* Basic health check callable.
|
||||||
* Useful for verifying function deployment and firebase-tools wiring.
|
* Useful for verifying function deployment and firebase-tools wiring.
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAA+C;AAC/C,sDAAuC;AAEvC,qEAAqE;AACrE,8EAA8E;AAC9E,gFAAgF;AAChF,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IAC5B,KAAK,CAAC,aAAa,EAAE,CAAA;AACvB,CAAC;AAED,iEAA+D;AAAtD,sHAAA,iBAAiB,OAAA;AAC1B,6DAA2D;AAAlD,kHAAA,eAAe,OAAA;AACxB,uDAGkC;AAFhC,sHAAA,yBAAyB,OAAA;AACzB,4HAAA,+BAA+B,OAAA;AAEjC,wEAAsE;AAA7D,4HAAA,oBAAoB,OAAA;AAC7B,2DAAqE;AAA5D,8HAAA,2BAA2B,OAAA;AACpC,uEAGwC;AAFtC,0HAAA,mBAAmB,OAAA;AACnB,kIAAA,2BAA2B,OAAA;AAE7B,+DAA6D;AAApD,kHAAA,eAAe,OAAA;AACxB,yDAAuD;AAA9C,8GAAA,aAAa,OAAA;AAEtB;;;GAGG;AACU,QAAA,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IAC3D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;AACxC,CAAC,CAAC,CAAA"}
|
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAA+C;AAC/C,sDAAuC;AAEvC,qEAAqE;AACrE,8EAA8E;AAC9E,gFAAgF;AAChF,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IAC5B,KAAK,CAAC,aAAa,EAAE,CAAA;AACvB,CAAC;AAED,iEAA+D;AAAtD,sHAAA,iBAAiB,OAAA;AAC1B,6DAA2D;AAAlD,kHAAA,eAAe,OAAA;AACxB,uDAGkC;AAFhC,sHAAA,yBAAyB,OAAA;AACzB,4HAAA,+BAA+B,OAAA;AAEjC,wEAAsE;AAA7D,4HAAA,oBAAoB,OAAA;AAC7B,2DAAqE;AAA5D,8HAAA,2BAA2B,OAAA;AACpC,uEAGwC;AAFtC,0HAAA,mBAAmB,OAAA;AACnB,kIAAA,2BAA2B,OAAA;AAE7B,+DAA6D;AAApD,kHAAA,eAAe,OAAA;AACxB,yDAAuD;AAA9C,8GAAA,aAAa,OAAA;AACtB,mEAAiE;AAAxD,0HAAA,mBAAmB,OAAA;AAE5B;;;GAGG;AACU,QAAA,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IAC3D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;AACxC,CAAC,CAAC,CAAA"}
|
||||||
|
|
@ -79,6 +79,7 @@ export const onGameSessionUpdate = functions.firestore
|
||||||
if (wasActive && isCompletedNow) {
|
if (wasActive && isCompletedNow) {
|
||||||
const completedBy = currentData.startedByUserId
|
const completedBy = currentData.startedByUserId
|
||||||
const partnerId = completedBy === partnerA ? partnerB : partnerA
|
const partnerId = completedBy === partnerA ? partnerB : partnerA
|
||||||
|
const completingPartnerName = completedBy === partnerA ? partnerAName : partnerBName
|
||||||
|
|
||||||
// Check if partner has also completed
|
// Check if partner has also completed
|
||||||
const partnerCompletedAt = currentData.partnerCompletedAt
|
const partnerCompletedAt = currentData.partnerCompletedAt
|
||||||
|
|
@ -108,10 +109,10 @@ export const onGameSessionUpdate = functions.firestore
|
||||||
db,
|
db,
|
||||||
messaging,
|
messaging,
|
||||||
partnerId,
|
partnerId,
|
||||||
partnerName,
|
completingPartnerName,
|
||||||
currentData.gameType ?? 'wheel',
|
currentData.gameType ?? 'wheel',
|
||||||
'partner_finished_game',
|
'partner_finished_game',
|
||||||
`${partnerName} has finished. Tap to continue playing!`
|
`${completingPartnerName} has finished. Tap to continue playing!`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue