}
+sub is_comment_allowed {
+ my $self = shift;
+ my $params = {@_};
+ my $uid = $params->{uid};
+ my $discuss = $params->{discussion};
+ my $did = $params->{discussion_id} || $params->{id};
+ return if !$uid || (!$did && !$discuss);
+
+ $discuss = $self->select(discussion_id => $did) if !$discuss;
+
+ my $relations = $self->new_instance_of("Relations");
+ my $users = $self->new_instance_of("Users");
+ return if !$discuss;
+
+ my $status = $discuss->{commentstatus};
+ my $the_uid = $discuss->{uid};
+
+ if ($status eq "disabled") {
+ return 0;
+ }
+
+ if ($status eq "enabled") {
+ return 1;
+ }
+
+ if ($uid == $the_uid) {
+ return 1;
+ }
+
+ if ($status eq "friends_only") {
+ return 1 if $relations->is_friend(of => $the_uid, uid => $uid);
+ }
+
+ if ($status eq "friends_fof_only") {
+ return 1 if $relations->is_friend_or_fof(of => $the_uid, uid => $uid);
+ }
+
+ if ($status eq "no_foe") {
+ return 1 if !$relations->is_foe(of => $the_uid, uid => $uid);
+ }
+
+ if ($status eq "friends_fof_only") {
+ return 1 if !$relations->is_foe_or_eof(of => $the_uid, uid => $uid);
+ }
+
+ if ($status eq "logged_in") {
+ return 1 if $uid != $users->is_anonymous_uid($uid);
+ }
+
+ return 0;
+}
+
1;