forked from aykutalparslan/Ferrite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5ea888
commit c7505ea
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
Ferrite.Core/Execution/Functions/BaseLayer/Contacts/GetContactIdsFunc.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Ferrite.Services; | ||
using Ferrite.TL; | ||
using Ferrite.TL.slim; | ||
using VectorOfLong = Ferrite.TL.slim.VectorOfLong; | ||
|
||
namespace Ferrite.Core.Execution.Functions.BaseLayer.Contacts; | ||
|
||
public class GetContactIdsFunc : ITLFunction | ||
{ | ||
private readonly IContactsService _contacts; | ||
|
||
public GetContactIdsFunc(IContactsService contacts) | ||
{ | ||
_contacts = contacts; | ||
} | ||
public async ValueTask<TLBytes?> Process(TLBytes q, TLExecutionContext ctx) | ||
{ | ||
var contacts = await _contacts.GetContactIds(ctx.AuthKeyId, q); | ||
return RpcResultGenerator.Generate(ToVectorOfLong(contacts), ctx.MessageId); | ||
} | ||
|
||
private static TLBytes ToVectorOfLong(ICollection<long> collection) | ||
{ | ||
VectorOfLong v = new (); | ||
foreach (var s in collection) | ||
{ | ||
v.Append(s); | ||
} | ||
|
||
var vBytes = v.ToReadOnlySpan().ToArray(); | ||
return new TLBytes(vBytes, 0, vBytes.Length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters