Esempio n. 1
0
        public virtual void UpdateUserSubscription(UserSubscription subscription)
        {
            var subscriptions        = Subscriptions[subscription.SubscriberUserId];
            var subscriptionToUpdate = subscriptions.First(x => x.Id == subscription.Id);
            var index = subscriptions.IndexOf(subscriptionToUpdate);

            subscriptions[index] = subscription;

            subscription.UpdateType = UpdateType.Update;
            var args = new UserSubscriptionUpdatedEventArgs {
                Subscription = subscription
            };

            UserSubscriptionUpdated?.Invoke(this, args);
        }
Esempio n. 2
0
        public virtual void RemoveUserSubscription(string subscriptionId)
        {
            var sub = this.GetUserSubscription(subscriptionId);

            var subscriptions        = Subscriptions[sub.SubscriberUserId];
            var subscriptionToRemove = subscriptions.First(x => x.Id == subscriptionId);

            subscriptions.Remove(subscriptionToRemove);

            subscriptionToRemove.UpdateType = UpdateType.Remove;
            var args = new UserSubscriptionUpdatedEventArgs {
                Subscription = subscriptionToRemove
            };

            UserSubscriptionUpdated?.Invoke(this, args);
        }
Esempio n. 3
0
        public virtual void AddUserSubscription(UserSubscription subscription)
        {
            subscription.Id = (++IndexCounter).ToString();

            if (!Subscriptions.TryGetValue(subscription.SubscriberUserId, out var subscriptions))
            {
                Subscriptions.Add(subscription.SubscriberUserId, subscriptions = new List <UserSubscription>());
            }
            subscriptions.Add(subscription);

            subscription.UpdateType = UpdateType.Add;
            var args = new UserSubscriptionUpdatedEventArgs {
                Subscription = subscription
            };

            UserSubscriptionUpdated?.Invoke(this, args);
        }
Esempio n. 4
0
        public ClientSubscriptionModule(Client client)
        {
            RPC = new ClientCalls(client);

            RequestHandler requestHandler;

            Attach(requestHandler = new RequestHandler());

            requestHandler.Register(nameof(IServerCalls.UserStatusUpdated), (RequestPacket request) => {
                var userUpdateArgs = new UserUpdatedEventArgs {
                    Client     = request.Context.Client,
                    User       = (User)request["user"],
                    UserStatus = (string)request["userStatus"]
                };
                UserUpdated?.Invoke(this, userUpdateArgs);
                return(Task.FromResult(ProcessResult.Processed));
            });

            requestHandler.Register(nameof(IServerCalls.UserSubscriptionUpdated), async(RequestPacket request) => {
                var subscription = UserSubscription.GetFromPacket(request);

                var usubArgs = new UserSubscriptionUpdatedEventArgs {
                    Client       = request.Context.Client,
                    Subscription = subscription
                };
                UserSubscriptionUpdated?.Invoke(this, usubArgs);
                if (subscription.UpdateType == UpdateType.Add)
                {
                    var userUpdateArgs = new UserUpdatedEventArgs {
                        Client     = request.Context.Client,
                        User       = (User)request["user"],
                        UserStatus = (string)request["userStatus"]
                    };
                    UserUpdated?.Invoke(this, userUpdateArgs);
                }
                return(ProcessResult.Processed);
            });
        }