diff options
author | Joas Schilling <coding@schilljs.com> | 2023-10-24 11:42:17 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-10-24 11:42:17 +0200 |
commit | bff46e52192c28a1172a04f0ee102841282e4df9 (patch) | |
tree | f44d24a44eb7cefe8c65653484abf5d8afcd69a7 /lib/Chat | |
parent | fc8e14d667180f2adbd53fff431d7698aec899c5 (diff) |
feat(sip-dialout): Add system messages for adding/removing phone numbers to a conversation
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Chat')
-rw-r--r-- | lib/Chat/Parser/SystemMessage.php | 42 | ||||
-rw-r--r-- | lib/Chat/SystemMessage/Listener.php | 4 |
2 files changed, 46 insertions, 0 deletions
diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php index 379073804..b3de52ee9 100644 --- a/lib/Chat/Parser/SystemMessage.php +++ b/lib/Chat/Parser/SystemMessage.php @@ -65,6 +65,8 @@ class SystemMessage { protected array $circleLinks = []; /** @var string[] */ protected array $guestNames = []; + /** @var array<string, array<string, string>> */ + protected array $phoneNames = []; public function __construct( protected IUserManager $userManager, @@ -339,6 +341,22 @@ class SystemMessage { } elseif ($cliIsActor) { $parsedMessage = $this->l->t('An administrator removed circle {circle}'); } + } elseif ($message === 'phone_added') { + $parsedParameters['phone'] = $this->getPhone($room, $parameters['phone'], $parameters['name']); + $parsedMessage = $this->l->t('{actor} added {phone}'); + if ($currentUserIsActor) { + $parsedMessage = $this->l->t('You added {phone}'); + } elseif ($cliIsActor) { + $parsedMessage = $this->l->t('An administrator added {phone}'); + } + } elseif ($message === 'phone_removed') { + $parsedParameters['phone'] = $this->getPhone($room, $parameters['phone'], $parameters['name']); + $parsedMessage = $this->l->t('{actor} removed {phone}'); + if ($currentUserIsActor) { + $parsedMessage = $this->l->t('You removed {phone}'); + } elseif ($cliIsActor) { + $parsedMessage = $this->l->t('An administrator removed {phone}'); + } } elseif ($message === 'moderator_promoted') { $parsedParameters['user'] = $this->getUser($parameters['user']); $parsedMessage = $this->l->t('{actor} promoted {user} to moderator'); @@ -770,6 +788,18 @@ class SystemMessage { ]; } + protected function getPhone(Room $room, string $actorId, string $fallbackDisplayName): array { + if (!isset($this->phoneNames[$room->getToken()][$actorId])) { + $this->phoneNames[$room->getToken()][$actorId] = $this->getDisplayNamePhone($room, $actorId, $fallbackDisplayName); + } + + return [ + 'type' => 'highlight', + 'id' => $actorId, + 'name' => $this->phoneNames[$room->getToken()][$actorId], + ]; + } + protected function getCircle(string $circleId): array { if (!isset($this->circleNames[$circleId])) { $this->loadCircleDetails($circleId); @@ -791,6 +821,18 @@ class SystemMessage { ]; } + protected function getDisplayNamePhone(Room $room, string $actorId, string $fallbackDisplayName): string { + try { + $participant = $this->participantService->getParticipantByActor($room, Attendee::ACTOR_PHONES, $actorId); + return $participant->getAttendee()->getDisplayName(); + } catch (ParticipantNotFoundException) { + if ($fallbackDisplayName) { + return $fallbackDisplayName; + } + return $this->l->t('Unknown number'); + } + } + protected function getDisplayNameGroup(string $gid): string { $group = $this->groupManager->get($gid); if ($group instanceof IGroup) { diff --git a/lib/Chat/SystemMessage/Listener.php b/lib/Chat/SystemMessage/Listener.php index a34fa102d..7b5602923 100644 --- a/lib/Chat/SystemMessage/Listener.php +++ b/lib/Chat/SystemMessage/Listener.php @@ -408,6 +408,8 @@ class Listener implements IEventListener { $this->sendSystemMessage($event->getRoom(), 'circle_added', ['circle' => $attendee->getActorId()]); } elseif ($attendee->getActorType() === Attendee::ACTOR_FEDERATED_USERS) { $this->sendSystemMessage($event->getRoom(), 'federated_user_added', ['federated_user' => $attendee->getActorId()]); + } elseif ($attendee->getActorType() === Attendee::ACTOR_PHONES) { + $this->sendSystemMessage($event->getRoom(), 'phone_added', ['phone' => $attendee->getActorId(), 'name' => $attendee->getDisplayName()]); } } } @@ -420,6 +422,8 @@ class Listener implements IEventListener { $this->sendSystemMessage($event->getRoom(), 'circle_removed', ['circle' => $attendee->getActorId()]); } elseif ($attendee->getActorType() === Attendee::ACTOR_FEDERATED_USERS) { $this->sendSystemMessage($event->getRoom(), 'federated_user_removed', ['federated_user' => $attendee->getActorId()]); + } elseif ($attendee->getActorType() === Attendee::ACTOR_PHONES) { + $this->sendSystemMessage($event->getRoom(), 'phone_removed', ['phone' => $attendee->getActorId(), 'name' => $attendee->getDisplayName()]); } } } |