mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-15 14:35:57 +08:00
update usercommand and fix callback (#1681)
* update set pin friends * update set pin friends * update set pin friends * update set pin friends * update set pin friends * update set pin friends * fix bugs * fix bugs * debug * debug * debug * debug * debug * debug * debug * debug * debug * debug * debug * debug * Update go.mod * Update friend.go * debug * debug * debug * add pin friend test * add pin friend test * add pin friend test * add pin friend test * add pin friend test * add pin friend test * add pin friend test * add pin friend test * add pin friend test * I cannot solve todo in test.sh * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * update user command * Update go.mod * fix group notification * fix group notification * update openimsdk tools * update openim server remove duplicate code * update openim server remove duplicate code * update user command get * update user command get * update response of callback response error * update black ex * update join group ex * update user pb2map * update go sum * update go sum * update updateUserInfoEx * update updateUserInfoEx * update updateUserInfoEx add callback functions * fix dismiss group function * fix dismiss group function * fix dismiss group function * fix dismiss group function * update pin friend to update friend * fix go mod * fix err golangci-lint * fix UserPb2DBMap * update comments, update go.mod check for register username * update comments, update go.mod check for register username * update comments, update go.mod check for register username * update comments, update go.mod check for register username * fix callback * fix go.mod * fix debug * fix bugs * update notification * update notification * update notification * update notification * update notification * update notification * update notification * update notification * fix updateUserInfoEx * fix updateUserInfoEx * modify go.mod * fix updateUserInfoEx * fix updateUserInfoEx * fix updateUserInfoEx * update user command notification * update user command get all notification * update user command get all notification * fix type = 0 * fix type = 0 * fix type = 0 * fix type = 0 * fix type = 0 * fix type = 0 * fix typing cause callback * add ex to usercommand * add ex to usercommand * update updatefriends * fix updatefriend map * fix updatefriend FriendsInfoUpdateNotification * fix push online and offline user, but why typing trigger callback push? * fix push online and offline user, but why typing trigger callback push? * update user command record not found and user access check * update user command get all user access check * update go.mod * fix callback name and place * upadtae callback test * fix callback typing * fix callback typing * fix callback typing * fix callback typing * fix lint on processusercommand --------- Co-authored-by: Xinwei Xiong <3293172751@qq.com>
This commit is contained in:
+14
-42
@@ -16,7 +16,6 @@ package mgo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
"github.com/OpenIMSDK/tools/mgoutil"
|
||||
"github.com/OpenIMSDK/tools/pagination"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
@@ -144,49 +143,22 @@ func (f *FriendMgo) FindFriendUserIDs(ctx context.Context, ownerUserID string) (
|
||||
return mgoutil.Find[string](ctx, f.coll, filter, options.Find().SetProjection(bson.M{"_id": 0, "friend_user_id": 1}))
|
||||
}
|
||||
|
||||
// UpdatePinStatus update friend's pin status
|
||||
func (f *FriendMgo) UpdatePinStatus(ctx context.Context, ownerUserID string, friendUserID string, isPinned bool) (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{"is_pinned": isPinned}}
|
||||
|
||||
// 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 pin error")
|
||||
func (f *FriendMgo) UpdateFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, val map[string]any) error {
|
||||
// Ensure there are IDs to update
|
||||
if len(friendUserIDs) == 0 {
|
||||
return nil // Or return an error if you expect there to always be IDs
|
||||
}
|
||||
|
||||
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")
|
||||
// Create a filter to match documents with the specified ownerUserID and any of the friendUserIDs
|
||||
filter := bson.M{
|
||||
"owner_user_id": ownerUserID,
|
||||
"friend_user_id": bson.M{"$in": friendUserIDs},
|
||||
}
|
||||
|
||||
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
|
||||
// Create an update document
|
||||
update := bson.M{"$set": val}
|
||||
|
||||
// Perform the update operation for all matching documents
|
||||
_, err := mgoutil.UpdateMany(ctx, f.coll, filter, update)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package mgo
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/protocol/user"
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
"time"
|
||||
|
||||
"github.com/OpenIMSDK/tools/mgoutil"
|
||||
@@ -100,7 +101,7 @@ func (u *UserMgo) CountTotal(ctx context.Context, before *time.Time) (count int6
|
||||
return mgoutil.Count(ctx, u.coll, bson.M{"create_time": bson.M{"$lt": before}})
|
||||
}
|
||||
|
||||
func (u *UserMgo) AddUserCommand(ctx context.Context, userID string, Type int32, UUID string, value string) error {
|
||||
func (u *UserMgo) AddUserCommand(ctx context.Context, userID string, Type int32, UUID string, value string, ex string) error {
|
||||
collection := u.coll.Database().Collection("userCommands")
|
||||
|
||||
// Create a new document instead of updating an existing one
|
||||
@@ -110,28 +111,48 @@ func (u *UserMgo) AddUserCommand(ctx context.Context, userID string, Type int32,
|
||||
"uuid": UUID,
|
||||
"createTime": time.Now().Unix(), // assuming you want the creation time in Unix timestamp
|
||||
"value": value,
|
||||
"ex": ex,
|
||||
}
|
||||
|
||||
_, err := collection.InsertOne(ctx, doc)
|
||||
return err
|
||||
}
|
||||
|
||||
func (u *UserMgo) DeleteUserCommand(ctx context.Context, userID string, Type int32, UUID string) error {
|
||||
collection := u.coll.Database().Collection("userCommands")
|
||||
|
||||
filter := bson.M{"userID": userID, "type": Type, "uuid": UUID}
|
||||
|
||||
_, err := collection.DeleteOne(ctx, filter)
|
||||
result, err := collection.DeleteOne(ctx, filter)
|
||||
if result.DeletedCount == 0 {
|
||||
// No records found to update
|
||||
return errs.Wrap(errs.ErrRecordNotFound)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func (u *UserMgo) UpdateUserCommand(ctx context.Context, userID string, Type int32, UUID string, value string) error {
|
||||
func (u *UserMgo) UpdateUserCommand(ctx context.Context, userID string, Type int32, UUID string, val map[string]any) error {
|
||||
if len(val) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
collection := u.coll.Database().Collection("userCommands")
|
||||
|
||||
filter := bson.M{"userID": userID, "type": Type, "uuid": UUID}
|
||||
update := bson.M{"$set": bson.M{"value": value}}
|
||||
update := bson.M{"$set": val}
|
||||
|
||||
_, err := collection.UpdateOne(ctx, filter, update)
|
||||
return err
|
||||
result, err := collection.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if result.MatchedCount == 0 {
|
||||
// No records found to update
|
||||
return errs.Wrap(errs.ErrRecordNotFound)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UserMgo) GetUserCommand(ctx context.Context, userID string, Type int32) ([]*user.CommandInfoResp, error) {
|
||||
collection := u.coll.Database().Collection("userCommands")
|
||||
filter := bson.M{"userID": userID, "type": Type}
|
||||
@@ -147,19 +168,23 @@ func (u *UserMgo) GetUserCommand(ctx context.Context, userID string, Type int32)
|
||||
|
||||
for cursor.Next(ctx) {
|
||||
var document struct {
|
||||
Type int32 `bson:"type"`
|
||||
UUID string `bson:"uuid"`
|
||||
Value string `bson:"value"`
|
||||
CreateTime int64 `bson:"createTime"`
|
||||
Ex string `bson:"ex"`
|
||||
}
|
||||
|
||||
if err := cursor.Decode(&document); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
commandInfo := &user.CommandInfoResp{ // Change here: use a pointer to the struct
|
||||
commandInfo := &user.CommandInfoResp{
|
||||
Type: document.Type,
|
||||
Uuid: document.UUID,
|
||||
Value: document.Value,
|
||||
CreateTime: document.CreateTime,
|
||||
Ex: document.Ex,
|
||||
}
|
||||
|
||||
commands = append(commands, commandInfo)
|
||||
@@ -171,7 +196,48 @@ func (u *UserMgo) GetUserCommand(ctx context.Context, userID string, Type int32)
|
||||
|
||||
return commands, nil
|
||||
}
|
||||
func (u *UserMgo) GetAllUserCommand(ctx context.Context, userID string) ([]*user.AllCommandInfoResp, error) {
|
||||
collection := u.coll.Database().Collection("userCommands")
|
||||
filter := bson.M{"userID": userID}
|
||||
|
||||
cursor, err := collection.Find(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cursor.Close(ctx)
|
||||
|
||||
// Initialize commands as a slice of pointers
|
||||
commands := []*user.AllCommandInfoResp{}
|
||||
|
||||
for cursor.Next(ctx) {
|
||||
var document struct {
|
||||
Type int32 `bson:"type"`
|
||||
UUID string `bson:"uuid"`
|
||||
Value string `bson:"value"`
|
||||
CreateTime int64 `bson:"createTime"`
|
||||
Ex string `bson:"ex"`
|
||||
}
|
||||
|
||||
if err := cursor.Decode(&document); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
commandInfo := &user.AllCommandInfoResp{
|
||||
Type: document.Type,
|
||||
Uuid: document.UUID,
|
||||
Value: document.Value,
|
||||
CreateTime: document.CreateTime,
|
||||
Ex: document.Ex,
|
||||
}
|
||||
|
||||
commands = append(commands, commandInfo)
|
||||
}
|
||||
|
||||
if err := cursor.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return commands, nil
|
||||
}
|
||||
func (u *UserMgo) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) {
|
||||
pipeline := bson.A{
|
||||
bson.M{
|
||||
|
||||
Reference in New Issue
Block a user