Skip to content

Commit

Permalink
messages.setTyping
Browse files Browse the repository at this point in the history
  • Loading branch information
aykutalparslan committed May 19, 2023
1 parent 4524b26 commit 3f1a2f2
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Ferrite.Services;
using Ferrite.TL;
using Ferrite.TL.slim;

namespace Ferrite.Core.Execution.Functions.BaseLayer.Messages;

public class SetTypingFunc : ITLFunction
{
private readonly IMessagesService _messages;

public SetTypingFunc(IMessagesService messages)
{
_messages = messages;
}
public async ValueTask<TLBytes?> Process(TLBytes q, TLExecutionContext ctx)
{
var result = await _messages.SetTyping(ctx.AuthKeyId, q);
return RpcResultGenerator.Generate(result, ctx.MessageId);
}
}
4 changes: 2 additions & 2 deletions Ferrite.Services/IMessagesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

using Ferrite.Data;
using Ferrite.Data.Messages;
using Ferrite.TL.slim;

namespace Ferrite.Services;

Expand Down Expand Up @@ -46,6 +47,5 @@ Task<ServiceResult<MessagesDTO>> Search(long authKeyId, InputPeerDTO peer, strin
int? topMessageId, MessagesFilterType filter, int minDate, int maxDate, int offsetId, int addOffset,
int limit, long maxId, long minId, long hash);

Task<ServiceResult<bool>> SetTyping(long authKeyId, InputPeerDTO peer,
SendMessageActionDTO action, int? topMessageId = null);
ValueTask<TLBool> SetTyping(long authKeyId, TLBytes q);
}
3 changes: 2 additions & 1 deletion Ferrite.Services/IUpdatesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System;
using Ferrite.Data;
using Ferrite.Data.Updates;
using Ferrite.TL.slim.layer150;

namespace Ferrite.Services;

Expand All @@ -26,7 +27,7 @@ public interface IUpdatesService
public Task<StateDTO> GetState(long authKeyId);
public Task<ServiceResult<DifferenceDTO>> GetDifference(long authKeyId, int pts, int date,
int qts, int? ptsTotalLimit = null);
public Task<bool> EnqueueUpdate(long userId, UpdateBase update);
public Task<bool> EnqueueUpdate(long userId, TLUpdate update);
public Task<int> IncrementUpdatesSequence(long authKeyId);
}

25 changes: 16 additions & 9 deletions Ferrite.Services/MessagesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
using Ferrite.Data.Messages;
using Ferrite.Data.Repositories;
using Ferrite.Data.Search;
using Ferrite.TL.slim;
using Ferrite.TL.slim.layer150;
using Ferrite.TL.slim.layer150.messages;
using Ferrite.Utils;
using PeerSettingsDTO = Ferrite.Data.Messages.PeerSettingsDTO;

Expand Down Expand Up @@ -410,7 +413,7 @@ private async Task DeletePeerMessagesInternal(int maxId, int? minDate, int? maxD
private async Task<int> DeleteMessagesInternal(int maxId, int? minDate, int? maxDate, IUpdatesContext userCtx,
IReadOnlyCollection<MessageDTO> messages, AuthInfoDTO auth)
{
List<int> deletedIds = new();
/*List<int> deletedIds = new();
int pts = await userCtx.Pts();
if (messages != null)
{
Expand All @@ -430,7 +433,8 @@ private async Task<int> DeleteMessagesInternal(int maxId, int? minDate, int? max
_updates.EnqueueUpdate(auth.UserId, deleteMessages);
}
return pts;
return pts;*/
throw new NotImplementedException();
}

public async Task<ServiceResult<AffectedMessagesDTO>> DeleteMessages(long authKeyId, ICollection<int> id, bool revoke = false)
Expand Down Expand Up @@ -662,16 +666,19 @@ public async Task<ServiceResult<MessagesDTO>> Search(long authKeyId, InputPeerDT
throw new NotImplementedException();
}

public async Task<ServiceResult<bool>> SetTyping(long authKeyId, InputPeerDTO peer, SendMessageActionDTO action, int? topMessageId = null)
public async ValueTask<TLBool> SetTyping(long authKeyId, TLBytes q)
{
/*var peerDTO = PeerFromInputPeer(peer);
using var peer = ((SetTyping)q).Get_Peer();
var auth = await _unitOfWork.AuthorizationRepository.GetAuthorizationAsync(authKeyId);
if (peerDTO.PeerType == PeerType.User)
if (peer.Type == TLInputPeer.InputPeerType.InputPeerUser)
{
var update = new UpdateUserTypingDTO(auth.UserId, action);
_updates.EnqueueUpdate(peerDTO.PeerId, update);
return new ServiceResult<bool>(true, true, ErrorMessages.None);
}*/
using TLUpdate update = UpdateUserTyping.Builder()
.UserId(auth.Value.AsAuthInfo().UserId)
.Action(((SetTyping)q).Action).
Build();
_updates.EnqueueUpdate(peer.AsInputPeerUser().UserId, update);
return new BoolTrue();
}
throw new NotImplementedException();
}

Expand Down
3 changes: 2 additions & 1 deletion Ferrite.Services/UpdatesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Ferrite.Data;
using Ferrite.Data.Repositories;
using Ferrite.Data.Updates;
using Ferrite.TL.slim.layer150;
using Ferrite.Utils;
using MessagePack;

Expand Down Expand Up @@ -101,7 +102,7 @@ public async Task<ServiceResult<DifferenceDTO>> GetDifference(long authKeyId, in
throw new NotImplementedException();
}

public async Task<bool> EnqueueUpdate(long userId, UpdateBase update)
public async Task<bool> EnqueueUpdate(long userId, TLUpdate update)
{
/*var user = _unitOfWork.UserRepository.GetUser(userId);
var authorizations = await _unitOfWork.AuthorizationRepository.GetAuthorizationsAsync(user.Phone);
Expand Down
5 changes: 3 additions & 2 deletions Ferrite.TL/currentLayer/messages/SetTyping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public SendMessageAction Action

public async Task<ITLObject> ExecuteAsync(TLExecutionContext ctx)
{
var serviceResult = await _messages.SetTyping(ctx.CurrentAuthKeyId,
/*var serviceResult = await _messages.SetTyping(ctx.CurrentAuthKeyId,
_mapper.MapToDTO<InputPeer, InputPeerDTO>(_peer),
_mapper.MapToDTO<SendMessageAction, SendMessageActionDTO>(_action), _flags[0] ? _topMsgId : null);
var rpcResult = factory.Resolve<RpcResult>();
Expand All @@ -128,7 +128,8 @@ public async Task<ITLObject> ExecuteAsync(TLExecutionContext ctx)
rpcResult.Result = serviceResult.Result ? new BoolTrue() : new BoolFalse();
}
return rpcResult;
return rpcResult;*/
throw new NotImplementedException();
}

public void Parse(ref SequenceReader buff)
Expand Down
10 changes: 10 additions & 0 deletions Ferrite/ServerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using Ferrite.Core.Execution.Functions.BaseLayer.Auth;
using Ferrite.Core.Execution.Functions.BaseLayer.Contacts;
using Ferrite.Core.Execution.Functions.BaseLayer.Help;
using Ferrite.Core.Execution.Functions.BaseLayer.Messages;
using Ferrite.Core.Execution.Functions.BaseLayer.Users;
using Ferrite.Core.Framing;
using Ferrite.Core.RequestChain;
Expand Down Expand Up @@ -144,6 +145,15 @@ private static void RegisterApiLayers(ContainerBuilder builder)
RegisterAccountMethods(builder);
RegisterUsersMethods(builder);
RegisterContactsMethods(builder);
RegisterMessagesMethods(builder);
}

private static void RegisterMessagesMethods(ContainerBuilder builder)
{
builder.RegisterType<SetTypingFunc>()
.Keyed<ITLFunction>(
new FunctionKey(DefaultLayer, Constructors.layer150_SetTyping))
.SingleInstance();
}

private static void RegisterContactsMethods(ContainerBuilder builder)
Expand Down

0 comments on commit 3f1a2f2

Please sign in to comment.