private async void OpenNotificationScreen(Usuario currentUser) { StringBuilder groupName = new StringBuilder(); groupName.Append(currentUser.IdComunidadeUsu); //groupName.Append("-"); //groupName.Append(currentUser.UserPlaceBlock); //bool openedScreen = false; //Verificando se há mensagens para serem respondidas IList <Notificacao> msgList = await NotifMsgService.GetInstance().GetNotifMsgList(Constants.GrupoNotifQuery, groupName.ToString()); if (msgList.Count > 0) { foreach (Notificacao msg in msgList) { if (msg.Completed != true) { if (currentUser.Id != msg.UserId) { if (string.IsNullOrEmpty(currentUser.RespostaNotifUsu)) { await Navigation.PushAsync(new Views.Notification.EmergencyNotificationReceiver(groupName.ToString()) { BindingContext = msg as Notificacao }); //openedScreen = true; } } } } } }
public async Task SendMessage(Usuario user, string msgType, string msg, string groupName) { try { Grupo group = await GrupoService.GetInstance().GetGroup(groupName); if (!group.Usuarios.Contains(user.Id)) { StringBuilder sbMsg = new(); sbMsg.Append("O usuário "); sbMsg.Append(user.NomeUsuario); sbMsg.Append(" não pertence ao grupo "); sbMsg.Append(group.Nome); await Clients.Caller.SendAsync("ReceiveMessage", null, group, sbMsg.ToString()); } Notificacao message = new() { Id = Guid.NewGuid().ToString(), GroupName = groupName, UserId = user.Id, UserJason = JsonConvert.SerializeObject(user), User = user, MsgType = msgType, Text = msg, Completed = false, CreatedDate = DateTime.Now }; var success = NotifMsgService.GetInstance().AddNotifMsg(message); await Clients.Group(groupName).SendAsync("ReceiveMessage", message, group, user.Id); await Clients.Caller.SendAsync("ReceiveMessage", message, group, user.Id); } catch (Exception e) { StringBuilder sbError = new(); sbError.Append("Erro: "); sbError.Append(e.ToString()); await Clients.Caller.SendAsync("ReceiveMessage", null, null, sbError.ToString()); } }
public async Task FinalizeNotification(string userQueryKey, Usuario currentUser) { try { var msgList = await NotifMsgService.GetInstance().GetNotifMsgList(Constants.GroupNameQuery, currentUser.IdComunidadeUsu); if (msgList.Any()) { foreach (Notificacao msg in msgList) { if (msg.Completed != true) { IList <Usuario> listUser = null; listUser = await UsersService.GetInstance().GetUsersList(Constants.IdComunidadeQuery, currentUser.IdComunidadeUsu); var listUserDB = listUser; if (listUserDB.Any()) { foreach (Usuario userDB in listUserDB) { userDB.RespostaNotifUsu = null; await UsersService.GetInstance().UpdateUser(userDB); } } else { StringBuilder sbError = new(); sbError.Append("List<UserRegistrationItem> Not Found!"); sbError.Append(Environment.NewLine); sbError.Append("queryKey: "); sbError.Append(userQueryKey); sbError.Append(Environment.NewLine); sbError.Append("groupName: "); sbError.Append(currentUser.IdComunidadeUsu); await Clients.Caller.SendAsync("ReceiveFinalization", sbError.ToString()); } msg.Completed = true; await NotifMsgService.GetInstance().UpdateNotifMsg(msg); await Clients.Caller.SendAsync("ReceiveFinalization", null); } } } else { StringBuilder sbError = new(); sbError.Append("NotificationsMessagesItem Not Found: "); sbError.Append(currentUser.IdComunidadeUsu); await Clients.Caller.SendAsync("ReceiveFinalization", sbError.ToString()); } } catch (Exception e) { StringBuilder sbError = new(); sbError.Append("Erro: "); sbError.Append(e.ToString()); await Clients.Caller.SendAsync("ReceiveFinalization", sbError.ToString()); } }