Skip to content

Commit

Permalink
refactor(Contact): improve the visual design
Browse files Browse the repository at this point in the history
Added the output of the necessary information at the stages. The text is included in the localization files. Fixed bugs/minor inaccuracies
  • Loading branch information
ZenonEl committed Jan 8, 2025
1 parent 608428c commit d79b4de
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
10 changes: 9 additions & 1 deletion TelegramBot/Menu/Contacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public static async Task ViewContacts(ITelegramBotClient botClient, Update updat
public static async Task EditContactGroup(ITelegramBotClient botClient, Update update, long chatId)
{
TelegramBot.userStates[chatId] = new ProcessContactGroupState();
await Utils.Utils.SendMessage(botClient, update, KeyboardUtils.GetReturnButtonMarkup(), cancellationToken, "(Инфо по группе) укажите айди группы для работы:");

int userId = DBforGetters.GetUserIDbyTelegramID(chatId);
List<string> groupInfos = UsersGroup.GetUserGroupByUserId(userId);

string messageText = groupInfos.Any()
? $"{Config.GetResourceString("YourGroupsText")}\n{string.Join("\n", groupInfos)}"
: Config.GetResourceString("AltYourGroupsText");

await Utils.Utils.SendMessage(botClient, update, KeyboardUtils.GetReturnButtonMarkup(), cancellationToken, string.Format(Config.GetResourceString("ContactGroupInfoText"), messageText));
}
}
33 changes: 24 additions & 9 deletions TelegramBot/States/ContactGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,25 @@ await Utils.Utils.SendMessage(
groupId,
DBforGroups.GetGroupDescriptionById(groupId), DBforGroups.GetGroupMemberCount(groupId),
DBforGroups.GetIsDefaultGroup(groupId));

List<int> allContactsIds = DBforGroups.GetAllUsersIdsInGroup(groupId);
List<string> allContactsNames = [];

foreach (int contactId in allContactsIds)
{
allContactsNames.Add(DBforGetters.GetUserNameByID(contactId) + $" (ID: {contactId})");
}

string allContactsText;
allContactsText = $"{Config.GetResourceString("AllContactsText")} {string.Join("\n", allContactsNames)}";

string messageText = $"{groupInfo}\n{allContactsText}\n{Config.GetResourceString("ChooseOptionText")}";
await Utils.Utils.SendMessage(
botClient,
update,
ContactGroup.GetContactGroupEditActionsKeyboardMarkup(groupId),
cancellationToken,
groupInfo + "\n (вывод всех участников)\n" + Config.GetResourceString("ChooseOptionText"));
messageText);
return false;
}
return null;
Expand All @@ -154,20 +167,19 @@ await Utils.Utils.SendMessage(
await Utils.Utils.SendMessage(
botClient,
update,
KeyboardUtils.GetConfirmForActionKeyboardMarkup(),
KeyboardUtils.GetReturnButton(),
cancellationToken,
Config.GetResourceString("InputContactIDsText"));
return true;
}
else if (callbackAction.StartsWith("user_remove_contact_from_group:"))
{
groupId = int.Parse(callbackAction.Split(':')[1]);
await Utils.Utils.SendMessage(
botClient,
update,
KeyboardUtils.GetConfirmForActionKeyboardMarkup(),
cancellationToken,
Config.GetResourceString("InputContactIDsText"));
await botClient.SendMessage(
Utils.Utils.GetIDfromUpdate(update),
Config.GetResourceString("InputContactIDsText"),
replyMarkup: KeyboardUtils.GetReturnButtonMarkup(),
cancellationToken: cancellationToken);
return true;
}
return null;
Expand All @@ -186,18 +198,21 @@ await Utils.Utils.SendMessage(
groupId = int.Parse(callbackAction.Split(':')[1]);
contactIDs = update.Message!.Text!.Split(" ").Select(x => int.Parse(x)).ToList();
List<int> allowedIds = [];

foreach (int contactId in contactIDs)
{
bool status = DBforContactGroups.CheckUserAndContactConnect(userId, contactId);
if (status) allowedIds.Add(contactId);
}

if (allowedIds.Count == 0) return null;
await Utils.Utils.SendMessage(
botClient,
update,
KeyboardUtils.GetConfirmForActionKeyboardMarkup("accept_add_contact_to_group"),
cancellationToken,
Config.GetResourceString("ConfirmAddContactsToGroupText"));
contactIDs = allowedIds;
return true;
}
else if (callbackAction.StartsWith("user_remove_contact_from_group:"))
Expand All @@ -214,7 +229,7 @@ await Utils.Utils.SendMessage(
}
return null;
}
catch (Exception ex)
catch (Exception)
{
return null;
}
Expand Down

0 comments on commit d79b4de

Please sign in to comment.