[feat]: 添加联系人去重和排序 (#201)
This commit is contained in:
parent
f8461401a7
commit
0f10aa4508
31
relations.go
31
relations.go
@ -103,6 +103,16 @@ func (f Friends) AsMembers() Members {
|
||||
return members
|
||||
}
|
||||
|
||||
// Sort 对好友进行排序
|
||||
func (f Friends) Sort() Friends {
|
||||
return f.AsMembers().Sort().Friends()
|
||||
}
|
||||
|
||||
// Uniq 对好友进行去重
|
||||
func (f Friends) Uniq() Friends {
|
||||
return f.AsMembers().Uniq().Friends()
|
||||
}
|
||||
|
||||
// SendText 向slice的好友依次发送文本消息
|
||||
func (f Friends) SendText(text string, delays ...time.Duration) error {
|
||||
if f.Count() == 0 {
|
||||
@ -180,6 +190,7 @@ func (g *Group) Members() (Members, error) {
|
||||
|
||||
// AddFriendsIn 拉好友入群
|
||||
func (g *Group) AddFriendsIn(friends ...*Friend) error {
|
||||
friends = Friends(friends).Uniq()
|
||||
return g.self.AddFriendsIntoGroup(g, friends...)
|
||||
}
|
||||
|
||||
@ -316,6 +327,16 @@ func (g Groups) AsMembers() Members {
|
||||
return members
|
||||
}
|
||||
|
||||
// Sort 对群组进行排序
|
||||
func (g Groups) Sort() Groups {
|
||||
return g.AsMembers().Sort().Groups()
|
||||
}
|
||||
|
||||
// Uniq 对群组进行去重
|
||||
func (g Groups) Uniq() Groups {
|
||||
return g.AsMembers().Uniq().Groups()
|
||||
}
|
||||
|
||||
// Mp 公众号对象
|
||||
type Mp struct{ *User }
|
||||
|
||||
@ -369,6 +390,16 @@ func (m Mps) AsMembers() Members {
|
||||
return members
|
||||
}
|
||||
|
||||
// Sort 对公众号进行排序
|
||||
func (m Mps) Sort() Mps {
|
||||
return m.AsMembers().Sort().MPs()
|
||||
}
|
||||
|
||||
// Uniq 对公众号进行去重
|
||||
func (m Mps) Uniq() Mps {
|
||||
return m.AsMembers().Uniq().MPs()
|
||||
}
|
||||
|
||||
// SearchByUserName 根据用户名查找
|
||||
func (m Mps) SearchByUserName(limit int, userName string) (results Mps) {
|
||||
return m.Search(limit, func(group *Mp) bool { return group.UserName == userName })
|
||||
|
3
user.go
3
user.go
@ -394,6 +394,7 @@ func (s *Self) SetRemarkNameToFriend(friend *Friend, remarkName string) error {
|
||||
// topic 群昵称,可以传递字符串
|
||||
// friends 群员,最少为2个,加上自己3个,三人才能成群
|
||||
func (s *Self) CreateGroup(topic string, friends ...*Friend) (*Group, error) {
|
||||
friends = Friends(friends).Uniq()
|
||||
if len(friends) < 2 {
|
||||
return nil, errors.New("a group must be at least 2 members")
|
||||
}
|
||||
@ -414,6 +415,7 @@ func (s *Self) AddFriendsIntoGroup(group *Group, friends ...*Friend) error {
|
||||
if len(friends) == 0 {
|
||||
return nil
|
||||
}
|
||||
friends = Friends(friends).Uniq()
|
||||
// 获取群的所有的群员
|
||||
groupMembers, err := group.Members()
|
||||
if err != nil {
|
||||
@ -466,6 +468,7 @@ func (s *Self) RemoveMemberFromGroup(group *Group, members Members) error {
|
||||
// AddFriendIntoManyGroups 拉好友进多个群聊
|
||||
// AddFriendIntoGroups, 名字和上面的有点像
|
||||
func (s *Self) AddFriendIntoManyGroups(friend *Friend, groups ...*Group) error {
|
||||
groups = Groups(groups).Uniq()
|
||||
for _, group := range groups {
|
||||
if err := s.AddFriendsIntoGroup(group, friend); err != nil {
|
||||
return err
|
||||
|
Loading…
x
Reference in New Issue
Block a user