5
5
// file LICENSE or copy at https://www.gnu.org/licenses/gpl-3.0.txt)
6
6
//
7
7
using System . Collections . Generic ;
8
- using System . Linq ;
9
8
using System . Text ;
10
- using Telegram . Common ;
11
9
12
10
namespace Telegram . Services . Settings
13
11
{
@@ -24,6 +22,7 @@ public partial class EmojiSettings : SettingsServiceBase
24
22
25
23
private readonly Dictionary < string , int > _emojiUseHistory = new Dictionary < string , int > ( ) ;
26
24
private readonly List < string > _recentEmoji = new List < string > ( ) ;
25
+ private readonly object _recentEmojiLock = new ( ) ;
27
26
private bool _recentEmojiLoaded ;
28
27
29
28
private const int MAX_RECENT_EMOJI_COUNT = 35 ;
@@ -37,40 +36,42 @@ public List<string> RecentEmoji
37
36
{
38
37
get
39
38
{
40
- LoadRecentEmoji ( ) ;
41
- return _recentEmoji ;
39
+ lock ( _recentEmojiLock )
40
+ {
41
+ LoadRecentEmoji ( ) ;
42
+ return _recentEmoji ;
43
+ }
42
44
}
43
45
}
44
46
45
-
46
- public EmojiData [ ] GetRecentEmoji ( )
47
- {
48
- LoadRecentEmoji ( ) ;
49
- return _recentEmoji . Select ( x => new EmojiData ( x ) ) . ToArray ( ) ;
50
- }
51
-
52
47
public void AddRecentEmoji ( string code )
53
48
{
54
- LoadRecentEmoji ( ) ;
55
-
56
- foreach ( var modifier in _modifiers )
49
+ lock ( _recentEmojiLock )
57
50
{
58
- code = code . Replace ( modifier , string . Empty ) ;
59
- }
51
+ LoadRecentEmoji ( ) ;
60
52
61
- _emojiUseHistory . TryGetValue ( code , out int count ) ;
53
+ foreach ( var modifier in _modifiers )
54
+ {
55
+ code = code . Replace ( modifier , string . Empty ) ;
56
+ }
62
57
63
- if ( count == 0 && _emojiUseHistory . Count >= MAX_RECENT_EMOJI_COUNT )
64
- {
65
- var emoji = _recentEmoji [ _recentEmoji . Count - 1 ] ;
66
- _emojiUseHistory . Remove ( emoji ) ;
67
- _recentEmoji [ _recentEmoji . Count - 1 ] = code ;
68
- }
58
+ _emojiUseHistory . TryGetValue ( code , out int count ) ;
59
+
60
+ if ( count == 0 && _emojiUseHistory . Count >= MAX_RECENT_EMOJI_COUNT )
61
+ {
62
+ var emoji = _recentEmoji [ _recentEmoji . Count - 1 ] ;
63
+ _emojiUseHistory . Remove ( emoji ) ;
64
+ _recentEmoji [ _recentEmoji . Count - 1 ] = code ;
65
+ }
66
+
67
+ _emojiUseHistory [ code ] = ++ count ;
69
68
70
- _emojiUseHistory [ code ] = ++ count ;
69
+ SortRecentEmoji ( ) ;
70
+ SaveRecentEmoji ( ) ;
71
+ }
71
72
}
72
73
73
- public void SortRecentEmoji ( )
74
+ private void SortRecentEmoji ( )
74
75
{
75
76
_recentEmoji . Clear ( ) ;
76
77
@@ -102,7 +103,7 @@ public void SortRecentEmoji()
102
103
}
103
104
}
104
105
105
- public void SaveRecentEmoji ( )
106
+ private void SaveRecentEmoji ( )
106
107
{
107
108
var stringBuilder = new StringBuilder ( ) ;
108
109
@@ -130,7 +131,7 @@ public void ClearRecentEmoji()
130
131
SaveRecentEmoji ( ) ;
131
132
}
132
133
133
- public void LoadRecentEmoji ( )
134
+ private void LoadRecentEmoji ( )
134
135
{
135
136
if ( _recentEmojiLoaded )
136
137
{
0 commit comments