Ejemplo n.º 1
0
        public RChatPlugin
            (ILocalizationService localizationService
            , ISettingService settingService
            , IStoreContext storeContext
            , IWebHelper webHelper
            , IPermissionService permissionService
            )
        {
            _localizationService = localizationService;
            _settingService      = settingService;
            _webHelper           = webHelper;
            _permissionService   = permissionService;

            RChatSettings rChatSettings = _settingService.LoadSetting <RChatSettings>(storeContext.CurrentStore.Id);

            RChatHistory.Resize(rChatSettings.numberOfHistoryMessages);
        }
Ejemplo n.º 2
0
        public async Task Send(string message)
        {
            if (!_permissions.Authorize(RChatPermissions.Send))
            {
                return;
            }

            message = message.Trim();
            if (message == "")
            {
                return;
            }
            RChatSettings rChatSettings = _settingService.LoadSetting <RChatSettings>(_storeContext.CurrentStore.Id);

            Customer customer = _workContext.CurrentCustomer;
            string   name     = customer.Username;
            int      id       = customer.Id;

            bool throttle = _throttleTracker.TryGetValue(id, out long millis) && millis > DateTime.Now.Ticks;

            _throttleTracker[id] = TimeSpan.TicksPerMillisecond * rChatSettings.throttleMilliseconds + DateTime.Now.Ticks;
            if (throttle)
            {
                return;
            }

            if (message.Length > rChatSettings.messageCharacterLimit)
            {
                message = message.Remove(rChatSettings.messageCharacterLimit);
            }
            if (name.Length > rChatSettings.nameCharacterLimit)
            {
                name = name.Remove(rChatSettings.nameCharacterLimit);
            }
            message = Sanitize(message);

            RChatHistory.AddMessage(id, name, message);
            await Clients.All.SendAsync("Send", id, name, message);
        }