Skip to content

Commit 97709a7

Browse files
author
jason
committed
Merge remote-tracking branch 'origin/master' into jason_dev
2 parents 8cb29b1 + a336cc9 commit 97709a7

File tree

12 files changed

+60
-14
lines changed

12 files changed

+60
-14
lines changed

src/Infrastructure/BotSharp.Abstraction/Infrastructures/Events/IEventPublisher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface IEventPublisher
1010
/// <returns></returns>
1111
Task BroadcastAsync(string channel, string message);
1212

13-
Task PublishAsync(string channel, string message, EventPriority? priority = null);
13+
Task<string?> PublishAsync(string channel, string message, EventPriority? priority = null);
1414

1515
Task ReDispatchAsync(string channel, int count = 10, string order = "asc");
1616

src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using BotSharp.Abstraction.Shared;
66
using BotSharp.Abstraction.Tasks.Models;
77
using BotSharp.Abstraction.Translation.Models;
8+
using BotSharp.Abstraction.Users.Enums;
89
using BotSharp.Abstraction.Users.Models;
910
using BotSharp.Abstraction.VectorStorage.Models;
1011

@@ -26,7 +27,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
2627

2728
#region User
2829
User? GetUserByEmail(string email) => throw new NotImplementedException();
29-
User? GetUserByPhone(string phone, string type = "client", string regionCode = "CN") => throw new NotImplementedException();
30+
User? GetUserByPhone(string phone, string type = UserType.Client, string regionCode = "CN") => throw new NotImplementedException();
3031
User? GetAffiliateUserByPhone(string phone) => throw new NotImplementedException();
3132
User? GetUserById(string id) => throw new NotImplementedException();
3233
List<User> GetUserByIds(List<string> ids) => throw new NotImplementedException();

src/Infrastructure/BotSharp.Abstraction/Users/Models/User.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class User
2323
public bool Verified { get; set; }
2424
public string RegionCode { get; set; } = "CN";
2525
public string? AffiliateId { get; set; }
26+
public string? AffiliateCode { get; set; }
2627
public string? EmployeeId { get; set; }
2728
public bool IsDisabled { get; set; }
2829
public IEnumerable<string> Permissions { get; set; } = [];

src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using BotSharp.Abstraction.Infrastructures;
2+
using System.Diagnostics;
23

34
namespace BotSharp.Abstraction.Utilities;
45

6+
[DebuggerStepThrough]
57
public class Pagination : ICacheKey
68
{
79
private int _page;

src/Infrastructure/BotSharp.Core/Infrastructures/Events/RedisPublisher.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public async Task BroadcastAsync(string channel, string message)
2121
await _subscriber.PublishAsync(channel, message);
2222
}
2323

24-
public async Task PublishAsync(string channel, string message, EventPriority? priority = null)
24+
public async Task<string?> PublishAsync(string channel, string message, EventPriority? priority = null)
2525
{
2626
var db = _redis.GetDatabase();
2727

@@ -34,7 +34,7 @@ public async Task PublishAsync(string channel, string message, EventPriority? pr
3434
if (CheckMessageExists(db, channel, "message", message))
3535
{
3636
_logger.LogError($"The message already exists {channel} {message}");
37-
return;
37+
return null;
3838
}
3939

4040
// Add a message to the stream, keeping only the latest 1 million messages
@@ -46,6 +46,8 @@ public async Task PublishAsync(string channel, string message, EventPriority? pr
4646
maxLength: 1000 * 10000);
4747

4848
_logger.LogInformation($"Published message {channel} {message} ({messageId})");
49+
50+
return messageId;
4951
}
5052

5153
private bool CheckMessageExists(IDatabase db, string channel, string fieldName, string desiredValue)
@@ -91,7 +93,10 @@ public async Task ReDispatchAsync(string channel, int count = 10, string order =
9193

9294
try
9395
{
94-
var messageId = await db.StreamAddAsync(channel, "message", entry.Values[0].Value);
96+
var messageId = await db.StreamAddAsync(channel, [
97+
new NameValueEntry("message", entry.Values[0].Value),
98+
new NameValueEntry("timestamp", DateTime.UtcNow.ToString("o"))
99+
]);
95100

96101
_logger.LogWarning($"ReDispatched message: {channel} {entry.Values[0].Value} ({messageId})");
97102

src/Infrastructure/BotSharp.Core/Infrastructures/Events/RedisSubscriber.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public async Task SubscribeAsync(string channel, string group, bool priorityEnab
4242

4343
while (true)
4444
{
45+
await Task.Delay(100);
46+
4547
if (priorityEnabled)
4648
{
4749
if (await HandleGroupMessage(db, $"{channel}-{EventPriority.High}", group, received) > 0)

src/Infrastructure/BotSharp.Core/Infrastructures/Utilities.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static string HashTextSha256(string text)
2323

2424
var data = sha256.ComputeHash(Encoding.UTF8.GetBytes(text));
2525
var sb = new StringBuilder();
26-
foreach(var c in data)
26+
foreach (var c in data)
2727
{
2828
sb.Append(c.ToString("x2"));
2929
}
@@ -47,4 +47,36 @@ public static void ClearCache()
4747
memcache.Compact(100);
4848
}
4949
}
50+
51+
public static string HideMiddleDigits(string input, bool isEmail = false)
52+
{
53+
if (string.IsNullOrWhiteSpace(input))
54+
{
55+
return input;
56+
}
57+
58+
if (isEmail)
59+
{
60+
int atIndex = input.IndexOf('@');
61+
if (atIndex > 1)
62+
{
63+
string localPart = input.Substring(0, atIndex);
64+
if (localPart.Length > 2)
65+
{
66+
string maskedLocalPart = $"{localPart[0]}{new string('*', localPart.Length - 2)}{localPart[^1]}";
67+
return $"{maskedLocalPart}@{input.Substring(atIndex + 1)}";
68+
}
69+
}
70+
}
71+
else
72+
{
73+
if (input.Length > 6)
74+
{
75+
return $"{input.Substring(0, 3)}{new string('*', input.Length - 6)}{input.Substring(input.Length - 3)}";
76+
}
77+
}
78+
79+
return input;
80+
}
81+
5082
}

src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public partial class FileRepository
1111
return Users.FirstOrDefault(x => x.Email == email.ToLower());
1212
}
1313

14-
public User? GetUserByPhone(string phone, string? type = "client", string regionCode = "CN")
14+
public User? GetUserByPhone(string phone, string? type = UserType.Client, string regionCode = "CN")
1515
{
1616
var query = Users.Where(x => x.Phone == phone);
1717

src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public async Task<bool> UpdatePassword(string password, string verificationCode)
172172
var base64 = Encoding.UTF8.GetString(Convert.FromBase64String(authorization));
173173
var (id, password) = base64.SplitAsTuple(":");
174174
var db = _services.GetRequiredService<IBotSharpRepository>();
175-
var record = db.GetUserByPhone(id, type: "internal");
175+
var record = db.GetUserByPhone(id, type: UserType.Internal);
176176
var isCanLogin = record != null && !record.IsDisabled
177177
&& record.Type == UserType.Internal && new List<string>
178178
{
@@ -548,7 +548,7 @@ public async Task<bool> VerifyPhoneExisting(string phone, string regionCode)
548548
}
549549

550550
var db = _services.GetRequiredService<IBotSharpRepository>();
551-
var UserByphone = db.GetUserByPhone(phone, regionCode);
551+
var UserByphone = db.GetUserByPhone(phone, regionCode: regionCode);
552552
if (UserByphone != null && UserByphone.Verified)
553553
{
554554
return true;

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Users/UserCreationModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class UserCreationModel
1313
public string Type { get; set; } = UserType.Client;
1414
public string Role { get; set; } = UserRole.User;
1515
public string RegionCode { get; set; } = "CN";
16+
public string? AffiliateCode { get; set; }
1617
public User ToUser()
1718
{
1819
return new User
@@ -25,7 +26,8 @@ public User ToUser()
2526
Password = Password,
2627
Role = Role,
2728
Type = Type,
28-
RegionCode = RegionCode
29+
RegionCode = RegionCode,
30+
AffiliateCode = AffiliateCode
2931
};
3032
}
3133
}

0 commit comments

Comments
 (0)