|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- package api
-
- import (
- "context"
- "gim/internal/business/comm/utils"
- "gim/internal/logic/app"
- "gim/pkg/grpclib"
- "gim/pkg/pb"
- "google.golang.org/protobuf/proto"
- )
-
- type LogicExtServer struct{}
-
- func (s *LogicExtServer) SetGroupRemoveBannedMembers(ctx context.Context, in *pb.SetGroupMemberRemoveBannedReq) (*pb.Empty, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
-
- err = app.GroupApp.SetGroupMemberRemoveBanned(ctx, userId, in.GroupId, in.RemoveUserIds)
- if err != nil {
- return nil, err
- }
- return &pb.Empty{}, nil
- }
-
- // SetGroupBannedMembers 设置禁言
- func (s *LogicExtServer) SetGroupBannedMembers(ctx context.Context, in *pb.SetGroupMemberBannedReq) (*pb.SetGroupMemberBannedResp, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
-
- var isAllMemberBanned = false
- if in.IsAllMemberBanned == pb.AllMemberBannedType_YES_All_Member_Banned {
- isAllMemberBanned = true
- }
- members, err := app.GroupApp.SetGroupMemberBanned(ctx, userId, in.GroupId, in.UserIds, isAllMemberBanned)
- return &pb.SetGroupMemberBannedResp{Members: members, IsAllMemberBanned: in.IsAllMemberBanned}, err
- }
-
- // GetGroupBannedMembers 获取群组禁言列表
- func (s *LogicExtServer) GetGroupBannedMembers(ctx context.Context, in *pb.GetGroupBannedMembersReq) (*pb.GetGroupBannedMembersResp, error) {
- members, err := app.GroupApp.GetBannedMembers(ctx, in.GroupId)
- return &pb.GetGroupBannedMembersResp{Members: members}, err
- }
-
- func (s *LogicExtServer) SendRedPacket(ctx context.Context, in *pb.SendRedPacketReq) (*pb.SendRedPacketResp, error) {
- userId, deviceId, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
- if in.MessageContentBack != "" {
- buf, err := proto.Marshal(&pb.Text{
- Text: in.MessageContentBack,
- })
- if err != nil {
- return nil, err
- }
- in.MessageContent = buf
- }
- sender := pb.Sender{
- SenderType: pb.SenderType_ST_USER,
- SenderId: userId,
- DeviceId: deviceId,
- }
- seq, err := app.MessageApp.SendRedPackage(ctx, &sender, in)
- if err != nil {
- return nil, err
- }
- return &pb.SendRedPacketResp{Seq: seq}, nil
- }
-
- func (s *LogicExtServer) RecallMessage(ctx context.Context, in *pb.RecallMessageReq) (*pb.RecallMessageResp, error) {
- userId, deviceId, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
- if in.MessageContentBack != "" {
- buf, err := proto.Marshal(&pb.RECALL{RecallSeq: utils.StrToInt64(in.MessageContentBack)})
- if err != nil {
- return nil, err
- }
- in.MessageContent = buf
- }
- sender := pb.Sender{
- SenderType: pb.SenderType_ST_USER,
- SenderId: userId,
- DeviceId: deviceId,
- }
- utils.FilePutContents("RecallMessage", utils.SerializeStr(map[string]interface{}{
- "args": in,
- }))
- seq, err := app.MessageApp.RecallMessage(ctx, &sender, in)
- if err != nil {
- return nil, err
- }
- return &pb.RecallMessageResp{Seq: seq}, nil
- }
-
- // RegisterDevice 注册设备
- func (*LogicExtServer) RegisterDevice(ctx context.Context, in *pb.RegisterDeviceReq) (*pb.RegisterDeviceResp, error) {
- deviceId, err := app.DeviceApp.Register(ctx, in)
- return &pb.RegisterDeviceResp{DeviceId: deviceId}, err
- }
-
- // SendMessage 发送消息
- func (*LogicExtServer) SendMessage(ctx context.Context, in *pb.SendMessageReq) (*pb.SendMessageResp, error) {
- userId, deviceId, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
- if in.MessageContentBack != "" {
- buf, err := proto.Marshal(&pb.Text{
- Text: in.MessageContentBack,
- })
- if err != nil {
- return nil, err
- }
- in.MessageContent = buf
- }
- sender := pb.Sender{
- SenderType: pb.SenderType_ST_USER,
- SenderId: userId,
- DeviceId: deviceId,
- }
- seq, err := app.MessageApp.SendMessage(ctx, &sender, in)
- if err != nil {
- return nil, err
- }
- return &pb.SendMessageResp{Seq: seq}, nil
- }
-
- // PushRoom 推送房间
- func (s *LogicExtServer) PushRoom(ctx context.Context, req *pb.PushRoomReq) (*pb.Empty, error) {
- userId, deviceId, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
- return &pb.Empty{}, app.RoomApp.Push(ctx, &pb.Sender{
- SenderType: pb.SenderType_ST_USER,
- SenderId: userId,
- DeviceId: deviceId,
- }, req)
- }
-
- func (s *LogicExtServer) AddFriend(ctx context.Context, in *pb.AddFriendReq) (*pb.Empty, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
-
- err = app.FriendApp.AddFriend(ctx, userId, in.FriendId, in.Remarks, in.Description)
- if err != nil {
- return nil, err
- }
-
- return &pb.Empty{}, nil
- }
-
- func (s *LogicExtServer) AgreeAddFriend(ctx context.Context, in *pb.AgreeAddFriendReq) (*pb.Empty, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
-
- err = app.FriendApp.AgreeAddFriend(ctx, userId, in.UserId, in.Remarks)
- if err != nil {
- return nil, err
- }
-
- return &pb.Empty{}, nil
- }
-
- func (s *LogicExtServer) DeleteFriend(ctx context.Context, in *pb.DeleteFriendReq) (*pb.Empty, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
- err = app.FriendApp.DeleteFriend(ctx, userId, in.UserId)
- if err != nil {
- return nil, err
- }
-
- return &pb.Empty{}, nil
- }
-
- func (s *LogicExtServer) SetFriend(ctx context.Context, req *pb.SetFriendReq) (*pb.SetFriendResp, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
-
- app.FriendApp.SetFriend(ctx, userId, req)
- if err != nil {
- return nil, err
- }
- return &pb.SetFriendResp{}, nil
- }
-
- func (s *LogicExtServer) GetFriends(ctx context.Context, in *pb.Empty) (*pb.GetFriendsResp, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
- friends, err := app.FriendApp.List(ctx, userId)
- return &pb.GetFriendsResp{Friends: friends}, err
- }
-
- // CreateGroup 创建群组
- func (*LogicExtServer) CreateGroup(ctx context.Context, in *pb.CreateGroupReq) (*pb.CreateGroupResp, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
-
- groupId, err := app.GroupApp.CreateGroup(ctx, userId, in)
- return &pb.CreateGroupResp{GroupId: groupId}, err
- }
-
- // UpdateGroup 更新群组
- func (*LogicExtServer) UpdateGroup(ctx context.Context, in *pb.UpdateGroupReq) (*pb.Empty, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
-
- return &pb.Empty{}, app.GroupApp.Update(ctx, userId, in)
- }
-
- // GetGroup 获取群组信息
- func (*LogicExtServer) GetGroup(ctx context.Context, in *pb.GetGroupReq) (*pb.GetGroupResp, error) {
- group, memberType, userStatusType, err := app.GroupApp.GetGroup(ctx, in.GroupId)
- return &pb.GetGroupResp{Group: group, MemberType: memberType, GroupUserStatusType: userStatusType}, err
- }
-
- // GetGroups 获取用户加入的所有群组
- func (*LogicExtServer) GetGroups(ctx context.Context, in *pb.Empty) (*pb.GetGroupsResp, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
-
- groups, err := app.GroupApp.GetUserGroups(ctx, userId)
- return &pb.GetGroupsResp{Groups: groups}, err
- }
-
- func (s *LogicExtServer) AddGroupMembers(ctx context.Context, in *pb.AddGroupMembersReq) (*pb.AddGroupMembersResp, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
-
- userIds, err := app.GroupApp.AddMembers(ctx, userId, in.GroupId, in.UserIds)
- return &pb.AddGroupMembersResp{UserIds: userIds}, err
- }
-
- // UpdateGroupMember 更新群组成员信息
- func (*LogicExtServer) UpdateGroupMember(ctx context.Context, in *pb.UpdateGroupMemberReq) (*pb.Empty, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
- return &pb.Empty{}, app.GroupApp.UpdateMember(ctx, in, userId)
- }
-
- // DeleteGroupMember 删除群组成员
- func (*LogicExtServer) DeleteGroupMember(ctx context.Context, in *pb.DeleteGroupMemberReq) (*pb.Empty, error) {
- userId, _, err := grpclib.GetCtxData(ctx)
- if err != nil {
- return nil, err
- }
-
- err = app.GroupApp.DeleteMember(ctx, in.GroupId, in.UserId, userId)
- return &pb.Empty{}, err
- }
-
- // GetGroupMembers 获取群组成员信息
- func (s *LogicExtServer) GetGroupMembers(ctx context.Context, in *pb.GetGroupMembersReq) (*pb.GetGroupMembersResp, error) {
- members, err := app.GroupApp.GetMembers(ctx, in.GroupId, in.Limit)
- utils.FilePutContents("GetGroupMembers", utils.SerializeStr(map[string]interface{}{
- "req": map[string]interface{}{
- "group_id": in.GroupId,
- "limit": in.Limit,
- },
- "resp": members,
- }))
- return &pb.GetGroupMembersResp{Members: members}, err
- }
|