fix: fix scripts and rea

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
pull/1546/head
Xinwei Xiong(cubxxw) 2 years ago
parent d39a961a29
commit 85d0093b79

@ -16,14 +16,12 @@ package msg
import (
"context"
cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
utils2 "github.com/OpenIMSDK/tools/utils"
"github.com/redis/go-redis/v9"
cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
"github.com/OpenIMSDK/protocol/constant"
"github.com/OpenIMSDK/protocol/conversation"
"github.com/OpenIMSDK/protocol/msg"
"github.com/OpenIMSDK/protocol/sdkws"
"github.com/OpenIMSDK/tools/errs"
@ -92,7 +90,10 @@ func (m *msgServer) SetConversationHasReadSeq(
return &msg.SetConversationHasReadSeqResp{}, nil
}
func (m *msgServer) MarkMsgsAsRead(ctx context.Context, req *msg.MarkMsgsAsReadReq) (resp *msg.MarkMsgsAsReadResp, err error) {
func (m *msgServer) MarkMsgsAsRead(
ctx context.Context,
req *msg.MarkMsgsAsReadReq,
) (resp *msg.MarkMsgsAsReadResp, err error) {
if len(req.Seqs) < 1 {
return nil, errs.ErrArgs.Wrap("seqs must not be empty")
}
@ -111,6 +112,7 @@ func (m *msgServer) MarkMsgsAsRead(ctx context.Context, req *msg.MarkMsgsAsReadR
if err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, req.Seqs); err != nil {
return
}
currentHasReadSeq, err := m.MsgDatabase.GetHasReadSeq(ctx, req.UserID, req.ConversationID)
if err != nil && errs.Unwrap(err) != redis.Nil {
return
@ -128,7 +130,10 @@ func (m *msgServer) MarkMsgsAsRead(ctx context.Context, req *msg.MarkMsgsAsReadR
return &msg.MarkMsgsAsReadResp{}, nil
}
func (m *msgServer) MarkConversationAsRead(ctx context.Context, req *msg.MarkConversationAsReadReq) (resp *msg.MarkConversationAsReadResp, err error) {
func (m *msgServer) MarkConversationAsRead(
ctx context.Context,
req *msg.MarkConversationAsReadReq,
) (resp *msg.MarkConversationAsReadResp, err error) {
conversation, err := m.Conversation.GetConversation(ctx, req.UserID, req.ConversationID)
if err != nil {
return nil, err
@ -137,34 +142,54 @@ func (m *msgServer) MarkConversationAsRead(ctx context.Context, req *msg.MarkCon
if err != nil && errs.Unwrap(err) != redis.Nil {
return nil, err
}
seqs := generateSeqs(hasReadSeq, req)
var seqs []int64
if len(seqs) > 0 || req.HasReadSeq > hasReadSeq {
err = m.updateReadStatus(ctx, req, conversation, seqs, hasReadSeq)
if err != nil {
log.ZDebug(ctx, "MarkConversationAsRead", "hasReadSeq", hasReadSeq,
"req.HasReadSeq", req.HasReadSeq)
if conversation.ConversationType == constant.SingleChatType {
for i := hasReadSeq + 1; i <= req.HasReadSeq; i++ {
seqs = append(seqs, i)
}
//avoid client missed call MarkConversationMessageAsRead by order
for _, val := range req.Seqs {
if !utils2.Contain(val, seqs...) {
seqs = append(seqs, val)
}
}
if len(seqs) > 0 {
log.ZDebug(ctx, "MarkConversationAsRead", "seqs", seqs, "conversationID", req.ConversationID)
if err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, seqs); err != nil {
return nil, err
}
}
if req.HasReadSeq > hasReadSeq {
err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq)
if err != nil {
return nil, err
}
hasReadSeq = req.HasReadSeq
}
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID,
m.conversationAndGetRecvID(conversation, req.UserID), seqs, hasReadSeq); err != nil {
return nil, err
}
}
return &msg.MarkConversationAsReadResp{}, nil
}
func generateSeqs(hasReadSeq int64, req *msg.MarkConversationAsReadReq) []int64 {
var seqs []int64
for _, val := range req.Seqs {
if val > hasReadSeq && !utils2.Contain(val, seqs...) {
seqs = append(seqs, val)
} else if conversation.ConversationType == constant.SuperGroupChatType ||
conversation.ConversationType == constant.NotificationChatType {
if req.HasReadSeq > hasReadSeq {
err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq)
if err != nil {
return nil, err
}
hasReadSeq = req.HasReadSeq
}
}
return seqs
}
func (m *msgServer) updateReadStatus(ctx context.Context, req *msg.MarkConversationAsReadReq, conversation *conversation.Conversation, seqs []int64, hasReadSeq int64) error {
if conversation.ConversationType == constant.SingleChatType && len(seqs) > 0 {
log.ZDebug(ctx, "MarkConversationAsRead", "seqs", seqs, "conversationID", req.ConversationID)
if err := m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, seqs); err != nil {
return err
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, constant.SingleChatType, req.UserID,
req.UserID, seqs, hasReadSeq); err != nil {
return nil, err
}
}
reqCall := &cbapi.CallbackGroupMsgReadReq{
SendID: conversation.OwnerUserID,
ReceiveID: req.UserID,
@ -172,21 +197,10 @@ func (m *msgServer) updateReadStatus(ctx context.Context, req *msg.MarkConversat
ContentType: int64(conversation.ConversationType),
}
if err := CallbackGroupMsgRead(ctx, reqCall); err != nil {
return err
}
if req.HasReadSeq > hasReadSeq {
if err := m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq); err != nil {
return err
}
}
recvID := m.conversationAndGetRecvID(conversation, req.UserID)
if conversation.ConversationType == constant.SuperGroupChatType || conversation.ConversationType == constant.NotificationChatType {
recvID = req.UserID
return nil, err
}
return m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID, recvID, seqs, req.HasReadSeq)
return &msg.MarkConversationAsReadResp{}, nil
}
func (m *msgServer) sendMarkAsReadNotification(

@ -24,10 +24,8 @@ OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"
# (en: Define a profile array that contains the name path of the profile to be generated.)
readonly ENV_FILE=${ENV_FILE:-"${OPENIM_ROOT}/scripts/install/environment.sh"}
# (en: Defines an associative array where the keys are the template files and the values are the corresponding output files.)
declare -A TEMPLATES=(
["${OPENIM_ROOT}/deployments/templates/env-template.yaml"]="${OPENIM_ROOT}/.env"
["${OPENIM_ROOT}/deployments/templates/openim.yaml"]="${OPENIM_ROOT}/config/config.yaml"
@ -37,6 +35,42 @@ declare -A TEMPLATES=(
openim::log::info "Read more configuration information: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/environment.md"
# New variables for argument handling
FORCE_OVERWRITE=false
SKIP_EXISTING=false
# Function to display help
show_help() {
echo "Usage: $(basename "$0") [options]"
echo "Options:"
echo " -h, --help Show this help message"
echo " --force Overwrite existing files without prompt"
echo " --skip Skip generation if file exists"
}
# Parse command-line options
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
show_help
exit 0
;;
--force)
FORCE_OVERWRITE=true
shift
;;
--skip)
SKIP_EXISTING=true
shift
;;
*)
echo "Unknown option: $1"
show_help
exit 1
;;
esac
done
for template in "${!TEMPLATES[@]}"; do
if [[ ! -f "${template}" ]]; then
openim::log::error_exit "Template file ${template} does not exist..."
@ -48,14 +82,19 @@ for template in "${!TEMPLATES[@]}"; do
IFS=';' read -ra OUTPUT_FILES <<< "${TEMPLATES[$template]}"
for output_file in "${OUTPUT_FILES[@]}"; do
if [[ -f "${output_file}" ]]; then
echo -n "File ${output_file} already exists. Overwrite? (Y/N): "
read -r -n 1 REPLY
echo # Adds a line to wrap after user input
if [[ $REPLY =~ ^[Yy]$ ]]; then
openim::log::info "Overwriting ${output_file}. Previous configuration will be lost."
else
openim::log::info "Skipping generation of ${output_file}."
if [[ "${FORCE_OVERWRITE}" == true ]]; then
openim::log::info "Force overwriting ${output_file}."
elif [[ "${SKIP_EXISTING}" == true ]]; then
openim::log::info "Skipping generation of ${output_file} as it already exists."
continue
else
echo -n "File ${output_file} already exists. Overwrite? (Y/N): "
read -r -n 1 REPLY
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
openim::log::info "Skipping generation of ${output_file}."
continue
fi
fi
fi
@ -72,5 +111,4 @@ for template in "${!TEMPLATES[@]}"; do
done
done
openim::log::success "✨ All configuration files have been successfully generated!"

Loading…
Cancel
Save