Files
open-im-server/internal/api/friend.go
T

83 lines
2.2 KiB
Go
Raw Normal View History

2023-02-28 14:20:26 +08:00
package api
2021-12-23 17:22:49 +08:00
2023-02-28 11:38:05 +08:00
import (
"context"
2023-03-16 20:21:10 +08:00
2023-03-17 11:27:34 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/a2r"
2023-03-16 10:46:06 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/friend"
2023-05-30 16:15:11 +08:00
"google.golang.org/grpc"
2023-03-08 17:29:03 +08:00
2023-02-28 11:38:05 +08:00
"github.com/gin-gonic/gin"
)
2023-06-02 20:52:16 +08:00
func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry) *Friend {
2023-06-07 15:06:50 +08:00
// conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName)
// if err != nil {
// panic(err)
// }
return &Friend{discov: discov}
2023-02-28 11:38:05 +08:00
}
type Friend struct {
2023-06-02 20:52:16 +08:00
conn *grpc.ClientConn
discov discoveryregistry.SvcDiscoveryRegistry
2023-02-28 11:38:05 +08:00
}
2023-05-08 12:39:45 +08:00
func (o *Friend) client(ctx context.Context) (friend.FriendClient, error) {
2023-06-02 20:52:16 +08:00
c, err := o.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImFriendName)
if err != nil {
return nil, err
}
return friend.NewFriendClient(c), nil
2023-02-28 11:38:05 +08:00
}
2023-03-02 14:41:59 +08:00
func (o *Friend) ApplyToAddFriend(c *gin.Context) {
a2r.Call(friend.FriendClient.ApplyToAddFriend, o.client, c)
2023-02-28 11:38:05 +08:00
}
2023-03-16 20:21:10 +08:00
func (o *Friend) RespondFriendApply(c *gin.Context) {
a2r.Call(friend.FriendClient.RespondFriendApply, o.client, c)
}
2023-03-02 14:41:59 +08:00
func (o *Friend) DeleteFriend(c *gin.Context) {
a2r.Call(friend.FriendClient.DeleteFriend, o.client, c)
2023-02-28 11:38:05 +08:00
}
2023-03-02 14:41:59 +08:00
func (o *Friend) GetFriendApplyList(c *gin.Context) {
2023-05-15 16:17:36 +08:00
a2r.Call(friend.FriendClient.GetPaginationFriendsApplyTo, o.client, c)
2023-02-28 11:38:05 +08:00
}
2023-03-02 14:41:59 +08:00
func (o *Friend) GetSelfApplyList(c *gin.Context) {
2023-05-15 16:17:36 +08:00
a2r.Call(friend.FriendClient.GetPaginationFriendsApplyFrom, o.client, c)
2023-02-28 11:38:05 +08:00
}
2023-03-02 14:41:59 +08:00
func (o *Friend) GetFriendList(c *gin.Context) {
2023-04-11 14:44:51 +08:00
a2r.Call(friend.FriendClient.GetPaginationFriends, o.client, c)
2023-02-28 11:38:05 +08:00
}
2023-03-02 14:41:59 +08:00
func (o *Friend) SetFriendRemark(c *gin.Context) {
a2r.Call(friend.FriendClient.SetFriendRemark, o.client, c)
2023-02-28 11:38:05 +08:00
}
2023-03-02 14:41:59 +08:00
func (o *Friend) AddBlack(c *gin.Context) {
a2r.Call(friend.FriendClient.AddBlack, o.client, c)
2023-02-28 11:38:05 +08:00
}
2023-03-02 14:41:59 +08:00
func (o *Friend) GetPaginationBlacks(c *gin.Context) {
a2r.Call(friend.FriendClient.GetPaginationBlacks, o.client, c)
2023-02-28 11:38:05 +08:00
}
2023-03-02 14:41:59 +08:00
func (o *Friend) RemoveBlack(c *gin.Context) {
a2r.Call(friend.FriendClient.RemoveBlack, o.client, c)
2023-02-28 11:38:05 +08:00
}
2023-03-02 14:41:59 +08:00
func (o *Friend) ImportFriends(c *gin.Context) {
a2r.Call(friend.FriendClient.ImportFriends, o.client, c)
2023-02-28 11:38:05 +08:00
}
2023-03-02 14:41:59 +08:00
func (o *Friend) IsFriend(c *gin.Context) {
a2r.Call(friend.FriendClient.IsFriend, o.client, c)
2023-02-28 11:38:05 +08:00
}