Esempio n. 1
0
def send_team_out_message(team: Team, mu: User):
    # mu: 被踢出的
    m = Message()
    m.owner = mu
    m.title = "您已被移出团队:" + team.name
    m.portrait = team.portrait if team.portrait else ''
    m.related_id = team.id
    m.type = 'out'
    try:
        m.save()
    except:
        return False
    return True
Esempio n. 2
0
def send_team_dismiss_message(team: Team, mu: User):
    # mu: 团队解散
    m = Message()
    m.owner = mu
    m.title = "团队已解散:" + team.name
    m.portrait = team.portrait if team.portrait else ''
    m.related_id = team.id
    m.type = 'dismiss'
    print(m)
    try:
        m.save()
    except:
        return False
    return True
Esempio n. 3
0
def send_team_admin_message(team: Team, su: User, mu: User):
    # tid:团队id,su:发起添加管理员的用户,mu:刚被设为管理员的用户
    # 我存的数据库原始id,使用msg/info给我发消息时请加密
    m = Message()
    m.owner = mu
    m.sender = su
    m.title = su.name + " 将你设为团队管理员:" + team.name
    m.portrait = team.portrait if team.portrait else ''
    m.related_id = team.id
    m.type = 'admin'
    try:
        m.save()
    except:
        return False
    return True
Esempio n. 4
0
def send_team_accept_message(team: Team, su: User, mu: User, if_accept: bool):
    # tid:团队id,su:发起邀请的用户,mu:处理邀请的用户,if_accept:是否接受邀请
    # 我存的数据库原始id,使用msg/info给我发消息时请加密
    m = Message()
    m.owner = su
    m.sender = mu
    m.title = mu.name + " 接受" if if_accept else " 拒绝" + "了您的团队邀请:" + team.name
    m.portrait = team.portrait if team.portrait else ''
    m.related_id = team.id
    m.type = 'accept'
    try:
        m.save()
    except:
        return False
    return True
Esempio n. 5
0
def send_team_invite_message(team: Team, su: User, mu: User):
    # tid:团队id,suid:发起邀请的用户,muid:接收邀请的用户
    # 我存的数据库原始id,使用msg/info给我发消息时请加密
    m = Message()
    m.owner = mu
    m.sender = su
    m.title = su.name + " 邀请你加入团队:" + team.name
    m.portrait = team.portrait if team.portrait else ''
    m.related_id = team.id
    m.type = 'join'
    try:
        m.save()
    except:
        return False
    return True
Esempio n. 6
0
 def post(self, request):
     if request.user.is_authenticated:
         data = json.loads(request.body.decode('utf-8'))
         user_2_id = str(data['user_2_id'])
         database = Database()
         id_room = database.check_box_chat(request.user.id, user_2_id)
         # lưu tin nhắn
         if data['content'] != '':
             Mess = Message()
             Mess.from_user = MyUser.objects.get(id=request.user.id)
             Mess.conversation = Conversation.objects.get(c_id=id_room)
             Mess.content = data['content']
             Mess.save()
         return HttpResponse('Gửi thành công rồi nhé Lalal')
     else:
         return redirect('home:home')
Esempio n. 7
0
def send_comment_message(comment=(), su=User(), mu=User()):
    # tid:团队id,su:发表评论的用户,mu:文档的拥有者
    # 我存的数据库原始id,使用msg/info给我发消息时请加密
    # 这里没有写完,注释的地方需要完善
    m = Message()
    m.owner = mu
    m.sender = su
    m.title = su.name + " 评论了您的文档:"  # + comment.doc.title
    m.content = comment.content
    m.portrait = su.portrait
    m.related_id = comment.id
    m.type = 'doc'
    try:
        m.save()
    except:
        return False
    return True
Esempio n. 8
0
def add_comment(request):
    data = request.data
    parent_id = data.get('parent_id', 0)
    content = data.get("content")
    article_id = data.get("article_id")
    if not (content and article_id):
        return Response({"status": 400, "msg": "参数错误"})

    kwargs = {"id": article_id}
    article = articleRepository.load(**kwargs)
    if not article:
        return Response({"status": 400, "msg": "文章不存在"})

    utc_time = TimeUtil.get_utc_time()
    catalog_type = data.get("catalog_type")
    workspace = WorkspaceUtil.get_workspace(request)
    passport_id = workspace.passport_id

    message = Message()
    message.reply_id = passport_id
    message.reply_name = workspace.name
    message.passport_id = article.passport_id
    message.article_id = article.id
    message.article_title = article.title
    message.created = utc_time
    message.status = 0
    message.reply_type = Message.Type.reply.value
    flag = True

    if parent_id == 0:
        message.reply_type = Message.Type.answer.value
        if article.passport_id == passport_id:
            flag = False
        # 判断是否有根节点存在
        kwargs = {}
        kwargs["layer"] = 0
        kwargs["article_id"] = article_id
        catalog_res = commentRepository.load(**kwargs)
        # 根节点不存在 先创建一个根节点
        if not catalog_res:
            catalog = Comment()
            catalog.passport_id = passport_id
            catalog.parent_id = 0
            catalog.layer = 0
            catalog.left_id = 1
            catalog.right_id = 4
            catalog.content = ""
            catalog.catalog_type = catalog_type
            catalog.version = 1
            catalog.created = utc_time
            catalog.article_id = article_id
            catalog.save()
            catalog_id = catalog.id

            catalog = Comment()
            catalog.parent_id = catalog_id
            catalog.layer = 1
            catalog.left_id = 2
            catalog.right_id = 3
            catalog.content = data["content"]
            catalog.passport_id = passport_id
            catalog.catalog_type = catalog_type
            catalog.article_id = article_id
            catalog.version = 1
            catalog.created = utc_time
            catalog.save()

        else:
            # 更新需要更新的左节点
            kwargs = {}
            kwargs["catalog_type"] = catalog_type
            kwargs["right_id"] = catalog_res.right_id
            commentRepository.update_left_id(**kwargs)

            # 更新需要更新的右节点
            commentRepository.update_right_id(**kwargs)

            parent_id = catalog_res.id
            catalog = Comment()
            catalog.parent_id = parent_id
            catalog.layer = catalog_res.layer + 1
            catalog.left_id = catalog_res.right_id
            catalog.right_id = catalog_res.right_id + 1
            catalog.catalog_type = catalog_type
            catalog.passport_id = passport_id
            catalog.article_id = article_id
            catalog.content = data["content"]
            catalog.version = 1
            catalog.created = utc_time
            catalog.save()

    else:
        # 新增节点
        kwargs = {}
        kwargs["id"] = parent_id
        catalog_res = commentRepository.load(**kwargs)
        message.passport_id = catalog_res.passport_id
        if catalog_res.passport_id == passport_id:
            flag = False

        # 更新需要更新的左节点
        kwargs = {}
        kwargs["catalog_type"] = catalog_res.catalog_type
        kwargs["right_id"] = catalog_res.right_id
        commentRepository.update_left_id(**kwargs)

        # 更新需要更新的右节点
        commentRepository.update_right_id(**kwargs)

        catalog = Comment()
        catalog.parent_id = parent_id
        catalog.layer = catalog_res.layer + 1
        catalog.left_id = catalog_res.right_id
        catalog.right_id = catalog_res.right_id + 1
        catalog.passport_id = passport_id
        catalog.article_id = article_id
        catalog.catalog_type = catalog_res.catalog_type
        catalog.content = data["content"]
        catalog.version = 1
        catalog.created = utc_time
        catalog.save()

    catalog = CommentSerializers(catalog).data

    if flag:
        message.save()

    return Response({"status": 200, "msg": "新增评论成功", "data": catalog})