-
Notifications
You must be signed in to change notification settings - Fork 1
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
Discover and subscribe to documents based on short code #17
Draft
sandreae
wants to merge
18
commits into
main
Choose a base branch
from
sandreae/onboarding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+687
−230
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
73de8ca
Introduce init_document method
sandreae 12552ff
WIP: create new document on network run
sandreae 2d1d2f5
Bump p2panda to latest
sandreae 8a77dc1
Introduce document module
sandreae 08b29df
Add ToApp message enum and send new document id to frontend
sandreae 90a1056
Introduce DiscoveryCode topic
sandreae 0089241
Introduce FromApp message enum
sandreae eb34ba8
Update application.rs
sandreae f113be1
ShortCode is actually 6 chars
sandreae fb7b3f5
Encapsulate all backend logic in new Node struct
sandreae 50d13c4
Small test improvement
sandreae dd19ad6
Set prune flag on extensions
sandreae 95c9582
Contain current topic state on Node
sandreae c278371
Rename Node methods and make non-public
sandreae eae8121
fmt
sandreae 1e97281
Rename message variants
sandreae 70a9e69
Add CreateDocument variant on FromApp
sandreae 5d1cadc
Update tests
sandreae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use std::collections::HashMap; | ||
use std::sync::{Arc, RwLock, RwLockWriteGuard}; | ||
|
||
use async_trait::async_trait; | ||
use p2panda_core::PublicKey; | ||
use p2panda_sync::log_sync::TopicLogMap; | ||
|
||
use crate::operation::LogId; | ||
use crate::topics::{AardvarkTopics, TextDocument}; | ||
|
||
pub type ShortCode = [char; 6]; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct TextDocumentStore { | ||
inner: Arc<RwLock<TextDocumentStoreInner>>, | ||
} | ||
|
||
impl Default for TextDocumentStore { | ||
fn default() -> Self { | ||
Self { | ||
inner: Arc::new(RwLock::new(TextDocumentStoreInner { | ||
authors: HashMap::new(), | ||
})), | ||
} | ||
} | ||
} | ||
|
||
impl TextDocumentStore { | ||
pub fn write(&self) -> RwLockWriteGuard<TextDocumentStoreInner> { | ||
self.inner.write().expect("acquire write lock") | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct TextDocumentStoreInner { | ||
pub authors: HashMap<PublicKey, Vec<TextDocument>>, | ||
} | ||
|
||
#[async_trait] | ||
impl TopicLogMap<AardvarkTopics, LogId> for TextDocumentStore { | ||
async fn get(&self, topic: &AardvarkTopics) -> Option<HashMap<PublicKey, Vec<LogId>>> { | ||
let text_document = match topic { | ||
// When discovering documents we don't want any sync sessions to occur, this is a | ||
// little hack to make sure that is the case, as if both peers resolve a topic to | ||
// "None" then the sync session will naturally end. | ||
AardvarkTopics::DiscoveryCode(_) => return None, | ||
AardvarkTopics::TextDocument(text_document) => text_document, | ||
}; | ||
|
||
let authors = &self.inner.read().unwrap().authors; | ||
let mut result = HashMap::<PublicKey, Vec<LogId>>::new(); | ||
|
||
for (public_key, documents) in authors { | ||
if documents.contains(text_document) { | ||
result | ||
.entry(*public_key) | ||
.and_modify(|logs| logs.push(text_document.hash())) | ||
.or_insert(vec![text_document.hash()]); | ||
} | ||
} | ||
|
||
Some(result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
pub mod document; | ||
pub mod network; | ||
pub mod operation; | ||
pub mod operation; | ||
pub mod topics; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Need to load a new document into the UI here. This event occurs when the app starts, and also after a preceding request from the frontend to subscribe to a document based on it's short code.
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.
Another approach (maybe nicer) for this messaging channel would be to still only have one message variant, but always include the document id as well as the message bytes. Then when a change in document id is detected we interpret this as a change of document.
Doesn't change anything about how the frontend would react, just how this change is communicated to the front end.