Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(chat): Add the mention id to parameters for easier editing #14270

Merged
merged 1 commit into from
Feb 7, 2025
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
5 changes: 5 additions & 0 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ protected function getUser(string $uid): array {
'type' => 'user',
'id' => $uid,
'name' => $this->displayNames[$uid],
'mention-id' => $uid,
];
}

Expand All @@ -941,6 +942,7 @@ protected function getRemoteUser(Room $room, string $federationId): array {
'id' => $cloudId->getUser(),
'name' => $displayName,
'server' => $cloudId->getRemote(),
'mention-id' => 'federated_user/' . $cloudId->getUser() . '@' . $cloudId->getRemote(),
];
}

Expand All @@ -962,6 +964,7 @@ protected function getGroup(string $gid): array {
'type' => 'group',
'id' => $gid,
'name' => $this->groupNames[$gid],
'mention-id' => 'user-group/' . $gid,
];
}

Expand Down Expand Up @@ -995,6 +998,7 @@ protected function getCircle(string $circleId): array {
'id' => $circleId,
'name' => $this->circleNames[$circleId],
'link' => $this->circleLinks[$circleId],
'mention-id' => 'team/' . $circleId,
];
}

Expand Down Expand Up @@ -1042,6 +1046,7 @@ protected function getGuest(Room $room, string $actorType, string $actorId): arr
'type' => 'guest',
'id' => ($actorType === Attendee::ACTOR_GUESTS ? 'guest/' : 'email/') . $actorId,
'name' => $this->guestNames[$key],
'mention-id' => ($actorType === Attendee::ACTOR_GUESTS ? 'guest/' : 'email/') . $actorId,
];
}

Expand Down
9 changes: 8 additions & 1 deletion lib/Chat/Parser/UserMention.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ protected function parseMessage(Message $chatMessage): void {
'name' => $chatMessage->getRoom()->getDisplayName($userId, true),
'call-type' => $this->getRoomType($chatMessage->getRoom()),
'icon-url' => $this->avatarService->getAvatarUrl($chatMessage->getRoom()),
'mention-id' => $search,
];
} elseif ($mention['type'] === 'guest') {
try {
Expand All @@ -174,6 +175,7 @@ protected function parseMessage(Message $chatMessage): void {
'type' => $mention['type'],
'id' => $mention['id'],
'name' => $displayName,
'mention-id' => $search,
];
} elseif ($mention['type'] === 'email') {
try {
Expand All @@ -187,6 +189,7 @@ protected function parseMessage(Message $chatMessage): void {
'type' => $mention['type'],
'id' => $mention['id'],
'name' => $displayName,
'mention-id' => $search,
];
} elseif ($mention['type'] === 'federated_user') {
try {
Expand All @@ -206,7 +209,8 @@ protected function parseMessage(Message $chatMessage): void {
'type' => 'user',
'id' => $cloudId->getUser(),
'name' => $displayName,
'server' => $cloudId->getRemote()
'server' => $cloudId->getRemote(),
'mention-id' => $search,
];
} elseif ($mention['type'] === 'group') {
$group = $this->groupManager->get($mention['id']);
Expand All @@ -220,6 +224,7 @@ protected function parseMessage(Message $chatMessage): void {
'type' => 'user-group',
'id' => $mention['id'],
'name' => $displayName,
'mention-id' => $search,
];
} elseif ($mention['type'] === 'team') {
$messageParameters[$mentionParameterId] = $this->getCircle($mention['id']);
Expand All @@ -236,6 +241,7 @@ protected function parseMessage(Message $chatMessage): void {
'type' => $mention['type'],
'id' => $mention['id'],
'name' => $displayName,
'mention-id' => $search,
];
}
}
Expand Down Expand Up @@ -293,6 +299,7 @@ protected function getCircle(string $circleId): array {
'id' => $circleId,
'name' => $this->circleNames[$circleId],
'link' => $this->circleLinks[$circleId],
'mention-id' => 'team/' . $circleId,
];
}

Expand Down
21 changes: 21 additions & 0 deletions lib/Federation/Proxy/TalkV1/UserConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ protected function convertMessageParameter(Room $room, array $parameter): array
if ($parameter['type'] === 'user') { // RichObjectDefinition, not Attendee::ACTOR_USERS
if (!isset($parameter['server'])) {
$parameter['server'] = $room->getRemoteServer();
if (!isset($parameter['mention-id'])) {
$parameter['mention-id'] = $parameter['id'];
}
} elseif ($parameter['server']) {
$localParticipants = $this->getLocalParticipants($room);
$cloudId = $this->createCloudIdFromUserIdAndFullServerUrl($parameter['id'], $parameter['server']);
if (!isset($parameter['mention-id'])) {
$parameter['mention-id'] = 'federated_user/' . $parameter['id'] . '@' . $parameter['server'];
}
if (isset($localParticipants[$cloudId])) {
unset($parameter['server']);
$parameter['name'] = $localParticipants[$cloudId]['displayName'];
Expand All @@ -96,6 +102,21 @@ protected function convertMessageParameter(Room $room, array $parameter): array
} elseif ($parameter['type'] === 'call' && $parameter['id'] === $room->getRemoteToken()) {
$parameter['id'] = $room->getToken();
$parameter['icon-url'] = $this->avatarService->getAvatarUrl($room);
if (!isset($parameter['mention-id'])) {
$parameter['mention-id'] = 'all';
}
} elseif ($parameter['type'] === 'circle') {
if (!isset($parameter['mention-id'])) {
$parameter['mention-id'] = 'team/' . $parameter['id'];
}
} elseif ($parameter['type'] === 'user-group') {
if (!isset($parameter['mention-id'])) {
$parameter['mention-id'] = 'group/' . $parameter['id'];
}
} elseif ($parameter['type'] === 'email' || $parameter['type'] === 'guest') {
if (!isset($parameter['mention-id'])) {
$parameter['mention-id'] = $parameter['type'] . '/' . $parameter['id'];
}
}
return $parameter;
}
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/features/callapi/notifications.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ Feature: callapi/notifications
Then user "participant2" checks call notification for "room" with 200 (v4)
Then user "participant2" sees the following system messages in room "room" with 200
| room | actorType | actorId | systemMessage | message | silent | messageParameters |
| room | users | participant1 | call_started | {actor} started a call | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} |
| room | users | participant1 | user_added | {actor} added you | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"user","id":"participant2","name":"participant2-displayname"}} |
| room | users | participant1 | conversation_created | {actor} created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} |
| room | users | participant1 | call_started | {actor} started a call | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} |
| room | users | participant1 | user_added | {actor} added you | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"},"user":{"type":"user","id":"participant2","name":"participant2-displayname","mention-id":"participant2"}} |
| room | users | participant1 | conversation_created | {actor} created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} |
Then user "participant2" has the following notifications
| app | object_type | object_id | subject |
| spreed | call | room | A group call has started in room |
Expand All @@ -57,9 +57,9 @@ Feature: callapi/notifications
| silent | true |
Then user "participant2" sees the following system messages in room "room" with 200
| room | actorType | actorId | systemMessage | message | silent | messageParameters |
| room | users | participant1 | call_started | {actor} started a silent call | true | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} |
| room | users | participant1 | user_added | {actor} added you | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"},"user":{"type":"user","id":"participant2","name":"participant2-displayname"}} |
| room | users | participant1 | conversation_created | {actor} created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname"}} |
| room | users | participant1 | call_started | {actor} started a silent call | true | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} |
| room | users | participant1 | user_added | {actor} added you | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"},"user":{"type":"user","id":"participant2","name":"participant2-displayname","mention-id":"participant2"}} |
| room | users | participant1 | conversation_created | {actor} created the conversation | !ISSET | {"actor":{"type":"user","id":"participant1","name":"participant1-displayname","mention-id":"participant1"}} |
Then user "participant2" has the following notifications
| app | object_type | object_id | subject |
Given user "participant1" leaves call "room" with 200 (v4)
Expand Down
Loading
Loading