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

77 lines
2.1 KiB
Go
Raw Normal View History

2023-02-28 14:20:26 +08:00
package api
2021-12-27 16:48:05 +08:00
import (
"context"
2023-05-08 12:39:45 +08:00
2023-05-06 10:27:07 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/apiresp"
"github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct"
2023-05-30 18:24:19 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
2023-05-06 10:27:07 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
2023-05-30 16:15:11 +08:00
"google.golang.org/grpc"
2023-03-28 19:24:59 +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/user"
2022-08-17 14:57:57 +08:00
"github.com/gin-gonic/gin"
2021-12-27 16:48:05 +08:00
)
2023-05-30 16:15:11 +08:00
func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
2023-05-30 16:24:07 +08:00
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName)
2023-05-30 16:15:11 +08:00
if err != nil {
panic(err)
}
2023-05-30 18:24:19 +08:00
log.ZInfo(context.Background(), "user rpc conn", "conn", conn)
2023-05-30 16:15:11 +08:00
return &User{conn: conn}
2022-04-28 15:13:39 +08:00
}
2023-02-28 11:38:05 +08:00
type User struct {
2023-05-30 16:15:11 +08:00
conn *grpc.ClientConn
2022-04-27 14:43:46 +08:00
}
2023-05-08 12:39:45 +08:00
func (u *User) client(ctx context.Context) (user.UserClient, error) {
2023-05-30 16:15:11 +08:00
return user.NewUserClient(u.conn), nil
2021-12-27 16:48:05 +08:00
}
2023-03-10 11:42:06 +08:00
func (u *User) UserRegister(c *gin.Context) {
a2r.Call(user.UserClient.UserRegister, u.client, c)
2023-03-03 18:08:26 +08:00
}
2023-03-10 11:42:06 +08:00
func (u *User) UpdateUserInfo(c *gin.Context) {
a2r.Call(user.UserClient.UpdateUserInfo, u.client, c)
2021-12-27 16:48:05 +08:00
}
2022-06-24 17:45:33 +08:00
2023-03-10 11:42:06 +08:00
func (u *User) SetGlobalRecvMessageOpt(c *gin.Context) {
a2r.Call(user.UserClient.SetGlobalRecvMessageOpt, u.client, c)
2022-06-16 19:33:35 +08:00
}
2022-01-13 11:10:29 +08:00
2023-03-10 11:42:06 +08:00
func (u *User) GetUsersPublicInfo(c *gin.Context) {
a2r.Call(user.UserClient.GetDesignateUsers, u.client, c)
2022-01-13 11:10:29 +08:00
}
2022-04-18 14:27:12 +08:00
2023-03-10 11:42:06 +08:00
func (u *User) GetAllUsersID(c *gin.Context) {
a2r.Call(user.UserClient.GetDesignateUsers, u.client, c)
2023-03-03 19:44:34 +08:00
}
func (u *User) AccountCheck(c *gin.Context) {
a2r.Call(user.UserClient.AccountCheck, u.client, c)
}
2023-02-28 11:38:05 +08:00
2023-03-10 11:42:06 +08:00
func (u *User) GetUsers(c *gin.Context) {
a2r.Call(user.UserClient.GetPaginationUsers, u.client, c)
2022-08-26 17:51:01 +08:00
}
2023-05-30 16:15:11 +08:00
2023-05-06 10:27:07 +08:00
func (u *User) GetUsersOnlineStatus(c *gin.Context) {
params := apistruct.ManagementSendMsgReq{}
if err := c.BindJSON(&params); err != nil {
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
return
}
if !tokenverify.IsAppManagerUid(c) {
apiresp.GinError(c, errs.ErrNoPermission.Wrap("only app manager can send message"))
return
}
}