Skip to content

Commit

Permalink
Refactoring messanges logic in Reviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
dyatlov-a committed Jan 14, 2024
1 parent 195b440 commit a441611
Show file tree
Hide file tree
Showing 46 changed files with 236 additions and 388 deletions.
7 changes: 0 additions & 7 deletions Inc.TeamAssistant.sln
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Inc.TeamAssistant.CheckIn.M
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{2819C5EE-D36B-4BE5-95D3-80BF8869051D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Inc.TeamAssistant.Languages", "src\Inc.TeamAssistant.Languages\Inc.TeamAssistant.Languages.csproj", "{BF988B2F-9090-42D7-8F72-6A0991968ACC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Inc.TeamAssistant.Primitives", "src\Inc.TeamAssistant.Primitives\Inc.TeamAssistant.Primitives.csproj", "{CA295F9A-5F4D-4616-992A-340A8C0A0D9A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Inc.TeamAssistant.Holidays", "src\Inc.TeamAssistant.Holidays\Inc.TeamAssistant.Holidays.csproj", "{2A6D584C-D381-4405-9DDD-51D5AEF6AC2E}"
Expand Down Expand Up @@ -142,10 +140,6 @@ Global
{9A44D500-411B-46B9-90CB-FC220F9BB5F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A44D500-411B-46B9-90CB-FC220F9BB5F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A44D500-411B-46B9-90CB-FC220F9BB5F7}.Release|Any CPU.Build.0 = Release|Any CPU
{BF988B2F-9090-42D7-8F72-6A0991968ACC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BF988B2F-9090-42D7-8F72-6A0991968ACC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF988B2F-9090-42D7-8F72-6A0991968ACC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF988B2F-9090-42D7-8F72-6A0991968ACC}.Release|Any CPU.Build.0 = Release|Any CPU
{CA295F9A-5F4D-4616-992A-340A8C0A0D9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA295F9A-5F4D-4616-992A-340A8C0A0D9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA295F9A-5F4D-4616-992A-340A8C0A0D9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -209,7 +203,6 @@ Global
{642949CD-0C5B-4596-9165-A7338DE1D88F} = {8285EFA4-C244-455D-94D1-86994A904BFF}
{9A44D500-411B-46B9-90CB-FC220F9BB5F7} = {15DCF7E1-1D36-4C21-A623-35A1D037A4DA}
{2819C5EE-D36B-4BE5-95D3-80BF8869051D} = {73CA6C4E-FE60-4BEF-9902-FFA9241616F9}
{BF988B2F-9090-42D7-8F72-6A0991968ACC} = {2819C5EE-D36B-4BE5-95D3-80BF8869051D}
{CA295F9A-5F4D-4616-992A-340A8C0A0D9A} = {2819C5EE-D36B-4BE5-95D3-80BF8869051D}
{2A6D584C-D381-4405-9DDD-51D5AEF6AC2E} = {2819C5EE-D36B-4BE5-95D3-80BF8869051D}
{39417B68-C33C-411E-8478-DD9C081A640A} = {1943C11E-7A4A-4300-BDC1-DA333BD3EBED}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task<NotificationMessage> Build(SummaryByStory summary)

var notification = summary.StoryExternalId.HasValue
? NotificationMessage.Edit(
new[] { new ChatMessage(summary.ChatId, summary.StoryExternalId.Value, Shared: false) },
new ChatMessage(summary.ChatId, summary.StoryExternalId.Value),
builder.ToString())
: NotificationMessage
.Create(summary.ChatId, builder.ToString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Inc.TeamAssistant.Languages\Inc.TeamAssistant.Languages.csproj" />
<ProjectReference Include="..\Inc.TeamAssistant.Primitives\Inc.TeamAssistant.Primitives.csproj" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion src/Inc.TeamAssistant.Appraiser.Domain/Story.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Inc.TeamAssistant.Appraiser.Domain.Exceptions;
using Inc.TeamAssistant.Languages;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Appraiser.Domain;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Inc.TeamAssistant.CheckIn.Application.Contracts;
using Inc.TeamAssistant.CheckIn.Domain;
using Inc.TeamAssistant.CheckIn.Model.Commands.AddLocationToMap;
using Inc.TeamAssistant.Languages;
using Inc.TeamAssistant.Primitives;
using MediatR;

Expand Down Expand Up @@ -54,10 +53,7 @@ public async Task<CommandResult> Handle(AddLocationToMapCommand command, Cancell

var notifications = new List<NotificationMessage>
{
NotificationMessage.Delete(new[]
{
new ChatMessage(command.MessageContext.ChatId, command.MessageContext.MessageId, Shared: false)
})
NotificationMessage.Delete(new ChatMessage(command.MessageContext.ChatId, command.MessageContext.MessageId))
};

if (existsMap is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
<ItemGroup>
<ProjectReference Include="..\Inc.TeamAssistant.CheckIn.Domain\Inc.TeamAssistant.CheckIn.Domain.csproj" />
<ProjectReference Include="..\Inc.TeamAssistant.CheckIn.Model\Inc.TeamAssistant.CheckIn.Model.csproj" />
<ProjectReference Include="..\Inc.TeamAssistant.Languages\Inc.TeamAssistant.Languages.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Inc.TeamAssistant.Connector.Application.CommandHandlers.Begin.Contracts;
using Inc.TeamAssistant.Connector.Application.Services;
using Inc.TeamAssistant.Connector.Domain;
using Inc.TeamAssistant.Connector.Model.Commands.Begin;
using Inc.TeamAssistant.Connector.Model.Commands.MarkMessageForDelete;
using Inc.TeamAssistant.Primitives;
using MediatR;
Expand All @@ -24,11 +23,8 @@ public Task<CommandResult> Handle(BeginCommand command, CancellationToken token)
var dialogState = _dialogContinuation.Begin(
command.MessageContext.PersonId,
command.Command,
(CommandStage)command.NextStage,
new ChatMessage(
command.MessageContext.ChatId,
command.MessageContext.MessageId,
command.MessageContext.Shared));
command.NextStage,
new ChatMessage(command.MessageContext.ChatId, command.MessageContext.MessageId));

if (command.SelectedTeamId.HasValue)
dialogState.SetTeamId(command.SelectedTeamId.Value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Inc.TeamAssistant.Connector.Domain;
using Inc.TeamAssistant.Primitives;
using MediatR;

namespace Inc.TeamAssistant.Connector.Model.Commands.Begin;
namespace Inc.TeamAssistant.Connector.Application.CommandHandlers.Begin.Contracts;

public sealed record BeginCommand(
MessageContext MessageContext,
object NextStage,
CommandStage NextStage,
Guid? SelectedTeamId,
string Command,
NotificationMessage Notification)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public Task<CommandResult> Handle(MarkMessageForDeleteCommand command, Cancellat
throw new ArgumentNullException(nameof(command));

var dialogState = _dialogContinuation.Find(command.MessageContext.PersonId);
dialogState?.Attach(new ChatMessage(
command.MessageContext.ChatId,
command.MessageId,
command.MessageContext.Shared));
dialogState?.Attach(new ChatMessage(command.MessageContext.ChatId, command.MessageId));

return Task.FromResult(CommandResult.Empty);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Inc.TeamAssistant.Languages;
using Inc.TeamAssistant.Primitives;
using Telegram.Bot.Types;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
<ItemGroup>
<ProjectReference Include="..\Inc.TeamAssistant.Connector.Domain\Inc.TeamAssistant.Connector.Domain.csproj" />
<ProjectReference Include="..\Inc.TeamAssistant.Connector.Model\Inc.TeamAssistant.Connector.Model.csproj" />
<ProjectReference Include="..\Inc.TeamAssistant.Languages\Inc.TeamAssistant.Languages.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Inc.TeamAssistant.Connector.Application.CommandHandlers.Begin.Contracts;
using Inc.TeamAssistant.Connector.Domain;
using Inc.TeamAssistant.Connector.Model.Commands.Begin;
using Inc.TeamAssistant.Connector.Model.Commands.LeaveFromTeam;
using Inc.TeamAssistant.Primitives;
using MediatR;
Expand Down Expand Up @@ -75,11 +75,12 @@ public CommandFactory(

await _dialogContinuation.End(
messageContext.PersonId,
new ChatMessage(messageContext.ChatId, messageContext.MessageId, messageContext.Shared),
new ChatMessage(messageContext.ChatId, messageContext.MessageId),
async (ms, t) =>
{
foreach (var m in ms)
await client.DeleteMessageAsync(m.ChatId, m.MessageId, t);
if (messageContext.Shared)
foreach (var m in ms)
await client.DeleteMessageAsync(m.ChatId, m.MessageId, t);
},
token);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public Task OnError(ITelegramBotClient client, Exception exception, string botNa
update.Message.From.FirstName,
update.Message.From.Username,
person.LanguageId,
TargetUser: null,
(update.Message.Location.Longitude, update.Message.Location.Latitude));
}

Expand All @@ -127,7 +126,6 @@ public Task OnError(ITelegramBotClient client, Exception exception, string botNa
update.Message.From.FirstName,
update.Message.From.Username,
person.LanguageId,
update.Message.GetTargetUser(),
Location: null);
}

Expand All @@ -152,7 +150,6 @@ public Task OnError(ITelegramBotClient client, Exception exception, string botNa
update.CallbackQuery.From.FirstName,
update.CallbackQuery.From.Username,
person.LanguageId,
TargetUser: null,
Location: null);
}

Expand Down Expand Up @@ -209,41 +206,41 @@ private async Task ProcessNotification(
if (messageContext is null)
throw new ArgumentNullException(nameof(messageContext));

if (notificationMessage.TargetChatIds?.Any() == true)
foreach (var targetChatId in notificationMessage.TargetChatIds)
{
var message = await client.SendTextMessageAsync(
targetChatId,
notificationMessage.Text,
replyMarkup: ToReplyMarkup(notificationMessage),
cancellationToken: token);
if (notificationMessage.TargetChatId.HasValue)
{
var message = await client.SendTextMessageAsync(
notificationMessage.TargetChatId.Value,
notificationMessage.Text,
replyMarkup: ToReplyMarkup(notificationMessage),
cancellationToken: token);

if (notificationMessage.Pinned)
await client.PinChatMessageAsync(
new ChatId(targetChatId),
message.MessageId,
cancellationToken: token);
if (notificationMessage.Pinned)
await client.PinChatMessageAsync(
new ChatId(notificationMessage.TargetChatId.Value),
message.MessageId,
cancellationToken: token);

if (notificationMessage.Handler is not null)
{
var command = notificationMessage.Handler(messageContext, message.MessageId);
if (notificationMessage.Handler is not null)
{
var command = notificationMessage.Handler(messageContext, message.MessageId);

await Execute(client, messageContext, command, token);
}
await Execute(client, messageContext, command, token);
}
}

if (notificationMessage.TargetMessages?.Any() == true)
foreach (var message in notificationMessage.TargetMessages)
await client.EditMessageTextAsync(
new(message.ChatId),
message.MessageId,
notificationMessage.Text,
replyMarkup: ToReplyMarkup(notificationMessage),
cancellationToken: token);
if (notificationMessage.TargetMessage is not null)
await client.EditMessageTextAsync(
new(notificationMessage.TargetMessage.ChatId),
notificationMessage.TargetMessage.MessageId,
notificationMessage.Text,
replyMarkup: ToReplyMarkup(notificationMessage),
cancellationToken: token);

if (notificationMessage.DeleteMessages?.Any() == true)
foreach (var message in notificationMessage.DeleteMessages)
await client.DeleteMessageAsync(new(message.ChatId), message.MessageId, token);
if (notificationMessage.DeleteMessage is not null)
await client.DeleteMessageAsync
(new(notificationMessage.DeleteMessage.ChatId),
notificationMessage.DeleteMessage.MessageId,
token);
}

private static InlineKeyboardMarkup? ToReplyMarkup(NotificationMessage message)
Expand Down
3 changes: 1 addition & 2 deletions src/Inc.TeamAssistant.Connector.Domain/DialogState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public DialogState Attach(ChatMessage chatMessage)
if (chatMessage is null)
throw new ArgumentNullException(nameof(chatMessage));

if (chatMessage.Shared)
_chatMessages.Add(chatMessage);
_chatMessages.Add(chatMessage);

return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Reflection;
using Inc.TeamAssistant.Appraiser.Model;
using Inc.TeamAssistant.Languages;
using Inc.TeamAssistant.Primitives;
using Microsoft.AspNetCore.Mvc.RazorPages;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Inc.TeamAssistant.Languages;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Gateway.Pages.Models;
Expand Down
2 changes: 1 addition & 1 deletion src/Inc.TeamAssistant.Gateway/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
using Inc.TeamAssistant.Connector.Application;
using Inc.TeamAssistant.Connector.DataAccess;
using Inc.TeamAssistant.Holidays;
using Inc.TeamAssistant.Languages;
using Inc.TeamAssistant.Gateway;
using Inc.TeamAssistant.Gateway.Hubs;
using Inc.TeamAssistant.Gateway.Services;
using Inc.TeamAssistant.Gateway.Services.CheckIn;
using Inc.TeamAssistant.Primitives;
using Inc.TeamAssistant.Reviewer.Application;
using Inc.TeamAssistant.Reviewer.Application.Contracts;
using Inc.TeamAssistant.Reviewer.DataAccess;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Inc.TeamAssistant.Appraiser.Model;
using Inc.TeamAssistant.Languages;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Gateway.Services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.Json;
using Inc.TeamAssistant.Appraiser.Model;
using Inc.TeamAssistant.Appraiser.Model.Common;
using Inc.TeamAssistant.Languages;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Gateway.Services.MessageProviders;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Inc.TeamAssistant.Languages;
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Gateway.Services;
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/Inc.TeamAssistant.Primitives/ChatMessage.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Inc.TeamAssistant.Primitives;

public sealed record ChatMessage(long ChatId, int MessageId, bool Shared);
public sealed record ChatMessage(long ChatId, int MessageId);
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Languages;
namespace Inc.TeamAssistant.Primitives;

public interface ITranslateProvider
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Inc.TeamAssistant.Primitives;

namespace Inc.TeamAssistant.Languages;
namespace Inc.TeamAssistant.Primitives;

public static class LanguageSettings
{
Expand Down
1 change: 0 additions & 1 deletion src/Inc.TeamAssistant.Primitives/MessageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public sealed record MessageContext(
string FirstName,
string? Username,
LanguageId LanguageId,
UserIdentity? TargetUser,
(double Longitude, double Latitude)? Location)
{
public bool Shared => ChatId != PersonId;
Expand Down
Loading

0 comments on commit a441611

Please sign in to comment.