misuzu/src/Messages/MessageInfo.php

148 lines
3.7 KiB
PHP

<?php
namespace Misuzu\Messages;
use Index\DateTime;
use Index\Data\IDbResult;
use Misuzu\Parsers\Parser;
class MessageInfo {
private string $messageId;
private string $ownerId;
private ?string $authorId;
private ?string $recipientId;
private ?string $replyTo;
private string $title;
private string $body;
private int $parser;
private int $created;
private ?int $sent;
private ?int $read;
private ?int $deleted;
public function __construct(IDbResult $result) {
$this->messageId = $result->getString(0);
$this->ownerId = $result->getString(1);
$this->authorId = $result->getStringOrNull(2);
$this->recipientId = $result->getStringOrNull(3);
$this->replyTo = $result->getStringOrNull(4);
$this->title = $result->getString(5);
$this->body = $result->getString(6);
$this->parser = $result->getInteger(7);
$this->created = $result->getInteger(8);
$this->sent = $result->getIntegerOrNull(9);
$this->read = $result->getIntegerOrNull(10);
$this->deleted = $result->getIntegerOrNull(11);
}
public function getId(): string {
return $this->messageId;
}
public function getOwnerId(): string {
return $this->ownerId;
}
public function hasAuthorId(): bool {
return $this->authorId !== null;
}
public function getAuthorId(): ?string {
return $this->authorId;
}
public function hasRecipientId(): bool {
return $this->recipientId !== null;
}
public function getRecipientId(): ?string {
return $this->recipientId;
}
public function hasReplyToId(): bool {
return $this->replyTo !== null;
}
public function getReplyToId(): ?string {
return $this->replyTo;
}
public function getTitle(): string {
return $this->title;
}
public function getBody(): string {
return $this->body;
}
public function getParser(): int {
return $this->parser;
}
public function isBodyPlain(): bool {
return $this->parser === Parser::PLAIN;
}
public function isBodyBBCode(): bool {
return $this->parser === Parser::BBCODE;
}
public function isBodyMarkdown(): bool {
return $this->parser === Parser::MARKDOWN;
}
public function getCreatedTime(): int {
return $this->created;
}
public function getCreatedAt(): DateTime {
return DateTime::fromUnixTimeSeconds($this->created);
}
public function isSent(): bool {
return $this->sent !== null;
}
public function getSentTime(): ?int {
return $this->sent;
}
public function getSentAt(): ?DateTime {
return $this->sent === null ? null : DateTime::fromUnixTimeSeconds($this->sent);
}
public function isRead(): bool {
return $this->read !== null;
}
public function getReadTime(): ?int {
return $this->read;
}
public function getReadAt(): ?DateTime {
return $this->read === null ? null : DateTime::fromUnixTimeSeconds($this->read);
}
public function isDeleted(): bool {
return $this->deleted !== null;
}
public function getDeletedTime(): ?int {
return $this->deleted;
}
public function getDeletedAt(): ?DateTime {
return $this->deleted === null ? null : DateTime::fromUnixTimeSeconds($this->deleted);
}
public function getDisplayTime(): int {
if($this->isSent())
return $this->getSentTime();
return $this->getCreatedTime();
}
public function getDisplayAt(): DateTime {
if($this->isSent())
return $this->getSentAt();
return $this->getCreatedAt();
}
}