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

Open
EDaoren opened this issue Oct 14, 2024 · 1 comment
Open
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

我在项目配置了Webhooks ,配置了 离线状态下消息推送前的回调(callbackBeforeOfflinePushCommand)和 在线状态下消息推送前的回调(callbackBeforeOnlinePushCommand),然后在用户离线的时候发送消息,可以收到 callbackBeforeOfflinePushCommand的回调通知,但是在 用户在线的时候确无法收到 callbackBeforeOnlinePushCommand 的回调通知。

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

No branches or pull requests

1 participant