Ejemplo n.º 1
0
        public string Reaction(string objectType, uint objectId)
        {
            var key = objectType + objectId;

            if (!Items.ContainsKey(key))
            {
                var reationRecord = Likes.GetByResourceAndPoster(objectId, objectType, (uint)_sourceId, _sourceType);
                Items[key] = reationRecord?.reaction ?? null;
                //Logger.Instance.Debug(
                //    $"getting like information for {objectType}:{objectType} by {_sourceId}:{_sourceType} resulted with {Items[key]}");
            }

            return(Items[key]);
        }
Ejemplo n.º 2
0
        protected override void CheckIfRefExists(out ActivityAction refActivity, out object activityRecord)
        {
            refActivity    = ActivityActions.GetRefActivity("like_activity_action", activity.ActivityId, "activity_action", userId, false);
            activityRecord = Likes.GetByResourceAndPoster((uint)activity.ActivityId, "activity_action", userId, "user");

            if (refActivity != null && !IsActivityUpdate(refActivity))
            {
                throw new Exception($"Like to {activity.ActivityId} by user {userId} already exists in activity actions");
            }
            if (activityRecord != null && !IsRecordUpdate(activityRecord))
            {
                throw new Exception($"Like to {activity.ActivityId} by user {userId} already exists in Likes table");
            }
        }
Ejemplo n.º 3
0
        protected override void CheckIfRefNotExists(out ActivityAction refActivityAction, out object actionRecord)
        {
            refActivityAction = ActivityActions.GetRefActivity("like_activity_action", activity.ActivityId, "activity_action", userId, true);
            actionRecord      = Likes.GetByResourceAndPoster((uint)activity.ActivityId, "activity_action", userId, "user");


            if ((actionRecord == null && refActivityAction != null) || (actionRecord != null && refActivityAction == null))
            {
                Logger.Instance.Warn($"Inconsistancy in likes and activity tables, to {activity.ActivityId} by user {userId}");
            }

            if (refActivityAction == null)
            {
                Logger.Instance.Warn($"like to {activity.ActivityId} by user {userId} not exists in activity actions");
            }
            if (actionRecord == null)
            {
                Logger.Instance.Warn($"like to {activity.ActivityId} by user {userId} not exists in likes table");
            }
        }
Ejemplo n.º 4
0
        public CommentInfo(Comment comment, ulong viewerId, bool?isLike = false, List <Comment> children = null, bool isReply = false)
        {
            Logger.Instance.Debug($"building comment info for comment {comment.comment_id}");
            var user = Users.GetById(comment.poster_id);

            action_id            = comment.resource_id;
            comment_id           = comment.comment_id;
            image                = comment.GetParam <string>("image");
            image_normal         = comment.GetParam <string>("image_normal");
            image_profile        = comment.GetParam <string>("image_profile");
            image_icon           = comment.GetParam <string>("image_icon");
            content_url          = comment.GetParam <string>("content_url");
            author_image         = comment.GetParam <string>("author_image");
            author_image_normal  = comment.GetParam <string>("author_image_normal");
            author_image_profile = comment.GetParam <string>("author_image_profile");
            author_image_icon    = comment.GetParam <string>("author_image_icon");
            author_title         = user.displayname;
            comment_body         = Encoding.UTF8.GetString(comment.body);
            user_id              = comment.poster_id;
            userTag              = string.Empty;
            //    //@params;
            comment_date = comment.creation_date.ToString("yyyy-MM-dd HH:mm:ss");
            attachment   = CommentAttachment.Create(comment, action_id);

            attachment_type = comment.attachment_type;
            attachment_id   = (ulong)comment.attachment_id;

            //build gutter menu
            List <CommentMenuItem> menu = new List <CommentMenuItem>();

            if (viewerId == comment.poster_id)
            {
                menu.Add(new CommentMenuItem("comment_delete", comment));
                menu.Add(new CommentMenuItem("comment_edit", comment));
            }
            menu.Add(new CommentMenuItem("comment_copy", comment));
            menu.Add(new CommentMenuItem("comment_cancel", comment));
            gutterMenu = menu.ToArray();

            if (!isReply)
            {
                if (children != null)
                {
                    List <CommentInfo> subCumments = new List <CommentInfo>();
                    children.ForEach(c => subCumments.Add(new CommentInfo(c, viewerId, null, null, true)));
                    reply_on_comment = subCumments.OrderByDescending(c => c.comment_id).ToArray();
                    reply_count      = reply_on_comment.Length;
                }
                reply = new CommentMenuItem("reply", comment);
            }

            this.isReply = isReply?0:1;

            if (!isLike.HasValue)
            {
                //find if user already like this commewnt
                isLike = Likes.GetByResourceAndPoster(comment.comment_id, "activity_comment", (uint)user_id, "user") != null;
            }


            if (isLike == true)
            {
                like = new CommentMenuItem("unlike", comment);
            }
            else
            {
                like = new CommentMenuItem("like", comment);
            }

            like_count = (uint)CoreLikes.CountByResource(comment.comment_id, "activity_comment").Count();
        }