Esempio n. 1
0
        public ResponseModel <List <Abstract.Model.Chat> > GetChats(IWorkerContext context, string userId)
        {
            var key      = GetChatKey(userId);
            var response = _cache[key] as ResponseModel <List <Abstract.Model.Chat> >;

            if (response == null)
            {
                response = _backend.GetChats(context, userId);
                _cache.Add(key, response, DateTimeOffset.Now.AddMinutes(5));
            }

            return(response);
        }
Esempio n. 2
0
        private void InitChatsAndInform(bool isOnline)
        {
            var resp = _backend.GetChats(WorkerContext, CurUserId);

            if (resp.Success && resp.Body != null)
            {
                foreach (var chat in resp.Body)
                {
                    if (string.IsNullOrWhiteSpace(chat.ChatId))
                    {
                        Logger.Warn("chat.ChatId==null");
                        continue;
                    }

                    if (!isOnline)
                    {
                        Clients.Group(chat.ChatId).UserOnline(CurUserId);
                    }

                    Groups.Add(Context.ConnectionId, chat.ChatId);
                }
            }
        }
Esempio n. 3
0
        public ResponseModel <List <Abstract.Model.Chat> > GetChats(IWorkerContext context, string userId)
        {
            var key  = Pref("GetChats_" + userId);
            var json = _redis.GetDatabase().StringGet(key);

            if (json.HasValue)
            {
                var model = JsonConvert.DeserializeObject <ResponseModel <List <Abstract.Model.Chat> > >(json);
                if (model != null)
                {
                    return(model);
                }
            }

            var resp = _backend.GetChats(context, userId);

            if (resp.Success)
            {
                var js = JsonConvert.SerializeObject(resp);
                _redis.GetDatabase().StringSet(key, js, TimeSpan.FromMinutes(_chatsExpiryInMin));
            }

            return(resp);
        }