Saturday, 21 April 2012

Suppressing DMs you have already read

I don't use direct messages often, so every time I fire up TTYtter, the same DMs appear in my timeline when it performs its "-- checking for most recent direct messages:" function.

It's not a huge issue, but I had a few minutes spare to write an extension to suppress them.

Download the extension here and read the TTYtter documentation on how to run extensions.

Note, the first time you use the extension, it will display the most recent DMs as it will not have stored the ids of them! 

$store->{last_dm_id} = 0; 
$store->{dmbookmark} = "$ENV{'HOME'}/.ttytter.dmbookmark";

if( open( DM, $store->{dmbookmark} ) ) {
 $store->{last_dm_id} = scalar( );
 close( DM ); 
}

$dmhandle = sub {

  my $ref = shift;

  if ( $ref->{id} > $store->{last_dm_id} ) {

    $store->{last_dm_id} = $ref->{id};
    &defaultdmhandle( $ref );

 }

};

$dmconclude = sub {

 if(open(DM, ">".$store->{dmbookmark})) {

   print DM $store->{last_dm_id};
   close( DM ); } 

  else { 
    print $stdout "Failed to write: $!\n"; 

  } 

  &defaultdmconclude; 

};

No comments: