vadvs (vadvs) wrote in changelog,
vadvs
vadvs
changelog

[livejournal] r17351: LJSUP-6482: SMS Notification RU

Committer: vsukhanov
LJSUP-6482: SMS Notification RU
U   trunk/cgi-bin/LJ/Event.pm
U   trunk/cgi-bin/LJ/NotificationMethod.pm
U   trunk/cgi-bin/LJ/Setting.pm
U   trunk/cgi-bin/LJ/Widget/SubscribeInterface.pm
U   trunk/htdocs/manage/profile/index.bml
Modified: trunk/cgi-bin/LJ/Event.pm
===================================================================
--- trunk/cgi-bin/LJ/Event.pm	2010-09-10 10:29:54 UTC (rev 17350)
+++ trunk/cgi-bin/LJ/Event.pm	2010-09-10 11:25:03 UTC (rev 17351)
@@ -818,6 +818,8 @@
     my $nclass = LJ::NotificationMethod->class($ntypeid);
     return 1 unless $nclass->configured_for_user($u);
 
+    return 1 unless $nclass->is_subtype_enabled($self);
+
     return 0;
 }
 

Modified: trunk/cgi-bin/LJ/NotificationMethod.pm
===================================================================
--- trunk/cgi-bin/LJ/NotificationMethod.pm	2010-09-10 10:29:54 UTC (rev 17350)
+++ trunk/cgi-bin/LJ/NotificationMethod.pm	2010-09-10 11:25:03 UTC (rev 17351)
@@ -28,6 +28,7 @@
 sub disabled_url { undef }
 sub url { undef }
 sub help_url { undef }
+sub is_subtype_enabled { 1 }
 
 # run a hook to see if a user can receive these kinds of notifications
 sub available_for_user  {

Modified: trunk/cgi-bin/LJ/Setting.pm
===================================================================
--- trunk/cgi-bin/LJ/Setting.pm	2010-09-10 10:29:54 UTC (rev 17350)
+++ trunk/cgi-bin/LJ/Setting.pm	2010-09-10 11:25:03 UTC (rev 17351)
@@ -164,7 +164,7 @@
                 $class->save($u, $post_args);
             };
             if (my $err = $@) {
-                warn $err;
+                warn LJ::D($err) . " ";
                 $save_errors = $err->field('map') if ref $err;
             }
         }

Modified: trunk/cgi-bin/LJ/Widget/SubscribeInterface.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/SubscribeInterface.pm	2010-09-10 10:29:54 UTC (rev 17350)
+++ trunk/cgi-bin/LJ/Widget/SubscribeInterface.pm	2010-09-10 11:25:03 UTC (rev 17351)
@@ -2,6 +2,7 @@
 
 use strict;
 use base qw(LJ::Widget);
+use LJ::SMS::API::RU::Phone;
 
 sub need_res {
     return qw(
@@ -21,7 +22,9 @@
 
     my @ntypes = @LJ::NOTIFY_TYPES;
     my (undef, $country) = LJ::GeoLocation->ip_class;
-    if ($country ne 'RU'){
+    if ($country ne 'RU' or
+        LJ::SMS::API::RU::Phone->is_users_number_supported($u)
+    ){
         @ntypes = grep { $_ ne 'LJ::NotificationMethod::SMSru' ? 1 : 0 } @ntypes;
     }
 

Modified: trunk/htdocs/manage/profile/index.bml
===================================================================
--- trunk/htdocs/manage/profile/index.bml	2010-09-10 10:29:54 UTC (rev 17350)
+++ trunk/htdocs/manage/profile/index.bml	2010-09-10 11:25:03 UTC (rev 17351)
@@ -506,8 +506,12 @@
 
             $ret .= "</div>\n";
 
-            $ret .= "<table class='field_block' id='phone_verification'>\n";
+            ##
+            my $block_id = 'phone_verification';
+               $block_id = '' if $LJ::DISABLED{smsru}; ## empty block_id disables JS script
 
+            $ret .= "<table class='field_block' id='$block_id'>\n";
+
             foreach (values %$tminfo) { LJ::text_out(\$_); }
 
             $ret .= "<tr><td class='field_name'>$ML{'.fn.txtnum'}</td><td>";
@@ -798,11 +802,27 @@
         # the provider or number have been set to null
         if ($tminfo->{'number'} && ! $POST{'txtmsg_number'} )
         {
-            $dbh->do("DELETE FROM txtmsg WHERE userid=?", undef, $u->{'userid'});
+            $dbh->do("DELETE FROM txtmsg WHERE userid=?", undef, $u->userid);
+            LJ::SMS::API::RU::Phone->delete($u->userid);
+
         } else {
+            my $number = $POST{'txtmsg_number'};
             $dbh->do("REPLACE INTO txtmsg (userid, number) VALUES (?, ?)",
-                     undef, $u->{'userid'}, $POST{'txtmsg_number'});
-            LJ::SMS::API::RU::Phone->set_status($u->{'userid'}, $POST{'txtmsg_number'}, 'not_verified');
+                     undef, $u->userid, $number);
+
+            ## update supported providers info
+            if (LJ::SMS::API::RU::Phone->is_supported($number)){
+                ## set the new phone number to table SMSru_phones if 
+                ## phone number has been changed.
+                LJ::SMS::API::RU::Phone->set($u->userid, $number => 'not_verified')
+                    if LJ::SMS::API::RU::Phone->normalize($number) ne 
+                        LJ::SMS::API::RU::Phone->normalize($tminfo->{number});
+
+            } elsif(LJ::SMS::API::RU::Phone->is_supported($tminfo->{number})) {
+                ## if previously there was a supported provider 
+                LJ::SMS::API::RU::Phone->delete($u->userid);
+            }
+
         }
 
         # clear text message security caches

Tags: bml, livejournal, pm, vadvs
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments