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

Add SENT_SYNC_RECORDS which is the callback of SEND_SYNC_RECORDS #358

Merged
merged 1 commit into from Nov 8, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add SENT_SYNC_RECORDS which is the callback of SEND_SYNC_RECORDS

  • Loading branch information
darkdh committed Nov 6, 2019
commit 4ca1dbb4c2ff157f328e1637d2e0e57141dab8d7
@@ -84,6 +84,12 @@ const messages = {
* to the sync server.
*/
SEND_SYNC_RECORDS: _, /* @param {string=} categoryName, @param {Array.<Object>} records */
/**
* webview -> browser
* browser can check whether the records in SEND_SYNC_RECORDS get uploaded
* successfully.
*/
SENT_SYNC_RECORDS: _, /* @param {string=} categoryName, @param {Array.<Object>} records */
/**
* browser -> webview
* browser sends this to delete the current user.
@@ -152,6 +152,8 @@ const startSync = (requester) => {
ipc.on(messages.SEND_SYNC_RECORDS, (e, category, records) => {
logSync(`Sending ${records.length} records`)
const categoryId = proto.categories[category]
const promisePuts = []
const sentRecords = []
records.forEach((record) => {
if (!record) {
logSync(`could not send empty record`, ERROR)
@@ -163,11 +165,17 @@ const startSync = (requester) => {
if (record.bookmark && record.bookmark.parentFolderObjectId) {
record.bookmark.parentFolderObjectId = new Uint8Array(record.bookmark.parentFolderObjectId)
}
requester.bufferedPut(categoryId, record).then(() => {
logSync(`sending record: ${JSON.stringify(record)}`)
}).catch((e) => {
logSync(`could not send record ${JSON.stringify(record)}: ${e}`, ERROR)
})
promisePuts.push(
requester.bufferedPut(categoryId, record).then(() => {
logSync(`sending record: ${JSON.stringify(record)}`)
sentRecords.push(record)
}).catch((e) => {
logSync(`could not send record ${JSON.stringify(record)}: ${e}`, ERROR)
})
)
})
Promise.all(promisePuts).then(() => {
ipc.send(messages.SENT_SYNC_RECORDS, category, sentRecords)
})
})
ipc.on(messages.DELETE_SYNC_USER, (e) => {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.