Browse Source

Merge pull request #5985 from nextcloud/bugfix/2232/missed-call-notifications

Add "missed call" chat system message for one-to-one
pull/5988/head
Vincent Petry 5 years ago
committed by GitHub
parent
commit
49d8d39f2f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      docs/chat.md
  2. 12
      lib/Activity/Listener.php
  3. 30
      lib/Chat/Parser/SystemMessage.php

2
docs/chat.md

@ -271,6 +271,8 @@ See [OCP\RichObjectStrings\Definitions](https://github.com/nextcloud/server/blob
* `call_joined` - {actor} joined the call
* `call_left` - {actor} left the call
* `call_ended` - Call with {user1}, {user2}, {user3}, {user4} and {user5} (Duration 30:23)
* `call_missed` - You missed a call from {user}
* `call_tried` - You tried to call {user}
* `read_only_off` - {actor} unlocked the conversation
* `read_only` - {actor} locked the conversation
* `listable_none` - {actor} limited the conversation to the current participants

12
lib/Activity/Listener.php

@ -122,10 +122,14 @@ class Listener {
$userIds = $this->participantService->getParticipantUserIds($room, $activeSince);
$numGuests = $this->participantService->getGuestCount($room, $activeSince);
$message = 'call_ended';
if ((\count($userIds) + $numGuests) === 1) {
// Single user pinged or guests only => no summary/activity
$room->resetActiveSince();
return false;
if ($room->getType() !== Room::ONE_TO_ONE_CALL) {
// Single user pinged or guests only => no summary/activity
$room->resetActiveSince();
return false;
}
$message = 'call_missed';
}
if (!$room->resetActiveSince()) {
@ -136,7 +140,7 @@ class Listener {
$actorId = $userIds[0] ?? 'guests-only';
$actorType = $actorId !== 'guests-only' ? Attendee::ACTOR_USERS : Attendee::ACTOR_GUESTS;
$this->chatManager->addSystemMessage($room, $actorType, $actorId, json_encode([
'message' => 'call_ended',
'message' => $message,
'parameters' => [
'users' => $userIds,
'guests' => $numGuests,

30
lib/Chat/Parser/SystemMessage.php

@ -167,6 +167,8 @@ class SystemMessage {
if ($currentUserIsActor) {
$parsedMessage = $this->l->t('You left the call');
}
} elseif ($message === 'call_missed') {
[$parsedMessage, $parsedParameters, $message] = $this->parseMissedCall($room, $parameters, $currentActorId);
} elseif ($message === 'call_ended') {
[$parsedMessage, $parsedParameters] = $this->parseCall($parameters);
} elseif ($message === 'read_only_off') {
@ -624,6 +626,34 @@ class SystemMessage {
}
}
protected function parseMissedCall(Room $room, array $parameters, string $currentActorId): array {
if ($parameters['users'][0] !== $currentActorId) {
return [
$this->l->t('You missed a call from {user}'),
[
'user' => $this->getUser($parameters['users'][0]),
],
'call_missed',
];
}
$participants = json_decode($room->getName(), true);
$other = '';
foreach ($participants as $participant) {
if ($participant !== $currentActorId) {
$other = $participant;
}
}
return [
$this->l->t('You tried to call {user}'),
[
'user' => $this->getUser($other),
],
'call_tried',
];
}
protected function parseCall(array $parameters): array {
sort($parameters['users']);
$numUsers = \count($parameters['users']);

Loading…
Cancel
Save