-
Notifications
You must be signed in to change notification settings - Fork 19
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
Refactor message history sync, add to CLI #930
Conversation
@neekolas @richardhuaaa @insipx There's a db lock issue when the responder is attempting to gather the groups + messages (from the local db) to send to the requester:
I'm confident any one of you can solve it in short order. There's also the matter of standardizing on the message-history "api contract" i.e. make the endpoints strictly REST-ful to send to e.g. Fix those and this whole feature-set should just work™ Best of luck |
a65da36
to
ddd5848
Compare
4519c26
to
c492b99
Compare
14c3e83
to
49edac1
Compare
) -> Result<MessageHistoryReply, MessageHistoryError> { | ||
let pending_request = self.get_pending_history_request().await?; | ||
|
||
if let Some((request_id, _)) = pending_request { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do i know which request I'm replying to? What happens if a recent request just snuck in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will reply the latest request message in the sync group, which is sync'd prior to checking. does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's fine for now. Just want to walk through a scenario.
- AppB receives a message history request from AppA and shows it to the user. They look at it and click OK.
- App receives a second message history request from App C
- libxmtp replies to the request from App C because it's the newest request at the time of reply
We can solve that issue later, but it's something we should write a ticket for
None, | ||
)?; | ||
|
||
let last_message = match messages.last() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nesting match statements can get messy & make it difficult to intuit what's happening
We can compose the Result<>
and Option<>
in order to retain one level of indentation in the match
But, we also need the result of the deserialization from_slice
operation. so we can make use of ok
on the result and flatten
on the what is now Option<Option>
to get just one Option<Result>
let last_message = messages.last().map(|m| serde_json::from_slice(msg.decrypted_message_bytes).ok()).flatten();
match last_message {
Some(Ok(MessageHistoryContent::Request(request))) => {
/* ... */
}
Some(Ok(MessageHistoryContent::Reply(_))) => {
/* */
},
None => return Err(MessageHistoryError::NoPendingRequest)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after implementing your suggestion, i realized that i need access to the value of msg
inside of the match
. any tips on how the accomplish that without a nested match
?
a176bb6
to
eb8d370
Compare
Summary
Refactored message history sync
message_history
modulebundle_hash
andsign_key
when managing history bundleshistory_sync_url
for syncingMessageHistoryError
when appropriateget_sync_group
function to get sync group and its IDallow_history_sync
to use existing sync group or create a new onesend_history_request
request_id
andpin_code
send_history_reply
get_pending_history_request
function that returns therequest_id
andpin_code
of a pending history requestreply_to_history_request
function that replies to a pending history requestget_latest_history_reply
function that returns a history reply if it's the last message in a sync groupprocess_history_reply
function that downloads a history bundle using the latest history reply messageNotes
send_history_request
andsend_history_reply
are currently very basic and don't account for spamming (no time based checks). Since all installations use the same sync group, the sync group will always contain a request followed by a reply. There cannot be multiple requests or replies in a row.verify_pin
function is not currently being used. I'm not sure what the use case is.Future enhancements
startTime
) to limit size and processing timeTODO
get_pending_history_request
get_latest_history_reply
reply_to_history_request
Enable message history sync-ing from the
examples/cli
mini-app.Note: This will only work if you provide the same
--seed-phrase
when creating both client instances:Request history sync
## in tab 1, for consistency ./xli.sh --db user1_a.db3 request-history-sync
Send history sync reply
## in tab 2 ./xli.sh --db user1_b.db3 reply-to-history-sync-request
Process history sync reply
This will download and process a history bundle.
## in tab 1, for consistency ./xli.sh --db user1_a.db3 process-history-sync-reply
List history sync messages
This will display all messages in the history sync group.
Inspect
Closes #877