include_once $dir . '/' . strtolower($cls) . '.php';
return false;
case 'Notice_to_status':
+ case 'Twitter_synch_status':
include_once $dir . '/' . $cls . '.php';
return false;
default:
{
$schema = Schema::get();
+ // For saving the last-synched status of various timelines
+ // home_timeline, messages (in), messages (out), ...
+
+ $schema->ensureTable('twitter_synch_status',
+ array(new ColumnDef('user_id', 'integer', null,
+ false, 'PRI'),
+ new ColumnDef('timeline', 'varchar', 255,
+ false, 'PRI'),
+ new ColumnDef('last_id', 'bigint', null, // XXX: check for PostgreSQL
+ false),
+ new ColumnDef('created', 'datetime', null,
+ false)));
+
// For storing user-submitted flags on profiles
$schema->ensureTable('notice_to_status',
array(new ColumnDef('notice_id', 'integer', null,
false, 'PRI'),
- new ColumnDef('status_id', 'integer', null,
+ new ColumnDef('status_id', 'bigint', null, // XXX: check for PostgreSQL
false, 'UNI'),
new ColumnDef('created', 'datetime', null,
false)));
'FROM notice LEFT JOIN notice_to_status ' .
'ON notice.id = notice_to_status.notice_id ' .
'WHERE notice.source = "twitter"' .
- 'AND notice_to_status.status_id = NULL');
+ 'AND notice_to_status.status_id IS NULL');
while ($n->fetch()) {
if (preg_match('#^http://twitter.com/[\w_.]+/status/(\d+)$#', $n->uri, $match)) {
return true;
}
+
+ /**
+ * If a notice gets deleted, remove the Notice_to_status mapping
+ *
+ * @param Notice $notice The notice getting deleted
+ *
+ * @return boolean hook value
+ */
+
+ function onNoticeDeleteRelated($notice)
+ {
+ $n2s = Notice_to_status::staticGet('notice_id', $notice->id);
+
+ if (!empty($n2s)) {
+
+ $user = common_current_user();
+
+ if (empty($user) || $user->id != $notice->profile_id) {
+ $this->log(LOG_INFO, "Skipping deleting notice for {$notice->id} since it doesn't seem to be by the author.");
+ return true;
+ }
+
+ $flink = Foreign_link::getByUserID($notice->profile_id,
+ TWITTER_SERVICE); // twitter service
+
+ if (empty($flink)) {
+ return true;
+ }
+
+ if (!TwitterOAuthClient::isPackedToken($flink->credentials)) {
+ $this->log(LOG_INFO, "Skipping deleting notice for {$notice->id} since link is not OAuth.");
+ return true;
+ }
+
+ $token = TwitterOAuthClient::unpackToken($flink->credentials);
+ $client = new TwitterOAuthClient($token->key, $token->secret);
+
+ $client->statusesDestroy($n2s->status_id);
+
+ $n2s->delete();
+ }
+ return true;
+ }
+
+ /**
+ * Notify remote users when their notices get favorited.
+ *
+ * @param Profile or User $profile of local user doing the faving
+ * @param Notice $notice being favored
+ * @return hook return value
+ */
+
+ function onEndFavorNotice(Profile $profile, Notice $notice)
+ {
+ $flink = Foreign_link::getByUserID($profile->id,
+ TWITTER_SERVICE); // twitter service
+
+ if (empty($flink)) {
+ return true;
+ }
+
+ if (!TwitterOAuthClient::isPackedToken($flink->credentials)) {
+ $this->log(LOG_INFO, "Skipping fave processing for {$profile->id} since link is not OAuth.");
+ return true;
+ }
+
+ $status_id = twitter_status_id($notice);
+
+ if (empty($status_id)) {
+ return true;
+ }
+
+ $token = TwitterOAuthClient::unpackToken($flink->credentials);
+ $client = new TwitterOAuthClient($token->key, $token->secret);
+
+ $client->favoritesCreate($status_id);
+
+ return true;
+ }
+
+ /**
+ * Notify remote users when their notices get de-favorited.
+ *
+ * @param Profile $profile Profile person doing the de-faving
+ * @param Notice $notice Notice being favored
+ *
+ * @return hook return value
+ */
+
+ function onEndDisfavorNotice(Profile $profile, Notice $notice)
+ {
+ $flink = Foreign_link::getByUserID($profile->id,
+ TWITTER_SERVICE); // twitter service
+
+ if (empty($flink)) {
+ return true;
+ }
+
+ if (!TwitterOAuthClient::isPackedToken($flink->credentials)) {
+ $this->log(LOG_INFO, "Skipping fave processing for {$profile->id} since link is not OAuth.");
+ return true;
+ }
+
+ $status_id = twitter_status_id($notice);
+
+ if (empty($status_id)) {
+ return true;
+ }
+
+ $token = TwitterOAuthClient::unpackToken($flink->credentials);
+ $client = new TwitterOAuthClient($token->key, $token->secret);
+
+ $client->favoritesDestroy($status_id);
+
+ return true;
+ }
}