mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 19:02:31 +08:00
update pin friend to update friend
This commit is contained in:
parent
e8c29272f8
commit
42a8d7e83c
5
go.mod
5
go.mod
@ -155,4 +155,7 @@ require (
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/OpenIMSDK/protocol v0.0.36 => github.com/AndrewZuo01/protocol v0.0.0-20231219031520-648989b91fca
|
||||
replace github.com/OpenIMSDK/protocol v0.0.36 => github.com/AndrewZuo01/protocol v0.0.0-20231220081029-2bda660f0e88
|
||||
|
||||
|
||||
|
||||
|
||||
@ -92,6 +92,6 @@ func (o *FriendApi) GetFriendIDs(c *gin.Context) {
|
||||
func (o *FriendApi) GetSpecifiedFriendsInfo(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.GetSpecifiedFriendsInfo, o.Client, c)
|
||||
}
|
||||
func (o *FriendApi) SetPinFriends(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.PinFriends, o.Client, c)
|
||||
func (o *FriendApi) UpdateFriends(c *gin.Context) {
|
||||
a2r.Call(friend.FriendClient.UpdateFriends, o.Client, c)
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
|
||||
friendRouterGroup.POST("/is_friend", f.IsFriend)
|
||||
friendRouterGroup.POST("/get_friend_id", f.GetFriendIDs)
|
||||
friendRouterGroup.POST("/get_specified_friends_info", f.GetSpecifiedFriendsInfo)
|
||||
friendRouterGroup.POST("/set_pin_friend", f.SetPinFriends)
|
||||
friendRouterGroup.POST("/update_friends", f.UpdateFriends)
|
||||
}
|
||||
g := NewGroupApi(*groupRpc)
|
||||
groupRouterGroup := r.Group("/group", ParseToken)
|
||||
|
||||
@ -436,35 +436,40 @@ func (s *friendServer) GetSpecifiedFriendsInfo(ctx context.Context, req *pbfrien
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
func (s *friendServer) PinFriends(
|
||||
func (s *friendServer) UpdateFriends(
|
||||
ctx context.Context,
|
||||
req *pbfriend.PinFriendsReq,
|
||||
) (*pbfriend.PinFriendsResp, error) {
|
||||
req *pbfriend.UpdateFriendsReq,
|
||||
) (*pbfriend.UpdateFriendsResp, error) {
|
||||
if len(req.FriendUserIDs) == 0 {
|
||||
return nil, errs.ErrArgs.Wrap("friendIDList is empty")
|
||||
}
|
||||
if utils.Duplicate(req.FriendUserIDs) {
|
||||
return nil, errs.ErrArgs.Wrap("friendIDList repeated")
|
||||
}
|
||||
var isPinned bool
|
||||
if req.IsPinned != nil {
|
||||
isPinned = req.IsPinned.Value
|
||||
} else {
|
||||
return nil, errs.ErrArgs.Wrap("isPinned is nil")
|
||||
}
|
||||
//check whther in friend list
|
||||
|
||||
_, err := s.friendDatabase.FindFriendsWithError(ctx, req.OwnerUserID, req.FriendUserIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//set friendslist friend pin status to isPinned
|
||||
for _, friendID := range req.FriendUserIDs {
|
||||
if err := s.friendDatabase.UpdateFriendPinStatus(ctx, req.OwnerUserID, friendID, isPinned); err != nil {
|
||||
return nil, err
|
||||
if req.IsPinned != nil {
|
||||
if err := s.friendDatabase.UpdateFriendPinStatus(ctx, req.OwnerUserID, friendID, req.IsPinned.Value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if req.Remark != nil {
|
||||
if err := s.friendDatabase.UpdateFriendRemark(ctx, req.OwnerUserID, friendID, req.Remark.Value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if req.Ex != nil {
|
||||
if err := s.friendDatabase.UpdateFriendEx(ctx, req.OwnerUserID, friendID, req.Ex.Value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resp := &pbfriend.PinFriendsResp{}
|
||||
resp := &pbfriend.UpdateFriendsResp{}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@ -1174,7 +1174,6 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbgroup.DismissGrou
|
||||
log.ZDebug(ctx, "debug", "???????????????????????????????", err)
|
||||
return nil, err
|
||||
}
|
||||
log.ZDebug(ctx, "debug", "continue", err)
|
||||
if !req.DeleteMember {
|
||||
num, err := s.db.FindGroupMemberNum(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
|
||||
@ -32,33 +32,56 @@ import (
|
||||
)
|
||||
|
||||
type FriendDatabase interface {
|
||||
// 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
// CheckIn checks if user2 is in user1's friend list (inUser1Friends==true) and if user1 is in user2's friend list (inUser2Friends==true)
|
||||
CheckIn(ctx context.Context, user1, user2 string) (inUser1Friends bool, inUser2Friends bool, err error)
|
||||
// 增加或者更新好友申请
|
||||
|
||||
// AddFriendRequest adds or updates a friend request
|
||||
AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error)
|
||||
// 先判断是否在好友表,如果在则不插入
|
||||
|
||||
// BecomeFriends first checks if the users are already in the friends table; if not, it inserts them as friends
|
||||
BecomeFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, addSource int32) (err error)
|
||||
// 拒绝好友申请
|
||||
|
||||
// RefuseFriendRequest refuses a friend request
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error)
|
||||
// 同意好友申请
|
||||
|
||||
// AgreeFriendRequest accepts a friend request
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error)
|
||||
// 删除好友
|
||||
|
||||
// Delete removes a friend or friends from the owner's friend list
|
||||
Delete(ctx context.Context, ownerUserID string, friendUserIDs []string) (err error)
|
||||
// 更新好友备注
|
||||
|
||||
// UpdateRemark updates the remark for a friend
|
||||
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||
// 获取ownerUserID的好友列表
|
||||
|
||||
// PageOwnerFriends retrieves the friend list of ownerUserID with pagination
|
||||
PageOwnerFriends(ctx context.Context, ownerUserID string, pagination pagination.Pagination) (total int64, friends []*relation.FriendModel, err error)
|
||||
// friendUserID在哪些人的好友列表中
|
||||
|
||||
// PageInWhoseFriends finds the users who have friendUserID in their friend list with pagination
|
||||
PageInWhoseFriends(ctx context.Context, friendUserID string, pagination pagination.Pagination) (total int64, friends []*relation.FriendModel, err error)
|
||||
// 获取我发出去的好友申请
|
||||
|
||||
// PageFriendRequestFromMe retrieves the friend requests sent by the user with pagination
|
||||
PageFriendRequestFromMe(ctx context.Context, userID string, pagination pagination.Pagination) (total int64, friends []*relation.FriendRequestModel, err error)
|
||||
// 获取我收到的的好友申请
|
||||
|
||||
// PageFriendRequestToMe retrieves the friend requests received by the user with pagination
|
||||
PageFriendRequestToMe(ctx context.Context, userID string, pagination pagination.Pagination) (total int64, friends []*relation.FriendRequestModel, err error)
|
||||
// 获取某人指定好友的信息
|
||||
|
||||
// FindFriendsWithError fetches specified friends of a user and returns an error if any do not exist
|
||||
FindFriendsWithError(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.FriendModel, err error)
|
||||
|
||||
// FindFriendUserIDs retrieves the friend IDs of a user
|
||||
FindFriendUserIDs(ctx context.Context, ownerUserID string) (friendUserIDs []string, err error)
|
||||
|
||||
// FindBothFriendRequests finds friend requests sent and received
|
||||
FindBothFriendRequests(ctx context.Context, fromUserID, toUserID string) (friends []*relation.FriendRequestModel, err error)
|
||||
|
||||
// UpdateFriendPinStatus updates the pinned status of a friend
|
||||
UpdateFriendPinStatus(ctx context.Context, ownerUserID string, friendUserID string, isPinned bool) (err error)
|
||||
|
||||
// UpdateFriendRemark updates the remark for a friend
|
||||
UpdateFriendRemark(ctx context.Context, ownerUserID string, friendUserID string, remark string) (err error)
|
||||
|
||||
// UpdateFriendEx updates the 'ex' field for a friend
|
||||
UpdateFriendEx(ctx context.Context, ownerUserID string, friendUserID string, ex string) (err error)
|
||||
}
|
||||
|
||||
type friendDatabase struct {
|
||||
@ -305,3 +328,15 @@ func (f *friendDatabase) UpdateFriendPinStatus(ctx context.Context, ownerUserID
|
||||
}
|
||||
return f.cache.DelFriend(ownerUserID, friendUserID).ExecDel(ctx)
|
||||
}
|
||||
func (f *friendDatabase) UpdateFriendRemark(ctx context.Context, ownerUserID string, friendUserID string, remark string) (err error) {
|
||||
if err := f.friend.UpdateFriendRemark(ctx, ownerUserID, friendUserID, remark); err != nil {
|
||||
return err
|
||||
}
|
||||
return f.cache.DelFriend(ownerUserID, friendUserID).ExecDel(ctx)
|
||||
}
|
||||
func (f *friendDatabase) UpdateFriendEx(ctx context.Context, ownerUserID string, friendUserID string, ex string) (err error) {
|
||||
if err := f.friend.UpdateFriendEx(ctx, ownerUserID, friendUserID, ex); err != nil {
|
||||
return err
|
||||
}
|
||||
return f.cache.DelFriend(ownerUserID, friendUserID).ExecDel(ctx)
|
||||
}
|
||||
|
||||
@ -160,3 +160,33 @@ func (f *FriendMgo) UpdatePinStatus(ctx context.Context, ownerUserID string, fri
|
||||
|
||||
return nil
|
||||
}
|
||||
func (f *FriendMgo) UpdateFriendRemark(ctx context.Context, ownerUserID string, friendUserID string, remark string) (err error) {
|
||||
|
||||
filter := bson.M{"owner_user_id": ownerUserID, "friend_user_id": friendUserID}
|
||||
// Create an update operation to set the "is_pinned" field to isPinned for all documents.
|
||||
update := bson.M{"$set": bson.M{"remark": remark}}
|
||||
|
||||
// Perform the update operation for all documents in the collection.
|
||||
_, err = f.coll.UpdateMany(ctx, filter, update)
|
||||
|
||||
if err != nil {
|
||||
return errs.Wrap(err, "update remark error")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
func (f *FriendMgo) UpdateFriendEx(ctx context.Context, ownerUserID string, friendUserID string, ex string) (err error) {
|
||||
|
||||
filter := bson.M{"owner_user_id": ownerUserID, "friend_user_id": friendUserID}
|
||||
// Create an update operation to set the "is_pinned" field to isPinned for all documents.
|
||||
update := bson.M{"$set": bson.M{"ex": ex}}
|
||||
|
||||
// Perform the update operation for all documents in the collection.
|
||||
_, err = f.coll.UpdateMany(ctx, filter, update)
|
||||
|
||||
if err != nil {
|
||||
return errs.Wrap(err, "update ex error")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -59,4 +59,8 @@ type FriendModelInterface interface {
|
||||
FindFriendUserIDs(ctx context.Context, ownerUserID string) (friendUserIDs []string, err error)
|
||||
// UpdatePinStatus update friend's pin status
|
||||
UpdatePinStatus(ctx context.Context, ownerUserID string, friendUserID string, isPinned bool) (err error)
|
||||
// UpdateFriendRemark update friend's remark
|
||||
UpdateFriendRemark(ctx context.Context, ownerUserID string, friendUserID string, remark string) (err error)
|
||||
// UpdateFriendEx update friend's ex
|
||||
UpdateFriendEx(ctx context.Context, ownerUserID string, friendUserID string, ex string) (err error)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user