From 5e7fc2dea1d18406ffd657ab95cff78ba419fecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Oestreicher?= Date: Sat, 17 Dec 2016 18:27:45 +0100 Subject: [PATCH] Use server id in article modification functions --- qml/js/WallaBase.js | 22 ++++++++++++---------- qml/types/Server.qml | 6 +++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/qml/js/WallaBase.js b/qml/js/WallaBase.js index af327b5..8458e26 100644 --- a/qml/js/WallaBase.js +++ b/qml/js/WallaBase.js @@ -309,7 +309,7 @@ function getArticles( serverId, cb, filter ) ); } -function articleExists( id, cb ) +function articleExists( server, id, cb ) { var db = getDatabase(); @@ -319,7 +319,7 @@ function articleExists( id, cb ) var err = null; try { - var res = tx.executeSql( "SELECT COUNT(*) AS count FROM articles WHERE id=?", [ id ] ); + var res = tx.executeSql( "SELECT COUNT(*) AS count FROM articles WHERE id=? AND server=?", [ id, server ] ); if ( res.rows.length === 1 ) { exists = ( res.rows[0].count === 0 ? false : true ); } @@ -339,6 +339,7 @@ function articleExists( id, cb ) function saveArticle( props ) { articleExists( + props.server, props.id, function( exists, err ) { if ( err !== null ) { @@ -392,7 +393,7 @@ function _updateArticle( props ) db.transaction( function( tx ) { tx.executeSql( - "UPDATE articles SET created=?, updated=?, mimetype=?, language=?, readingTime=?, url=?, domain=?, archived=?, starred=?, title=?, content=? WHERE id=?", + "UPDATE articles SET created=?, updated=?, mimetype=?, language=?, readingTime=?, url=?, domain=?, archived=?, starred=?, title=?, content=? WHERE id=? AND server=?", [ props.created, props.updated, @@ -405,21 +406,22 @@ function _updateArticle( props ) props.starred, props.title, props.content, - props.id + props.id, + props.server ] ); } ); } -function deleteArticle( id ) +function deleteArticle( server, id ) { var db = getDatabase(); db.transaction( function( tx ) { console.debug( "Delete article " + id + " from database" ); - tx.executeSql( "DELETE FROM articles WHERE id=?", [ id ] ); + tx.executeSql( "DELETE FROM articles WHERE id=? AND server=?", [ id, server ] ); } ); } @@ -507,24 +509,24 @@ function _downloadNextArticles( url, token, page, cb ) http.send(); } -function setArticleStar( id, star ) +function setArticleStar( server, id, star ) { var db = getDatabase(); db.transaction( function( tx ) { - tx.executeSql( "UPDATE articles SET starred=? WHERE id=?", [ star, id ] ); + tx.executeSql( "UPDATE articles SET starred=? WHERE id=? AND server=?", [ star, id, server ] ); } ); } -function setArticleRead( id, read ) +function setArticleRead( server, id, read ) { var db = getDatabase(); db.transaction( function( tx ) { - tx.executeSql( "UPDATE articles SET archived=? WHERE id=?", [ read, id ] ); + tx.executeSql( "UPDATE articles SET archived=? WHERE id=? AND server=?", [ read, id, server ] ); } ); } diff --git a/qml/types/Server.qml b/qml/types/Server.qml index 3aa1b84..80a70b2 100644 --- a/qml/types/Server.qml +++ b/qml/types/Server.qml @@ -188,7 +188,7 @@ Item { else { console.debug( "Done toggling starred status for article " + article.id ) var json = JSON.parse( content ) - WallaBase.setArticleStar( article.id, json.is_starred ) + WallaBase.setArticleStar( serverId, article.id, json.is_starred ) cb( json.is_starred, null ) } } @@ -230,7 +230,7 @@ Item { else { console.debug( "Done toggling archived status for article " + article.id ) var json = JSON.parse( content ) - WallaBase.setArticleRead( article.id, json.is_archived ) + WallaBase.setArticleRead( serverId, article.id, json.is_archived ) cb( json.is_archived, null ) } } @@ -268,7 +268,7 @@ Item { } else { console.debug( "Done deleting article " + id ) - WallaBase.deleteArticle( id ) + WallaBase.deleteArticle( serverId, id ) cb( null ) } }