Example #1
0
        /// <summary>
        /// Sends the status to the followers of this user.
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        public static async Task <LCStatus> SendToFollowers(LCStatus status)
        {
            if (status == null)
            {
                throw new ArgumentNullException(nameof(status));
            }
            LCUser user = await LCUser.GetCurrent();

            if (user == null)
            {
                throw new ArgumentNullException("current user");
            }

            status.Data[SourceKey] = user;

            LCQuery <LCObject> query = new LCQuery <LCObject>("_Follower")
                                       .WhereEqualTo("user", user)
                                       .Select("follower");

            status.query = query;

            status.InboxType = InboxTypeDefault;

            return(await status.Send());
        }
Example #2
0
        /// <summary>
        /// Sends the status to the user with targetId in private.
        /// </summary>
        /// <param name="status"></param>
        /// <param name="targetId"></param>
        /// <returns></returns>
        public static async Task <LCStatus> SendPrivately(LCStatus status, string targetId)
        {
            if (status == null)
            {
                throw new ArgumentNullException(nameof(status));
            }
            if (string.IsNullOrEmpty(targetId))
            {
                throw new ArgumentNullException(nameof(targetId));
            }
            LCUser user = await LCUser.GetCurrent();

            if (user == null)
            {
                throw new ArgumentNullException("current user");
            }

            status.Data[SourceKey] = user;
            LCQuery <LCObject> query = new LCQuery <LCObject>("_User")
                                       .WhereEqualTo("objectId", targetId);

            status.query = query;

            status.InboxType = InboxTypePrivate;

            return(await status.Send());
        }
Example #3
0
        public new async Task <LCUser> Save(bool fetchWhenSave = false, LCQuery <LCObject> query = null)
        {
            await base.Save(fetchWhenSave, query);

            currentUser = this;
            await SaveToLocal();

            return(this);
        }
Example #4
0
        public static LCQuery <T> And(IEnumerable <LCQuery <T> > queries)
        {
            if (queries == null || queries.Count() < 1)
            {
                throw new ArgumentNullException(nameof(queries));
            }
            LCQuery <T> compositionQuery = new LCQuery <T>(null);
            string      className        = null;

            foreach (LCQuery <T> query in queries)
            {
                if (className != null && className != query.ClassName)
                {
                    throw new Exception("All of the queries in an or query must be on the same class.");
                }
                className = query.ClassName;
                compositionQuery.condition.Add(query.condition);
            }
            compositionQuery.ClassName = className;
            return(compositionQuery);
        }
Example #5
0
        /// <summary>
        /// Saves this object to the cloud.
        /// </summary>
        /// <param name="fetchWhenSave">Whether or not fetch data when saved.</param>
        /// <param name="query">The condition for saving.</param>
        /// <returns></returns>
        public async Task <LCObject> Save(bool fetchWhenSave = false, LCQuery <LCObject> query = null)
        {
            if (LCBatch.HasCircleReference(this, new HashSet <LCObject>()))
            {
                throw new ArgumentException("Found a circle dependency when save.");
            }

            Stack <LCBatch> batches = LCBatch.BatchObjects(new List <LCObject> {
                this
            }, false);

            if (batches.Count > 0)
            {
                await SaveBatches(batches);
            }

            string path = ObjectId == null ? $"classes/{ClassName}" : $"classes/{ClassName}/{ObjectId}";
            Dictionary <string, object> queryParams = new Dictionary <string, object>();

            if (fetchWhenSave)
            {
                queryParams["fetchWhenSave"] = true;
            }
            if (query != null)
            {
                queryParams["where"] = query.BuildWhere();
            }
            Dictionary <string, object> response = ObjectId == null ?
                                                   await LCCore.HttpClient.Post <Dictionary <string, object> >(path, data : LCEncoder.Encode(operationDict) as Dictionary <string, object>, queryParams : queryParams) :
                                                   await LCCore.HttpClient.Put <Dictionary <string, object> >(path, data : LCEncoder.Encode(operationDict) as Dictionary <string, object>, queryParams : queryParams);

            LCObjectData data = LCObjectData.Decode(response);

            Merge(data);
            return(this);
        }