Commit 8d3d8f13 authored by MBoretto's avatar MBoretto

moving tryMention in entities

parent cc66da85
......@@ -68,7 +68,7 @@ class ChatsCommand extends Command
$chat = new Chat($result);
if ($chat->isPrivateChat()) {
$text .= '- P '.$this->tryMentionChat($chat)."\n";
$text .= '- P '.$chat->tryMentionChat()."\n";
++$user_chats;
} elseif ($chat->isGroupChat()) {
$text .= '- G '.$chat->getTitle()."\n";
......
......@@ -125,26 +125,4 @@ abstract class Command
{
return $this->public;
}
public function tryMention(User $user)
{
if (!is_null($user->getUsername())) {
return '@'.$user->getUsername();
} else {
return $user->getFirstName();
}
}
public function tryMentionChat(Chat $chat)
{
if ($chat->isGroupChat()) {
return $chat->getTitle();
} else {
if (!is_null($chat->getUsername())) {
return '@'.$chat->getUsername();
} else {
return $chat->getFirstName();
}
}
}
}
......@@ -30,13 +30,13 @@ class NewchatparticipantCommand extends Command
$participant = $message->getNewChatParticipant();
$chat_id = $message->getChat()->getId();
$data = array();
$data = [];
$data['chat_id'] = $chat_id;
if (strtolower($participant->getUsername()) == strtolower($this->getTelegram()->getBotName())) {
$text = 'Hi there!';
} else {
$text = 'Hi '.$this->tryMention($participant).' !';
$text = 'Hi '.$participant->tryMention().' !';
}
$data['text'] = $text;
......
......@@ -121,4 +121,18 @@ class Chat extends Entity
return $this->username;
}
public function tryMention()
{
if ($chat->isPrivateChat()) {
if (is_null($this->username)) {
if (!is_null($this->last_name)) {
return $this->first_name.' '.$this->last_name;
}
return $this->first_name;
}
return '@'.$this->username;
}
return $chat->getTitle();
}
}
......@@ -59,4 +59,15 @@ class User extends Entity
{
return $this->username;
}
public function tryMention()
{
if (is_null($this->username)) {
if (!is_null($this->last_name)) {
return $this->first_name.' '.$this->last_name;
}
return $this->first_name;
}
return '@'.$this->username;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment