Use server id in article modification functions

pull/1/head
Grégory Oestreicher 2016-12-17 18:27:45 +01:00
parent 66fe16c9b8
commit 5e7fc2dea1
2 changed files with 15 additions and 13 deletions

View File

@ -309,7 +309,7 @@ function getArticles( serverId, cb, filter )
); );
} }
function articleExists( id, cb ) function articleExists( server, id, cb )
{ {
var db = getDatabase(); var db = getDatabase();
@ -319,7 +319,7 @@ function articleExists( id, cb )
var err = null; var err = null;
try { 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 ) { if ( res.rows.length === 1 ) {
exists = ( res.rows[0].count === 0 ? false : true ); exists = ( res.rows[0].count === 0 ? false : true );
} }
@ -339,6 +339,7 @@ function articleExists( id, cb )
function saveArticle( props ) function saveArticle( props )
{ {
articleExists( articleExists(
props.server,
props.id, props.id,
function( exists, err ) { function( exists, err ) {
if ( err !== null ) { if ( err !== null ) {
@ -392,7 +393,7 @@ function _updateArticle( props )
db.transaction( db.transaction(
function( tx ) { function( tx ) {
tx.executeSql( 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.created,
props.updated, props.updated,
@ -405,21 +406,22 @@ function _updateArticle( props )
props.starred, props.starred,
props.title, props.title,
props.content, props.content,
props.id props.id,
props.server
] ]
); );
} }
); );
} }
function deleteArticle( id ) function deleteArticle( server, id )
{ {
var db = getDatabase(); var db = getDatabase();
db.transaction( db.transaction(
function( tx ) { function( tx ) {
console.debug( "Delete article " + id + " from database" ); 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(); http.send();
} }
function setArticleStar( id, star ) function setArticleStar( server, id, star )
{ {
var db = getDatabase(); var db = getDatabase();
db.transaction( db.transaction(
function( tx ) { 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(); var db = getDatabase();
db.transaction( db.transaction(
function( tx ) { 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 ] );
} }
); );
} }

View File

@ -188,7 +188,7 @@ Item {
else { else {
console.debug( "Done toggling starred status for article " + article.id ) console.debug( "Done toggling starred status for article " + article.id )
var json = JSON.parse( content ) 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 ) cb( json.is_starred, null )
} }
} }
@ -230,7 +230,7 @@ Item {
else { else {
console.debug( "Done toggling archived status for article " + article.id ) console.debug( "Done toggling archived status for article " + article.id )
var json = JSON.parse( content ) 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 ) cb( json.is_archived, null )
} }
} }
@ -268,7 +268,7 @@ Item {
} }
else { else {
console.debug( "Done deleting article " + id ) console.debug( "Done deleting article " + id )
WallaBase.deleteArticle( id ) WallaBase.deleteArticle( serverId, id )
cb( null ) cb( null )
} }
} }