Files
open-im-server/internal/rpc/msg/pull_message.go
T

75 lines
2.4 KiB
Go
Raw Normal View History

2021-12-23 17:34:32 +08:00
package msg
2021-05-26 19:40:38 +08:00
import (
"context"
2021-09-13 15:48:19 +08:00
"github.com/garyburd/redigo/redis"
2021-05-26 19:40:38 +08:00
commonDB "Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
2021-10-11 22:00:38 +08:00
pbMsg "Open_IM/pkg/proto/chat"
2022-01-20 11:36:43 +08:00
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
2021-05-26 19:40:38 +08:00
)
func (rpc *rpcChat) GetMaxAndMinSeq(_ context.Context, in *pbMsg.GetMaxAndMinSeqReq) (*pbMsg.GetMaxAndMinSeqResp, error) {
2022-05-10 09:09:37 +08:00
log.NewInfo(in.OperationID, "rpc getMaxAndMinSeq is arriving", in.String())
2021-05-26 19:40:38 +08:00
//seq, err := model.GetBiggestSeqFromReceive(in.UserID)
maxSeq, err1 := commonDB.DB.GetUserMaxSeq(in.UserID)
minSeq, err2 := commonDB.DB.GetUserMinSeq(in.UserID)
resp := new(pbMsg.GetMaxAndMinSeqResp)
if err1 == nil {
2022-01-20 11:36:43 +08:00
resp.MaxSeq = uint32(maxSeq)
} else if err1 == redis.ErrNil {
resp.MaxSeq = 0
2021-05-26 19:40:38 +08:00
} else {
log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err1.Error())
resp.ErrCode = 200
resp.ErrMsg = "redis get err"
2021-05-26 19:40:38 +08:00
}
if err2 == nil {
2022-01-20 11:36:43 +08:00
resp.MinSeq = uint32(minSeq)
} else if err2 == redis.ErrNil {
resp.MinSeq = 0
} else {
log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err2.Error())
resp.ErrCode = 201
resp.ErrMsg = "redis get err"
}
return resp, nil
2021-05-26 19:40:38 +08:00
}
2021-12-23 17:34:32 +08:00
func (rpc *rpcChat) PullMessageBySeqList(_ context.Context, in *open_im_sdk.PullMessageBySeqListReq) (*open_im_sdk.PullMessageBySeqListResp, error) {
log.NewInfo(in.OperationID, "rpc PullMessageBySeqList is arriving", in.String())
2021-12-23 17:34:32 +08:00
resp := new(open_im_sdk.PullMessageBySeqListResp)
2022-02-23 12:00:02 +08:00
//msgList, err := commonDB.DB.GetMsgBySeqList(in.UserID, in.SeqList, in.OperationID)
msgList, err := commonDB.DB.GetMsgBySeqListMongo2(in.UserID, in.SeqList, in.OperationID)
if err != nil {
2022-05-10 10:52:32 +08:00
log.Error(in.OperationID, "PullMessageBySeqList data error", in.String(), err.Error())
2022-01-20 18:36:30 +08:00
resp.ErrCode = 201
resp.ErrMsg = err.Error()
return resp, nil
}
2022-01-20 11:36:43 +08:00
//respSingleMsgFormat = singleMsgHandleByUser(SingleMsgFormat, in.UserID)
//respGroupMsgFormat = groupMsgHandleByUser(GroupMsgFormat)
resp.ErrCode = 0
resp.ErrMsg = ""
resp.List = msgList
return resp, nil
2021-05-26 19:40:38 +08:00
}
2021-12-23 17:34:32 +08:00
type MsgFormats []*open_im_sdk.MsgData
2021-05-26 19:40:38 +08:00
2021-05-31 10:03:57 +08:00
// Implement the sort.Interface interface to get the number of elements method
2021-05-26 19:40:38 +08:00
func (s MsgFormats) Len() int {
return len(s)
}
2021-05-31 10:03:57 +08:00
//Implement the sort.Interface interface comparison element method
2021-05-26 19:40:38 +08:00
func (s MsgFormats) Less(i, j int) bool {
return s[i].SendTime < s[j].SendTime
}
2021-05-31 10:03:57 +08:00
//Implement the sort.Interface interface exchange element method
2021-05-26 19:40:38 +08:00
func (s MsgFormats) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}