forked from GNUsocial/gnu-social
twiddle a few bits to make replies work correctly
darcs-hash:20080707054358-84dde-916977a2af4f792e0dc9e02a9f5344ec60911319.gz
This commit is contained in:
parent
f6303475aa
commit
8d3ec9c920
@ -75,8 +75,8 @@ class NewnoticeAction extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
common_save_replies($notice);
|
common_save_replies($notice);
|
||||||
|
|
||||||
common_broadcast_notice($notice);
|
common_broadcast_notice($notice);
|
||||||
|
|
||||||
$returnto = $this->trimmed('returnto');
|
$returnto = $this->trimmed('returnto');
|
||||||
if ($returnto) {
|
if ($returnto) {
|
||||||
$url = common_local_url($returnto,
|
$url = common_local_url($returnto,
|
||||||
|
@ -44,7 +44,7 @@ class RepliesAction extends StreamAction {
|
|||||||
|
|
||||||
# Looks like we're good; show the header
|
# Looks like we're good; show the header
|
||||||
|
|
||||||
common_show_header($profile->nickname . _t(" and friends"),
|
common_show_header(_t("Replies to ") . $profile->nickname,
|
||||||
array($this, 'show_header'), $user,
|
array($this, 'show_header'), $user,
|
||||||
array($this, 'show_top'));
|
array($this, 'show_top'));
|
||||||
|
|
||||||
@ -55,23 +55,21 @@ class RepliesAction extends StreamAction {
|
|||||||
|
|
||||||
function show_header($user) {
|
function show_header($user) {
|
||||||
common_element('link', array('rel' => 'alternate',
|
common_element('link', array('rel' => 'alternate',
|
||||||
'href' => common_local_url('allrss', array('nickname' =>
|
'href' => common_local_url('repliesrss', array('nickname' =>
|
||||||
$user->nickname)),
|
$user->nickname)),
|
||||||
'type' => 'application/rss+xml',
|
'type' => 'application/rss+xml',
|
||||||
'title' => _t('Feed for friends of ') . $user->nickname));
|
'title' => _t('Feed for replies to ') . $user->nickname));
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_top($user) {
|
function show_top($user) {
|
||||||
$cur = common_current_user();
|
|
||||||
|
|
||||||
$this->views_menu();
|
$this->views_menu();
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_replies($profile) {
|
function show_replies($profile) {
|
||||||
|
|
||||||
$reply = DB_DataObject::factory('reply');
|
$reply = new Reply();
|
||||||
|
|
||||||
$reply->user_id = $profile->id;
|
$reply->profile_id = $profile->id;
|
||||||
|
|
||||||
$reply->orderBy('created DESC');
|
$reply->orderBy('created DESC');
|
||||||
|
|
||||||
@ -83,11 +81,14 @@ class RepliesAction extends StreamAction {
|
|||||||
|
|
||||||
if ($cnt > 0) {
|
if ($cnt > 0) {
|
||||||
common_element_start('ul', array('id' => 'replies'));
|
common_element_start('ul', array('id' => 'replies'));
|
||||||
for ($i = 0; $i < min($cnt, REPLIES_PER_PAGE); $i++) {
|
for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) {
|
||||||
if ($reply->fetch()) {
|
if ($reply->fetch()) {
|
||||||
$notice = DB_DataObject::factory('notice');
|
$notice = new Notice();
|
||||||
$notice->id = $reply->notice_id;
|
$notice->id = $reply->notice_id;
|
||||||
$notice->find(1);
|
$result = $notice->find(true);
|
||||||
|
if (!$result) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$this->show_reply($notice, $reply->replied_id);
|
$this->show_reply($notice, $reply->replied_id);
|
||||||
} else {
|
} else {
|
||||||
// shouldn't happen!
|
// shouldn't happen!
|
||||||
@ -97,7 +98,7 @@ class RepliesAction extends StreamAction {
|
|||||||
common_element_end('ul');
|
common_element_end('ul');
|
||||||
}
|
}
|
||||||
|
|
||||||
common_pagination($page > 1, $cnt > REPLIES_PER_PAGE,
|
common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
|
||||||
$page, 'all', array('nickname' => $profile->nickname));
|
$page, 'all', array('nickname' => $profile->nickname));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,4 +137,19 @@ class Profile extends DB_DataObject
|
|||||||
function getBestName() {
|
function getBestName() {
|
||||||
return ($this->fullname) ? $this->fullname : $this->nickname;
|
return ($this->fullname) ? $this->fullname : $this->nickname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Get latest notice on or before date; default now
|
||||||
|
function getCurrentNotice($dt=NULL) {
|
||||||
|
$notice = new Notice();
|
||||||
|
$notice->profile_id = $this->id;
|
||||||
|
if ($dt) {
|
||||||
|
$notice->whereAdd('created < "' . $dt . '"');
|
||||||
|
}
|
||||||
|
$notice->orderBy('created DESC');
|
||||||
|
$notice->limit(1);
|
||||||
|
if ($notice->find(true)) {
|
||||||
|
return $notice;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,17 +95,8 @@ class User extends DB_DataObject
|
|||||||
return !in_array($nickname, $merged);
|
return !in_array($nickname, $merged);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentNotice() {
|
function getCurrentNotice($dt=NULL) {
|
||||||
$notice = DB_DataObject::factory('notice');
|
|
||||||
$profile = $this->getProfile();
|
$profile = $this->getProfile();
|
||||||
$notice->profile_id = $profile->id;
|
return $profile->getCurrentNotice($dt);
|
||||||
$notice->limit(1);
|
|
||||||
$notice->orderBy('created DESC');
|
|
||||||
if ($notice->find()) {
|
|
||||||
$notice->fetch();
|
|
||||||
return $notice;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
if (!defined('LACONICA')) { exit(1); }
|
if (!defined('LACONICA')) { exit(1); }
|
||||||
|
|
||||||
define('NOTICES_PER_PAGE', 20);
|
define('NOTICES_PER_PAGE', 20);
|
||||||
define('REPLIES_PER_PAGE', 20);
|
|
||||||
|
|
||||||
class StreamAction extends Action {
|
class StreamAction extends Action {
|
||||||
|
|
||||||
@ -48,7 +47,7 @@ class StreamAction extends Action {
|
|||||||
common_menu_item(common_local_url('replies', array('nickname' =>
|
common_menu_item(common_local_url('replies', array('nickname' =>
|
||||||
$nickname)),
|
$nickname)),
|
||||||
_t('Replies'),
|
_t('Replies'),
|
||||||
($user && $user->fullname) ? $user->fullname : $nickname,
|
_t('Replies to ') . (($user && $user->fullname) ? $user->fullname : $nickname),
|
||||||
$action == 'replies');
|
$action == 'replies');
|
||||||
common_menu_item(common_local_url('showstream', array('nickname' =>
|
common_menu_item(common_local_url('showstream', array('nickname' =>
|
||||||
$nickname)),
|
$nickname)),
|
||||||
@ -91,6 +90,8 @@ class StreamAction extends Action {
|
|||||||
common_element_end('li');
|
common_element_end('li');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# XXX: these are almost identical functions!
|
||||||
|
|
||||||
function show_reply($notice, $replied_id) {
|
function show_reply($notice, $replied_id) {
|
||||||
global $config;
|
global $config;
|
||||||
$profile = $notice->getProfile();
|
$profile = $notice->getProfile();
|
||||||
@ -120,7 +121,7 @@ class StreamAction extends Action {
|
|||||||
common_element('a', array('class' => 'notice',
|
common_element('a', array('class' => 'notice',
|
||||||
'href' => $noticeurl),
|
'href' => $noticeurl),
|
||||||
common_date_string($notice->created));
|
common_date_string($notice->created));
|
||||||
common_element('a', array('class' => 'notice',
|
common_element('a', array('class' => 'inreplyto',
|
||||||
'href' => $replyurl),
|
'href' => $replyurl),
|
||||||
" in reply to ".$profile->nickname );
|
" in reply to ".$profile->nickname );
|
||||||
common_element_end('p');
|
common_element_end('p');
|
||||||
|
58
lib/util.php
58
lib/util.php
@ -578,34 +578,48 @@ function common_render_content($text, $notice) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function common_at_link($sender_id, $nickname) {
|
function common_at_link($sender_id, $nickname) {
|
||||||
|
$sender = Profile::staticGet($sender_id);
|
||||||
|
$recipient = common_relative_profile($sender, $nickname);
|
||||||
|
if ($recipient) {
|
||||||
|
return '<a href="'.htmlspecialchars($recipient->profileurl).'" class="atlink">'.$nickname.'</a>';
|
||||||
|
} else {
|
||||||
|
return $nickname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function common_relative_profile($sender, $nickname, $dt) {
|
||||||
# Try to find profiles this profile is subscribed to that have this nickname
|
# Try to find profiles this profile is subscribed to that have this nickname
|
||||||
$recipient = new Profile();
|
$recipient = new Profile();
|
||||||
# XXX: chokety and bad
|
# XXX: use a join instead of a subquery
|
||||||
$recipient->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$sender_id.' and subscribed = id)', 'AND');
|
$recipient->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$sender_id.' and subscribed = id)', 'AND');
|
||||||
$recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND');
|
$recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND');
|
||||||
if ($recipient->find(TRUE)) {
|
if ($recipient->find(TRUE)) {
|
||||||
return '<a href="'.htmlspecialchars($recipient->profileurl).'" class="atlink tolistenee">'.$nickname.'</a>';
|
# XXX: should probably differentiate between profiles with
|
||||||
|
# the same name by date of most recent update
|
||||||
|
return $recipient;
|
||||||
}
|
}
|
||||||
# Try to find profiles that listen to this profile and that have this nickname
|
# Try to find profiles that listen to this profile and that have this nickname
|
||||||
$recipient = new Profile();
|
$recipient = new Profile();
|
||||||
# XXX: chokety and bad
|
# XXX: use a join instead of a subquery
|
||||||
$recipient->whereAdd('EXISTS (SELECT subscriber from subscription where subscribed = '.$sender_id.' and subscriber = id)', 'AND');
|
$recipient->whereAdd('EXISTS (SELECT subscriber from subscription where subscribed = '.$sender_id.' and subscriber = id)', 'AND');
|
||||||
$recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND');
|
$recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND');
|
||||||
if ($recipient->find(TRUE)) {
|
if ($recipient->find(TRUE)) {
|
||||||
return '<a href="'.htmlspecialchars($recipient->profileurl).'" class="atlink tolistener">'.$nickname.'</a>';
|
# XXX: should probably differentiate between profiles with
|
||||||
|
# the same name by date of most recent update
|
||||||
|
return $recipient;
|
||||||
}
|
}
|
||||||
# If this is a local user, try to find a local user with that nickname.
|
# If this is a local user, try to find a local user with that nickname.
|
||||||
$sender = User::staticGet($sender_id);
|
$sender = User::staticGet($sender->id);
|
||||||
if ($sender) {
|
if ($sender) {
|
||||||
$recipient_user = User::staticGet('nickname', $nickname);
|
$recipient_user = User::staticGet('nickname', $nickname);
|
||||||
if ($recipient_user) {
|
if ($recipient_user) {
|
||||||
return '<a href="'.htmlspecialchars(common_profile_url($nickname)).'" class="atlink usertouser">'.$nickname.'</a>';
|
return $recipient_user->getProfile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# Otherwise, no links. @messages from local users to remote users,
|
# Otherwise, no links. @messages from local users to remote users,
|
||||||
# or from remote users to other remote users, are just
|
# or from remote users to other remote users, are just
|
||||||
# outside our ability to make intelligent guesses about
|
# outside our ability to make intelligent guesses about
|
||||||
return $nickname;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// where should the avatar go for this user?
|
// where should the avatar go for this user?
|
||||||
@ -811,27 +825,27 @@ function common_redirect($url, $code=307) {
|
|||||||
|
|
||||||
function common_save_replies($notice) {
|
function common_save_replies($notice) {
|
||||||
# extract all @messages
|
# extract all @messages
|
||||||
preg_match_all('/(?:^|\s)@([a-z0-9]{1,64})/', $notice->content, $match);
|
$cnt = preg_match_all('/(?:^|\s)@([a-z0-9]{1,64})/', $notice->content, $match);
|
||||||
$current_user = common_current_user();
|
if (!$cnt) {
|
||||||
$sender = $current_user->getProfile();
|
return true;
|
||||||
#store replied only for first @ (what user/notice what the reply directed, we assume first @ is it)
|
}
|
||||||
$reply_for = User::staticGet('nickname', $match[1][0]);
|
$sender = Profile::staticGet($notice->profile_id);
|
||||||
|
# store replied only for first @ (what user/notice what the reply directed,
|
||||||
|
# we assume first @ is it)
|
||||||
for ($i=0; $i<count($match[1]); $i++) {
|
for ($i=0; $i<count($match[1]); $i++) {
|
||||||
$nickname = $match[1][$i];
|
$nickname = $match[1][$i];
|
||||||
#don't reply to myself
|
$recipient = common_relative_profile($sender, $nickname, $notice->created);
|
||||||
if ($sender->nickname == $nickname) {
|
if (!$recipient) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$reply = DB_DataObject::factory('reply');
|
if ($i == 0) {
|
||||||
|
$reply_for = $recipient;
|
||||||
|
}
|
||||||
|
$reply = new Reply();
|
||||||
$reply->notice_id = $notice->id;
|
$reply->notice_id = $notice->id;
|
||||||
$recipient_user = User::staticGet('nickname', $nickname);
|
$reply->profile_id = $recipient->id;
|
||||||
#if recipient doesn't exist, skip
|
|
||||||
if (!$recipient_user) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$reply->user_id = $recipient_user->id;
|
|
||||||
$reply->created = DB_DataObject_Cast::dateTime();
|
$reply->created = DB_DataObject_Cast::dateTime();
|
||||||
$recipient_notice = $reply_for->getCurrentNotice();
|
$recipient_notice = $reply_for->getCurrentNotice($notice->created);
|
||||||
$reply->replied_id = $recipient_notice->id;
|
$reply->replied_id = $recipient_notice->id;
|
||||||
$id = $reply->insert();
|
$id = $reply->insert();
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
|
@ -204,6 +204,7 @@ class XMPPDaemon {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$notice->query('COMMIT');
|
$notice->query('COMMIT');
|
||||||
|
common_save_replies($notice);
|
||||||
common_real_broadcast($notice);
|
common_real_broadcast($notice);
|
||||||
$this->log(LOG_INFO,
|
$this->log(LOG_INFO,
|
||||||
'Added notice ' . $notice->id . ' from user ' . $user->nickname);
|
'Added notice ' . $notice->id . ' from user ' . $user->nickname);
|
||||||
|
Loading…
Reference in New Issue
Block a user