mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-06 04:27:05 +08:00
fix: fix scripts and rea
Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
This commit is contained in:
parent
d39a961a29
commit
85d0093b79
@ -16,14 +16,12 @@ package msg
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
|
|
||||||
|
|
||||||
utils2 "github.com/OpenIMSDK/tools/utils"
|
utils2 "github.com/OpenIMSDK/tools/utils"
|
||||||
|
|
||||||
"github.com/redis/go-redis/v9"
|
"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/constant"
|
||||||
"github.com/OpenIMSDK/protocol/conversation"
|
|
||||||
"github.com/OpenIMSDK/protocol/msg"
|
"github.com/OpenIMSDK/protocol/msg"
|
||||||
"github.com/OpenIMSDK/protocol/sdkws"
|
"github.com/OpenIMSDK/protocol/sdkws"
|
||||||
"github.com/OpenIMSDK/tools/errs"
|
"github.com/OpenIMSDK/tools/errs"
|
||||||
@ -92,7 +90,10 @@ func (m *msgServer) SetConversationHasReadSeq(
|
|||||||
return &msg.SetConversationHasReadSeqResp{}, nil
|
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 {
|
if len(req.Seqs) < 1 {
|
||||||
return nil, errs.ErrArgs.Wrap("seqs must not be empty")
|
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 {
|
if err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, req.Seqs); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
currentHasReadSeq, err := m.MsgDatabase.GetHasReadSeq(ctx, req.UserID, req.ConversationID)
|
currentHasReadSeq, err := m.MsgDatabase.GetHasReadSeq(ctx, req.UserID, req.ConversationID)
|
||||||
if err != nil && errs.Unwrap(err) != redis.Nil {
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
||||||
return
|
return
|
||||||
@ -128,7 +130,10 @@ func (m *msgServer) MarkMsgsAsRead(ctx context.Context, req *msg.MarkMsgsAsReadR
|
|||||||
return &msg.MarkMsgsAsReadResp{}, nil
|
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)
|
conversation, err := m.Conversation.GetConversation(ctx, req.UserID, req.ConversationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if err != nil && errs.Unwrap(err) != redis.Nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
seqs := generateSeqs(hasReadSeq, req)
|
|
||||||
|
|
||||||
if len(seqs) > 0 || req.HasReadSeq > hasReadSeq {
|
|
||||||
err = m.updateReadStatus(ctx, req, conversation, seqs, hasReadSeq)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return &msg.MarkConversationAsReadResp{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateSeqs(hasReadSeq int64, req *msg.MarkConversationAsReadReq) []int64 {
|
|
||||||
var seqs []int64
|
var seqs []int64
|
||||||
|
|
||||||
|
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 {
|
for _, val := range req.Seqs {
|
||||||
if val > hasReadSeq && !utils2.Contain(val, seqs...) {
|
if !utils2.Contain(val, seqs...) {
|
||||||
seqs = append(seqs, val)
|
seqs = append(seqs, val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return seqs
|
if len(seqs) > 0 {
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
log.ZDebug(ctx, "MarkConversationAsRead", "seqs", seqs, "conversationID", req.ConversationID)
|
||||||
if err := m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, seqs); err != nil {
|
if err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, seqs); err != nil {
|
||||||
return err
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
} 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
|
||||||
|
}
|
||||||
|
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, constant.SingleChatType, req.UserID,
|
||||||
|
req.UserID, seqs, hasReadSeq); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
reqCall := &cbapi.CallbackGroupMsgReadReq{
|
reqCall := &cbapi.CallbackGroupMsgReadReq{
|
||||||
SendID: conversation.OwnerUserID,
|
SendID: conversation.OwnerUserID,
|
||||||
ReceiveID: req.UserID,
|
ReceiveID: req.UserID,
|
||||||
@ -172,21 +197,10 @@ func (m *msgServer) updateReadStatus(ctx context.Context, req *msg.MarkConversat
|
|||||||
ContentType: int64(conversation.ConversationType),
|
ContentType: int64(conversation.ConversationType),
|
||||||
}
|
}
|
||||||
if err := CallbackGroupMsgRead(ctx, reqCall); err != nil {
|
if err := CallbackGroupMsgRead(ctx, reqCall); err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.HasReadSeq > hasReadSeq {
|
return &msg.MarkConversationAsReadResp{}, nil
|
||||||
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 m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID, recvID, seqs, req.HasReadSeq)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *msgServer) sendMarkAsReadNotification(
|
func (m *msgServer) sendMarkAsReadNotification(
|
||||||
|
|||||||
@ -24,10 +24,8 @@ OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
|||||||
|
|
||||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
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"}
|
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=(
|
declare -A TEMPLATES=(
|
||||||
["${OPENIM_ROOT}/deployments/templates/env-template.yaml"]="${OPENIM_ROOT}/.env"
|
["${OPENIM_ROOT}/deployments/templates/env-template.yaml"]="${OPENIM_ROOT}/.env"
|
||||||
["${OPENIM_ROOT}/deployments/templates/openim.yaml"]="${OPENIM_ROOT}/config/config.yaml"
|
["${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"
|
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
|
for template in "${!TEMPLATES[@]}"; do
|
||||||
if [[ ! -f "${template}" ]]; then
|
if [[ ! -f "${template}" ]]; then
|
||||||
openim::log::error_exit "Template file ${template} does not exist..."
|
openim::log::error_exit "Template file ${template} does not exist..."
|
||||||
@ -48,16 +82,21 @@ for template in "${!TEMPLATES[@]}"; do
|
|||||||
IFS=';' read -ra OUTPUT_FILES <<< "${TEMPLATES[$template]}"
|
IFS=';' read -ra OUTPUT_FILES <<< "${TEMPLATES[$template]}"
|
||||||
for output_file in "${OUTPUT_FILES[@]}"; do
|
for output_file in "${OUTPUT_FILES[@]}"; do
|
||||||
if [[ -f "${output_file}" ]]; then
|
if [[ -f "${output_file}" ]]; then
|
||||||
|
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): "
|
echo -n "File ${output_file} already exists. Overwrite? (Y/N): "
|
||||||
read -r -n 1 REPLY
|
read -r -n 1 REPLY
|
||||||
echo # Adds a line to wrap after user input
|
echo
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||||
openim::log::info "Overwriting ${output_file}. Previous configuration will be lost."
|
|
||||||
else
|
|
||||||
openim::log::info "Skipping generation of ${output_file}."
|
openim::log::info "Skipping generation of ${output_file}."
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
openim::log::info "⌚ Working with template file: ${template} to ${output_file}..."
|
openim::log::info "⌚ Working with template file: ${template} to ${output_file}..."
|
||||||
if [[ ! -f "${OPENIM_ROOT}/scripts/genconfig.sh" ]]; then
|
if [[ ! -f "${OPENIM_ROOT}/scripts/genconfig.sh" ]]; then
|
||||||
@ -72,5 +111,4 @@ for template in "${!TEMPLATES[@]}"; do
|
|||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
openim::log::success "✨ All configuration files have been successfully generated!"
|
openim::log::success "✨ All configuration files have been successfully generated!"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user