Only show twitter msgs in your own inbox

This commit is contained in:
Evan Prodromou 2009-06-18 11:45:48 -07:00
parent b761cfd409
commit 3f54840b51
6 changed files with 81 additions and 37 deletions

View File

@ -98,7 +98,13 @@ class AllAction extends ProfileAction
function showContent() function showContent()
{ {
$notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); $cur = common_current_user();
if (!empty($cur) && $cur->id == $this->user->id) {
$notice = $this->user->noticeInbox(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
} else {
$notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
}
$nl = new NoticeList($notice, $this); $nl = new NoticeList($notice, $this);

View File

@ -81,6 +81,14 @@ class AllrssAction extends Rss10Action
*/ */
function getNotices($limit=0) function getNotices($limit=0)
{ {
$cur = common_current_user();
if (!empty($cur) && $cur->id == $user->id) {
$notice = $this->user->noticeInbox(0, $limit);
} else {
$notice = $this->user->noticesWithFriends(0, $limit);
}
$user = $this->user; $user = $this->user;
$notice = $user->noticesWithFriends(0, $limit); $notice = $user->noticesWithFriends(0, $limit);
$notices = array(); $notices = array();

View File

@ -21,29 +21,28 @@ if (!defined('LACONICA')) { exit(1); }
require_once INSTALLDIR.'/lib/facebookaction.php'; require_once INSTALLDIR.'/lib/facebookaction.php';
class FacebookhomeAction extends FacebookAction class FacebookhomeAction extends FacebookAction
{ {
var $page = null; var $page = null;
function prepare($argarray) function prepare($argarray)
{ {
parent::prepare($argarray); parent::prepare($argarray);
$this->page = $this->trimmed('page'); $this->page = $this->trimmed('page');
if (!$this->page) { if (!$this->page) {
$this->page = 1; $this->page = 1;
} }
return true; return true;
} }
function handle($args) function handle($args)
{ {
parent::handle($args); parent::handle($args);
// If the user has opted not to initially allow the app to have // If the user has opted not to initially allow the app to have
// Facebook status update permission, store that preference. Only // Facebook status update permission, store that preference. Only
// promt the user the first time she uses the app // promt the user the first time she uses the app
@ -73,7 +72,7 @@ class FacebookhomeAction extends FacebookAction
$this->updateProfileBox($notice); $this->updateProfileBox($notice);
} }
if ($this->arg('status_submit') == 'Send') { if ($this->arg('status_submit') == 'Send') {
$this->saveNewNotice(); $this->saveNewNotice();
} }
@ -81,7 +80,7 @@ class FacebookhomeAction extends FacebookAction
// Facebook status update permission? Then show the main page // Facebook status update permission? Then show the main page
// of the app // of the app
$this->showPage(); $this->showPage();
} else { } else {
// User hasn't authenticated yet, prompt for creds // User hasn't authenticated yet, prompt for creds
@ -89,12 +88,12 @@ class FacebookhomeAction extends FacebookAction
} }
} }
function login() function login()
{ {
$this->showStylesheets(); $this->showStylesheets();
$nickname = common_canonical_nickname($this->trimmed('nickname')); $nickname = common_canonical_nickname($this->trimmed('nickname'));
$password = $this->arg('password'); $password = $this->arg('password');
@ -141,13 +140,12 @@ class FacebookhomeAction extends FacebookAction
$this->facebook->api_client->data_setUserPreference( $this->facebook->api_client->data_setUserPreference(
FACEBOOK_PROMPTED_UPDATE_PREF, 'false'); FACEBOOK_PROMPTED_UPDATE_PREF, 'false');
} }
function showNoticeForm() function showNoticeForm()
{ {
$post_action = "$this->app_uri/index.php"; $post_action = "$this->app_uri/index.php";
$notice_form = new FacebookNoticeForm($this, $post_action, null, $notice_form = new FacebookNoticeForm($this, $post_action, null,
$post_action, $this->user); $post_action, $this->user);
$notice_form->show(); $notice_form->show();
} }
@ -163,9 +161,8 @@ class FacebookhomeAction extends FacebookAction
function showContent() function showContent()
{ {
$notice = $this->user->noticesWithFriends(($this->page-1) * $notice = $this->user->noticeInbox(($this->page-1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
$nl = new NoticeList($notice, $this); $nl = new NoticeList($notice, $this);
$cnt = $nl->show(); $cnt = $nl->show();
@ -176,7 +173,7 @@ class FacebookhomeAction extends FacebookAction
function showNoticeList($notice) function showNoticeList($notice)
{ {
$nl = new NoticeList($notice, $this); $nl = new NoticeList($notice, $this);
return $nl->show(); return $nl->show();
} }
@ -201,16 +198,16 @@ class FacebookhomeAction extends FacebookAction
$this->elementStart('ul', array('id' => 'fb-permissions-list')); $this->elementStart('ul', array('id' => 'fb-permissions-list'));
$this->elementStart('li', array('id' => 'fb-permissions-item')); $this->elementStart('li', array('id' => 'fb-permissions-item'));
$next = urlencode("$this->app_uri/index.php"); $next = urlencode("$this->app_uri/index.php");
$api_key = common_config('facebook', 'apikey'); $api_key = common_config('facebook', 'apikey');
$auth_url = 'http://www.facebook.com/authorize.php?api_key=' . $auth_url = 'http://www.facebook.com/authorize.php?api_key=' .
$api_key . '&v=1.0&ext_perm=status_update&next=' . $next . $api_key . '&v=1.0&ext_perm=status_update&next=' . $next .
'&next_cancel=' . $next . '&submit=skip'; '&next_cancel=' . $next . '&submit=skip';
$this->elementStart('span', array('class' => 'facebook-button')); $this->elementStart('span', array('class' => 'facebook-button'));
$this->element('a', array('href' => $auth_url), $this->element('a', array('href' => $auth_url),
sprintf(_('Okay, do it!'), $this->app_name)); sprintf(_('Okay, do it!'), $this->app_name));
$this->elementEnd('span'); $this->elementEnd('span');
@ -225,7 +222,7 @@ class FacebookhomeAction extends FacebookAction
$this->elementEnd('div'); $this->elementEnd('div');
} }
/** /**
* Generate pagination links * Generate pagination links
* *
@ -239,11 +236,11 @@ class FacebookhomeAction extends FacebookAction
*/ */
function pagination($have_before, $have_after, $page, $action, $args=null) function pagination($have_before, $have_after, $page, $action, $args=null)
{ {
// Does a little before-after block for next/prev page // Does a little before-after block for next/prev page
// XXX: Fix so this uses common_local_url() if possible. // XXX: Fix so this uses common_local_url() if possible.
if ($have_before || $have_after) { if ($have_before || $have_after) {
$this->elementStart('div', array('class' => 'pagination')); $this->elementStart('div', array('class' => 'pagination'));
$this->elementStart('dl', null); $this->elementStart('dl', null);
@ -254,7 +251,7 @@ class FacebookhomeAction extends FacebookAction
if ($have_before) { if ($have_before) {
$pargs = array('page' => $page-1); $pargs = array('page' => $page-1);
$newargs = $args ? array_merge($args, $pargs) : $pargs; $newargs = $args ? array_merge($args, $pargs) : $pargs;
$this->elementStart('li', array('class' => 'nav_prev')); $this->elementStart('li', array('class' => 'nav_prev'));
$this->element('a', array('href' => "$action?page=$newargs[page]", 'rel' => 'prev'), $this->element('a', array('href' => "$action?page=$newargs[page]", 'rel' => 'prev'),
_('After')); _('After'));
$this->elementEnd('li'); $this->elementEnd('li');
@ -274,6 +271,5 @@ class FacebookhomeAction extends FacebookAction
$this->elementEnd('div'); $this->elementEnd('div');
} }
} }
} }

View File

@ -406,8 +406,10 @@ class Notice extends Memcached_DataObject
while ($user->fetch()) { while ($user->fetch()) {
$cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id)); $cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id));
$cache->delete(common_cache_key('notice_inbox:by_user_own:'.$user->id));
if ($blowLast) { if ($blowLast) {
$cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id.';last')); $cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id.';last'));
$cache->delete(common_cache_key('notice_inbox:by_user_own:'.$user->id.';last'));
} }
} }
$user->free(); $user->free();

View File

@ -47,20 +47,25 @@ class Notice_inbox extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */ /* the code above is auto generated do not remove the tag below */
###END_AUTOCODE ###END_AUTOCODE
function stream($user_id, $offset, $limit, $since_id, $max_id, $since) function stream($user_id, $offset, $limit, $since_id, $max_id, $since, $own=false)
{ {
return Notice::stream(array('Notice_inbox', '_streamDirect'), return Notice::stream(array('Notice_inbox', '_streamDirect'),
array($user_id), array($user_id, $own),
'notice_inbox:by_user:'.$user_id, ($own) ? 'notice_inbox:by_user:'.$user_id :
'notice_inbox:by_user_own:'.$user_id,
$offset, $limit, $since_id, $max_id, $since); $offset, $limit, $since_id, $max_id, $since);
} }
function _streamDirect($user_id, $offset, $limit, $since_id, $max_id, $since) function _streamDirect($user_id, $own, $offset, $limit, $since_id, $max_id, $since)
{ {
$inbox = new Notice_inbox(); $inbox = new Notice_inbox();
$inbox->user_id = $user_id; $inbox->user_id = $user_id;
if (!$own) {
$inbox->whereAdd('source != ' . NOTICE_INBOX_SOURCE_GATEWAY);
}
if ($since_id != 0) { if ($since_id != 0) {
$inbox->whereAdd('notice_id > ' . $since_id); $inbox->whereAdd('notice_id > ' . $since_id);
} }

View File

@ -437,6 +437,33 @@ class User extends Memcached_DataObject
// Complicated code, depending on whether we support inboxes yet // Complicated code, depending on whether we support inboxes yet
// XXX: make this go away when inboxes become mandatory // XXX: make this go away when inboxes become mandatory
if ($enabled === false ||
($enabled == 'transitional' && $this->inboxed == 0)) {
$qry =
'SELECT notice.* ' .
'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' .
'WHERE subscription.subscriber = %d ' .
'AND notice.is_local != ' . NOTICE_GATEWAY;
return Notice::getStream(sprintf($qry, $this->id),
'user:notices_with_friends:' . $this->id,
$offset, $limit, $since_id, $before_id,
$order, $since);
} else if ($enabled === true ||
($enabled == 'transitional' && $this->inboxed == 1)) {
$ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
return Notice::getStreamByIds($ids);
}
}
function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
$enabled = common_config('inboxes', 'enabled');
// Complicated code, depending on whether we support inboxes yet
// XXX: make this go away when inboxes become mandatory
if ($enabled === false || if ($enabled === false ||
($enabled == 'transitional' && $this->inboxed == 0)) { ($enabled == 'transitional' && $this->inboxed == 0)) {
$qry = $qry =
@ -450,7 +477,7 @@ class User extends Memcached_DataObject
} else if ($enabled === true || } else if ($enabled === true ||
($enabled == 'transitional' && $this->inboxed == 1)) { ($enabled == 'transitional' && $this->inboxed == 1)) {
$ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since); $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
return Notice::getStreamByIds($ids); return Notice::getStreamByIds($ids);
} }