From 1329a9858487c2e95ea7191c2b7808b7533c20d3 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Sat, 24 May 2025 15:09:08 +0300 Subject: Refactored minor things and added a terminology.md file which will be expanded later --- internal/client/ui/core/state/state.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'internal/client/ui/core/state') diff --git a/internal/client/ui/core/state/state.go b/internal/client/ui/core/state/state.go index 1eafaee..fec4695 100644 --- a/internal/client/ui/core/state/state.go +++ b/internal/client/ui/core/state/state.go @@ -269,10 +269,13 @@ func GetLastMessage(id snowflake.ID) *snowflake.ID { } func IsFrequency(id snowflake.ID) bool { - // Note this is very expensive and inefficient + // OPTIMIZE: this is very expensive and inefficient // A map is better but as most of the time frequencies are iterated // over based on a network id, this would add overhead // And this function is only used once in notifications + // Maybe there should be a special bit in the snowflake to determine this? + // This could work if frequencies, user IDs, network IDs etc would all have + // their own "pool" to generate from (using the "machine id" bits) for _, frequencies := range State.Frequencies { for _, frequency := range frequencies { @@ -296,7 +299,10 @@ func UpdateNotifications(info *packet.NotificationsInfo) []snowflake.ID { if ping != nil { State.RemoteNotifications[source] = int(*ping) - if !IsFrequency(source) && !slices.Contains(Data.Signals, source) { + // When someone messages you, and you don't have a signal with him + // already, add a signal with him so you see his messages + // PERF: IsFrequency is expensive so contains is checked first + if !slices.Contains(Data.Signals, source) && !IsFrequency(source) { signals = append(signals, source) } } else { @@ -420,8 +426,8 @@ func UpdateUsersInfo(info *packet.UsersInfo) { } } -func MergedNotification(id snowflake.ID) (pings int, ok bool) { - remotePings, remoteOk := State.RemoteNotifications[id] - localPings, localOk := State.LocalNotifications[id] +func MergedNotification(chatId snowflake.ID) (pings int, ok bool) { + remotePings, remoteOk := State.RemoteNotifications[chatId] + localPings, localOk := State.LocalNotifications[chatId] return remotePings + localPings, remoteOk || localOk } -- cgit v1.3.1