]> mj.ucw.cz Git - pciids.git/commitdiff
Discuss -> notification
authorMichal Vaner <vorner@ucw.cz>
Wed, 3 Sep 2008 12:29:04 +0000 (14:29 +0200)
committerMichal Vaner <vorner@ucw.cz>
Wed, 3 Sep 2008 12:29:04 +0000 (14:29 +0200)
Add a checkbox for subscribing notifications in discussion

PciIds/DBQ.pm
PciIds/Html/Changes.pm

index c2aef4b1b73d6cafefc2c076051270b2dc965740..6df3380ec8abc2dc16e348263dda79fcd63d43b6 100644 (file)
@@ -96,7 +96,8 @@ sub new( $ ) {
                'searchname' => 'SELECT l.id, l.name, p.name FROM locations AS l JOIN locations AS p ON l.parent = p.id WHERE l.name LIKE ? ORDER BY l.id',
                'searchlocalname' => 'SELECT l.id, l.name, p.name FROM locations AS l JOIN locations AS p ON l.parent = p.id WHERE l.name LIKE ? AND l.id LIKE ? ORDER BY l.id',
                'hasChildren' => 'SELECT DISTINCT 1 FROM locations WHERE parent = ?',
-               'hasMain' => 'SELECT DISTINCT 1 FROM locations WHERE id = ? AND mainhistory IS NOT NULL'
+               'hasMain' => 'SELECT DISTINCT 1 FROM locations WHERE id = ? AND mainhistory IS NOT NULL',
+               'notif-exists' => 'SELECT DISTINCT 1 FROM notifications WHERE user = ? AND ( location = ? OR ( recursive = 1 AND type <= 1 AND SUBSTR( ?, 1, LENGTH( location ) ) = location ) )'
        } );
 }
 
@@ -315,6 +316,11 @@ sub pushNotifications( $$$$$ ) {
        $self->command( 'newtime-xmpp', [ $priority, $location, $location ] );
 }
 
+sub notifExists( $$$ ) {
+       my( $self, $user, $location ) = @_;
+       return scalar @{$self->query( 'notif-exists', [ $user, $location, $location ] )};
+}
+
 sub mailNotifs( $$ ) {
        my( $self, $time ) = @_;
        return $self->query( 'mailout', [ $time ] );
index 7978fa83e891c634f1785e27836abcf0d31af3fe..fe50ec7a67504f27c7f5ab8c62af761dd7ae3fdc 100644 (file)
@@ -61,7 +61,8 @@ sub newItemSubmit( $$$$ ) {
                                return undef;
                        },
                        'note' => sub { return ( length shift > 1024 ) ? 'Note can not be longer than 1024 characters' : undef; },
-                       'discussion' => sub { return ( length shift > 1024 ) ? 'Discussion can not be longer than 1024 characters' : undef; }
+                       'discussion' => sub { return ( length shift > 1024 ) ? 'Discussion can not be longer than 1024 characters' : undef; },
+                       'subscribe' => undef
                }, [ sub { my( $data ) = @_;
                        my $errstr;
                        return undef unless( length $data->{'id'} );#No address, so let it for the first check
@@ -81,7 +82,7 @@ sub newItemSubmit( $$$$ ) {
                        return genNewItemForm( $req, $args, $auth, $tables, $result, $data );
                }
                notify( $tables, $data->{'address'}->parent()->get(), $comName, 2, 0 );#Notify the parent (parent gets new items)
-               $tables->submitNotification( $auth->{'authid'}, $data->{'address'}->get(), { 'recursive' => 0, 'notification' => 1, 'way' => 0 } );
+               $tables->submitNotification( $auth->{'authid'}, $data->{'address'}->get(), { 'recursive' => 0, 'notification' => 1, 'way' => 0 } ) if( defined $data->{'subscribe'} && $data->{'subscribe'} eq 'subscribe' );
                tulog( $auth->{'authid'}, "Item created ".$data->{'address'}->get()." ".logEscape( $data->{'name'} )." ".logEscape( $data->{'note'} )." ".logEscape( $data->{'discussion'} )." $comName" );
                return HTTPRedirect( $req, '/read/'.$data->{'address'}->get().'?action=list' );
        } else {
@@ -101,6 +102,7 @@ sub genNewHistoryForm( $$$$$$ ) {
                [ 'input', 'Request deletion', 'checkbox', 'delete', 'value="delete"' ],
                [ 'input', 'Name:', 'text', 'name', 'maxlength="200"' ],
                [ 'input', 'Note:', 'text', 'note', 'maxlength="1024"' ],
+               !$tables->notifExists( $auth->{'authid'}, $address->get() ) ? [ 'input', 'Subscribe:', 'checkbox', 'subscribe', "value='subscribe' checked='checked'" ] : (),
                [ 'input', '', 'submit', 'submit', 'value="Submit"' ] ], $values );
        print '</table></form>';
        genHtmlTail();
@@ -135,7 +137,8 @@ sub newHistorySubmit( $$$$ ) {
                                return undef if $delete eq 'delete';
                                return 'Invalid form value';
                                return undef;
-                       }
+                       },
+                       'subscribe' => undef
                }, [ sub { my( $data ) = @_;
                        return 'You must provide either name, text or request a deletion' if( ! length $data->{'name'} && ! length $data->{'text'} && ! $data->{'delete'} );
                        return undef;
@@ -150,6 +153,7 @@ sub newHistorySubmit( $$$$ ) {
                my $hid = $tables->submitHistory( $data, $auth, $address );
                tulog( $auth->{'authid'}, "Discussion created $hid ".$address->get()." ".logEscape( $data->{'name'} )." ".logEscape( $data->{'description'} )." ".logEscape( $data->{'text'} ) );
                notify( $tables, $address->get(), $hid, ( defined $name && ( $name ne '' ) ) ? 1 : 0, 1 );
+               $tables->submitNotification( $auth->{'authid'}, $address->get(), { 'recursive' => 0, 'notification' => 1, 'way' => 0 } ) if( defined $data->{'subscribe'} && $data->{'subscribe'} eq 'subscribe' );
                return HTTPRedirect( $req, '/read/'.$address->get().'?action=list' );
        } else {
                return notLoggedComplaint( $req, $args, $auth );