From db3875710bcf9f29baa360d91d7b11b0199229a9 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 5 Jan 2021 22:46:35 +0300 Subject: [PATCH 1/2] Show recently joined voice chat participants as recent speakers. --- td/telegram/GroupCallManager.cpp | 5 +++-- td/telegram/GroupCallManager.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index e81456046..e94061660 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -2076,7 +2076,8 @@ void GroupCallManager::on_receive_group_call_version(InputGroupCallId input_grou void GroupCallManager::on_participant_speaking_in_group_call(InputGroupCallId input_group_call_id, const GroupCallParticipant &participant) { - if (participant.active_date < G()->unix_time() - RECENT_SPEAKER_TIMEOUT) { + auto active_date = td::max(participant.active_date, participant.joined_date - 60); + if (active_date < G()->unix_time() - RECENT_SPEAKER_TIMEOUT) { return; } @@ -2085,7 +2086,7 @@ void GroupCallManager::on_participant_speaking_in_group_call(InputGroupCallId in return; } - on_user_speaking_in_group_call(group_call->group_call_id, participant.user_id, participant.active_date, true); + on_user_speaking_in_group_call(group_call->group_call_id, participant.user_id, active_date, true); } void GroupCallManager::on_user_speaking_in_group_call(GroupCallId group_call_id, UserId user_id, int32 date, diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index 03de5dd73..c55fe6d22 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -88,7 +88,7 @@ class GroupCallManager : public Actor { struct GroupCallRecentSpeakers; struct PendingJoinRequest; - static constexpr int32 RECENT_SPEAKER_TIMEOUT = 5 * 60; + static constexpr int32 RECENT_SPEAKER_TIMEOUT = 60 * 60; static constexpr int32 CHECK_GROUP_CALL_IS_JOINED_TIMEOUT = 10; void tear_down() override; From 62c18729f1cf8c5f1b7dc6f0d37edbffd2bb78b5 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 7 Jan 2021 04:03:38 +0300 Subject: [PATCH 2/2] Fix td::unique. --- tdutils/td/utils/algorithm.h | 2 +- tdutils/td/utils/translit.cpp | 1 + tdutils/test/misc.cpp | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tdutils/td/utils/algorithm.h b/tdutils/td/utils/algorithm.h index 9baedc620..06f5fbb62 100644 --- a/tdutils/td/utils/algorithm.h +++ b/tdutils/td/utils/algorithm.h @@ -98,7 +98,7 @@ void unique(V &v) { size_t j = 1; for (size_t i = 1; i < v.size(); i++) { - if (v[i] != v[i - 1]) { + if (v[i] != v[j - 1]) { if (i != j) { v[j] = std::move(v[i]); } diff --git a/tdutils/td/utils/translit.cpp b/tdutils/td/utils/translit.cpp index 60ee4e78a..239fa7f5c 100644 --- a/tdutils/td/utils/translit.cpp +++ b/tdutils/td/utils/translit.cpp @@ -7,6 +7,7 @@ #include "td/utils/translit.h" #include "td/utils/algorithm.h" +#include "td/utils/format.h" #include "td/utils/misc.h" #include "td/utils/utf8.h" diff --git a/tdutils/test/misc.cpp b/tdutils/test/misc.cpp index 08c437922..55d172ac1 100644 --- a/tdutils/test/misc.cpp +++ b/tdutils/test/misc.cpp @@ -349,8 +349,14 @@ TEST(Misc, remove) { } static void test_unique(td::vector v, td::vector expected) { + auto v_str = td::transform(v, &td::to_string); + auto expected_str = td::transform(expected, &td::to_string); + td::unique(v); ASSERT_EQ(expected, v); + + td::unique(v_str); + ASSERT_EQ(expected_str, v_str); } TEST(Misc, unique) { @@ -362,6 +368,7 @@ TEST(Misc, unique) { test_unique({0, 1}, {0, 1}); test_unique({1, 0}, {0, 1}); test_unique({1, 1}, {1}); + test_unique({1, 1, 0, 0}, {0, 1}); test_unique({3, 3, 3, 3, 3, 2, 2, 2, 1, 1, 0}, {0, 1, 2, 3}); test_unique({3, 3, 3, 3, 3}, {3}); test_unique({3, 3, -1, 3, 3}, {-1, 3});