Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Callback before message push in online state No callback is triggered #2715

Closed
EDaoren opened this issue Oct 14, 2024 · 1 comment · Fixed by #2805
Closed

[BUG] Callback before message push in online state No callback is triggered #2715

EDaoren opened this issue Oct 14, 2024 · 1 comment · Fixed by #2805
Assignees
Labels
bug Categorizes issue or PR as related to a bug.

Comments

@EDaoren
Copy link

EDaoren commented Oct 14, 2024

OpenIM Server Version

3.8.1

Operating System and CPU Architecture

Linux (AMD)

Deployment Method

Source Code Deployment

Bug Description and Steps to Reproduce

I configured Webhooks in the project, setting up a callback for message push before offline delivery (callbackBeforeOfflinePushCommand) and another for message push before online delivery (callbackBeforeOnlinePushCommand). When sending a message while the user is offline, I receive the callbackBeforeOfflinePushCommand notification. However, when the user is online, I’m not receiving the callbackBeforeOnlinePushCommand notification.

Screenshots Link

配置如下:
image

在线
image

离线
image

@EDaoren EDaoren added the bug Categorizes issue or PR as related to a bug. label Oct 14, 2024
@EDaoren
Copy link
Author

EDaoren commented Oct 14, 2024

我尝试按照日志的打印的位置阅读了一下源码,我发现了以下一段代码:

func (c *ConsumerHandler) webhookBeforeOnlinePush(ctx context.Context, before *config.BeforeConfig, userIDs []string, msg *sdkws.MsgData) error {
	return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
		if datautil.Contain(msg.SendID, userIDs...) || msg.ContentType == constant.Typing {
			return nil
		}
		req := callbackstruct.CallbackBeforePushReq{
			UserStatusBatchCallbackReq: callbackstruct.UserStatusBatchCallbackReq{
				UserStatusBaseCallback: callbackstruct.UserStatusBaseCallback{
					CallbackCommand: callbackstruct.CallbackBeforeOnlinePushCommand,
					OperationID:     mcontext.GetOperationID(ctx),
					PlatformID:      int(msg.SenderPlatformID),
					Platform:        constant.PlatformIDToName(int(msg.SenderPlatformID)),
				},
				UserIDList: userIDs,
			},
			ClientMsgID: msg.ClientMsgID,
			SendID:      msg.SendID,
			GroupID:     msg.GroupID,
			ContentType: msg.ContentType,
			SessionType: msg.SessionType,
			AtUserIDs:   msg.AtUserIDList,
			Content:     GetContent(msg),
		}
		resp := &callbackstruct.CallbackBeforePushResp{}
		if err := c.webhookClient.SyncPost(ctx, req.GetCallbackCommand(), req, resp, before); err != nil {
			return err
		}
		return nil
	})
}

问题很可能出现在这个判断上:

if datautil.Contain(msg.SendID, userIDs...) || msg.ContentType == constant.Typing {
			return nil
		}

日志中,msg.SendID 的值为 sendID:4514183745,userIDs的值为:"userIDs" : [ 6346834060" , "4514183745"],这里判断然后return 返回了,没有继续下面的回调的逻辑了。

我继续向上追查,看到有下面一个方法:

func (c *ConsumerHandler) handleMs2PsChat(ctx context.Context, msg []byte) {
	msgFromMQ := pbpush.PushMsgReq{}
	if err := proto.Unmarshal(msg, &msgFromMQ); err != nil {
		log.ZError(ctx, "push Unmarshal msg err", err, "msg", string(msg))
		return
	}

	sec := msgFromMQ.MsgData.SendTime / 1000
	nowSec := timeutil.GetCurrentTimestampBySecond()

	if nowSec-sec > 10 {
		prommetrics.MsgLoneTimePushCounter.Inc()
		log.ZWarn(ctx, "it’s been a while since the message was sent", nil, "msg", msgFromMQ.String(), "sec", sec, "nowSec", nowSec, "nowSec-sec", nowSec-sec)
	}
	var err error

	switch msgFromMQ.MsgData.SessionType {
	case constant.ReadGroupChatType:
		err = c.Push2Group(ctx, msgFromMQ.MsgData.GroupID, msgFromMQ.MsgData)
	default:
		var pushUserIDList []string
		isSenderSync := datautil.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsSenderSync)
		if !isSenderSync || msgFromMQ.MsgData.SendID == msgFromMQ.MsgData.RecvID {
			pushUserIDList = append(pushUserIDList, msgFromMQ.MsgData.RecvID)
		} else {
			pushUserIDList = append(pushUserIDList, msgFromMQ.MsgData.RecvID, msgFromMQ.MsgData.SendID)
		}
		err = c.Push2User(ctx, pushUserIDList, msgFromMQ.MsgData)
	}
	if err != nil {
		log.ZWarn(ctx, "push failed", err, "msg", msgFromMQ.String())
	}
}

pushUserIDList 这里应该是把 RecvID 和 SendID 都往数组里面塞了。

我不太清楚这里面的逻辑,离线推送里面的代码并没有这个判断。
if datautil.Contain(msg.SendID, userIDs...) || msg.ContentType == constant.Typing {
return nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants