first commit
This commit is contained in:
24
gateway/api/v1/internal/logic/group/change_owner.go
Normal file
24
gateway/api/v1/internal/logic/group/change_owner.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
"gitlab.33.cn/utils/go-kit/convert"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) ChangeOwner(req *types.ChangeOwnerReq) (*types.ChangeOwnerResp, error) {
|
||||
groupId := convert.ToInt64(req.Id)
|
||||
personId := l.getOpe()
|
||||
memberId := req.MemberId
|
||||
|
||||
_, err := l.svcCtx.GroupClient.ChangeOwner(l.ctx, &pb.ChangeOwnerReq{
|
||||
GroupId: groupId,
|
||||
PersonId: personId,
|
||||
MemberId: memberId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.ChangeOwnerResp{}, nil
|
||||
}
|
||||
51
gateway/api/v1/internal/logic/group/create_group.go
Normal file
51
gateway/api/v1/internal/logic/group/create_group.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) CreateGroup(req *types.CreateGroupReq) (*types.CreateGroupResp, error) {
|
||||
name := req.Name
|
||||
addr := l.getOpe()
|
||||
owner := &pb.GroupMemberInfo{
|
||||
Id: addr,
|
||||
Name: "",
|
||||
}
|
||||
members := make([]*pb.GroupMemberInfo, 0, len(req.MemberIds))
|
||||
for _, memberId := range req.MemberIds {
|
||||
members = append(members, &pb.GroupMemberInfo{
|
||||
Id: memberId,
|
||||
Name: "",
|
||||
})
|
||||
}
|
||||
|
||||
resp1, err := l.svcCtx.GroupClient.CreateGroup(l.ctx, &pb.CreateGroupReq{
|
||||
Name: name,
|
||||
GroupType: pb.GroupType_GROUP_TYPE_NORMAL,
|
||||
Owner: owner,
|
||||
Members: members,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
groupId := resp1.GroupId
|
||||
|
||||
resp2, err := l.svcCtx.GroupClient.GetPriGroupInfo(l.ctx, &pb.GetPriGroupInfoReq{
|
||||
GroupId: groupId,
|
||||
PersonId: addr,
|
||||
DisplayNum: int32(1 + len(members)),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Group := NewTypesGroupInfo(resp2.Group)
|
||||
Members := NewTypesGroupMemberInfos(resp2.Group.Members)
|
||||
|
||||
return &types.CreateGroupResp{
|
||||
GroupInfo: Group,
|
||||
Members: Members,
|
||||
}, nil
|
||||
}
|
||||
29
gateway/api/v1/internal/logic/group/get_group_info.go
Normal file
29
gateway/api/v1/internal/logic/group/get_group_info.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) GetPriGroupInfo(req *types.GetGroupInfoReq) (*types.GetGroupInfoResp, error) {
|
||||
if req.DisPlayNum == 0 {
|
||||
req.DisPlayNum = 10
|
||||
}
|
||||
|
||||
resp, err := l.svcCtx.GroupClient.GetPriGroupInfo(l.ctx, &pb.GetPriGroupInfoReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
DisplayNum: int32(req.DisPlayNum),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Group := NewTypesGroupInfo(resp.Group)
|
||||
Members := NewTypesGroupMemberInfos(resp.Group.Members)
|
||||
|
||||
return &types.GetGroupInfoResp{
|
||||
GroupInfo: Group,
|
||||
Members: Members,
|
||||
}, nil
|
||||
}
|
||||
23
gateway/api/v1/internal/logic/group/get_group_list.go
Normal file
23
gateway/api/v1/internal/logic/group/get_group_list.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) GetGroupList(req *types.GetGroupListReq) (*types.GetGroupListResp, error) {
|
||||
personId := l.getOpe()
|
||||
|
||||
resp, err := l.svcCtx.GroupClient.GetGroupList(l.ctx, &pb.GetGroupListReq{
|
||||
PersonId: personId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Groups := NewTypesGroupInfos(resp.Groups)
|
||||
|
||||
return &types.GetGroupListResp{
|
||||
Groups: Groups,
|
||||
}, nil
|
||||
}
|
||||
26
gateway/api/v1/internal/logic/group/get_group_member_info.go
Normal file
26
gateway/api/v1/internal/logic/group/get_group_member_info.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) GetGroupMemberInfo(req *types.GetGroupMemberInfoReq) (*types.GetGroupMemberInfoResp, error) {
|
||||
groupId := req.Id
|
||||
memberId := req.MemberId
|
||||
|
||||
resp, err := l.svcCtx.GroupClient.GetGroupMemberInfo(l.ctx, &pb.GetGroupMemberInfoReq{
|
||||
GroupId: groupId,
|
||||
PersonId: l.getOpe(),
|
||||
MemberId: memberId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Member := NewTypesGroupMemberInfo(resp.Member)
|
||||
res := &types.GetGroupMemberInfoResp{}
|
||||
res.GroupMember = Member
|
||||
|
||||
return res, nil
|
||||
}
|
||||
27
gateway/api/v1/internal/logic/group/get_group_member_list.go
Normal file
27
gateway/api/v1/internal/logic/group/get_group_member_list.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
"gitlab.33.cn/utils/go-kit/convert"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) GetGroupMemberList(req *types.GetGroupMemberListReq) (*types.GetGroupMemberListResp, error) {
|
||||
groupId := req.Id
|
||||
|
||||
resp, err := l.svcCtx.GroupClient.GetGroupMemberList(l.ctx, &pb.GetGroupMemberListReq{
|
||||
GroupId: groupId,
|
||||
PersonId: l.getOpe(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Members := NewTypesGroupMemberInfos(resp.Members)
|
||||
|
||||
return &types.GetGroupMemberListResp{
|
||||
Id: groupId,
|
||||
IdStr: convert.ToString(groupId),
|
||||
Members: Members,
|
||||
}, nil
|
||||
}
|
||||
19
gateway/api/v1/internal/logic/group/get_mute_list.go
Normal file
19
gateway/api/v1/internal/logic/group/get_mute_list.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) GetMuteList(req *types.GetMuteListReq) (*types.GetMuteListResp, error) {
|
||||
resp, err := l.svcCtx.GroupClient.GetMuteList(l.ctx, &pb.GetMuteListReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Members := NewTypesGroupMemberInfos(resp.Members)
|
||||
return &types.GetMuteListResp{Members: Members}, nil
|
||||
}
|
||||
21
gateway/api/v1/internal/logic/group/get_pub_group_info.go
Normal file
21
gateway/api/v1/internal/logic/group/get_pub_group_info.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) GetPubGroupInfo(req *types.GetGroupPubInfoReq) (*types.GetGroupPubInfoResp, error) {
|
||||
resp, err := l.svcCtx.GroupClient.GetPubGroupInfo(l.ctx, &pb.GetPubGroupInfoReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res := &types.GetGroupPubInfoResp{}
|
||||
Group := NewTypesGroupInfo(resp.Group)
|
||||
res.GroupInfo = Group
|
||||
return res, nil
|
||||
}
|
||||
18
gateway/api/v1/internal/logic/group/group_disband.go
Normal file
18
gateway/api/v1/internal/logic/group/group_disband.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) GroupDisband(req *types.GroupDisbandReq) (*types.GroupDisbandResp, error) {
|
||||
_, err := l.svcCtx.GroupClient.GroupDisband(l.ctx, &pb.GroupDisbandReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.GroupDisbandResp{}, nil
|
||||
}
|
||||
18
gateway/api/v1/internal/logic/group/group_exit.go
Normal file
18
gateway/api/v1/internal/logic/group/group_exit.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) GroupExit(req *types.GroupExitReq) (*types.GroupExitResp, error) {
|
||||
_, err := l.svcCtx.GroupClient.GroupExit(l.ctx, &pb.GroupExitReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.GroupExitResp{}, nil
|
||||
}
|
||||
22
gateway/api/v1/internal/logic/group/group_remove.go
Normal file
22
gateway/api/v1/internal/logic/group/group_remove.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) GroupRemove(req *types.GroupRemoveReq) (*types.GroupRemoveResp, error) {
|
||||
resp, err := l.svcCtx.GroupClient.GroupRemove(l.ctx, &pb.GroupRemoveReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
MemberIds: req.MemberIds,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.GroupRemoveResp{
|
||||
MemberNum: resp.MemberNum,
|
||||
MemberIds: resp.MemberIds,
|
||||
}, nil
|
||||
}
|
||||
25
gateway/api/v1/internal/logic/group/invite_group_members.go
Normal file
25
gateway/api/v1/internal/logic/group/invite_group_members.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
"gitlab.33.cn/utils/go-kit/convert"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) InviteGroupMembers(req *types.InviteGroupMembersReq) (*types.InviteGroupMembersResp, error) {
|
||||
groupId := req.Id
|
||||
|
||||
_, err := l.svcCtx.GroupClient.InviteGroupMembers(l.ctx, &pb.InviteGroupMembersReq{
|
||||
GroupId: groupId,
|
||||
InviterId: l.getOpe(),
|
||||
MemberIds: req.NewMemberIds,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.InviteGroupMembersResp{
|
||||
Id: groupId,
|
||||
IdStr: convert.ToString(groupId),
|
||||
}, nil
|
||||
}
|
||||
25
gateway/api/v1/internal/logic/group/join_group.go
Normal file
25
gateway/api/v1/internal/logic/group/join_group.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
"gitlab.33.cn/utils/go-kit/convert"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) JoinGroup(req *types.JoinGroupReq) (*types.JoinGroupResp, error) {
|
||||
groupId := req.Id
|
||||
|
||||
_, err := l.svcCtx.GroupClient.InviteGroupMembers(l.ctx, &pb.InviteGroupMembersReq{
|
||||
GroupId: groupId,
|
||||
InviterId: req.InviterId,
|
||||
MemberIds: []string{l.getOpe()},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.JoinGroupResp{
|
||||
Id: groupId,
|
||||
IdStr: convert.ToString(groupId),
|
||||
}, nil
|
||||
}
|
||||
96
gateway/api/v1/internal/logic/group/newlogic.go
Normal file
96
gateway/api/v1/internal/logic/group/newlogic.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/svc"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
"gitlab.33.cn/chat/dtalk/pkg/api"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
"gitlab.33.cn/utils/go-kit/convert"
|
||||
)
|
||||
|
||||
type GroupLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGroupLogic(ctx context.Context, svcCtx *svc.ServiceContext) GroupLogic {
|
||||
return GroupLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GroupLogic) getOpe() string {
|
||||
return api.NewAddrWithContext(l.ctx)
|
||||
}
|
||||
|
||||
func NewTypesGroupInfo(do *pb.GroupBizInfo) *types.GroupInfo {
|
||||
if do == nil {
|
||||
return &types.GroupInfo{}
|
||||
}
|
||||
|
||||
res := &types.GroupInfo{
|
||||
Id: do.Id,
|
||||
IdStr: convert.ToString(do.Id),
|
||||
MarkId: do.MarkId,
|
||||
Name: do.Name,
|
||||
PublicName: do.PubName,
|
||||
Avatar: do.Avatar,
|
||||
Introduce: do.Introduce,
|
||||
Owner: nil,
|
||||
Person: nil,
|
||||
MemberNum: do.MemberNum,
|
||||
Maximum: do.MemberMaximum,
|
||||
Status: int32(do.Status),
|
||||
CreateTime: do.CreateTime,
|
||||
JoinType: int32(do.JoinType),
|
||||
MuteType: int32(do.MuteType),
|
||||
FriendType: int32(do.FriendType),
|
||||
MuteNum: do.MuteNum,
|
||||
AdminNum: do.AdminNum,
|
||||
AESKey: do.AESKey,
|
||||
GroupType: int32(do.GetType()),
|
||||
}
|
||||
|
||||
if do.Owner != nil {
|
||||
res.Owner = NewTypesGroupMemberInfo(do.Owner)
|
||||
}
|
||||
|
||||
if do.Person != nil {
|
||||
res.Person = NewTypesGroupMemberInfo(do.Person)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func NewTypesGroupInfos(dos []*pb.GroupBizInfo) []*types.GroupInfo {
|
||||
dtos := make([]*types.GroupInfo, 0, len(dos))
|
||||
for _, do := range dos {
|
||||
dtos = append(dtos, NewTypesGroupInfo(do))
|
||||
}
|
||||
|
||||
return dtos
|
||||
}
|
||||
|
||||
func NewTypesGroupMemberInfo(do *pb.GroupMemberBizInfo) *types.GroupMember {
|
||||
if do == nil {
|
||||
return &types.GroupMember{}
|
||||
}
|
||||
|
||||
return &types.GroupMember{
|
||||
MemberId: do.Id,
|
||||
MemberName: do.Name,
|
||||
MemberType: int32(do.Type),
|
||||
MemberMuteTime: do.MuteTime,
|
||||
}
|
||||
}
|
||||
|
||||
func NewTypesGroupMemberInfos(dos []*pb.GroupMemberBizInfo) []*types.GroupMember {
|
||||
dtos := make([]*types.GroupMember, 0, len(dos))
|
||||
for _, do := range dos {
|
||||
dtos = append(dtos, NewTypesGroupMemberInfo(do))
|
||||
}
|
||||
|
||||
return dtos
|
||||
}
|
||||
25
gateway/api/v1/internal/logic/group/set_admin.go
Normal file
25
gateway/api/v1/internal/logic/group/set_admin.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
xerror "gitlab.33.cn/chat/dtalk/pkg/error"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) SetAdmin(req *types.SetAdminReq) (*types.SetAdminResp, error) {
|
||||
if _, ok := pb.GroupMemberType_name[req.MemberType]; !ok {
|
||||
return nil, xerror.NewError(xerror.ParamsError)
|
||||
}
|
||||
|
||||
_, err := l.svcCtx.GroupClient.SetAdmin(l.ctx, &pb.SetAdminReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
MemberId: req.MemberId,
|
||||
GroupMemberType: pb.GroupMemberType(req.MemberType),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.SetAdminResp{}, nil
|
||||
}
|
||||
19
gateway/api/v1/internal/logic/group/update_group_avatar.go
Normal file
19
gateway/api/v1/internal/logic/group/update_group_avatar.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) UpdateGroupAvatar(req *types.UpdateGroupAvatarReq) (*types.UpdateGroupAvatarResp, error) {
|
||||
_, err := l.svcCtx.GroupClient.UpdateGroupAvatar(l.ctx, &pb.UpdateGroupAvatarReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
Avatar: req.Avatar,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.UpdateGroupAvatarResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) UpdateGroupFriendType(req *types.UpdateGroupFriendTypeReq) (*types.UpdateGroupFriendTypeResp, error) {
|
||||
_, err := l.svcCtx.GroupClient.UpdateGroupFriendType(l.ctx, &pb.UpdateGroupFriendTypeReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
GroupFriendType: pb.GroupFriendType(req.FriendType),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.UpdateGroupFriendTypeResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) UpdateGroupJoinType(req *types.UpdateGroupJoinTypeReq) (*types.UpdateGroupJoinTypeResp, error) {
|
||||
_, err := l.svcCtx.GroupClient.UpdateGroupJoinType(l.ctx, &pb.UpdateGroupJoinTypeReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
GroupJoinType: pb.GroupJoinType(req.JoinType),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.UpdateGroupJoinTypeResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) UpdateGroupMemberMuteTime(req *types.UpdateGroupMemberMuteTimeReq) (*types.UpdateGroupMemberMuteTimeResp, error) {
|
||||
resp, err := l.svcCtx.GroupClient.UpdateGroupMemberMuteTime(l.ctx, &pb.UpdateGroupMemberMuteTimeReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
MemberIds: req.MemberIds,
|
||||
MuteTime: req.MuteTime,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Members := NewTypesGroupMemberInfos(resp.Members)
|
||||
|
||||
return &types.UpdateGroupMemberMuteTimeResp{Members: Members}, nil
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) UpdateGroupMemberName(req *types.UpdateGroupMemberNameReq) (*types.UpdateGroupMemberNameResp, error) {
|
||||
_, err := l.svcCtx.GroupClient.UpdateGroupMemberName(l.ctx, &pb.UpdateGroupMemberNameReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
MemberName: req.MemberName,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.UpdateGroupMemberNameResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) UpdateGroupMuteType(req *types.UpdateGroupMuteTypeReq) (*types.UpdateGroupMuteTypeResp, error) {
|
||||
_, err := l.svcCtx.GroupClient.UpdateGroupMuteType(l.ctx, &pb.UpdateGroupMuteTypeReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
GroupMuteType: pb.GroupMuteType(req.MuteType),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.UpdateGroupMuteTypeResp{}, nil
|
||||
}
|
||||
20
gateway/api/v1/internal/logic/group/update_group_name.go
Normal file
20
gateway/api/v1/internal/logic/group/update_group_name.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
pb "gitlab.33.cn/chat/dtalk/service/group/api"
|
||||
)
|
||||
|
||||
func (l *GroupLogic) UpdateGroupName(req *types.UpdateGroupNameReq) (*types.UpdateGroupNameResp, error) {
|
||||
_, err := l.svcCtx.GroupClient.UpdateGroupName(l.ctx, &pb.UpdateGroupNameReq{
|
||||
GroupId: req.Id,
|
||||
PersonId: l.getOpe(),
|
||||
Name: req.Name,
|
||||
PublicName: req.PublicName,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.UpdateGroupNameResp{}, nil
|
||||
}
|
||||
87
gateway/api/v1/internal/logic/record/focus.go
Normal file
87
gateway/api/v1/internal/logic/record/focus.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package record
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
xproto "github.com/golang/protobuf/proto"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/model"
|
||||
"gitlab.33.cn/chat/dtalk/pkg/util"
|
||||
"gitlab.33.cn/chat/dtalk/service/group/model/biz"
|
||||
"gitlab.33.cn/chat/imparse/proto"
|
||||
)
|
||||
|
||||
func (l *Logic) FocusPersonal(Operator string, logId int64) error {
|
||||
//查找消息
|
||||
rd, err := l.svcCtx.StoreClient.GetRecord(l.ctx, proto.Channel_ToUser, logId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
target := rd.ReceiverId
|
||||
sender := rd.SenderId
|
||||
if Operator == sender || Operator != target {
|
||||
return model.ErrPermission
|
||||
}
|
||||
now := uint64(util.TimeNowUnixNano() / int64(time.Millisecond))
|
||||
num, err := l.svcCtx.StoreClient.AddRecordFocus(l.ctx, Operator, logId, now)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
action := &proto.SignalFocusMessage{
|
||||
Mid: logId,
|
||||
Uid: Operator,
|
||||
CurrentNum: num,
|
||||
Time: now,
|
||||
}
|
||||
body, err := xproto.Marshal(action)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "proto.Marshal, action=%+v", action)
|
||||
}
|
||||
err = l.svcCtx.AnswerClient.UniCastSignal(l.ctx, proto.SignalType_FocusMessage, sender, body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return l.svcCtx.AnswerClient.UniCastSignal(l.ctx, proto.SignalType_FocusMessage, target, body)
|
||||
}
|
||||
|
||||
func (l *Logic) FocusGroup(Operator string, logId int64) error {
|
||||
//查找消息
|
||||
rd, err := l.svcCtx.StoreClient.GetRecord(l.ctx, proto.Channel_ToGroup, logId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
target := rd.ReceiverId
|
||||
sender := rd.SenderId
|
||||
if Operator == sender {
|
||||
return model.ErrPermission
|
||||
}
|
||||
//群成员判断
|
||||
memOpt, err := l.svcCtx.GroupClient.GetMember(l.ctx, util.ToInt64(target), Operator)
|
||||
if err != nil || memOpt == nil {
|
||||
return err
|
||||
}
|
||||
switch memOpt.GroupMemberType {
|
||||
case biz.GroupMemberTypeOwner:
|
||||
case biz.GroupMemberTypeAdmin:
|
||||
case biz.GroupMemberTypeNormal:
|
||||
default:
|
||||
return model.ErrPermission
|
||||
}
|
||||
|
||||
now := uint64(util.TimeNowUnixNano() / int64(time.Millisecond))
|
||||
num, err := l.svcCtx.StoreClient.AddRecordFocus(l.ctx, Operator, logId, now)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
action := &proto.SignalFocusMessage{
|
||||
Mid: logId,
|
||||
Uid: Operator,
|
||||
CurrentNum: num,
|
||||
Time: now,
|
||||
}
|
||||
body, err := xproto.Marshal(action)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "proto.Marshal, action=%+v", action)
|
||||
}
|
||||
return l.svcCtx.AnswerClient.GroupCastSignal(l.ctx, proto.SignalType_FocusMessage, target, body)
|
||||
}
|
||||
5
gateway/api/v1/internal/logic/record/push.go
Normal file
5
gateway/api/v1/internal/logic/record/push.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package record
|
||||
|
||||
func (l *Logic) Push(key, from string, body []byte) (int64, uint64, error) {
|
||||
return l.svcCtx.AnswerClient.PushCommonMsg(l.ctx, key, from, body)
|
||||
}
|
||||
47
gateway/api/v1/internal/logic/record/record.go
Normal file
47
gateway/api/v1/internal/logic/record/record.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package record
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/model"
|
||||
xerror "gitlab.33.cn/chat/dtalk/pkg/error"
|
||||
"gitlab.33.cn/chat/dtalk/pkg/util"
|
||||
store "gitlab.33.cn/chat/dtalk/service/record/store/api"
|
||||
storeModel "gitlab.33.cn/chat/dtalk/service/record/store/model"
|
||||
"gitlab.33.cn/chat/imparse/proto"
|
||||
)
|
||||
|
||||
func (l *Logic) GetPriRecord(req *model.GetPriRecordsReq) (*model.GetPriRecordsResp, error) {
|
||||
resp, err := l.svcCtx.StoreClient.GetRecordsAfterMid(l.ctx, &store.GetRecordsAfterMidReq{
|
||||
Tp: proto.Channel_ToUser,
|
||||
Mid: util.ToInt64(req.Mid),
|
||||
From: req.FromId,
|
||||
Target: req.TargetId,
|
||||
Count: req.RecordCount,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, xerror.NewError(xerror.QueryFailed).SetExtMessage(err.Error())
|
||||
}
|
||||
|
||||
res := &model.GetPriRecordsResp{
|
||||
RecordCount: len(resp.Records),
|
||||
Records: toChatRecord(resp.Records),
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// toChatRecord []MsgContent -> []Record , content json -> proto
|
||||
func toChatRecord(msgs []*store.GetRecordReply) []*model.Record {
|
||||
Result := make([]*model.Record, len(msgs))
|
||||
for i, msg := range msgs {
|
||||
Result[i] = &model.Record{
|
||||
Mid: msg.Mid,
|
||||
Seq: msg.Seq,
|
||||
FromId: msg.SenderId,
|
||||
TargetId: msg.ReceiverId,
|
||||
MsgType: int32(msg.MsgType),
|
||||
Content: storeModel.JsonUnmarshal(msg.MsgType, []byte(msg.Content)),
|
||||
CreateTime: msg.CreateTime,
|
||||
}
|
||||
}
|
||||
return Result
|
||||
}
|
||||
101
gateway/api/v1/internal/logic/record/revoke.go
Normal file
101
gateway/api/v1/internal/logic/record/revoke.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package record
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gitlab.33.cn/chat/dtalk/service/group/model/biz"
|
||||
"time"
|
||||
|
||||
xproto "github.com/golang/protobuf/proto"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/model"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/svc"
|
||||
"gitlab.33.cn/chat/dtalk/pkg/util"
|
||||
"gitlab.33.cn/chat/imparse/proto"
|
||||
)
|
||||
|
||||
type Logic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewLogic(ctx context.Context, svcCtx *svc.ServiceContext) Logic {
|
||||
return Logic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Logic) RevokePersonal(Operator string, mid int64) error {
|
||||
//查找消息
|
||||
rd, err := l.svcCtx.StoreClient.GetRecord(l.ctx, proto.Channel_ToUser, mid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
target := rd.ReceiverId
|
||||
if rd.SenderId != Operator || time.Since(util.UnixToTime(int64(rd.CreateTime))) > time.Duration(l.svcCtx.Config().Revoke.Expire) {
|
||||
return model.ErrPermission
|
||||
}
|
||||
action := &proto.SignalRevoke{
|
||||
Mid: mid,
|
||||
Operator: Operator,
|
||||
Self: rd.SenderId == Operator,
|
||||
}
|
||||
body, err := xproto.Marshal(action)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "proto.Marshal, action=%+v", action)
|
||||
}
|
||||
err = l.svcCtx.AnswerClient.UniCastSignal(l.ctx, proto.SignalType_Revoke, target, body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := l.svcCtx.StoreClient.DelRecord(l.ctx, proto.Channel_ToUser, mid); err != nil {
|
||||
return err
|
||||
}
|
||||
return l.svcCtx.AnswerClient.UniCastSignal(l.ctx, proto.SignalType_Revoke, Operator, body)
|
||||
}
|
||||
|
||||
func (l *Logic) RevokeGroup(Operator string, mid int64) error {
|
||||
//查找消息
|
||||
rd, err := l.svcCtx.StoreClient.GetRecord(l.ctx, proto.Channel_ToGroup, mid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
target := rd.ReceiverId
|
||||
if rd.SenderId == Operator && time.Since(util.UnixToTime(int64(rd.CreateTime))) > time.Duration(l.svcCtx.Config().Revoke.Expire) {
|
||||
return model.ErrPermission
|
||||
}
|
||||
if rd.SenderId != Operator {
|
||||
//执行者
|
||||
memOpt, err := l.svcCtx.GroupClient.GetMember(l.ctx, util.ToInt64(target), Operator)
|
||||
if err != nil || memOpt == nil {
|
||||
return err
|
||||
}
|
||||
//消息所有者
|
||||
memOwn, err := l.svcCtx.GroupClient.GetMember(l.ctx, util.ToInt64(target), rd.SenderId)
|
||||
if err != nil || memOwn == nil {
|
||||
return err
|
||||
}
|
||||
switch memOpt.GroupMemberType {
|
||||
case biz.GroupMemberTypeOwner:
|
||||
case biz.GroupMemberTypeAdmin:
|
||||
if memOwn.GroupMemberType == biz.GroupMemberTypeOwner {
|
||||
return model.ErrPermission
|
||||
}
|
||||
default:
|
||||
return model.ErrPermission
|
||||
}
|
||||
}
|
||||
action := &proto.SignalRevoke{
|
||||
Mid: mid,
|
||||
Operator: Operator,
|
||||
Self: rd.SenderId == Operator,
|
||||
}
|
||||
body, err := xproto.Marshal(action)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "proto.Marshal, action=%+v", action)
|
||||
}
|
||||
if err := l.svcCtx.StoreClient.DelRecord(l.ctx, proto.Channel_ToGroup, mid); err != nil {
|
||||
return err
|
||||
}
|
||||
return l.svcCtx.AnswerClient.GroupCastSignal(l.ctx, proto.SignalType_Revoke, target, body)
|
||||
}
|
||||
24
gateway/api/v1/internal/logic/test/testlogic.go
Normal file
24
gateway/api/v1/internal/logic/test/testlogic.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/svc"
|
||||
"gitlab.33.cn/chat/dtalk/gateway/api/v1/internal/types"
|
||||
)
|
||||
|
||||
type TestLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewTestLogic(ctx context.Context, svcCtx *svc.ServiceContext) TestLogic {
|
||||
return TestLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *TestLogic) GetHelloWorld() (*types.Hello, error) {
|
||||
return &types.Hello{Content: "hello world"}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user