76 lines
1.3 KiB
PHP
76 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Slack\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Arr;
|
|
use Leenooks\Traits\ScopeActive;
|
|
|
|
class Channel extends Model
|
|
{
|
|
use ScopeActive;
|
|
|
|
protected $fillable = ['team_id','channel_id','name','active'];
|
|
protected $table = 'slack_channels';
|
|
|
|
/* RELATIONS */
|
|
|
|
public function team()
|
|
{
|
|
return $this->belongsTo(Team::class);
|
|
}
|
|
|
|
/* ATTRIBUTES */
|
|
|
|
/**
|
|
* Return if the user is allowed to use this bot
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function getIsAllowedAttribute(): bool
|
|
{
|
|
return $this->active;
|
|
}
|
|
|
|
/**
|
|
* Return the channel name
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getNameAttribute(): string
|
|
{
|
|
return Arr::get($this->attributes,'name') ?: $this->channel_id;
|
|
}
|
|
|
|
public function getSlackUrlAttribute(): string
|
|
{
|
|
return sprintf('<#%s>',$this->channel_id);
|
|
}
|
|
|
|
/* METHODS */
|
|
|
|
/**
|
|
* Is this channel a direct message channel?
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function isDirect(): bool
|
|
{
|
|
return preg_match('/^D/',$this->channel_id) OR $this->name == 'directmessage';
|
|
}
|
|
|
|
/**
|
|
* Return a slack URL to the timestamp
|
|
*
|
|
* @param string $ts
|
|
* @return string
|
|
*/
|
|
public function url(string $ts): string
|
|
{
|
|
if (! $this->team->url)
|
|
return '';
|
|
|
|
return sprintf('https://%s/archives/%s/p%s',$this->team->url,$this->channel_id,str_replace('.','',$ts));
|
|
}
|
|
}
|