예제 #1
0
        /// <summary>
        /// Use this method to make the initial load of a room. After the initial load you may subscribe to the room messages stream.
        /// </summary>
        /// <returns>The history.</returns>
        /// <param name="roomId">The room id</param>
        /// <param name="oldestMessage">the oldest message date  - this is used to do pagination</param>
        /// <param name="quantity">The message quantity</param>
        /// <param name="lastUpdate">A date object - the date of the last time the client got data for the room</param>
        public async Task <List <Message> > LoadHistory(DateTime oldestMessage, int quantity, DateTime lastUpdate)
        {
            var oldest  = TypeUtils.DateTimeToTimestamp(oldestMessage);
            var updated = TypeUtils.DateTimeToTimestamp(lastUpdate);

            var oldestObj = (oldest == 0) ? null : new Dictionary <string, long>()
            {
                { "$date", oldest }
            };
            var updatedObj = new Dictionary <string, long>()
            {
                { "$date", updated }
            };

            return(await LoadHistory(oldestObj, quantity, updatedObj));
        }
예제 #2
0
        /// <summary>
        /// This method is used to retrieve the public settings, such as Site Name.
        /// It accepts a date as the first and only parameter which causes the results to be an object that
        /// contains the updated and removed settings after the provided time.
        /// </summary>
        /// <returns>The time after which settings should be returned.</returns>
        /// <param name="since">Since.</param>
        public async Task <CollectionDiff <KeyValuePair <string, object> > > GetPublicSettingsSince(DateTime since)
        {
            var res = await _meteor.CallWithResult("public-settings/get", new object[] { new Dictionary <string, object>()
                                                                                         {
                                                                                             { "$date", TypeUtils.DateTimeToTimestamp(since) }
                                                                                         } });

            CollectionDiff <KeyValuePair <string, object> > output = new CollectionDiff <KeyValuePair <string, object> >();


            if (res == null)
            {
                return(output);
            }

            var result = res["result"];

            if (result == null)
            {
                return(output);
            }

            var updates   = result["update"] != null ? (result as JObject)["update"] as JArray : null;
            var additions = result["add"] != null ? (result as JObject)["add"] as JArray : null;
            var removes   = result["remove"] != null ? (result as JObject)["remove"] as JArray : null;

            if (additions != null)
            {
                foreach (var channelTok in additions)
                {
                    output.Added.Add(TypeUtils.ParseKeyValuePair(channelTok as JObject));
                }
            }

            if (updates != null)
            {
                foreach (var channelTok in updates)
                {
                    output.Updated.Add(TypeUtils.ParseKeyValuePair(channelTok as JObject));
                }
            }

            if (removes != null)
            {
                foreach (var channelTok in removes)
                {
                    output.Removed.Add(TypeUtils.ParseKeyValuePair(channelTok as JObject));
                }
            }

            return(output);
        }
        /// <summary>
        /// Returns a collection diff an user’s subscription collection. If a date is passed the result will only contains changes to the subscriptions
        /// </summary>
        /// <returns>The subscriptions.</returns>
        /// <param name="since">Date since the last update</param>
        public async Task <CollectionDiff <Subscription> > GetSubscriptions(DateTime since)
        {
            var res = await _meteor.CallWithResult("subscriptions/get", new object[] { new Dictionary <string, object>()
                                                                                       {
                                                                                           { "$date", TypeUtils.DateTimeToTimestamp(since) }
                                                                                       } });

            return(ProcessSubscriptions(res));
        }