When importing a retweet, "RT @username:" is put in front of the tweet, and is added to the 140 characters. Hence, the actual tweet is being truncated.

Is there any solution for this?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

colin_vanarts’s picture

Priority: Normal » Major

I feel your pain..

This is resulting in multiple broken links on the new Drupal 7 website we launched last week, diminishing the usefulness of this module. I'm starting to look into fixing this bug (and if I do so, I'll try to write up a patch, but I'm new to Drupal and have not written one before).

I think the full solution is to use the image of the original tweeter, as suggested here:
https://drupal.org/node/2022717

colin_vanarts’s picture

Title: Retweets get truncated » Retweets get truncated - fixed
Version: 6.x-5.0 » 7.x-5.8
Category: support » bug
Status: Active » Needs review
FileSize
2.14 KB

I've written a patch that fixes this issue (and 2022717) by adding a check for retweet_status on each status as the timeline is loaded.

If found to be a retweet, it is now being loaded in the constructor as a sub-tweet. When saving to the database, the user and text from the retweet are saved. The timestamp is from the retweet is not used, as this could place it in the wrong spot in the user's timeline unless further patching is done.

xurizaemon’s picture

Status: Needs review » Needs work

Thanks. Patch works as advertised and stores RT in DB, but doesn't associate with the user who actually performed the RT.

I think we need to tie it back to the account which performed the RT (although I like that this preserves the original author's user pic in the Tweets view).

Have you tested what happens when multiple people RT the same Tweet? Might be only the first RT shows up, since twitter_id is a primary key.

EDIT: I guess we're going to need a second column for 'rt_screenname' or similar, and override the values when loaded or something. Need to check that a view filtered by screen_name produces the right results also.

leewillis77’s picture

We hit this problem and solved it with a modified version of the previous patch that doesn't clobber the screen name of the account that the RT was made by - it simply solves the truncation issue. Our patch attached.

Baysaa’s picture

Status: Needs work » Needs review

Patch at #4 works for me. However old tweets have still been truncated. After running cron however new tweets which get imported are fully displayed

DamienMcKenna’s picture

Version: 7.x-5.8 » 7.x-5.x-dev
Status: Needs review » Needs work

Triggering the testbot.

DamienMcKenna’s picture

Status: Needs work » Needs review

Triggering the testbot.

The last submitted patch, 2: twitter-retweets_truncated-1929126-2.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 4: twitter-retweets-truncated-1929126-4.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: twitter-retweets-truncated-1929126-4.patch, failed testing.

AdamPS’s picture

Setting parent issue - it would be great to have this one fixed in 5.9 as the truncation often chops a minimised URL contained in the tweet making the URL useless. I have rerolled the patch for the latest code.

AdamPS’s picture

AdamPS’s picture

Status: Needs work » Needs review

The last submitted patch, 4: twitter-retweets-truncated-1929126-4.patch, failed testing.

AdamPS’s picture

Status: Needs review » Reviewed & tested by the community
DamienMcKenna’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.44 KB

The patch needed a little work - please pay attention to the Drupal coding standards. I've updated the code accordingly, and reworked the trinary operator to be easier to read (i.e., got rid of it).

DamienMcKenna’s picture

I opened a new issue for properly handling the retweet_status value: #2499505: Properly store retweet_status

DamienMcKenna’s picture

Title: Retweets get truncated - fixed » Store the entire message for retweets

  • DamienMcKenna committed 0b6e9a5 on 7.x-5.x
    Issue #1929126 by colin_vanarts, leewillis77, AdamPS, DamienMcKenna:...
DamienMcKenna’s picture

Version: 7.x-5.x-dev » 7.x-6.x-dev
Status: Needs review » Patch (to be ported)

This needs to be ported to the 7.x-6.x branch.

  • DamienMcKenna committed 1277463 on 6.x-5.x
    Issue #1929126 by colin_vanarts, leewillis77, AdamPS, DamienMcKenna:...
DamienMcKenna’s picture

The patch applied a-ok to the 6.x-5.x branch, so it has been fixed there too.

tobiasb’s picture

Hmm now the text is RT @user: RT @user: Foobar. Why we add this, when RT is part of the tweet text?

DamienMcKenna’s picture

Version: 7.x-6.x-dev » 7.x-5.x-dev
Status: Patch (to be ported) » Needs review
FileSize
842 bytes

@tobiasb: Oh, whoops. Lets remove the redundant RT: bit.

DamienMcKenna’s picture

  • DamienMcKenna committed aabc536 on 6.x-5.x
    Issue #1929126 by DamienMcKenna: Remove redundant RT: bit from retweets.
    

  • DamienMcKenna committed f146468 on
    Issue #1929126 by DamienMcKenna: Remove redundant RT: bit from retweets.
    
DamienMcKenna’s picture

Status: Needs review » Fixed

I've uploaded the fixes for 6.x-5.x and 7.x-5.x.

DamienMcKenna’s picture

Version: 7.x-5.x-dev » 7.x-6.x-dev
Status: Fixed » Patch (to be ported)

Still need to port the change to 7.x-6.0.

AdamPS’s picture

Status: Patch (to be ported) » Needs work

@DamienMcKenna Thanks for you continued hard work on this module, but I think your latest changes have broken the fix.

  • The patch in #12 works for me.
  • The whole point of this fix is to use $status->retweeted_status->text, which excludes "RT: @user" and hence there is space for the entire tweet in 140 characters. "RT: @user" is then added on separately.
  • Your "tidy up for coding standards" accidentally switched back to using $status->text, but still added "RT: @user" so we had a truncated tweet and a double RT.
  • You final commit seems to more-or-less back out the whole fix and take us back where we started:-)

I think the right fix now is to back out the final commit then apply another patch effectively like this. (I've not supplied a patch file as I'm not sure exactly what it would need to base against by now and hopefully it's obvious!)

- $text = 'RT @' . $status->retweeted_status->user->screen_name . ': ' . $text;
+ $text = 'RT @'.$status->retweeted_status->user->screen_name.': '.$status->retweeted_status->text,
AdamPS’s picture

Version: 7.x-6.x-dev » 7.x-5.x-dev
DamienMcKenna’s picture

LOLWhoops. X-) Thanks for double-checking my work.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
919 bytes

So like this?

AdamPS’s picture

FileSize
705 bytes

Yes that's the essence of it. But I can't actually apply your patch to the latest dev build - this is what I used. Maybe you already backed out the other change locally which is why you have a different patch.

Status: Needs review » Needs work

The last submitted patch, 36: twitter.n1929126-36.patch, failed testing.

AdamPS’s picture

I guess the latest dev build which I have downloaded doesn't include a check-in that's in GIT which is why we have slightly different patches. But it looks like we are all heading for the same result! Here is the whole function that I tested with.

/**
 * Saves a TwitterStatus object to {twitter}
 */
function twitter_status_save($status) {
  // RT's get special handling.
  if (!empty($status->retweeted_status)) {
    $text = 'RT @' . $status->retweeted_status->user->screen_name . ': ' . $status->retweeted_status->text;
  }
  else {
    $text = $status->text;
  }

  $row = array(
    'twitter_id' => $status->id,
    'screen_name' => $status->user->screen_name,
    'created_time' => strtotime($status->created_at),
    'text' => $text,
    'source' => $status->source,
    'in_reply_to_status_id' => ($status->in_reply_to_status_id > 0) ? (string) $status->in_reply_to_status_id : NULL,
    'in_reply_to_user_id' => $status->in_reply_to_user_id,
    'in_reply_to_screen_name' => $status->in_reply_to_screen_name,
    'truncated' => (int) $status->truncated,
    'entities' => isset($status->entities) ? serialize($status->entities) : NULL,
  );
  db_merge('twitter')
    ->key(array('twitter_id' => $row['twitter_id']))
    ->fields($row)
    ->execute();
  // Let other modules know that a status has been saved.
  module_invoke_all('twitter_status_save', $status);
}

DamienMcKenna’s picture

Version: 7.x-5.x-dev » 7.x-6.x-dev
Status: Needs work » Patch (to be ported)

Ok, committed. It still needs to be ported to the 7.x-6.x branch, but the rest are a-ok.

DamienMcKenna’s picture

Status: Patch (to be ported) » Needs review
FileSize
1.71 KB

Untested.

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed.

  • DamienMcKenna committed 6782928 on 7.x-6.x
    Issue #1929126 by colin_vanarts, leewillis77, AdamPS, DamienMcKenna:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

stropharis’s picture

Maybe I'm the only one, but for me imported retweets with this very module versions result in just the text "RT @: ", nothing more. User-created tweets are imported just fine, though. Could this issue be related?

domignon’s picture

You're not alone stropharis,
Same here . User-created AND tweets created by other people mentioning user imported just fine but no RT available. The database record shows an almost empty text field like if something gone wrong from line 156 of twitter.inc file

...
function twitter_status_save($status) {
  // RT's get special handling.
  if (!empty($status->retweeted_status)) {
    $text = 'RT @' . $status->retweeted_status->user->screen_name . ': ' . $status->retweeted_status->text;
  }
  else {
    $text = $status->text;
  }
...
ChaseOnTheWeb’s picture

Status: Closed (fixed) » Needs review
FileSize
591 bytes

The code is wrong, at least for 7.x-6.x, because $status->retweeted_status is an array, not an object. That might be a bug elsewhere in the module, since you would expect it to be an object just like $status. Attached is a patch to use array operators to address the immediate pain.

ChaseOnTheWeb’s picture

Status: Needs review » Closed (fixed)

Doh, the same patch was posted at #2624178: Retweeted text not appears

domignon’s picture

Many thanks ChaseONTheWeb