Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waiting Queue Implementation #600

Merged

Conversation

prateek-kommunicate
Copy link
Contributor

@prateek-kommunicate prateek-kommunicate commented Feb 6, 2025

Screen_recording_20250206_160026.webm

Summary by CodeRabbit

  • New Features
    • Introduced waiting queue support in conversations, displaying an "In Queue" indicator and updating the conversation header when messages are pending.
    • Enhanced the user interface with a custom view that shows the user’s position in the queue, updated visuals, and tailored messaging.
    • Improved image loading for placeholders to support the new visual elements seamlessly.

Copy link

coderabbitai bot commented Feb 6, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request adds functionality for handling in-queue messages. A new method and constant in the channel service enable retrieval of queue information. A constant and logic update in the conversation model allow proper status mapping for in-queue conversations. A dedicated data class represents the queue status, and a new use case fetches and processes this information asynchronously. UI components, including a custom in-queue view, layout modifications, a vector drawable, and string resources, support the display of waiting status. An additional image loading utility method simplifies placeholder image loading.

Changes

File(s) Change Summary
.../ChannelClientService.java Added constant IN_QUEUE_MESSAGE_URL and method getChannelInQueueStatus(Long teamId) to fetch in-queue messages.
.../Channel.java Introduced constant IN_QUEUE_CONVERSATION and updated generateKmStatus to return it based on metadata.
.../InQueueData.kt Created new data class InQueueData with properties status, generatedAt, and response.
.../WaitingQueueStatusUseCase.kt Added new use-case class with suspend execute() and static executeWithExecutor methods for fetching waiting queue status.
.../QuickConversationAdapter.java, .../MobiComConversationFragment.java Modified UI logic to detect IN_QUEUE_CONVERSATION status, updating text, images, and navigation flow.
.../KmInQueueView.kt, .../km_message_in_queue.xml, .../mobicom_message_list.xml, .../strings.xml Introduced a custom view for displaying in-queue status, added associated layout components, vector drawable, and new string resources.
.../KmViewHelper.kt Added an overloaded loadImage method to load a placeholder image into a CircleImageView using Glide.

Sequence Diagram(s)

sequenceDiagram
    participant UI as MobiComConversationFragment
    participant UC as WaitingQueueStatusUseCase
    participant CS as ChannelClientService
    participant HTTP as httpRequestUtils

    UI->>UC: updateWaitingStatus()
    UC->>CS: getChannelInQueueStatus(teamId)
    CS->>HTTP: getResponse(IN_QUEUE_MESSAGE_URL + teamId)
    HTTP-->>CS: InQueueData response
    CS-->>UC: Return InQueueData
    UC-->>UI: APIResult (success/failure)
    UI->>UI: Update KmInQueueView display
Loading

Suggested reviewers

  • adarshmishra

Poem

I'm a little rabbit, hopping through the code,
Carrots of constants and methods neatly bestowed.
In-queue status blooms like springtime anew,
With UI views shining in a vibrant hue.
Bugs hide in the shadows while I celebrate this load!
🐰🥕 Happy coding in our digital meadow!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@prateek-kommunicate
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Feb 6, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (8)
kommunicate/src/main/java/io/kommunicate/models/InQueueData.kt (1)

3-7: Add documentation and consider validation for required fields.

The data class properties would benefit from:

  1. KDoc comments explaining the purpose of each field
  2. Validation or default values to prevent null pointer issues
 data class InQueueData(
+    /** Status of the queue request (e.g., "success", "error") */
     val status: String,
+    /** Timestamp when the queue status was generated */
     val generatedAt: Long,
+    /** List of response IDs in the queue */
     val response: List<Long>
 ) {
+    init {
+        require(status.isNotEmpty()) { "Status cannot be empty" }
+        require(generatedAt > 0) { "Generated timestamp must be positive" }
+    }
 }
kommunicateui/src/main/java/com/applozic/mobicomkit/uiwidgets/kommunicate/views/KmInQueueView.kt (1)

17-18: Remove unnecessary public visibility of awayMessageTv.

The property has a private setter but public getter which is unnecessary. Consider making it private.

-    lateinit var awayMessageTv: TextView
-        private set
+    private lateinit var awayMessageTv: TextView
kommunicate/src/main/java/io/kommunicate/usecase/WaitingQueueStatusUseCase.kt (1)

30-34: Optimize string comparison and improve error handling.

The case-insensitive string comparison can be optimized, and error details should be included in failure case.

-            if (response.status.lowercase() == "success") {
+            if (response.status.equals("success", ignoreCase = true)) {
                 APIResult.success(response.response)
             }else {
-                APIResult.failed(INTERNAL_ERR)
+                APIResult.failed("$INTERNAL_ERR: ${response.status}")
             }
kommunicate/src/main/java/com/applozic/mobicommons/people/channel/Channel.java (1)

293-295: Consider using a constant for the status value "7".

The hardcoded string "7" in the metadata check could be replaced with a constant to improve maintainability and prevent magic numbers.

+private static final String IN_QUEUE_STATUS = "7";
+
 if (getMetadata().containsKey(CONVERSATION_STATUS) && 
-    ("7".equals(getMetadata().get(CONVERSATION_STATUS)))) {
+    (IN_QUEUE_STATUS.equals(getMetadata().get(CONVERSATION_STATUS)))) {
kommunicate/src/main/java/com/applozic/mobicomkit/channel/service/ChannelClientService.java (1)

261-264: Enhance error handling in the getChannelInQueueStatus method.

While the method correctly handles the basic flow, consider adding more robust error handling:

  1. Validate the teamId parameter
  2. Add specific error handling for HTTP and JSON parsing errors
 public InQueueData getChannelInQueueStatus(Long teamId) throws Exception {
+    if (teamId == null || teamId <= 0) {
+        throw new IllegalArgumentException("Invalid teamId");
+    }
+    try {
         String response = httpRequestUtils.getResponse(getBaseUrl() + IN_QUEUE_MESSAGE_URL + teamId);
+        if (TextUtils.isEmpty(response)) {
+            throw new Exception("Empty response from server");
+        }
         return GsonUtils.getObjectFromJson(response, InQueueData.class);
+    } catch (Exception e) {
+        Utils.printLog(context, TAG, "Error fetching queue status: " + e.getMessage());
+        throw e;
+    }
 }
kommunicateui/src/main/java/com/applozic/mobicomkit/uiwidgets/conversation/fragment/MobiComConversationFragment.java (1)

3590-3599: Consider adding a loading state while fetching queue status.

The UI updates for queue status are good, but there's no indication to the user that the status is being fetched. Consider showing a loading indicator before the API call completes.

 if (channel.getKmStatus() == Channel.IN_QUEUE_CONVERSATION) {
+    kmInQueueView.showLoadingState();
     toolbarTitleText.setText(R.string.in_queue);
     toolbarAwayColorDot.setVisibility(GONE);
     toolbarSubtitleText.setVisibility(GONE);
     updateWaitingStatus();
 }
kommunicateui/src/main/res/values/strings.xml (1)

310-311: New In-Queue String Resources Added

The new string resources (in_queue_position and in_queue) are clearly defined to support the waiting queue feature. Please verify that the %1$s placeholder in in_queue_position matches the expected data format within your code. Overall, these additions look good and align with the intended UI feedback for queue status.

kommunicateui/src/main/res/layout/mobicom_message_list.xml (1)

278-285: Integration of KmInQueueView into Layout

The new <com.applozic.mobicomkit.uiwidgets.kommunicate.views.KmInQueueView> has been properly inserted within the view hierarchy to display waiting queue information. One detail to note: the attribute android:layout_alignParentBottom="true" is a RelativeLayout-specific property, and since this view is placed within a LinearLayout, it will have no effect. Removing it could simplify the layout and avoid any potential confusion.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ffa6e9 and 168c726.

📒 Files selected for processing (11)
  • kommunicate/src/main/java/com/applozic/mobicomkit/channel/service/ChannelClientService.java (3 hunks)
  • kommunicate/src/main/java/com/applozic/mobicommons/people/channel/Channel.java (2 hunks)
  • kommunicate/src/main/java/io/kommunicate/models/InQueueData.kt (1 hunks)
  • kommunicate/src/main/java/io/kommunicate/usecase/WaitingQueueStatusUseCase.kt (1 hunks)
  • kommunicateui/src/main/java/com/applozic/mobicomkit/uiwidgets/conversation/adapter/QuickConversationAdapter.java (3 hunks)
  • kommunicateui/src/main/java/com/applozic/mobicomkit/uiwidgets/conversation/fragment/MobiComConversationFragment.java (11 hunks)
  • kommunicateui/src/main/java/com/applozic/mobicomkit/uiwidgets/kommunicate/views/KmInQueueView.kt (1 hunks)
  • kommunicateui/src/main/java/com/applozic/mobicomkit/uiwidgets/utils/KmViewHelper.kt (1 hunks)
  • kommunicateui/src/main/res/drawable/km_message_in_queue.xml (1 hunks)
  • kommunicateui/src/main/res/layout/mobicom_message_list.xml (1 hunks)
  • kommunicateui/src/main/res/values/strings.xml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • kommunicateui/src/main/res/drawable/km_message_in_queue.xml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build Project
🔇 Additional comments (9)
kommunicate/src/main/java/com/applozic/mobicommons/people/channel/Channel.java (1)

51-51: LGTM!

The constant IN_QUEUE_CONVERSATION is appropriately defined with a unique value of 4 to represent the in-queue status.

kommunicateui/src/main/java/com/applozic/mobicomkit/uiwidgets/conversation/adapter/QuickConversationAdapter.java (3)

202-207: LGTM!

The UI changes for in-queue conversations are well-implemented:

  • Setting appropriate text and image resources
  • Ensuring proper visibility of UI elements

249-251: LGTM!

The message text view is correctly hidden for in-queue conversations.


304-306: LGTM!

The unread count is appropriately hidden for in-queue conversations.

kommunicate/src/main/java/com/applozic/mobicomkit/channel/service/ChannelClientService.java (1)

39-39: LGTM!

The URL constant is appropriately defined for fetching in-queue messages.

kommunicateui/src/main/java/com/applozic/mobicomkit/uiwidgets/conversation/fragment/MobiComConversationFragment.java (4)

161-162: LGTM! Field declarations for queue view look good.

The import and field declarations for KmInQueueView are properly added and follow the existing code structure.

Also applies to: 352-352


563-568: LGTM! Theme setup for queue view follows existing patterns.

The theme setup for kmInQueueView follows the same pattern as other views, maintaining consistency in the codebase.


1122-1127: LGTM! Queue status condition check is well implemented.

The condition check for showing away message based on queue status is clear and follows good practices:

  • Checks for null channel
  • Uses proper enum comparison
  • Groups related conditions logically

3719-3725: LGTM! Proper visibility handling for queue status UI elements.

The code correctly handles the visibility of status indicators when in queue state:

  • Hides all status dots
  • Hides subtitle text
  • Early returns to prevent further processing

@prateek-kommunicate prateek-kommunicate merged commit 888faf4 into development Feb 13, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants