public async Task Join(HubRequest <MessengerConnection> request) { // Set connection Id request.Data.ConnectionId = Context.ConnectionId; request.Data.DeviceId = request.Data.DeviceId ?? defaultDevice; // Mapping connecting user to db models var user = new ViewModels.MixMessengerUsers.ConnectViewModel(request.Data); user.CreatedDate = DateTime.UtcNow; // Save user and current device to db var result = await user.Join(); // save success if (result.IsSucceed) { // Send success msg to caller var getAvailableUsers = ViewModels.MixMessengerUsers.DefaultViewModel.Repository.GetModelListBy(u => u.Status == (int)MixChatEnums.OnlineStatus.Connected); SendToCaller(getAvailableUsers.Data, MessageReponseKey.ConnectSuccess); // Announce every one there's new member SendToAll(user, MessageReponseKey.NewMember, false); } else { // Send failed msg to caller SendToConnection(result, MessageReponseKey.ConnectFailed, Context.ConnectionId, false); } }
private async Task JoinGroup(HubRequest <JObject> request) { var connection = request.Data.ToObject <MessengerConnection>(); // Set connection Id connection.ConnectionId = Context.ConnectionId; connection.DeviceId = connection.DeviceId ?? Constants.DefaultDevice; // Add User to group connections await Groups.AddToGroupAsync(Context.ConnectionId, request.Room); // Announce Other Group member there is new user await SendToGroup(connection, Constants.Enums.MessageReponseKey.NewMember, request.Room); // Get Online users var getAvailableUsers = ViewModels.MixMessengerUsers.DefaultViewModel.Repository.GetModelListBy( u => u.Status == Constants.Enums.OnlineStatus.Connected.ToString()); if (getAvailableUsers.IsSucceed) { // Announce User Connected to Group and list available users await SendToCaller(getAvailableUsers.Data, Constants.Enums.MessageReponseKey.ConnectSuccess); } var getPreviousMsgs = Mix.Cms.Service.SignalR.ViewModels.MixAttributeSetDatas.ReadViewModel.Repository.GetModelListBy( m => m.AttributeSetName == request.Room && m.Specificulture == request.Specificulture , "CreatedDateTime", Heart.Enums.MixHeartEnums.DisplayDirection.Desc, 10, 0); // Get previous messages if (getPreviousMsgs.IsSucceed) { getPreviousMsgs.Data.Items = getPreviousMsgs.Data.Items.OrderBy(m => m.CreatedDateTime).ToList(); await SendToCaller(getPreviousMsgs.Data, Constants.Enums.MessageReponseKey.PreviousMessages); } var groupMembers = GetGroupMembersAsync(request); var result = new RepositoryResponse <bool>(); // Mapping connecting user to db models var user = new ViewModels.MixMessengerUsers.ConnectViewModel(connection) { CreatedDate = DateTime.UtcNow }; result = user.Join(); }
private Task JoinGroup(HubRequest <JObject> request) { var groupMembers = GetGroupMembers(request); var connection = request.Data.ToObject <MessengerConnection>(); // Set connection Id connection.ConnectionId = Context.ConnectionId; connection.DeviceId = connection.DeviceId ?? Constants.DefaultDevice; // Mapping connecting user to db models var user = new ViewModels.MixMessengerUsers.ConnectViewModel(connection) { CreatedDate = DateTime.UtcNow }; // Save user and current device to db return(user.Join().ContinueWith((task) => { // save success if (task.Result.IsSucceed) { // Get Online users var getAvailableUsers = ViewModels.MixMessengerUsers.DefaultViewModel.Repository.GetModelListBy(u => u.Status == (int)Constants.Enums.OnlineStatus.Connected); var hubMsg = new RepositoryResponse <MessengerConnection>() { Status = 200, Data = connection }; return Task.WhenAll(new Task[] { Groups.AddToGroupAsync(Context.ConnectionId, request.Room), SendToCaller(getAvailableUsers.Data, Constants.Enums.MessageReponseKey.ConnectSuccess), SendToGroup(connection, Constants.Enums.MessageReponseKey.NewMember, request.Room), // Announce every one there's new member SendToAll(user, Constants.Enums.MessageReponseKey.NewMember, false) }); } else { // Send failed msg to caller return SendToConnection(task.Result, Constants.Enums.MessageReponseKey.ConnectFailed, Context.ConnectionId, false); } })); }