2heoh (2heoh) wrote in changelog,
2heoh
2heoh
changelog

[livejournal] r20287: LJSUP-9803: Push Notifications (WP7, And...

Committer: slobin
LJSUP-9803: Push Notifications (WP7, Android, iOS)

M cgi-bin/LJ/NotificationMethod.pm
M bin/upgrading/proplists.dat
M cgi-bin/LJ/Event/UserMessageRecvd.pm
M cgi-bin/LJ/User.pm
M cgi-bin/ljprotocol.pl
U   trunk/bin/upgrading/proplists.dat
U   trunk/cgi-bin/LJ/Event/UserMessageRecvd.pm
U   trunk/cgi-bin/LJ/NotificationMethod.pm
U   trunk/cgi-bin/LJ/User.pm
U   trunk/cgi-bin/ljprotocol.pl
Modified: trunk/bin/upgrading/proplists.dat
===================================================================
--- trunk/bin/upgrading/proplists.dat	2011-10-11 12:19:14 UTC (rev 20286)
+++ trunk/bin/upgrading/proplists.dat	2011-10-11 13:34:35 UTC (rev 20287)
@@ -1206,6 +1206,27 @@
   multihomed: 0
   prettyname: ZIP code
 
+userproplist.wp7notification_url:
+  cldversion: 8
+  datatype: char
+  des: Both tile & toast push notification url
+  multihomed: 0
+  prettyname: Push notification url for Windows Phone
+
+userproplist.android_c2dm_data:
+  cldversion: 8
+  datatype: char
+  des: Data for C2DM channel
+  multihomed: 0
+  prettyname: Push channel data for Android
+
+userproplist.ios_device_token:
+  cldversion: 8
+  datatype: char
+  des: device token for push notifications
+  multihomed: 0
+  prettyname: Device token for push notification service for iOS
+
 talkproplist.edit_time:
   datatype: num
   des: Unix time of the last edit.  undef if never edited.

Modified: trunk/cgi-bin/LJ/Event/UserMessageRecvd.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/UserMessageRecvd.pm	2011-10-11 12:19:14 UTC (rev 20286)
+++ trunk/cgi-bin/LJ/Event/UserMessageRecvd.pm	2011-10-11 13:34:35 UTC (rev 20287)
@@ -185,6 +185,17 @@
         });
 }
 
+sub as_push {
+    my $self = shift;
+    my $u = shift;
+    my %args = @_;
+
+    my $message = LJ::Lang::get_text($u->prop('browselang'), 'esn.push.notification.usermessagerecvd');
+
+    return $message;
+}
+
+
 sub subscription_as_html {
     my ($class, $subscr) = @_;
     my $journal = $subscr->journal or croak "No user";

Modified: trunk/cgi-bin/LJ/NotificationMethod.pm
===================================================================
--- trunk/cgi-bin/LJ/NotificationMethod.pm	2011-10-11 12:19:14 UTC (rev 20286)
+++ trunk/cgi-bin/LJ/NotificationMethod.pm	2011-10-11 13:34:35 UTC (rev 20287)
@@ -10,6 +10,7 @@
                        LJ::NotificationMethod::IM
                        LJ::NotificationMethod::DebugLog
                        LJ::NotificationMethod::Alerts
+                       LJ::NotificationMethod::Push
                        );
 
 # this mofo is basically just an interface

Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm	2011-10-11 12:19:14 UTC (rev 20286)
+++ trunk/cgi-bin/LJ/User.pm	2011-10-11 13:34:35 UTC (rev 20287)
@@ -3511,10 +3511,25 @@
 sub subscribe {
     my ($u, %opts) = @_;
     croak "No subscription options" unless %opts;
-
     return LJ::Subscription->create($u, %opts);
 }
 
+# unsubscribe from an event(s)
+sub unsubscribe {
+    my ($u, %opts) = @_;
+    croak "No subscription options" unless %opts;
+
+    # find all matching subscriptions
+    my @subs = LJ::Subscription->find($u, %opts);
+
+    foreach (@subs) {
+        # run delete method on each subscription
+        $_->delete();
+    }
+}
+
+
+
 sub subscribe_entry_comments_via_sms {
     my ($u, $entry) = @_;
     croak "Invalid LJ::Entry passed"

Modified: trunk/cgi-bin/ljprotocol.pl
===================================================================
--- trunk/cgi-bin/ljprotocol.pl	2011-10-11 12:19:14 UTC (rev 20286)
+++ trunk/cgi-bin/ljprotocol.pl	2011-10-11 13:34:35 UTC (rev 20287)
@@ -17,6 +17,7 @@
                       LJ::RateLimit
                       LJ::EmbedModule
                       LJ::DelayedEntry
+                      LJ::PushNotification
                       );
 
 use LJ::TimeUtil;
@@ -175,6 +176,8 @@
     getpoll           => \&getpoll,
     editpoll          => \&editpoll,
     votepoll          => \&votepoll,
+    registerpush      => \&registerpush,
+    unregisterpush    => \&unregisterpush,
 );
 
 sub translate
@@ -4695,7 +4698,64 @@
     }
 }
 
+# registerpush: adding push-notification params to user prop
+# specific for each mobile platform (windows phone 7, android, iOS)
+#
+# takes:
+# - platform:       wp7 / android / ios
+# - registrationid: argument which we use in communication with notification
+#                   servers, specific for each OS 
+# - deviceid:       id of registred device (not use yet)
+#
+# returns: { status => 'OK'} if success
+#
+sub registerpush {
+    my ($req, $err, $flags) = @_;
+    return undef
+        unless authenticate($req, $err, $flags);
 
+    my $u = $flags->{u};
+
+    return fail($err, 200)
+        unless $req->{platform} && $req->{registrationid};
+
+    my $res = LJ::PushNotification->subscribe($u, $req);
+
+    return fail($err, 200)
+        unless $res;
+    
+    return { status => 'OK' };
+}
+
+# unregisterpush: deletes subscription on push notification and clears user prop 
+#                 with notification servers connection arguments
+#
+# takes: 
+# - platform: wp7 / android / ios
+# - deviceid: id of registred device (not use yet)
+#
+# returns:  { status => 'OK'} if success
+#
+sub unregisterpush {
+    my ($req, $err, $flags) = @_;
+    return undef
+        unless authenticate($req, $err, $flags);
+
+    my $u = $flags->{u};
+
+    return fail($err,200)
+        unless $req->{platform};
+
+    my $res = LJ::PushNotification->unsubscribe($u, $req);
+
+    return fail($err,200)
+        unless $res;
+
+    return { status => 'OK' };
+}
+
+
+
 #### Old interface (flat key/values) -- wrapper aruond LJ::Protocol
 package LJ;
 

Tags: 2heoh, dat, livejournal, pl, pm, slobin
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