Пример #1
0
        private void OnRoomJoined(BaseEvent evt)
        {
            Message message;

            Messages              = new Queue <Message>(maxMessages);
            IsConnected           = true;
            isConnecting          = false;
            haveConnectionProblem = false;

            var room         = (Room)evt.Params["room"];
            var roomVariable = room.GetVariable("messages");

            if (roomVariable == null)
            {
                return;
            }

            var array = JsonConvert.DeserializeObject <List <RoomVariable> >(roomVariable.GetStringValue());

            if (array == null)
            {
                return;
            }

            foreach (var item in array)
            {
                var time = new Lifetime();
                time.CreationTime = item.t * 1000;
                time.Duration     = -1000;
                time.CanExpire    = false;
                if (IsBannedUser(item.uid, time.CreationTime))
                {
                    continue;
                }

                unchecked
                {
                    message = new TextMessage()
                    {
                        Id       = new Id <Message>((int)(time.CreationTime / 1000)),
                        Sender   = new UserId(item.uid),
                        Text     = ToolHelper.Base64Decode(item.m),
                        Lifetime = time
                    };
                }

                if (Messages.Count >= maxMessages)
                {
                    Messages.Dequeue();
                }
                Messages.Enqueue(message);
            }

            if (Messages.Any())
            {
                MessageArrived(Messages.Last());
            }
            D.Log(LoggingTags.Chat, "Joined room is successfull:");
        }