[twiddle a few bits to make replies work correctly Evan Prodromou **20080707054358] { hunk ./actions/newnotice.php 78 - hunk ./actions/newnotice.php 79 + hunk ./actions/replies.php 47 - common_show_header($profile->nickname . _t(" and friends"), + common_show_header(_t("Replies to ") . $profile->nickname, hunk ./actions/replies.php 58 - 'href' => common_local_url('allrss', array('nickname' => - $user->nickname)), + 'href' => common_local_url('repliesrss', array('nickname' => + $user->nickname)), hunk ./actions/replies.php 61 - 'title' => _t('Feed for friends of ') . $user->nickname)); + 'title' => _t('Feed for replies to ') . $user->nickname)); hunk ./actions/replies.php 65 - $cur = common_current_user(); - hunk ./actions/replies.php 70 - $reply = DB_DataObject::factory('reply'); + $reply = new Reply(); hunk ./actions/replies.php 72 - $reply->user_id = $profile->id; + $reply->profile_id = $profile->id; hunk ./actions/replies.php 84 - for ($i = 0; $i < min($cnt, REPLIES_PER_PAGE); $i++) { + for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) { hunk ./actions/replies.php 86 - $notice = DB_DataObject::factory('notice'); - $notice->id = $reply->notice_id; - $notice->find(1); + $notice = new Notice(); + $notice->id = $reply->notice_id; + $result = $notice->find(true); + if (!$result) { + continue; + } hunk ./actions/replies.php 101 - common_pagination($page > 1, $cnt > REPLIES_PER_PAGE, + common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, hunk ./classes/Profile.php 139 + } + + # 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; hunk ./classes/User.php 98 - function getCurrentNotice() { - $notice = DB_DataObject::factory('notice'); - $profile = $this->getProfile(); - $notice->profile_id = $profile->id; - $notice->limit(1); - $notice->orderBy('created DESC'); - if ($notice->find()) { - $notice->fetch(); - return $notice; - } - return NULL; - } - + function getCurrentNotice($dt=NULL) { + $profile = $this->getProfile(); + return $profile->getCurrentNotice($dt); + } hunk ./lib/stream.php 23 -define('REPLIES_PER_PAGE', 20); hunk ./lib/stream.php 50 - ($user && $user->fullname) ? $user->fullname : $nickname, + _t('Replies to ') . (($user && $user->fullname) ? $user->fullname : $nickname), hunk ./lib/stream.php 93 + # XXX: these are almost identical functions! + hunk ./lib/stream.php 124 - common_element('a', array('class' => 'notice', + common_element('a', array('class' => 'inreplyto', hunk ./lib/util.php 581 + $sender = Profile::staticGet($sender_id); + $recipient = common_relative_profile($sender, $nickname); + if ($recipient) { + return ''.$nickname.''; + } else { + return $nickname; + } +} + +function common_relative_profile($sender, $nickname, $dt) { hunk ./lib/util.php 593 - # XXX: chokety and bad + # XXX: use a join instead of a subquery hunk ./lib/util.php 597 - return ''.$nickname.''; + # XXX: should probably differentiate between profiles with + # the same name by date of most recent update + return $recipient; hunk ./lib/util.php 603 - # XXX: chokety and bad + # XXX: use a join instead of a subquery hunk ./lib/util.php 607 - return ''.$nickname.''; + # XXX: should probably differentiate between profiles with + # the same name by date of most recent update + return $recipient; hunk ./lib/util.php 612 - $sender = User::staticGet($sender_id); + $sender = User::staticGet($sender->id); hunk ./lib/util.php 616 - return ''.$nickname.''; + return $recipient_user->getProfile(); hunk ./lib/util.php 622 - return $nickname; + return NULL; hunk ./lib/util.php 827 - # extract all @messages - preg_match_all('/(?:^|\s)@([a-z0-9]{1,64})/', $notice->content, $match); - $current_user = common_current_user(); - $sender = $current_user->getProfile(); - #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]); - for ($i=0; $inickname == $nickname) { - continue; - } - $reply = DB_DataObject::factory('reply'); - $reply->notice_id = $notice->id; - $recipient_user = User::staticGet('nickname', $nickname); - #if recipient doesn't exist, skip - if (!$recipient_user) { - continue; - } - $reply->user_id = $recipient_user->id; - $reply->created = DB_DataObject_Cast::dateTime(); - $recipient_notice = $reply_for->getCurrentNotice(); - $reply->replied_id = $recipient_notice->id; - $id = $reply->insert(); - if (!$id) { - common_server_error(_t('Problem saving reply.')); - return; - } - } + # extract all @messages + $cnt = preg_match_all('/(?:^|\s)@([a-z0-9]{1,64})/', $notice->content, $match); + if (!$cnt) { + return true; + } + $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; $icreated); + if (!$recipient) { + continue; + } + if ($i == 0) { + $reply_for = $recipient; + } + $reply = new Reply(); + $reply->notice_id = $notice->id; + $reply->profile_id = $recipient->id; + $reply->created = DB_DataObject_Cast::dateTime(); + $recipient_notice = $reply_for->getCurrentNotice($notice->created); + $reply->replied_id = $recipient_notice->id; + $id = $reply->insert(); + if (!$id) { + common_server_error(_t('Problem saving reply.')); + return; + } + } hunk ./xmppdaemon.php 207 + common_save_replies($notice); }