afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
afuna ([personal profile] afuna) wrote in [site community profile] changelog2009-10-24 05:46 pm

[dw-free] Inbox sometimes inaccessible because of an undefined event

[commit: http://hg.dwscoalition.org/dw-free/rev/67156ed04d1e]

http://bugs.dwscoalition.org/show_bug.cgi?id=1391

Be safe: check for existence of the event, before doing anything with it.

Code from henrylyne @ LiveJournal, packaged for Dreamwidth by [staff profile] denise, with some suggested changes by [personal profile] kareila

Files modified:
  • cgi-bin/LJ/NotificationInbox.pm
--------------------------------------------------------------------------------
diff -r 8c60dc737e7e -r 67156ed04d1e cgi-bin/LJ/NotificationInbox.pm
--- a/cgi-bin/LJ/NotificationInbox.pm	Fri Oct 23 07:40:19 2009 -0500
+++ b/cgi-bin/LJ/NotificationInbox.pm	Sat Oct 24 17:45:04 2009 +0000
@@ -71,7 +71,7 @@ sub all_items {
 sub all_items {
     my $self = shift;
 
-    return grep { $_->event->class ne "LJ::Event::UserMessageSent" } $self->items;
+    return grep { $_->event && $_->event->class ne "LJ::Event::UserMessageSent" } $self->items;
 }
 
 # returns a list of friend-related notificationitems
@@ -268,7 +268,7 @@ sub instantiate_comment_singletons {
     # instantiate all the comment singletons so that they will all be
     # loaded efficiently later as soon as preload_rows is called on
     # the first comment object
-    my @comment_items = grep { $_->event->class eq 'LJ::Event::JournalNewComment' } $self->items;
+    my @comment_items = grep { $_->event && $_->event->class eq 'LJ::Event::JournalNewComment' } $self->items;
     my @comment_events = map { $_->event } @comment_items;
     # instantiate singletons
     LJ::Comment->new($_->event_journal, jtalkid => $_->jtalkid) foreach @comment_events;
@@ -282,7 +282,7 @@ sub instantiate_message_singletons {
     # instantiate all the message singletons so that they will all be
     # loaded efficiently later as soon as preload_rows is called on
     # the first message object
-    my @message_items = grep { $_->event->class eq 'LJ::Event::UserMessageRecvd' } $self->items;
+    my @message_items = grep { $_->event && $_->event->class eq 'LJ::Event::UserMessageRecvd' } $self->items;
     my @message_events = map { $_->event } @message_items;
     # instantiate singletons
     LJ::Message->load({msgid => $_->arg1, journalid => $_->u->{userid}}) foreach @message_events;
@@ -644,14 +644,14 @@ sub subset_unread_count {
     my ($self, @subset) = @_;
 
     my %subset_events = map { "LJ::Event::" . $_ => 1 } @subset;
-    my @events = grep { $subset_events{$_->event->class} && $_->unread } $self->items;
+    my @events = grep { $_->event && $subset_events{$_->event->class} && $_->unread } $self->items;
     return scalar @events;
 }
 
 sub all_event_count {
     my $self = shift;
 
-    my @events = grep { $_->event->class ne 'LJ::Event::UserMessageSent' && $_->unread } $self->items;
+    my @events = grep { $_->event && $_->event->class ne 'LJ::Event::UserMessageSent' && $_->unread } $self->items;
     return scalar @events;
 }
 
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org