Skip to content

Commit

Permalink
Fix issue with notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
wh0o7 committed Sep 8, 2023
1 parent 72ca675 commit 0169bb5
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions TeachersTimetable/Services/ParseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,20 @@ public async Task ParseDay()

if (teacherInfoFromTimetable is null || teacherInfoFromTimetable.Equals(teacherInfo)) continue;

_ = this._botService.SendAdminMessageAsync(new SendMessageArgs(0,
$"Расписание у преподавателя {teacherInfo.Name}"));

notificationUsersList.AddRange((await this._mongoService.Database.GetCollection<User>("Users")
.FindAsync(u =>
u.Teacher != null && Regex.Replace(u.Teacher, "[^0-9]", "") == teacherInfo.Name &&
u.Notifications))
.ToList());
try
{
_ = this._botService.SendAdminMessageAsync(
new SendMessageArgs(0, $"Расписание у группы {teacherInfo.Name}"));

var userList = (await this._mongoService.Database.GetCollection<User>("Users")
.FindAsync(u => u.Teacher != null && u.Notifications && u.Teacher == teacherInfo.Name)).ToList();

notificationUsersList.AddRange(userList);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}

Timetable.Clear();
Expand All @@ -298,13 +304,20 @@ public async Task ParseDay()
if (notificationUsersList.Count == 0) return;
_ = Task.Run(() =>
{
foreach (var user in notificationUsersList)
try
{
_ = this._distributionService.SendDayTimetable(user);
}
foreach (var user in notificationUsersList)
{
_ = this._distributionService.SendDayTimetable(user);
}
this._botService.SendAdminMessageAsync(new SendMessageArgs(0,
$"{notificationUsersList.Count} notifications sent"));
this._botService.SendAdminMessageAsync(new SendMessageArgs(0,
$"{notificationUsersList.Count} notifications sent"));
}
catch (Exception e)
{
Console.WriteLine(e);
}
});
}

Expand Down

0 comments on commit 0169bb5

Please sign in to comment.