东莞市连易网络科技有限公司
东莞市连易网络科技有限公司
  • 网站
  • 用户
  • 购物车
  • 购物车
  • 搜索
  • 网站
  • 用户
帮助
帮助
开发文档 点赞
  • 用户文档
  • 开发文档
  • API文档
  • 提及
  • 标签
  • 更多
  • 取消
  • 新建
  • +开始
  • +UI 自定义
  • +外部集成
  • -插件/框架扩展
    • -插件
      • 异常和日志记录
      • 插件生命周期
      • -插件示例
        • 使用小组件从插件渲染内容
        • 公开数据给外部源
        • 公开配置选项
        • 创建动态
        • -创建自定义应用程序和内容
          • -向内容添加核心服务支持
            • 书签
            • 审核/滥用管理
            • 提及
            • 搜索
            • +标签
            • 点赞
            • 评论
        • 基于模板的电子邮件
        • 处理事件
        • 处理内容中的嵌入文件
        • 定义权限
        • 扩展规则支持
        • 文件交互
        • 文件查看器
        • 注册模板令牌
        • 管理依赖关系
        • 管理物理文件存储
        • 翻译插件文本
        • 通知
    • +设置开发环境
    • +进程 API

点赞

ILikeableContentType 接口支持点赞的内容。

我为什么要让我的内容支持点赞?

如果您希望用户通过其他人喜欢您的内容来提供反馈,请考虑在您的 IContentType 插件中实现 ILikeableContentType。

创建一个 ILikeableContentType 插件

ILikeableContentType 是在 Limyee.Core.dll 的 Limyee.Extensibility.Content.Version1 命名空间中定义。

请务必注意,可以在同一 IContentType 类中实现一个或多个核心服务。

首先定义用户是否可以点赞您的内容。在此示例中,我们将点赞限制为不是内容作者的用户。验证内容是否存在也是一种很好的做法。

同样,需要定义谁可以取消点赞内容。此逻辑可以类似于 CanLike 方法。

SupportsLikes 属性返回是否可以点赞此内容类型的任何内容。此属性可以简单地返回 true。

public bool CanLike(Guid contentId, int userId)
{
    var content = LinksData.GetLink(contentId) as IContent;
    if (content == null) return false;

    return content.CreatedByUserId != userId;
}

public bool CanUnlike(Guid contentId, int userId)
{
    var content = LinksData.GetLink(contentId) as IContent;
    if (content == null) return false;

    return content.CreatedByUserId != userId;
}

public bool SupportsLikes
{
    get { return true; }
}

下面是完整示例。

using System;
using System.Collections.Generic;
using System.Linq;
using Limyee.Extensibility;
using Limyee.Extensibility.Api.Entities.Version1;
using Limyee.Extensibility.Api.Version1;
using Limyee.Extensibility.Content.Version1;
using IContent = Limyee.Extensibility.Content.Version1.IContent;

namespace Samples.Links
{
    public class LinkItemContentType : IContentType, ILikeableContentType
    {
        IContentStateChanges _contentState = null;

        #region IPlugin Members

        public string Description
        {
            get { return "Items in a Links collection"; }
        }

        public void Initialize()
        {
        
        }

        public string Name
        {
            get { return "Link Items"; }
        }
        
        #endregion

        #region IContentType Members

        public Guid[] ApplicationTypes
        {
            get { return new Guid[] { ContentTypes.LinksApplicationId }; }
        }

        public void AttachChangeEvents(IContentStateChanges stateChanges)
        {
            _contentState = stateChanges;
        }

        public Guid ContentTypeId
        {
            get { return ContentTypes.LinksItemId; }
        }

        public string ContentTypeName
        {
            get { return "Links Item"; }
        }

        public IContent Get(Guid contentId)
        {
            return LinksData.GetLink(contentId);
        }

        #endregion

        #region ILikeableContentType

        public bool CanLike(Guid contentId, int userId)
        {
            var content = LinksData.GetLink(contentId) as IContent;
            if (content == null) return false;

            return content.CreatedByUserId != userId;
        }

        public bool CanUnlike(Guid contentId, int userId)
        {
            var content = LinksData.GetLink(contentId) as IContent;
            if (content == null) return false;

            return content.CreatedByUserId != userId;
        }

        public bool SupportsLikes
        {
            get { return true; }
        }

        #endregion
    }
}

  • 分享
  • 历史
  • 更多
  • 取消
相关
推荐
Copyright © 2021 东莞市连易网络科技有限公司. All rights reserved.
Powered by Limyee Commerce System(3.0.0). © 2014 - 2025 Limyee Inc.