Skip to content

Commit

Permalink
tweet update bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearfog committed Jan 7, 2021
1 parent d550eef commit 79738e1
Showing 1 changed file with 47 additions and 35 deletions.
82 changes: 47 additions & 35 deletions app/src/main/java/org/nuclearfog/twidda/database/AppDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,42 +335,10 @@ public List<Tweet> getAnswers(long tweetId) {
* @param tweet Tweet
*/
public void updateStatus(Tweet tweet) {
String[] tweetIdArg = {Long.toString(tweet.getId())};
String[] userIdArg = {Long.toString(tweet.getUser().getId())};

SQLiteDatabase db = getDbWrite();
ContentValues statColumn = new ContentValues();
ContentValues userColumn = new ContentValues();
int flags = getTweetFlags(db, tweet.getId());
if (tweet.retweeted())
flags |= RTW_MASK;
else
flags &= ~RTW_MASK;
if (tweet.favored())
flags |= FAV_MASK;
else
flags &= ~FAV_MASK;
statColumn.put("tweet", tweet.getTweet());
statColumn.put("retweet", tweet.getRetweetCount());
statColumn.put("favorite", tweet.getFavorCount());
statColumn.put("retweeterID", tweet.getMyRetweetId());
statColumn.put("replyname", tweet.getReplyName());
statColumn.put("statusregister", flags);
statColumn.put("media", getMediaLinks(tweet));

User user = tweet.getUser();
userColumn.put("username", user.getUsername());
userColumn.put("scrname", user.getScreenname());
userColumn.put("pbLink", user.getImageLink());
userColumn.put("bio", user.getBio());
userColumn.put("link", user.getLink());
userColumn.put("location", user.getLocation());
userColumn.put("banner", user.getBannerLink());
userColumn.put("following", user.getFollowing());
userColumn.put("follower", user.getFollower());

db.update("tweet", statColumn, "tweet.tweetID=?", tweetIdArg);
db.update("user", userColumn, "user.userID=?", userIdArg);
updateStatus(tweet, db);
if (tweet.getEmbeddedTweet() != null)
updateStatus(tweet.getEmbeddedTweet(), db);
commit(db);
}

Expand Down Expand Up @@ -721,6 +689,50 @@ private void storeStatus(Tweet tweet, int statusRegister, SQLiteDatabase db) {
db.insertWithOnConflict("tweet", null, status, CONFLICT_REPLACE);
}

/**
* updates existing tweet
*
* @param tweet update of the tweet
* @param db database instance
*/
private void updateStatus(Tweet tweet, SQLiteDatabase db) {
String[] tweetIdArg = {Long.toString(tweet.getId())};
String[] userIdArg = {Long.toString(tweet.getUser().getId())};

ContentValues statColumn = new ContentValues();
ContentValues userColumn = new ContentValues();
int flags = getTweetFlags(db, tweet.getId());
if (tweet.retweeted())
flags |= RTW_MASK;
else
flags &= ~RTW_MASK;
if (tweet.favored())
flags |= FAV_MASK;
else
flags &= ~FAV_MASK;
statColumn.put("tweet", tweet.getTweet());
statColumn.put("retweet", tweet.getRetweetCount());
statColumn.put("favorite", tweet.getFavorCount());
statColumn.put("retweeterID", tweet.getMyRetweetId());
statColumn.put("replyname", tweet.getReplyName());
statColumn.put("statusregister", flags);
statColumn.put("media", getMediaLinks(tweet));

User user = tweet.getUser();
userColumn.put("username", user.getUsername());
userColumn.put("scrname", user.getScreenname());
userColumn.put("pbLink", user.getImageLink());
userColumn.put("bio", user.getBio());
userColumn.put("link", user.getLink());
userColumn.put("location", user.getLocation());
userColumn.put("banner", user.getBannerLink());
userColumn.put("following", user.getFollowing());
userColumn.put("follower", user.getFollower());

db.update("tweet", statColumn, "tweet.tweetID=?", tweetIdArg);
db.update("user", userColumn, "user.userID=?", userIdArg);
}

/**
* Store Tweet into favorite table of a user
*
Expand Down

0 comments on commit 79738e1

Please sign in to comment.