Skip to content

Commit

Permalink
ref: remove guild FindMember func & remove guild members cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s committed Dec 4, 2021
1 parent 34bb74d commit a2e7548
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
27 changes: 4 additions & 23 deletions client/guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ type (
CoverUrl string
AvatarUrl string
Channels []*ChannelInfo
Bots []*GuildMemberInfo
Members []*GuildMemberInfo
Admins []*GuildMemberInfo
// Bots []*GuildMemberInfo
// Members []*GuildMemberInfo
// Admins []*GuildMemberInfo
}

// GuildMeta 频道数据
Expand Down Expand Up @@ -145,25 +145,6 @@ func (s *GuildService) FindGuild(guildId uint64) *GuildInfo {
return nil
}

func (g *GuildInfo) FindMember(tinyId uint64) *GuildMemberInfo {
for i := 0; i < len(g.Members); i++ {
if g.Members[i].TinyId == tinyId {
return g.Members[i]
}
}
for i := 0; i < len(g.Admins); i++ {
if g.Admins[i].TinyId == tinyId {
return g.Admins[i]
}
}
for i := 0; i < len(g.Bots); i++ {
if g.Bots[i].TinyId == tinyId {
return g.Bots[i]
}
}
return nil
}

func (g *GuildInfo) FindChannel(channelId uint64) *ChannelInfo {
for _, c := range g.Channels {
if c.ChannelId == channelId {
Expand Down Expand Up @@ -785,7 +766,7 @@ func decodeGuildPushFirstView(c *QQClient, _ *incomingPacketInfo, payload []byte
} else {
info.Channels = channels
}
info.Bots, info.Members, info.Admins, _ = c.GuildService.GetGuildMembers(info.GuildId)
// info.Bots, info.Members, info.Admins, _ = c.GuildService.GetGuildMembers(info.GuildId)
c.GuildService.Guilds = append(c.GuildService.Guilds, info)
}
}
Expand Down
4 changes: 3 additions & 1 deletion client/guild_eventflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,12 @@ func (c *QQClient) processGuildEventBody(m *channel.ChannelMsgContent, eventBody
NewChannelInfo: newInfo,
})
case eventBody.JoinGuild != nil:
/* 应该不会重复推送把, 不会吧不会吧
if mem := guild.FindMember(eventBody.JoinGuild.GetMemberTinyid()); mem != nil {
c.Info("ignore join guild event: member %v already exists", mem.TinyId)
return
}
*/
profile, err := c.GuildService.GetGuildMemberProfileInfo(guild.GuildId, eventBody.JoinGuild.GetMemberTinyid())
if err != nil {
c.Error("error to decode member join guild event: get member profile error: %v", err)
Expand All @@ -187,7 +189,7 @@ func (c *QQClient) processGuildEventBody(m *channel.ChannelMsgContent, eventBody
TinyId: profile.TinyId,
Nickname: profile.Nickname,
}
guild.Members = append(guild.Members, info)
// guild.Members = append(guild.Members, info)
c.dispatchMemberJoinedGuildEvent(&MemberJoinGuildEvent{
Guild: guild,
Member: info,
Expand Down

0 comments on commit a2e7548

Please sign in to comment.