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

feat(conversations): create conversation list with last message #1437

Merged
merged 15 commits into from
Dec 20, 2024

Conversation

mchenani
Copy link
Contributor

@mchenani mchenani commented Dec 19, 2024

Summary:
Added a SQL view to represent the list of client conversations, including the last message in each conversation.

  • If the last message is an application message, its timestamp is used.
  • Otherwise, the group creation time determines the order.

Context:
Previously, all conversations were loaded, and the last message for each conversation was fetched individually, resulting in inefficiencies.

Solution:
Introduced a SQL-level View to streamline fetching the conversation list, with each row including the latest message, improving performance and clarity.

close #1181

@@ -1141,6 +1161,12 @@ pub struct FfiConversation {
inner: MlsGroup<RustXmtpClient>,
}

#[derive(uniffi::Object)]
pub struct FfiConversationListItem {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

introduced this struct to avoid changing all the current functions!

@@ -965,6 +965,26 @@ impl FfiConversations {
Ok(convo_list)
}

pub async fn list_conversations(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

default order is:
ORDER BY COALESCE(rm.sent_at_ns, g.created_at_ns) DESC

@mchenani mchenani marked this pull request as ready for review December 20, 2024 09:42
@mchenani mchenani requested a review from a team as a code owner December 20, 2024 09:42
@mchenani mchenani requested a review from insipx December 20, 2024 18:29
Copy link
Contributor

@insipx insipx left a comment

Choose a reason for hiding this comment

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

nice!

@mchenani mchenani merged commit e7630ac into main Dec 20, 2024
11 checks passed
@mchenani mchenani deleted the mc/conversation-list-w-last-message branch December 20, 2024 19:40
@mchenani
Copy link
Contributor Author

resolves #1181

@@ -947,6 +947,26 @@ impl FfiConversations {
Ok(convo_list)
}

pub async fn list_conversations(
Copy link
Contributor

@nplasterer nplasterer Dec 21, 2024

Choose a reason for hiding this comment

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

I'm not sure I understand when this is supposed to be used instead of the list() function above? cc @mchenani

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I saw in android, we fetched the conversations and the get the last message one by one and map them together.
we can replace it with this.

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.

Join table on group and groupMessages for sorting by last message
4 participants