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

添加好友成功的通知 #1547

Open
water2060 opened this issue Aug 9, 2024 · 2 comments
Open

添加好友成功的通知 #1547

water2060 opened this issue Aug 9, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@water2060
Copy link

作者你好。我的业务里面有个需求:当同意添加对方为好友时,业务系统需要执行一定的逻辑。这个IM怎么修改,通知到业务系统。能简单说一些吗?

@JamesChenX JamesChenX added documentation Improvements or additions to documentation enhancement New feature or request labels Aug 9, 2024
@JamesChenX
Copy link
Member

In simple words, there are many ways to implement the feature according to your business requirements.

  1. The simplest way: For clients, you can use notificationService.addNotificationListener to listen to any notifications and then implement your business logic. e.g.:
notificationService.addNotificationListener { 
    notification ->
    if (!notification.relayedRequest.hasUpdateFriendRequestRequest()) {
        return@addNotificationListener
    }
    val updateFriendRequestRequest = notification.relayedRequest.updateFriendRequestRequest
    when (updateFriendRequestRequest.responseAction) {
        ResponseAction.ACCEPT -> {
            // do something when the recipient accepts the friend requests sent by the current user.
        }
        ResponseAction.DECLINE -> {
            // do something
        }
        ResponseAction.IGNORE ->  {
            // do something
        }
        ResponseAction.UNRECOGNIZED -> {
            throw IllegalArgumentException("Unrecognized response action: ${updateFriendRequestRequest.responseAction}")
        }
    }
}
  1. Write a plugin to implement the interface im.turms.service.infra.plugin.extension.ClientRequestHandler for turms-service, and then you can do anything you want to view/modify the client request and response/notification in the plugin as you can control the code, you can control anything.

  2. Almost all proto models include a field customAttributes, which is designed for developers to send any arbitrary data between the Turms clients and servers to implement your business logic.

@water2060
Copy link
Author

这个是对于客户端的监听。我是想 IM服务端 通知给 业务服务端,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants