Skip to content

Commit

Permalink
refactor: 字段精简
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Nov 29, 2024
1 parent e0fdf8c commit b22bfd7
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 96 deletions.
7 changes: 2 additions & 5 deletions client/entity/group_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ const (
)

type GroupMember struct {
Uin uint32
UID string
User
Permission GroupMemberPermission
GroupLevel uint32
MemberCard string
MemberName string
SpecialTitle string
JoinTime uint32
LastMsgTime uint32
ShutUpTime uint32
Avatar string
}

func (m *GroupMember) DisplayName() string {
if m.MemberCard != "" {
return m.MemberCard
}
return m.MemberName
return m.Nickname
}
140 changes: 73 additions & 67 deletions client/event/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,109 +10,105 @@ import (
)

type (
// GroupEvent 通用群事件
GroupEvent struct {
GroupUin uint32
// 触发事件的主体 详看各事件注释
UserUin uint32
UserUID string
}

// GroupMemberPermissionChanged 群成员权限变更
GroupMemberPermissionChanged struct {
GroupEvent
TargetUin uint32
TargetUID string
IsAdmin bool
IsAdmin bool
}

// GroupNameUpdated 群名变更
GroupNameUpdated struct {
GroupUin uint32
NewName string
OperatorUin uint32
OperatorUID string
GroupEvent
NewName string
}

// GroupMute 群内禁言事件 user为被禁言的成员
GroupMute struct {
GroupEvent
OperatorUID string
OperatorUID string // when TargetUID is empty, mute all members
OperatorUin uint32
TargetUID string // when TargetUID is empty, mute all members
TargetUin uint32
Duration uint32 // Duration == math.MaxUint32 when means mute all
}

// GroupRecall 群内消息撤回 user为消息发送者
GroupRecall struct {
GroupEvent
AuthorUID string
AuthorUin uint32
OperatorUID string
OperatorUin uint32
Sequence uint64
Time uint32
Random uint32
}

// GroupMemberJoinRequest 加群请求 user为请求加群的成员
GroupMemberJoinRequest struct {
GroupEvent
TargetUID string
TargetUin uint32
TargetNick string
InvitorUID string
InvitorUin uint32
Answer string // 问题:(.*)答案:(.*)
RequestSeq uint64
}

// GroupMemberIncrease 群成员增加事件 user为新加群的成员
GroupMemberIncrease struct {
GroupEvent
MemberUID string
MemberUin uint32
InvitorUID string
InvitorUin uint32
JoinType uint32
}

// GroupMemberDecrease 群成员减少事件 user为退群的成员
GroupMemberDecrease struct {
GroupEvent
MemberUID string
MemberUin uint32
OperatorUID string
OperatorUin uint32
ExitType uint32
}

// GroupDigestEvent 群精华消息 from miraigo
// GroupDigestEvent 群精华消息 user为消息发送者
// from miraigo
GroupDigestEvent struct {
GroupUin uint32
GroupEvent
MessageID uint32
InternalMessageID uint32
OperationType uint32 // 1 -> 设置精华消息, 2 -> 移除精华消息
OperateTime uint32
SenderUin uint32
OperatorUin uint32
SenderNick string
OperatorNick string
}

// GroupPokeEvent 群戳一戳事件 from miraigo
// GroupPokeEvent 群戳一戳事件 user为发送者
// from miraigo
GroupPokeEvent struct {
GroupUin uint32
Sender uint32
GroupEvent
Receiver uint32
Suffix string
Action string
}

// GroupReactionEvent 群消息表态 user为发送表态的成员
GroupReactionEvent struct {
GroupUin uint32
TargetSeq uint32
OperatorUID string
OperatorUin uint32
IsAdd bool
Code string
Count uint32
GroupEvent
TargetSeq uint32
IsAdd bool
Code string
Count uint32
}

// MemberSpecialTitleUpdated 群成员头衔更新事件 from miraigo
// MemberSpecialTitleUpdated 群成员头衔更新事件
// from miraigo
MemberSpecialTitleUpdated struct {
GroupUin uint32
Uin uint32
GroupEvent
NewTitle string
}
)
Expand Down Expand Up @@ -151,7 +147,7 @@ func (g *GroupDigestEvent) IsSet() bool {
}

func (g *GroupMemberPermissionChanged) ResolveUin(f func(uid string, groupUin ...uint32) uint32) {
g.TargetUin = f(g.TargetUID, g.GroupUin)
g.UserUin = f(g.UserUID, g.GroupUin)
}

func ParseGroupMemberPermissionChanged(event *message.GroupAdmin) *GroupMemberPermissionChanged {
Expand All @@ -167,21 +163,23 @@ func ParseGroupMemberPermissionChanged(event *message.GroupAdmin) *GroupMemberPe
return &GroupMemberPermissionChanged{
GroupEvent: GroupEvent{
GroupUin: event.GroupUin,
UserUID: uid,
},
TargetUID: uid,
IsAdmin: isAdmin,
IsAdmin: isAdmin,
}
}

func (g *GroupNameUpdated) ResolveUin(f func(uid string, groupUin ...uint32) uint32) {
g.OperatorUin = f(g.OperatorUID, g.GroupUin)
g.UserUin = f(g.UserUID, g.GroupUin)
}

func ParseGroupNameUpdatedEvent(event *message.NotifyMessageBody, groupName string) *GroupNameUpdated {
return &GroupNameUpdated{
GroupUin: event.GroupUin,
NewName: groupName,
OperatorUID: event.OperatorUid,
GroupEvent: GroupEvent{
GroupUin: event.GroupUin,
UserUID: event.OperatorUid,
},
NewName: groupName,
}
}

Expand All @@ -194,9 +192,9 @@ func ParseRequestJoinNotice(event *message.GroupJoin) *GroupMemberJoinRequest {
return &GroupMemberJoinRequest{
GroupEvent: GroupEvent{
GroupUin: event.GroupUin,
UserUID: event.TargetUid,
},
TargetUID: event.TargetUid,
Answer: event.RequestField.Unwrap(),
Answer: event.RequestField.Unwrap(),
}
}

Expand All @@ -206,8 +204,8 @@ func ParseRequestInvitationNotice(event *message.GroupInvitation) *GroupMemberJo
return &GroupMemberJoinRequest{
GroupEvent: GroupEvent{
GroupUin: inn.GroupUin,
UserUID: inn.TargetUid,
},
TargetUID: inn.TargetUid,
InvitorUID: inn.InvitorUid,
}
}
Expand All @@ -226,48 +224,48 @@ func ParseInviteNotice(event *message.GroupInvite) *GroupInvite {

func (g *GroupMemberIncrease) ResolveUin(f func(uid string, groupUin ...uint32) uint32) {
g.InvitorUin = f(g.InvitorUID, g.GroupUin)
g.MemberUin = f(g.MemberUID, g.GroupUin)
g.UserUin = f(g.UserUID, g.GroupUin)
}

func ParseMemberIncreaseEvent(event *message.GroupChange) *GroupMemberIncrease {
return &GroupMemberIncrease{
GroupEvent: GroupEvent{
GroupUin: event.GroupUin,
UserUID: event.MemberUid,
},
MemberUID: event.MemberUid,
InvitorUID: utils.B2S(event.Operator),
JoinType: event.IncreaseType,
}
}

func (g *GroupMemberDecrease) ResolveUin(f func(uid string, groupUin ...uint32) uint32) {
g.OperatorUin = f(g.OperatorUID, g.GroupUin)
g.MemberUin = f(g.MemberUID, g.GroupUin)
g.UserUin = f(g.UserUID, g.GroupUin)
}

func ParseMemberDecreaseEvent(event *message.GroupChange) *GroupMemberDecrease {
return &GroupMemberDecrease{
GroupEvent: GroupEvent{
GroupUin: event.GroupUin,
UserUID: event.MemberUid,
},
MemberUID: event.MemberUid,
OperatorUID: utils.B2S(event.Operator),
ExitType: event.DecreaseType,
}
}

func (g *GroupRecall) ResolveUin(f func(uid string, groupUin ...uint32) uint32) {
g.OperatorUin = f(g.OperatorUID, g.GroupUin)
g.AuthorUin = f(g.AuthorUID, g.GroupUin)
g.UserUin = f(g.UserUID, g.GroupUin)
}

func ParseGroupRecallEvent(event *message.NotifyMessageBody) *GroupRecall {
info := event.Recall.RecallMessages[0]
result := GroupRecall{
GroupEvent: GroupEvent{
GroupUin: event.GroupUin,
UserUID: info.AuthorUid,
},
AuthorUID: info.AuthorUid,
OperatorUID: event.Recall.OperatorUid.Unwrap(),
Sequence: info.Sequence,
Time: info.Time,
Expand All @@ -278,28 +276,30 @@ func ParseGroupRecallEvent(event *message.NotifyMessageBody) *GroupRecall {

func (g *GroupMute) ResolveUin(f func(uid string, groupUin ...uint32) uint32) {
g.OperatorUin = f(g.OperatorUID, g.GroupUin)
g.TargetUin = f(g.TargetUID, g.GroupUin)
g.UserUin = f(g.UserUID, g.GroupUin)
}

func ParseGroupMuteEvent(event *message.GroupMute) *GroupMute {
return &GroupMute{
GroupEvent: GroupEvent{
GroupUin: event.GroupUin,
UserUID: event.Data.State.TargetUid.Unwrap(),
},
OperatorUID: event.OperatorUid.Unwrap(),
TargetUID: event.Data.State.TargetUid.Unwrap(),
Duration: event.Data.State.Duration,
}
}

func ParseGroupDigestEvent(event *message.NotifyMessageBody) *GroupDigestEvent {
return &GroupDigestEvent{
GroupUin: event.EssenceMessage.GroupUin,
GroupEvent: GroupEvent{
GroupUin: event.EssenceMessage.GroupUin,
UserUin: event.EssenceMessage.AuthorUin,
},
MessageID: event.EssenceMessage.MsgSequence,
InternalMessageID: event.EssenceMessage.Random,
OperationType: event.EssenceMessage.SetFlag,
OperateTime: event.EssenceMessage.TimeStamp,
SenderUin: event.EssenceMessage.AuthorUin,
OperatorUin: event.EssenceMessage.OperatorUin,
SenderNick: event.EssenceMessage.AuthorName,
OperatorNick: event.EssenceMessage.OperatorName,
Expand All @@ -309,8 +309,10 @@ func ParseGroupDigestEvent(event *message.NotifyMessageBody) *GroupDigestEvent {
func ParseGroupPokeEvent(event *message.NotifyMessageBody, groupUin uint32) *GroupPokeEvent {
e := ParsePokeEvent(event.GrayTipInfo)
return &GroupPokeEvent{
GroupUin: groupUin,
Sender: e.Sender,
GroupEvent: GroupEvent{
GroupUin: groupUin,
UserUin: e.Sender,
},
Receiver: e.Receiver,
Suffix: e.Suffix,
Action: e.Action,
Expand All @@ -329,24 +331,28 @@ func ParseGroupMemberSpecialTitleUpdatedEvent(event *message.GroupSpecialTitle,
return nil
}
return &MemberSpecialTitleUpdated{
GroupUin: groupUin,
Uin: event.TargetUin,
GroupEvent: GroupEvent{
GroupUin: groupUin,
UserUin: event.TargetUin,
},
NewTitle: medalData.Text,
}
}

func (g *GroupReactionEvent) ResolveUin(f func(uid string, groupUin ...uint32) uint32) {
g.OperatorUin = f(g.OperatorUID, g.GroupUin)
g.UserUin = f(g.UserUID, g.GroupUin)
}

func ParseGroupReactionEvent(event *message.GroupReaction) *GroupReactionEvent {
return &GroupReactionEvent{
GroupUin: event.GroupUid,
TargetSeq: event.Data.Data.Data.Target.Sequence,
OperatorUID: event.Data.Data.Data.Data.OperatorUid,
IsAdd: event.Data.Data.Data.Data.Type == 1,
Code: event.Data.Data.Data.Data.Code,
Count: event.Data.Data.Data.Data.Count,
GroupEvent: GroupEvent{
GroupUin: event.GroupUid,
UserUID: event.Data.Data.Data.Data.OperatorUid,
},
TargetSeq: event.Data.Data.Data.Target.Sequence,
IsAdd: event.Data.Data.Data.Data.Type == 1,
Code: event.Data.Data.Data.Data.Code,
Count: event.Data.Data.Data.Data.Count,
}
}

Expand All @@ -356,7 +362,7 @@ func (g *GroupPokeEvent) From() uint32 {

func (g *GroupPokeEvent) Content() string {
if g.Suffix != "" {
return fmt.Sprintf("%d%s%d的%s", g.Sender, g.Action, g.Receiver, g.Suffix)
return fmt.Sprintf("%d%s%d的%s", g.UserUin, g.Action, g.Receiver, g.Suffix)
}
return fmt.Sprintf("%d%s%d", g.Sender, g.Action, g.Receiver)
return fmt.Sprintf("%d%s%d", g.UserUin, g.Action, g.Receiver)
}
Loading

0 comments on commit b22bfd7

Please sign in to comment.