Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app-modules/activity/database/factories/MessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function definition(): array
return [
'id' => fake()->uuid(),
'tenant_id' => Tenant::factory(),
'provider_id' => ExternalIdentity::factory(),
'external_identity_id' => ExternalIdentity::factory(),
'provider_message_id' => fake()->randomNumber(4),
'channel_id' => fake()->randomNumber(4),
'content' => fake()->sentence(),
Expand Down
4 changes: 2 additions & 2 deletions app-modules/activity/src/Actions/NewMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function persist(NewMessageDTO $messageDTO): void
$userDto = ResolveUserProviderDTO::make([
'tenant_id' => $messageDTO->tenantId,
'provider' => $messageDTO->provider,
'provider_id' => $messageDTO->providerId,
'external_account_id' => $messageDTO->externalAccountId,
'model_type' => User::class,
'username' => $messageDTO->providerUsername,
]);
Expand All @@ -49,7 +49,7 @@ public function persist(NewMessageDTO $messageDTO): void

} catch (Throwable $throwable) {
Log::error('NewMessage failed', [
'provider_id' => $messageDTO->providerId,
'external_account_id' => $messageDTO->externalAccountId,
'tenant_id' => $messageDTO->tenantId,
'error' => $throwable->getMessage(),
'trace' => $throwable->getTraceAsString(),
Expand Down
4 changes: 2 additions & 2 deletions app-modules/activity/src/Actions/NewVoiceMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function persist(array $payload): void
$voiceDTO = NewVoiceMessageDTO::make($payload);
$externalIdentity = $this->findExternalIdentity->handle(
$voiceDTO->provider->value,
$voiceDTO->providerId
$voiceDTO->externalAccountId
);

$characterId = Character::query()
Expand All @@ -37,7 +37,7 @@ public function persist(array $payload): void

Voice::query()->create([
'tenant_id' => request()->tenant_id,
'provider_id' => $externalIdentity->id,
'external_identity_id' => $externalIdentity->id,
'channel_name' => $voiceDTO->channelName,
'state' => $voiceDTO->voiceState->value,
'obtained_experience' => $obtainedExperience,
Expand Down
2 changes: 1 addition & 1 deletion app-modules/activity/src/Actions/PersistMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function handle(
): Message {
return Message::query()->create([
'tenant_id' => $messageDTO->tenantId,
'provider_id' => $providerEntity,
'external_identity_id' => $providerEntity,
'provider_message_id' => $messageDTO->providerMessageId,
'channel_id' => $messageDTO->channelId,
'content' => $messageDTO->content,
Expand Down
4 changes: 2 additions & 2 deletions app-modules/activity/src/DTOs/NewMessageDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(
public int $tenantId,
public IdentityProvider $provider,
public string $providerUsername,
public string $providerId,
public string $externalAccountId,
public string $providerMessageId,
public string $channelId,
public string $content,
Expand All @@ -26,7 +26,7 @@ public static function make(array $payload): self
tenantId: $payload['tenant_id'],
provider: IdentityProvider::from($payload['provider']),
providerUsername: $payload['provider_username'],
providerId: $payload['provider_id'],
externalAccountId: $payload['external_account_id'],
providerMessageId: $payload['provider_message_id'],
channelId: $payload['channel_id'],
content: $payload['content'],
Expand Down
4 changes: 2 additions & 2 deletions app-modules/activity/src/DTOs/NewVoiceMessageDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{
public function __construct(
public IdentityProvider $provider,
public string $providerId,
public string $externalAccountId,
public VoiceStatesEnum $voiceState,
public string $channelName,
) {}
Expand All @@ -20,7 +20,7 @@ public static function make(array $payload): self
{
return new self(
provider: IdentityProvider::from($payload['provider']),
providerId: $payload['provider_id'],
externalAccountId: $payload['external_account_id'],
voiceState: VoiceStatesEnum::from($payload['state']),
channelName: $payload['channel_name']
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function configure(Schema $schema): Schema
{
return $schema
->components([
Select::make('provider_id')
Select::make('external_identity_id')
->label('Provider')
->getOptionLabelFromRecordUsing(fn (ExternalIdentity $record) => $record->provider->getLabel())
->preload()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function rules(): array
return [
'tenant_id' => ['required'],
'provider' => ['required', 'in:twitch,discord'],
'provider_id' => ['required'],
'external_account_id' => ['required'],
'provider_message_id' => ['required'],
'channel_id' => ['required'],
'content' => ['required', 'string'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function rules(): array
{
return [
'provider' => ['required', 'in:twitch,discord'],
'provider_id' => ['required'],
'external_account_id' => ['required'],
'state' => ['required', 'in:muted,unmuted,disabled'],
'channel_name' => ['required', 'string'],
];
Expand Down
4 changes: 2 additions & 2 deletions app-modules/activity/src/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class Message extends Model
protected $fillable = [
'id',
'tenant_id',
'provider_id',
'external_identity_id',
'provider_message_id',
'channel_id',
'content',
Expand All @@ -35,7 +35,7 @@ final class Message extends Model
*/
public function provider(): BelongsTo
{
return $this->belongsTo(ExternalIdentity::class, 'provider_id');
return $this->belongsTo(ExternalIdentity::class, 'external_identity_id');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app-modules/activity/src/Models/Voice.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class Voice extends Model

protected $fillable = [
'tenant_id',
'provider_id',
'external_identity_id',
'channel_name',
'state',
'obtained_experience',
Expand All @@ -25,6 +25,6 @@ final class Voice extends Model
*/
public function provider(): BelongsTo
{
return $this->belongsTo(ExternalIdentity::class);
return $this->belongsTo(ExternalIdentity::class, 'external_identity_id');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

$data = [
'tenant_id' => $tenant->getKey(),
'provider_id' => $provider->getKey(),
'external_identity_id' => $provider->getKey(),
'channel_id' => 1,
'provider_message_id' => 'prov-msg-123',
'content' => 'Mensagem de teste enviada',
Expand All @@ -40,7 +40,7 @@

assertDatabaseHas(Message::class, [
'tenant_id' => $tenant->getKey(),
'provider_id' => $provider->getKey(),
'external_identity_id' => $provider->getKey(),
'content' => 'Mensagem de teste enviada',
]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
])
->assertOk()
->assertSchemaStateSet([
'provider_id' => $message->provider_id,
'external_identity_id' => $message->external_identity_id,
'channel_id' => $message->channel_id,
'content' => $message->content,
'provider_message_id' => $message->provider_message_id,
Expand Down
12 changes: 6 additions & 6 deletions app-modules/activity/tests/Feature/NewMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ExternalIdentity::factory([
'tenant_id' => $tenant->getKey(),
'provider' => IdentityProvider::Discord,
'provider_id' => '123',
'external_account_id' => '123',
])->create();
})
->create();
Expand All @@ -31,7 +31,7 @@
$provider = $user->providers[0];
$payload = [
'provider' => $provider->provider->value,
'provider_id' => $provider->provider_id,
'external_account_id' => $provider->external_account_id,
'provider_message_id' => '12312312',
'channel_id' => '312321',
'content' => '321312',
Expand Down Expand Up @@ -59,7 +59,7 @@
ExternalIdentity::factory([
'tenant_id' => $tenant->getKey(),
'provider' => IdentityProvider::Discord,
'provider_id' => '123',
'external_account_id' => '123',
])->create();
})
->create();
Expand All @@ -71,7 +71,7 @@
$provider = $user->providers[0];
$payload = [
'provider' => $provider->provider->value,
'provider_id' => $provider->provider_id,
'external_account_id' => $provider->external_account_id,
'provider_message_id' => '12312312',
'channel_id' => '312321',
'content' => '321312',
Expand All @@ -97,7 +97,7 @@
ExternalIdentity::factory([
'tenant_id' => $tenant->getKey(),
'provider' => IdentityProvider::Discord,
'provider_id' => '123',
'external_account_id' => '123',
])->create();
})
->create();
Expand All @@ -116,7 +116,7 @@
$provider = $user->providers[0];
$payload = [
'provider' => $provider->provider->value,
'provider_id' => $provider->provider_id,
'external_account_id' => $provider->external_account_id,
'provider_message_id' => '12312312',
'channel_id' => '312321',
'content' => '321312',
Expand Down
4 changes: 2 additions & 2 deletions app-modules/activity/tests/Feature/NewVoiceMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ExternalIdentity::factory([
'tenant_id' => $tenant->getKey(),
'provider' => IdentityProvider::Discord,
'provider_id' => '123',
'external_account_id' => '123',
])->create();
})
->create();
Expand All @@ -30,7 +30,7 @@
$provider = $user->providers[0];
$payload = [
'provider' => $provider->provider->value,
'provider_id' => $provider->provider_id,
'external_account_id' => $provider->external_account_id,
'state' => VoiceStatesEnum::Muted->value,
'channel_name' => 'Estudando',
];
Expand Down
6 changes: 3 additions & 3 deletions app-modules/activity/tests/Unit/Actions/NewMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
'id' => '1',
'model_id' => 'id-user-foda',
'provider' => 'twitch',
'provider_id' => '12312312',
'external_account_id' => '12312312',
];

$findProviderStub
->shouldReceive('handle')
->with($provider, $payload['provider_id'])
->with($provider, $payload['external_account_id'])
->andReturn($providerEntityMock);

$findCharacterStub
Expand Down Expand Up @@ -81,7 +81,7 @@
'payload' => [
'provider' => 'twitch',
'tenant_id' => 1,
'provider_id' => '1234',
'external_account_id' => '1234',
'provider_message_id' => '78781237',
'channel_id' => '31231267312',
'content' => 'deixa o sub',
Expand Down
4 changes: 2 additions & 2 deletions app-modules/bot-discord/src/Events/MessageReceivedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public function handle(Message $message, Discord $discord): void
try {
$tenantProvider = ExternalIdentity::query()
->where('model_type', Tenant::class)
->where('provider_id', (string) $message->guild_id)
->where('external_account_id', (string) $message->guild_id)
->firstOrFail();

resolve(NewMessage::class)->persist(new NewMessageDTO(
tenantId: $tenantProvider->tenant_id,
provider: IdentityProvider::Discord,
providerUsername: $message->author->username.'#'.$message->author->discriminator,
providerId: $message->user_id,
externalAccountId: $message->user_id,
providerMessageId: $message->id,
channelId: $message->channel_id,
content: $message->content,
Expand Down
6 changes: 3 additions & 3 deletions app-modules/bot-discord/src/Events/WelcomeMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public function handle(Member $member, Discord $discord): void

$tenantProvider = ExternalIdentity::query()
->where('model_type', Tenant::class)
->where('provider_id', (string) $member->guild_id)
->where('external_account_id', (string) $member->guild_id)
->firstOrFail();

try {
$userDto = ResolveUserProviderDTO::make([
'tenant_id' => $tenantProvider->tenant_id,
'provider' => $tenantProvider->provider,
'provider_id' => $member->user->id,
'external_account_id' => $member->user->id,
'model_type' => User::class,
'username' => $member->user->username,
'avatar' => $member->user->avatar,
Expand All @@ -44,7 +44,7 @@ public function handle(Member $member, Discord $discord): void
Log::error('Falha ao resolver usuário no evento WelcomeMember', [
'tenant_id' => $tenantProvider->tenant_id ?? null,
'provider' => $tenantProvider->provider ?? null,
'provider_id' => $member->user->id ?? null,
'external_account_id' => $member->user->id ?? null,
'exception' => $throwable,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ private function beforePipeline(Interaction $interaction): void
$this->tenantProvider = ExternalIdentity::query()
->where('model_type', Tenant::class)
->where('provider', IdentityProvider::Discord)
->where('provider_id', $interaction->guild_id)
->where('external_account_id', $interaction->guild_id)
->first();

$this->memberProvider = ExternalIdentity::query()
->where('tenant_id', $this->tenantProvider->tenant_id)
->where('model_type', User::class)
->where('provider', IdentityProvider::Discord)
->where('provider_id', $interaction->user->id)
->where('external_account_id', $interaction->user->id)
->first();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private function persistData(
$payload = UpdateProfileDTO::fromPayload([
'tenant_id' => $this->memberProvider->tenant_id,
'provider' => $this->memberProvider->provider,
'provider_id' => $interaction->user->id,
'external_account_id' => $interaction->user->id,
'name' => $components->get('custom_id', 'name')?->value,
'nickname' => $components->get('custom_id', 'nickname')?->value,
'linkedin_url' => $components->get('custom_id', 'linkedin_url')?->value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ private function persistData(Interaction $interaction, Collection $components):
{
$tenantProvider = ExternalIdentity::query()
->where('model_type', Tenant::class)
->where('provider_id', (string) $interaction->guild_id)
->where('external_account_id', (string) $interaction->guild_id)
->firstOrFail();

$userDto = ResolveUserProviderDTO::make([
'tenant_id' => $tenantProvider->tenant_id,
'provider' => $tenantProvider->provider,
'provider_id' => $interaction->user->id,
'external_account_id' => $interaction->user->id,
'model_type' => User::class,
'username' => $interaction->user->username,
'avatar' => $interaction->user->avatar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function handle(Interaction $interaction): void
$mentionedUser = $interaction->user;

if ($userId = $this->value('user')) {
$this->memberProvider = $this->getMemberProviderQuery()->where('provider_id', $userId)->first();
$this->memberProvider = $this->getMemberProviderQuery()->where('external_account_id', $userId)->first();
$mentionedUser = $interaction->data->resolved->users->get('id', $userId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function postMeeting(
): JsonResponse {
try {
return response()->json(
$startMeeting->handle($provider, $request->input('provider_id'), $request->input('meeting_type_id')),
$startMeeting->handle($provider, $request->input('external_account_id'), $request->input('meeting_type_id')),
Response::HTTP_CREATED
);
} catch (MeetingException $meetingException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function rules(): array
{
return [
'meeting_type_id' => ['required', 'integer'],
'provider_id' => ['required'],
'external_account_id' => ['required'],
'provider' => ['required'],
];
}
Expand Down
Loading
Loading