diff --git a/include/class.thread.php b/include/class.thread.php
index 5b412f2357ca7f25d211bb77a3f4bfc669e9542d..bf4d4010ef3c2fcb5428ac03a834efc39481e9e4 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -1574,9 +1574,9 @@ class ThreadEvent extends VerySimpleModel {
 
     function getUserName() {
         if ($this->uid && $this->uid_type == 'S')
-            return $this->agent->getName();
+            return $this->agent ? $this->agent->getName() : $this->username;
         if ($this->uid && $this->uid_type == 'U')
-            return $this->user->getName();
+            return $this->user ? $this->user->getName() : $this->username;
         return $this->username;
     }