public void 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 Service.ViewModels.SignalR.MixMessengerUsers.ConnectViewModel(request.Data); user.CreatedDate = DateTime.UtcNow; // Save user and current device to db var result = user.Join(); // save success if (result.IsSucceed) { // Send success msg to caller var getAvailableUsers = Service.ViewModels.SignalR.MixMessengerUsers.DefaultViewModel.Repository.GetModelListBy(u => u.Status == MixContentStatus.Published.ToString()); 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 ?? SignalRConstants.DefaultDevice; // Add User to group connections await Groups.AddToGroupAsync(Context.ConnectionId, request.Room); // Announce Other Group member there is new user await SendToGroup(connection, MessageReponseKey.NewMember, request.Room); // Get Online users var getAvailableUsers = Service.ViewModels.SignalR.MixMessengerUsers.DefaultViewModel.Repository.GetModelListBy( u => u.Status == OnlineStatus.Connected.ToString()); if (getAvailableUsers.IsSucceed) { // Announce User Connected to Group and list available users await SendToCaller(getAvailableUsers.Data, MessageReponseKey.ConnectSuccess); } var getPreviousMsgs = ViewModels.MixDatabaseDatas.ReadViewModel.Repository.GetModelListBy( m => m.MixDatabaseName == request.Room && m.Specificulture == request.Specificulture , "CreatedDateTime", 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, MessageReponseKey.PreviousMessages); } var groupMembers = GetGroupMembersAsync(request); var result = new RepositoryResponse <bool>(); // Mapping connecting user to db models var user = new Service.ViewModels.SignalR.MixMessengerUsers.ConnectViewModel(connection) { CreatedDate = DateTime.UtcNow }; result = user.Join(); }