github.com/LagrangeDev/LagrangeGo@v0.0.0-20240512064304-ad4a85e10cb4/client/packets/oidb/FetchMembers.go (about)

     1  package oidb
     2  
     3  import (
     4  	"github.com/LagrangeDev/LagrangeGo/client/entity"
     5  	"github.com/LagrangeDev/LagrangeGo/client/packets/pb/service/oidb"
     6  	"github.com/LagrangeDev/LagrangeGo/internal/proto"
     7  	"github.com/LagrangeDev/LagrangeGo/utils"
     8  )
     9  
    10  func BuildFetchMembersReq(groupUin uint32, token string) (*OidbPacket, error) {
    11  	body := &oidb.OidbSvcTrpcTcp0XFE7_3{
    12  		GroupUin: groupUin,
    13  		Field2:   5,
    14  		Field3:   2,
    15  		Body: &oidb.OidbSvcTrpcScp0XFE7_3Body{
    16  			MemberName:       true,
    17  			MemberCard:       true,
    18  			Level:            true,
    19  			JoinTimestamp:    true,
    20  			LastMsgTimestamp: true,
    21  			Permission:       true,
    22  		},
    23  		Token: proto.Some(token),
    24  	}
    25  	return BuildOidbPacket(0xFE7, 3, body, false, false)
    26  }
    27  
    28  func ParseFetchMembersResp(data []byte) ([]*entity.GroupMember, string, error) {
    29  	var resp oidb.OidbSvcTrpcTcp0XFE7_2Response
    30  	_, err := ParseOidbPacket(data, &resp)
    31  	if err != nil {
    32  		return nil, "", err
    33  	}
    34  	interner := utils.NewStringInterner()
    35  	members := make([]*entity.GroupMember, len(resp.Members))
    36  	for i, member := range resp.Members {
    37  		// 由于protobuf的优化策略,默认值不会被编码进实际的二进制流中
    38  		m := &entity.GroupMember{
    39  			Uin:         member.Uin.Uin,
    40  			Uid:         interner.Intern(member.Uin.Uid),
    41  			Permission:  entity.GroupMemberPermission(member.Permission),
    42  			MemberCard:  interner.Intern(member.MemberCard.MemberCard.Unwrap()),
    43  			MemberName:  interner.Intern(member.MemberName),
    44  			JoinTime:    member.JoinTimestamp,
    45  			LastMsgTime: member.LastMsgTimestamp,
    46  			Avatar:      interner.Intern(entity.FriendAvatar(member.Uin.Uin)),
    47  		}
    48  		if member.Level != nil {
    49  			m.GroupLevel = member.Level.Level
    50  		}
    51  		members[i] = m
    52  	}
    53  	return members, resp.Token.Unwrap(), nil
    54  }