Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.lambda_bbb_events.controller

import com.example.lambda_bbb_events.model.AdminLog
import com.example.lambda_bbb_events.model.LogType
import com.example.lambda_bbb_events.model.admin.AdminLog
import com.example.lambda_bbb_events.model.admin.LogType
import com.example.lambda_bbb_events.model.repository.AdminLogRepository

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ class AdminLogController(
* The original identifiers are preserved for internal use.
*
* @param logs The logs containing user and campsite identifiers.
* @param profileNames A map of user IDs to user names.
* @param profileNames A map of user IDs to usernames.
* @param campsiteNames A map of campsite IDs to campsite names.
* @return A list of logs containing resolved display names.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import com.example.lambda_bbb_events.model.services.PlaceSearch
* @property reviewReplies Controller for the replies under reviews.
* @property reviewReactions Controller for the emoji reactions to reviews.
* @property places Searches for places by name.
* @property notifications Controller for notification operations.
* @property messages Controller for messaging operations.
* @property notificationPreferences Controller for notification preferences.
* @property messageNotifications Controller for incoming message alerts.
* @property notificationPreferences Controller for notification preferences from individual messaging contacts
* @property messageNotifications Controller for incoming android alerts for eligible incoming messages.
* @property adminLogs Controller for administrative notification and message logs.
* @property adminLotteries Controller for admin-only lottery actions.
* @property adminLotteries Controller for administrating lottery actions.
*/
class AppControllers(
val users: UserController,
Expand All @@ -38,13 +39,10 @@ class AppControllers(
val places: PlaceSearch = FallbackPlaceSearch(),
val notifications: NotificationController,
val messages: MessageController = MessageController(users),
/** Manages preferences for notifications from individual messaging contacts. */
val notificationPreferences: NotificationPreferenceController =
NotificationPreferenceController(users),
/** Posts Android notifications for eligible incoming messages. */
val messageNotifications: MessageNotificationController =
MessageNotificationController(users),
val adminLogs: AdminLogController = AdminLogController(),
/** Coordinates administrator actions for running lotteries. */
val adminLotteries: AdminLotteryController = AdminLotteryController()
)
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CampsitePhotoController(
*
* @param campsiteId The ID of the campsite.
* @param uploaderId The ID of the user adding the photo.
* @param photo The photo.
* @param photo The photo to be added.
* @throws IllegalStateException if the campsite already has [MAX_PHOTOS] photos.
* @throws Exception if the photo could not be uploaded or saved.
*/
Expand Down Expand Up @@ -64,6 +64,8 @@ class CampsitePhotoController(
* Removes a photo from a campsite, then deletes it. If deleting it fails, it is still
* removed from the campsite.
*
* @param campsiteId The ID of the campsite.
* @param imageId The ID of the photo to be removed.
* @throws Exception if the change could not be saved, in which case the photo is kept.
*/
suspend fun removePhoto(campsiteId: String, imageId: String) {
Expand All @@ -74,6 +76,8 @@ class CampsitePhotoController(
/**
* Moves a photo to the front, making it the thumbnail. The others keep their order.
*
* @param campsiteId The ID of the campsite.
* @param imageId The ID of the photo to be removed.
* @throws Exception if the change could not be saved.
*/
suspend fun makeThumbnail(campsiteId: String, imageId: String) {
Expand All @@ -83,6 +87,10 @@ class CampsitePhotoController(
/**
* Changes the part of a photo that stays in view when it is cropped.
*
* @param campsiteId The ID of the campsite.
* @param imageId The ID of the photo.
* @param focusX The horizontal focus position.
* @param focusY The vertical focus position.
* @throws Exception if the change could not be saved.
*/
suspend fun changeFocus(campsiteId: String, imageId: String, focusX: Float, focusY: Float) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.example.lambda_bbb_events.controller

import com.example.lambda_bbb_events.model.lottery.Lottery
import com.example.lambda_bbb_events.model.lottery.LotteryStatus
import com.example.lambda_bbb_events.model.Message
import com.example.lambda_bbb_events.model.message.Message
import com.example.lambda_bbb_events.model.repository.LotteryRepository
import java.time.LocalDate
import java.time.ZoneId
Expand Down Expand Up @@ -187,7 +187,7 @@ class LotteryController(
* @param bookingEnd The end date of the booking period.
* @param numberOfWinnersString The number of winners of the lottery (as a string).
* @param waitlistCapacityString The maximum number of entries (as a string).
* @return `null` if the lottery was created successfully. An error message otherwise.
* @return `null` if the lottery was updated successfully. An error message otherwise.
*/
suspend fun updateLottery(
lotteryId: String,
Expand Down Expand Up @@ -297,6 +297,7 @@ class LotteryController(
* Deletes a lottery.
*
* @param lottery The lottery to delete.
* @throws Exception if deleting lottery fails.
*/
suspend fun deleteLottery(lottery: Lottery) {
lotteryRepository.deleteLottery(lottery)
Expand All @@ -311,6 +312,7 @@ class LotteryController(
* @param ownerId The device ID of the owner.
* @param campsiteName Gets a campsite's name from its ID, for the message, or `null` if unknown.
* @return The number of winners sent a message.
* @throws Exception if retrieving lotteries or cancelling a lottery or notifying winners fails.
*/
suspend fun cancelLotteriesOfDeletedOwner(
ownerId: String,
Expand Down Expand Up @@ -358,7 +360,7 @@ class LotteryController(
}

/**
* Gets the lotteries of a campsite that match a filter.
* Returns the lotteries of a campsite that match a filter.
*
* @param campsiteId The `campsiteId` to search for.
* @param filter Which lotteries to return. The default is only the active ones.
Expand Down Expand Up @@ -459,6 +461,7 @@ class LotteryController(
*
* @param lottery The lottery being accepted.
* @param ownerId The device ID of the owner accepting.
* @throws Exception if updating the lottery fails.
*/
suspend fun acceptLotteryRequest(lottery: Lottery, ownerId: String) {
lotteryRepository.updateLottery(
Expand All @@ -470,6 +473,7 @@ class LotteryController(
* Declines a lottery request. This cancels the whole lottery.
*
* @param lottery The lottery being declined.
* @throws Exception if updating the lottery fails.
*/
suspend fun declineLotteryRequest(lottery: Lottery) {
lotteryRepository.updateLottery(lottery.copy(status = LotteryStatus.CANCELLED))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.example.lambda_bbb_events.controller
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.example.lambda_bbb_events.model.Message
import com.example.lambda_bbb_events.model.Conversation
import com.example.lambda_bbb_events.model.message.Message
import com.example.lambda_bbb_events.model.message.Conversation
import com.example.lambda_bbb_events.model.message.ConversationType
import com.example.lambda_bbb_events.model.repository.MessageRepository
import com.example.lambda_bbb_events.model.repository.ConversationRepository
Expand All @@ -22,8 +22,7 @@ import kotlinx.coroutines.flow.Flow
* current user and their role.
*
* @param userController Controller responsible for user operations.
* @param conversationRepository Repository responsible
* for managing conversations.
* @param conversationRepository Repository responsible for managing conversations.
*/
class MessageController(
private val userController: UserController,
Expand Down Expand Up @@ -61,14 +60,15 @@ class MessageController(
* @param contactId Device ID of the campsite owner or administrator.
* @param type Type of conversation.
* @return Unique identifier of the conversation.
* @throws IllegalStateException If no user is signed in.
*
* Reference:
* Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model].
* https://claude.com/claude-code
* Changed with the help of this AI tool.
* Prompts:
* - "Now on the notification page as well. Please also remove the profile duplication bug.
* Also please fix the way the admins work since it seems all admins share an account. One
* Also, please fix the way the admins work since it seems all admins share an account. One
* more thing is to fix the notification page so that the spacing looks right."
* - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate
* chats per admin".
Expand Down Expand Up @@ -136,6 +136,7 @@ class MessageController(
* Should only be called after conversation access is checked.
*
* @param conversationId Unique identifier of the conversation.
* @throws IllegalStateException If no user is signed in.
*/
fun openConversation(conversationId: String) {
check(userController.currentUser != null) {
Expand Down Expand Up @@ -171,7 +172,7 @@ class MessageController(
* Changed with the help of this AI tool.
* Prompts:
* - "Now on the notification page as well. Please also remove the profile duplication bug.
* Also please fix the way the admins work since it seems all admins share an account. One
* Also, please fix the way the admins work since it seems all admins share an account. One
* more thing is to fix the notification page so that the spacing looks right."
* - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate
* chats per admin".
Expand All @@ -193,7 +194,7 @@ class MessageController(
* message in their conversations.
*
* @param messageId Unique identifier of the message.
* @throws IllegalStateException If no conversation is open
* @throws IllegalStateException If no conversation is open, no user signed in,
* or the current user may not delete the message.
*
* Reference:
Expand All @@ -220,6 +221,7 @@ class MessageController(
* Whether the current user may delete [message].
*
* @param message The message to check.
* @return `true` if the current user may delete the message, `false` if otherwise.
*
* Reference:
* Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model].
Expand Down Expand Up @@ -247,7 +249,7 @@ class MessageController(
* Changed with the help of this AI tool.
* Prompts:
* - "Now on the notification page as well. Please also remove the profile duplication bug.
* Also please fix the way the admins work since it seems all admins share an account. One
* Also, please fix the way the admins work since it seems all admins share an account. One
* more thing is to fix the notification page so that the spacing looks right."
* - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate
* chats per admin".
Expand Down Expand Up @@ -295,7 +297,7 @@ class MessageController(
* Changed with the help of this AI tool.
* Prompts:
* - "Now on the notification page as well. Please also remove the profile duplication bug.
* Also please fix the way the admins work since it seems all admins share an account. One
* Also, please fix the way the admins work since it seems all admins share an account. One
* more thing is to fix the notification page so that the spacing looks right."
* - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate
* chats per admin".
Expand Down Expand Up @@ -340,7 +342,7 @@ class MessageController(
* Changed with the help of this AI tool.
* Prompts:
* - "Now on the notification page as well. Please also remove the profile duplication bug.
* Also please fix the way the admins work since it seems all admins share an account. One
* Also, please fix the way the admins work since it seems all admins share an account. One
* more thing is to fix the notification page so that the spacing looks right."
* - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate
* chats per admin".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import com.example.lambda_bbb_events.MainActivity
import com.example.lambda_bbb_events.R
import com.example.lambda_bbb_events.model.Conversation
import com.example.lambda_bbb_events.model.Message
import com.example.lambda_bbb_events.model.message.Conversation
import com.example.lambda_bbb_events.model.message.Message
import com.example.lambda_bbb_events.model.repository.NotificationPreferenceRepository

/**
Expand All @@ -41,19 +41,19 @@ class MessageNotificationController(
* @param conversation Conversation containing the message.
* @param message Incoming message.
* @return True if notifications are permitted.
*
* Reference:
* Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model].
* https://claude.com/claude-code
* Changed with the help of this AI tool.
* Prompts:
* - "Now on the notification page as well. Please also remove the profile duplication bug.
* Also please fix the way the admins work since it seems all admins share an account. One
* more thing is to fix the notification page so that the spacing looks right."
* - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate
* chats per admin".
*/
suspend fun shouldNotify(
// Reference:
// Anthropic. (2026). Claude Code (Claude Opus 5.5) [Large language model].
// https://claude.com/claude-code
// Changed with the help of this AI tool.
// Prompts:
// - "Now on the notification page as well. Please also remove the profile duplication bug.
// Also, please fix the way the admins work since it seems all admins share an account. One
// more thing is to fix the notification page so that the spacing looks right."
// - Answers chosen when the AI asked how to do this: "Merge repeated contacts" and "Separate
// chats per admin".

conversation: Conversation,
message: Message
): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

package com.example.lambda_bbb_events.controller

/*
* builds notifications and verifies if app and user preference both have notification enabled
*/
Expand All @@ -21,7 +22,9 @@ import com.example.lambda_bbb_events.model.notification.NotificationCategory
import com.example.lambda_bbb_events.model.notification.NotificationMode

/**
* Builds and displays notifications
* Builds notification and delivery as wel as preferences and history
*
* Checks user and Android notification settings before displaying notifications.
*
* @property context Context used for system services
* @property users Used to verify user notification preference
Expand All @@ -44,6 +47,7 @@ class NotificationController(
/**
* Shows a notification if the user and system both allow it.
* @param notification The notification content.
* @param category Category used to determine the delivery.
*/
fun showNotification(
notification: Notification,
Expand Down Expand Up @@ -85,6 +89,14 @@ class NotificationController(
}
}

/**
* Helper function that checks notification permission and builds the notification.
*
* High priority notifications go to a separate channel ID.
*
* @param notification The notification content.
* @param mode The notification delivery mode.
*/
private fun postNotification(
notification: Notification,
mode: NotificationMode
Expand Down Expand Up @@ -177,7 +189,12 @@ class NotificationController(
}
}

/** Observes changes to the saved notification history for [userId]. */
/**
* Observes changes to the notification history for a user.
*
* @param userId ID of the user whose notification history is observed.
* @return A flow of the user's notification history.
*/
fun observeHistory(userId: String) =
historyStore.observeHistory(userId)

Expand All @@ -189,15 +206,26 @@ class NotificationController(
historyStore.clear(userId)
}

/** Returns the delivery mode for the given user and notification category. */
/**
* Returns the delivery mode for a user's notification category.
*
* @param userId ID of the user whose preference is retrieved.
* @param category Notification category.
* @return The saved notification delivery mode.
*/
fun getCategoryMode(
userId: String,
category: NotificationCategory
): NotificationMode {
return categoryStore.getMode(userId, category)
}

/** Saves a category delivery preference for the signed-in user. */
/**
* Saves a notification delivery preference for the signed-in user.
*
* @param category Notification category.
* @param mode Delivery mode to save.
*/
fun setCategoryMode(
category: NotificationCategory,
mode: NotificationMode
Expand Down
Loading
Loading