private void UnreadFutureReadMail() { var localMail = Repository.Instance.Fetch <Mail>(x => x.Status == MailStatus.Read && x.ToFarmerId == _farmerService.CurrentFarmer.Id ); if (!localMail.Any()) { return; } var currentGameDateTime = ModHelper.GetGameDayTime(); var futureMail = localMail.Where(x => x.ReadInGameDate == null || x.ReadInGameDate > currentGameDateTime.GetNightBefore()).ToList(); foreach (var mail in futureMail) { mail.Status = MailStatus.Delivered; mail.ReadInGameDate = null; } if (!futureMail.Any()) { return; } Repository.Instance.Upsert(futureMail.AsEnumerable()); }
private void MailComposed(object sender, MailComposedEventArgs e) { var toFarmerId = e.ToFarmerId; var fromFarmer = _farmerService.CurrentFarmer; var item = e.Item; if (item == null) { return; } var messageText = string.Format(_messageFormat, fromFarmer.Name, item.ParentSheetIndex, item.Stack); // Consider: Moving this to own service var mail = new Mail() { Id = Guid.NewGuid(), ToFarmerId = toFarmerId, FromFarmerId = fromFarmer.Id, Text = messageText, CreatedDate = DateTime.Now.ToUniversalTime(), Status = MailStatus.Composed, CreatedInGameDate = ModHelper.GetGameDayTime() }; Repository.Instance.Insert(mail); ModHelper.ShowInfoMessage(_letterPostedNotification); }
private void MailRead(object sender, MailReadEventArgs e) { var currentFarmerId = _farmerService.CurrentFarmer.Id; var mail = Repository.Instance.FirstOrDefault <Mail>(x => x.Id == e.Id); if (mail != null) { mail.Status = MailStatus.Read; mail.ReadInGameDate = ModHelper.GetGameDayTime(); Repository.Instance.Update(mail); } }
private void DeleteFutureComposedMail() { var localMail = Repository.Instance.Fetch <Mail>(x => x.Status == MailStatus.Composed && x.ToFarmerId == _farmerService.CurrentFarmer.Id ); if (!localMail.Any()) { return; } var currentGameDateTime = ModHelper.GetGameDayTime(); var futureMail = localMail.Where(x => x.CreatedInGameDate > currentGameDateTime.GetNightBefore()).ToList(); foreach (var mail in futureMail) { Repository.Instance.Delete <Mail>(x => x.Id == mail.Id); } }
private async Task DeleteReadMail() { var localMail = Repository.Instance.Fetch <Mail>(x => x.Status == MailStatus.Read && x.ToFarmerId == _farmerService.CurrentFarmer.Id ); if (!localMail.Any()) { return; } var logPrefix = "[CleanRead] "; _mod.Monitor.Log($"{logPrefix}Clean up read cloud mail...", LogLevel.Debug); var currentGameDateTime = ModHelper.GetGameDayTime(); var readMail = localMail.Where(x => x.ReadInGameDate != null && x.ReadInGameDate <= currentGameDateTime.GetNightBefore()).ToList(); if (readMail.Any()) { _mod.Monitor.Log($"{logPrefix}.clearing {readMail.Count} read mail...", LogLevel.Debug); foreach (var mail in readMail) { var deleted = await DeleteRemoteMail(mail, logPrefix); if (deleted) { try { var i = Repository.Instance.Delete <Mail>(x => x.Id == mail.Id); } catch { } } } } _mod.Monitor.Log($"{logPrefix}.done", LogLevel.Debug); }