Index: branches/liquidthreads/maintenance/lqt.sql |
— | — | @@ -39,3 +39,12 @@ |
40 | 40 | hthread_change_object int(8) unsigned NULL, |
41 | 41 | PRIMARY KEY hthread_id_revision (hthread_id, hthread_revision) |
42 | 42 | ) TYPE=InnoDB; |
| 43 | + |
| 44 | +CREATE TABLE /*$wgDBprefix*/user_message_state ( |
| 45 | + ums_user int unsigned NOT NULL, |
| 46 | + ums_thread int(8) unsigned NOT NULL, |
| 47 | + ums_read_timestamp varbinary(14), |
| 48 | + |
| 49 | + PRIMARY KEY (ums_user, ums_thread) |
| 50 | + |
| 51 | +) TYPE=InnoDB; |
Index: branches/liquidthreads/extensions/LqtPages.php |
— | — | @@ -910,7 +910,9 @@ |
911 | 911 | <table ><tr> |
912 | 912 | <td style="padding-right: 1em; vertical-align: top; padding-top: 1em;" > |
913 | 913 | <form method="POST"> |
914 | | - <input type="submit" value="Read" title="Remove this thread from New Messages." /> |
| 914 | + <input type="hidden" name="lqt_method" value="mark_as_read" /> |
| 915 | + <input type="hidden" name="lqt_operand" value="{$t->id()}" /> |
| 916 | + <input type="submit" value="Read" name="lqt_read_button" title="Remove this thread from New Messages." /> |
915 | 917 | </form> |
916 | 918 | </td> |
917 | 919 | <td> |
— | — | @@ -925,10 +927,6 @@ |
926 | 928 | HTML |
927 | 929 | ); |
928 | 930 | } |
929 | | - |
930 | | - private function showClearButtonForThread($thread) { |
931 | | - $this->output->addHTML('<input type="submit">'); |
932 | | - } |
933 | 931 | |
934 | 932 | function postDivClass($thread) { |
935 | 933 | |
— | — | @@ -936,9 +934,16 @@ |
937 | 935 | |
938 | 936 | function show() { |
939 | 937 | $this->addJSandCSS(); |
940 | | - |
| 938 | + |
941 | 939 | $threads = NewMessages::newUserMessages($this->user); |
942 | 940 | foreach($threads as $t) { |
| 941 | + |
| 942 | + if( $this->request->wasPosted() && $this->methodAppliesToThread('mark_as_read', $t) ) { |
| 943 | + NewMessages::markThreadAsReadByUser($t, $this->user); |
| 944 | + continue; |
| 945 | + } |
| 946 | + |
| 947 | + // Call for POST as well as GET so that edit, reply, etc. will work. |
943 | 948 | $this->preShowThread($t); |
944 | 949 | $this->showThread($t); |
945 | 950 | $this->postShowThread($t); |
Index: branches/liquidthreads/extensions/LqtModel.php |
— | — | @@ -825,7 +825,7 @@ |
826 | 826 | return $newthread; |
827 | 827 | } |
828 | 828 | |
829 | | - static function where( $where, $options = array(), $extra_tables = array() ) { |
| 829 | + static function where( $where, $options = array(), $extra_tables = array(), $joins = "" ) { |
830 | 830 | $dbr = wfGetDB( DB_SLAVE ); |
831 | 831 | if ( is_array($where) ) $where = $dbr->makeList( $where, LIST_AND ); |
832 | 832 | if ( is_array($options) ) $options = implode(',', $options); |
— | — | @@ -837,7 +837,7 @@ |
838 | 838 | } else { |
839 | 839 | $tables = ""; |
840 | 840 | } |
841 | | - |
| 841 | + |
842 | 842 | /* Select the client's threads, AND all their children. |
843 | 843 | The ones the client actually asked for are marked with root_test. |
844 | 844 | In theory we could also grab the page and revision data, to avoid having |
— | — | @@ -848,7 +848,7 @@ |
849 | 849 | $root_test = str_replace( 'thread.', 'children.', $where ); // TODO fragile? |
850 | 850 | |
851 | 851 | $sql = <<< SQL |
852 | | -SELECT children.*, child_page.*, ($root_test) as is_root FROM $tables thread, thread children, page child_page |
| 852 | +SELECT children.*, child_page.*, ($root_test) as is_root FROM $tables thread, thread children, page child_page $joins |
853 | 853 | WHERE $where |
854 | 854 | AND children.thread_path LIKE CONCAT(thread.thread_path, "%") |
855 | 855 | AND child_page.page_id = children.thread_root |
— | — | @@ -989,22 +989,20 @@ |
990 | 990 | |
991 | 991 | class NewMessages { |
992 | 992 | |
| 993 | + static function markThreadAsReadByUser($thread, $user) { |
| 994 | + $dbr =& wfGetDB( DB_MASTER ); |
| 995 | + $res = $dbr->insert('user_message_state', |
| 996 | + array( 'ums_user' => $user->getID(), |
| 997 | + 'ums_thread' => $thread->id(), |
| 998 | + 'ums_read_timestamp' => wfTimestampNow() ), |
| 999 | + __METHOD__); |
| 1000 | + } |
| 1001 | + |
993 | 1002 | static function newUserMessages($user) { |
994 | | -/* $article_clause = Threads::articleClause(new Article($user->getUserPage())) |
995 | | - $sql = <<< SQL |
996 | | - select * from thread, page, recentchanges |
997 | | - where thread_root = rc_cur_id |
998 | | - and $article_clause |
999 | | -SQL; |
1000 | | - $dbr = wfGetDB( DB_SLAVE ); |
1001 | | - res = $dbr->query($sql); |
1002 | | - while ( $line = $dbr->fetchObject($res) ) { |
1003 | | - |
1004 | | - }*/ |
1005 | | - |
1006 | | - $ts = Threads::where( array('thread.thread_root = rc_cur_id', |
| 1003 | + |
| 1004 | + $ts = Threads::where( array('ums_read_timestamp is null', |
1007 | 1005 | Threads::articleClause(new Article($user->getUserPage()))), |
1008 | | - array(), array('recentchanges') ); |
| 1006 | + array(), array(), 'left outer join user_message_state on ums_user is null or (ums_user = 2 and ums_thread = thread.thread_id)' ); |
1009 | 1007 | return $ts; |
1010 | 1008 | } |
1011 | 1009 | |