'array', 'meta' => 'array', 'is_sensitive' => 'boolean', 'edited_at' => 'datetime', ]; } protected static function booted(): void { static::saving(function (DmMessage $message) { if ($message->isDirty('ap_object_uri')) { $message->ap_object_hash = $message->ap_object_uri ? self::hashUri($message->ap_object_uri) : null; } }); } /** * Object ids are looked up by hash so the unique index never depends on * how long a remote server makes its ids. */ public static function hashUri(string $uri): string { return hash('sha256', $uri); } protected function scopeWhereObjectUri(Builder $query, string $uri): Builder { return $query->where('ap_object_hash', self::hashUri($uri)); } public static function localObjectUri(int|string $id): string { return url('/i/dm/messages/'.$id); } /** * The id this message is known by on the network. */ public function objectUri(): string { return $this->ap_object_uri ?: self::localObjectUri($this->id); } public function conversation(): BelongsTo { return $this->belongsTo(DmConversation::class, 'conversation_id'); } public function author(): BelongsTo { return $this->belongsTo(Profile::class, 'profile_id'); } public function parent(): BelongsTo { return $this->belongsTo(self::class, 'in_reply_to_id'); } public function media(): BelongsToMany { return $this->belongsToMany(Media::class, 'dm_message_media', 'message_id', 'media_id') ->withPivot('position') ->orderBy('dm_message_media.position'); } }