add: chat service
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
package chatservice
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
ChatSessions = pb.ChatSessions
|
||||
AddChatSessionsReq = pb.AddChatSessionsReq
|
||||
AddChatSessionsResp = pb.AddChatSessionsResp
|
||||
UpdateChatSessionsReq = pb.UpdateChatSessionsReq
|
||||
UpdateChatSessionsResp = pb.UpdateChatSessionsResp
|
||||
DelChatSessionsReq = pb.DelChatSessionsReq
|
||||
DelChatSessionsResp = pb.DelChatSessionsResp
|
||||
GetChatSessionsByIdReq = pb.GetChatSessionsByIdReq
|
||||
GetChatSessionsByIdResp = pb.GetChatSessionsByIdResp
|
||||
SearchChatSessionsReq = pb.SearchChatSessionsReq
|
||||
SearchChatSessionsResp = pb.SearchChatSessionsResp
|
||||
AddParticipantReq = pb.AddParticipantReq
|
||||
AddParticipantResp = pb.AddParticipantResp
|
||||
RemoveParticipantReq = pb.RemoveParticipantReq
|
||||
RemoveParticipantResp = pb.RemoveParticipantResp
|
||||
ChatMessages = pb.ChatMessages
|
||||
AddChatMessagesReq = pb.AddChatMessagesReq
|
||||
AddChatMessagesResp = pb.AddChatMessagesResp
|
||||
DelChatMessagesReq = pb.DelChatMessagesReq
|
||||
DelChatMessagesResp = pb.DelChatMessagesResp
|
||||
GetChatMessagesByIdReq = pb.GetChatMessagesByIdReq
|
||||
GetChatMessagesByIdResp = pb.GetChatMessagesByIdResp
|
||||
SearchChatMessagesReq = pb.SearchChatMessagesReq
|
||||
SearchChatMessagesResp = pb.SearchChatMessagesResp
|
||||
|
||||
ChatService interface {
|
||||
AddChatSessions(ctx context.Context, in *AddChatSessionsReq, opts ...grpc.CallOption) (*AddChatSessionsResp, error)
|
||||
UpdateChatSessions(ctx context.Context, in *UpdateChatSessionsReq, opts ...grpc.CallOption) (*UpdateChatSessionsResp, error)
|
||||
DelChatSessions(ctx context.Context, in *DelChatSessionsReq, opts ...grpc.CallOption) (*DelChatSessionsResp, error)
|
||||
GetChatSessionsById(ctx context.Context, in *GetChatSessionsByIdReq, opts ...grpc.CallOption) (*GetChatSessionsByIdResp, error)
|
||||
SearchChatSessions(ctx context.Context, in *SearchChatSessionsReq, opts ...grpc.CallOption) (*SearchChatSessionsResp, error)
|
||||
AddParticipant(ctx context.Context, in *AddParticipantReq, opts ...grpc.CallOption) (*AddParticipantResp, error)
|
||||
RemoveParticipant(ctx context.Context, in *RemoveParticipantReq, opts ...grpc.CallOption) (*RemoveParticipantResp, error)
|
||||
AddChatMessages(ctx context.Context, in *AddChatMessagesReq, opts ...grpc.CallOption) (*AddChatMessagesResp, error)
|
||||
DelChatMessages(ctx context.Context, in *DelChatMessagesReq, opts ...grpc.CallOption) (*DelChatMessagesResp, error)
|
||||
GetChatMessagesById(ctx context.Context, in *GetChatMessagesByIdReq, opts ...grpc.CallOption) (*GetChatMessagesByIdResp, error)
|
||||
SearchChatMessages(ctx context.Context, in *SearchChatMessagesReq, opts ...grpc.CallOption) (*SearchChatMessagesResp, error)
|
||||
}
|
||||
|
||||
defaultChatService struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewChatService(cli zrpc.Client) ChatService {
|
||||
return &defaultChatService{cli: cli}
|
||||
}
|
||||
|
||||
func (m *defaultChatService) AddChatSessions(ctx context.Context, in *AddChatSessionsReq, opts ...grpc.CallOption) (*AddChatSessionsResp, error) {
|
||||
client := pb.NewChatServiceClient(m.cli.Conn())
|
||||
return client.AddChatSessions(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultChatService) UpdateChatSessions(ctx context.Context, in *UpdateChatSessionsReq, opts ...grpc.CallOption) (*UpdateChatSessionsResp, error) {
|
||||
client := pb.NewChatServiceClient(m.cli.Conn())
|
||||
return client.UpdateChatSessions(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultChatService) DelChatSessions(ctx context.Context, in *DelChatSessionsReq, opts ...grpc.CallOption) (*DelChatSessionsResp, error) {
|
||||
client := pb.NewChatServiceClient(m.cli.Conn())
|
||||
return client.DelChatSessions(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultChatService) GetChatSessionsById(ctx context.Context, in *GetChatSessionsByIdReq, opts ...grpc.CallOption) (*GetChatSessionsByIdResp, error) {
|
||||
client := pb.NewChatServiceClient(m.cli.Conn())
|
||||
return client.GetChatSessionsById(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultChatService) SearchChatSessions(ctx context.Context, in *SearchChatSessionsReq, opts ...grpc.CallOption) (*SearchChatSessionsResp, error) {
|
||||
client := pb.NewChatServiceClient(m.cli.Conn())
|
||||
return client.SearchChatSessions(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultChatService) AddParticipant(ctx context.Context, in *AddParticipantReq, opts ...grpc.CallOption) (*AddParticipantResp, error) {
|
||||
client := pb.NewChatServiceClient(m.cli.Conn())
|
||||
return client.AddParticipant(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultChatService) RemoveParticipant(ctx context.Context, in *RemoveParticipantReq, opts ...grpc.CallOption) (*RemoveParticipantResp, error) {
|
||||
client := pb.NewChatServiceClient(m.cli.Conn())
|
||||
return client.RemoveParticipant(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultChatService) AddChatMessages(ctx context.Context, in *AddChatMessagesReq, opts ...grpc.CallOption) (*AddChatMessagesResp, error) {
|
||||
client := pb.NewChatServiceClient(m.cli.Conn())
|
||||
return client.AddChatMessages(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultChatService) DelChatMessages(ctx context.Context, in *DelChatMessagesReq, opts ...grpc.CallOption) (*DelChatMessagesResp, error) {
|
||||
client := pb.NewChatServiceClient(m.cli.Conn())
|
||||
return client.DelChatMessages(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultChatService) GetChatMessagesById(ctx context.Context, in *GetChatMessagesByIdReq, opts ...grpc.CallOption) (*GetChatMessagesByIdResp, error) {
|
||||
client := pb.NewChatServiceClient(m.cli.Conn())
|
||||
return client.GetChatMessagesById(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultChatService) SearchChatMessages(ctx context.Context, in *SearchChatMessagesReq, opts ...grpc.CallOption) (*SearchChatMessagesResp, error) {
|
||||
client := pb.NewChatServiceClient(m.cli.Conn())
|
||||
return client.SearchChatMessages(ctx, in, opts...)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
Name: pb.rpc
|
||||
ListenOn: 0.0.0.0:8080
|
||||
|
||||
Log:
|
||||
Level: debug
|
||||
@@ -0,0 +1,7 @@
|
||||
package config
|
||||
|
||||
import "github.com/zeromicro/go-zero/zrpc"
|
||||
|
||||
type Config struct {
|
||||
zrpc.RpcServerConf
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/chat/rpc/internal/svc"
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddChatMessagesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddChatMessagesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddChatMessagesLogic {
|
||||
return &AddChatMessagesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AddChatMessagesLogic) AddChatMessages(in *pb.AddChatMessagesReq) (*pb.AddChatMessagesResp, error) {
|
||||
if in.GetSessionId() <= 0 {
|
||||
return nil, errors.New("sessionId is required")
|
||||
}
|
||||
if in.GetSenderId() <= 0 {
|
||||
return nil, errors.New("senderId is required")
|
||||
}
|
||||
if in.GetContent() == "" {
|
||||
return nil, errors.New("content is required")
|
||||
}
|
||||
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.Lock()
|
||||
defer store.Mu.Unlock()
|
||||
|
||||
if _, ok := store.Sessions[in.GetSessionId()]; !ok {
|
||||
return nil, errors.New("session not found")
|
||||
}
|
||||
|
||||
now := nowUnix(0)
|
||||
msgType := in.GetType()
|
||||
if msgType == "" {
|
||||
msgType = "text"
|
||||
}
|
||||
|
||||
msg := &pb.ChatMessages{
|
||||
Id: store.NextMessage(),
|
||||
SessionId: in.GetSessionId(),
|
||||
SenderId: in.GetSenderId(),
|
||||
Type: msgType,
|
||||
Content: in.GetContent(),
|
||||
CreatedAt: now,
|
||||
}
|
||||
store.Messages[msg.Id] = msg
|
||||
store.SessionMessages[in.GetSessionId()] = append(store.SessionMessages[in.GetSessionId()], msg.Id)
|
||||
|
||||
session := store.Sessions[in.GetSessionId()]
|
||||
session.LastMessage = in.GetContent()
|
||||
session.LastMessageAt = now
|
||||
session.UpdatedAt = now
|
||||
|
||||
return &pb.AddChatMessagesResp{Id: msg.Id}, nil
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/chat/rpc/internal/svc"
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddChatSessionsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddChatSessionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddChatSessionsLogic {
|
||||
return &AddChatSessionsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AddChatSessionsLogic) AddChatSessions(in *pb.AddChatSessionsReq) (*pb.AddChatSessionsResp, error) {
|
||||
if in.GetType() == "" {
|
||||
return nil, errors.New("type is required")
|
||||
}
|
||||
if in.GetCreatorId() <= 0 {
|
||||
return nil, errors.New("creatorId is required")
|
||||
}
|
||||
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.Lock()
|
||||
defer store.Mu.Unlock()
|
||||
|
||||
now := nowUnix(0)
|
||||
participants := append([]int64(nil), in.GetParticipants()...)
|
||||
hasCreator := false
|
||||
for _, p := range participants {
|
||||
if p == in.GetCreatorId() {
|
||||
hasCreator = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasCreator {
|
||||
participants = append(participants, in.GetCreatorId())
|
||||
}
|
||||
|
||||
session := &pb.ChatSessions{
|
||||
Id: store.NextSession(),
|
||||
Type: in.GetType(),
|
||||
Name: in.GetName(),
|
||||
CreatorId: in.GetCreatorId(),
|
||||
Participants: participants,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
store.Sessions[session.Id] = session
|
||||
|
||||
return &pb.AddChatSessionsResp{Id: session.Id}, nil
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/chat/rpc/internal/svc"
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddParticipantLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddParticipantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddParticipantLogic {
|
||||
return &AddParticipantLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AddParticipantLogic) AddParticipant(in *pb.AddParticipantReq) (*pb.AddParticipantResp, error) {
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.Lock()
|
||||
defer store.Mu.Unlock()
|
||||
|
||||
session, ok := store.Sessions[in.GetSessionId()]
|
||||
if !ok {
|
||||
return nil, errors.New("session not found")
|
||||
}
|
||||
|
||||
for _, p := range session.Participants {
|
||||
if p == in.GetUserId() {
|
||||
return &pb.AddParticipantResp{}, nil
|
||||
}
|
||||
}
|
||||
session.Participants = append(session.Participants, in.GetUserId())
|
||||
session.UpdatedAt = nowUnix(0)
|
||||
|
||||
return &pb.AddParticipantResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/chat/rpc/internal/svc"
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DelChatMessagesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDelChatMessagesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelChatMessagesLogic {
|
||||
return &DelChatMessagesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DelChatMessagesLogic) DelChatMessages(in *pb.DelChatMessagesReq) (*pb.DelChatMessagesResp, error) {
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.Lock()
|
||||
defer store.Mu.Unlock()
|
||||
|
||||
msg, ok := store.Messages[in.GetId()]
|
||||
if ok {
|
||||
ids := store.SessionMessages[msg.SessionId]
|
||||
filtered := make([]int64, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
if id != in.GetId() {
|
||||
filtered = append(filtered, id)
|
||||
}
|
||||
}
|
||||
store.SessionMessages[msg.SessionId] = filtered
|
||||
}
|
||||
delete(store.Messages, in.GetId())
|
||||
|
||||
return &pb.DelChatMessagesResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/chat/rpc/internal/svc"
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DelChatSessionsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDelChatSessionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelChatSessionsLogic {
|
||||
return &DelChatSessionsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DelChatSessionsLogic) DelChatSessions(in *pb.DelChatSessionsReq) (*pb.DelChatSessionsResp, error) {
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.Lock()
|
||||
defer store.Mu.Unlock()
|
||||
|
||||
delete(store.Sessions, in.GetId())
|
||||
delete(store.SessionMessages, in.GetId())
|
||||
|
||||
return &pb.DelChatSessionsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/chat/rpc/internal/svc"
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetChatMessagesByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetChatMessagesByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetChatMessagesByIdLogic {
|
||||
return &GetChatMessagesByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetChatMessagesByIdLogic) GetChatMessagesById(in *pb.GetChatMessagesByIdReq) (*pb.GetChatMessagesByIdResp, error) {
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.RLock()
|
||||
defer store.Mu.RUnlock()
|
||||
|
||||
msg, ok := store.Messages[in.GetId()]
|
||||
if !ok {
|
||||
return nil, errors.New("message not found")
|
||||
}
|
||||
|
||||
return &pb.GetChatMessagesByIdResp{ChatMessages: msg}, nil
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/chat/rpc/internal/svc"
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetChatSessionsByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetChatSessionsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetChatSessionsByIdLogic {
|
||||
return &GetChatSessionsByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetChatSessionsByIdLogic) GetChatSessionsById(in *pb.GetChatSessionsByIdReq) (*pb.GetChatSessionsByIdResp, error) {
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.RLock()
|
||||
defer store.Mu.RUnlock()
|
||||
|
||||
session, ok := store.Sessions[in.GetId()]
|
||||
if !ok {
|
||||
return nil, errors.New("session not found")
|
||||
}
|
||||
|
||||
return &pb.GetChatSessionsByIdResp{ChatSessions: session}, nil
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package logic
|
||||
|
||||
import "time"
|
||||
|
||||
func nowUnix(ts int64) int64 {
|
||||
if ts > 0 {
|
||||
return ts
|
||||
}
|
||||
return time.Now().Unix()
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/chat/rpc/internal/svc"
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type RemoveParticipantLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewRemoveParticipantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RemoveParticipantLogic {
|
||||
return &RemoveParticipantLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *RemoveParticipantLogic) RemoveParticipant(in *pb.RemoveParticipantReq) (*pb.RemoveParticipantResp, error) {
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.Lock()
|
||||
defer store.Mu.Unlock()
|
||||
|
||||
session, ok := store.Sessions[in.GetSessionId()]
|
||||
if !ok {
|
||||
return nil, errors.New("session not found")
|
||||
}
|
||||
|
||||
filtered := make([]int64, 0, len(session.Participants))
|
||||
for _, p := range session.Participants {
|
||||
if p != in.GetUserId() {
|
||||
filtered = append(filtered, p)
|
||||
}
|
||||
}
|
||||
session.Participants = filtered
|
||||
session.UpdatedAt = nowUnix(0)
|
||||
|
||||
return &pb.RemoveParticipantResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/chat/rpc/internal/svc"
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchChatMessagesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchChatMessagesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchChatMessagesLogic {
|
||||
return &SearchChatMessagesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchChatMessagesLogic) SearchChatMessages(in *pb.SearchChatMessagesReq) (*pb.SearchChatMessagesResp, error) {
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.RLock()
|
||||
defer store.Mu.RUnlock()
|
||||
|
||||
msgIDs := store.SessionMessages[in.GetSessionId()]
|
||||
var results []*pb.ChatMessages
|
||||
for _, id := range msgIDs {
|
||||
msg, ok := store.Messages[id]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if in.SenderId != nil && msg.SenderId != *in.SenderId {
|
||||
continue
|
||||
}
|
||||
results = append(results, msg)
|
||||
}
|
||||
|
||||
limit := in.GetLimit()
|
||||
if limit <= 0 {
|
||||
limit = 20
|
||||
}
|
||||
offset := in.GetPage() * limit
|
||||
if offset >= int64(len(results)) {
|
||||
return &pb.SearchChatMessagesResp{}, nil
|
||||
}
|
||||
end := offset + limit
|
||||
if end > int64(len(results)) {
|
||||
end = int64(len(results))
|
||||
}
|
||||
|
||||
return &pb.SearchChatMessagesResp{ChatMessages: results[offset:end]}, nil
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/chat/rpc/internal/svc"
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchChatSessionsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchChatSessionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchChatSessionsLogic {
|
||||
return &SearchChatSessionsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchChatSessionsLogic) SearchChatSessions(in *pb.SearchChatSessionsReq) (*pb.SearchChatSessionsResp, error) {
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.RLock()
|
||||
defer store.Mu.RUnlock()
|
||||
|
||||
var results []*pb.ChatSessions
|
||||
for _, s := range store.Sessions {
|
||||
if in.Type != nil && s.Type != *in.Type {
|
||||
continue
|
||||
}
|
||||
if in.UserId != nil {
|
||||
found := false
|
||||
for _, p := range s.Participants {
|
||||
if p == *in.UserId {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
}
|
||||
results = append(results, s)
|
||||
}
|
||||
|
||||
limit := in.GetLimit()
|
||||
if limit <= 0 {
|
||||
limit = 20
|
||||
}
|
||||
offset := in.GetPage() * limit
|
||||
if offset >= int64(len(results)) {
|
||||
return &pb.SearchChatSessionsResp{}, nil
|
||||
}
|
||||
end := offset + limit
|
||||
if end > int64(len(results)) {
|
||||
end = int64(len(results))
|
||||
}
|
||||
|
||||
return &pb.SearchChatSessionsResp{ChatSessions: results[offset:end]}, nil
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/chat/rpc/internal/svc"
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateChatSessionsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateChatSessionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateChatSessionsLogic {
|
||||
return &UpdateChatSessionsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateChatSessionsLogic) UpdateChatSessions(in *pb.UpdateChatSessionsReq) (*pb.UpdateChatSessionsResp, error) {
|
||||
store := l.svcCtx.Store
|
||||
store.Mu.Lock()
|
||||
defer store.Mu.Unlock()
|
||||
|
||||
session, ok := store.Sessions[in.GetId()]
|
||||
if !ok {
|
||||
return nil, errors.New("session not found")
|
||||
}
|
||||
|
||||
if in.Name != nil {
|
||||
session.Name = *in.Name
|
||||
}
|
||||
if in.LastMessage != nil {
|
||||
session.LastMessage = *in.LastMessage
|
||||
}
|
||||
if in.LastMessageAt != nil {
|
||||
session.LastMessageAt = *in.LastMessageAt
|
||||
}
|
||||
session.UpdatedAt = nowUnix(0)
|
||||
|
||||
return &pb.UpdateChatSessionsResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"juwan-backend/app/chat/rpc/internal/logic"
|
||||
"juwan-backend/app/chat/rpc/internal/svc"
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
)
|
||||
|
||||
type ChatServiceServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
pb.UnimplementedChatServiceServer
|
||||
}
|
||||
|
||||
func NewChatServiceServer(svcCtx *svc.ServiceContext) *ChatServiceServer {
|
||||
return &ChatServiceServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ChatServiceServer) AddChatSessions(ctx context.Context, in *pb.AddChatSessionsReq) (*pb.AddChatSessionsResp, error) {
|
||||
l := logic.NewAddChatSessionsLogic(ctx, s.svcCtx)
|
||||
return l.AddChatSessions(in)
|
||||
}
|
||||
|
||||
func (s *ChatServiceServer) UpdateChatSessions(ctx context.Context, in *pb.UpdateChatSessionsReq) (*pb.UpdateChatSessionsResp, error) {
|
||||
l := logic.NewUpdateChatSessionsLogic(ctx, s.svcCtx)
|
||||
return l.UpdateChatSessions(in)
|
||||
}
|
||||
|
||||
func (s *ChatServiceServer) DelChatSessions(ctx context.Context, in *pb.DelChatSessionsReq) (*pb.DelChatSessionsResp, error) {
|
||||
l := logic.NewDelChatSessionsLogic(ctx, s.svcCtx)
|
||||
return l.DelChatSessions(in)
|
||||
}
|
||||
|
||||
func (s *ChatServiceServer) GetChatSessionsById(ctx context.Context, in *pb.GetChatSessionsByIdReq) (*pb.GetChatSessionsByIdResp, error) {
|
||||
l := logic.NewGetChatSessionsByIdLogic(ctx, s.svcCtx)
|
||||
return l.GetChatSessionsById(in)
|
||||
}
|
||||
|
||||
func (s *ChatServiceServer) SearchChatSessions(ctx context.Context, in *pb.SearchChatSessionsReq) (*pb.SearchChatSessionsResp, error) {
|
||||
l := logic.NewSearchChatSessionsLogic(ctx, s.svcCtx)
|
||||
return l.SearchChatSessions(in)
|
||||
}
|
||||
|
||||
func (s *ChatServiceServer) AddParticipant(ctx context.Context, in *pb.AddParticipantReq) (*pb.AddParticipantResp, error) {
|
||||
l := logic.NewAddParticipantLogic(ctx, s.svcCtx)
|
||||
return l.AddParticipant(in)
|
||||
}
|
||||
|
||||
func (s *ChatServiceServer) RemoveParticipant(ctx context.Context, in *pb.RemoveParticipantReq) (*pb.RemoveParticipantResp, error) {
|
||||
l := logic.NewRemoveParticipantLogic(ctx, s.svcCtx)
|
||||
return l.RemoveParticipant(in)
|
||||
}
|
||||
|
||||
func (s *ChatServiceServer) AddChatMessages(ctx context.Context, in *pb.AddChatMessagesReq) (*pb.AddChatMessagesResp, error) {
|
||||
l := logic.NewAddChatMessagesLogic(ctx, s.svcCtx)
|
||||
return l.AddChatMessages(in)
|
||||
}
|
||||
|
||||
func (s *ChatServiceServer) DelChatMessages(ctx context.Context, in *pb.DelChatMessagesReq) (*pb.DelChatMessagesResp, error) {
|
||||
l := logic.NewDelChatMessagesLogic(ctx, s.svcCtx)
|
||||
return l.DelChatMessages(in)
|
||||
}
|
||||
|
||||
func (s *ChatServiceServer) GetChatMessagesById(ctx context.Context, in *pb.GetChatMessagesByIdReq) (*pb.GetChatMessagesByIdResp, error) {
|
||||
l := logic.NewGetChatMessagesByIdLogic(ctx, s.svcCtx)
|
||||
return l.GetChatMessagesById(in)
|
||||
}
|
||||
|
||||
func (s *ChatServiceServer) SearchChatMessages(ctx context.Context, in *pb.SearchChatMessagesReq) (*pb.SearchChatMessagesResp, error) {
|
||||
l := logic.NewSearchChatMessagesLogic(ctx, s.svcCtx)
|
||||
return l.SearchChatMessages(in)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package svc
|
||||
|
||||
import "juwan-backend/app/chat/rpc/internal/config"
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
Store *ChatStore
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
Store: NewChatStore(),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
)
|
||||
|
||||
type ChatStore struct {
|
||||
Mu sync.RWMutex
|
||||
|
||||
nextSessionID int64
|
||||
nextMessageID int64
|
||||
|
||||
Sessions map[int64]*pb.ChatSessions
|
||||
Messages map[int64]*pb.ChatMessages
|
||||
SessionMessages map[int64][]int64
|
||||
}
|
||||
|
||||
func NewChatStore() *ChatStore {
|
||||
return &ChatStore{
|
||||
nextSessionID: 1000,
|
||||
nextMessageID: 1000,
|
||||
Sessions: make(map[int64]*pb.ChatSessions),
|
||||
Messages: make(map[int64]*pb.ChatMessages),
|
||||
SessionMessages: make(map[int64][]int64),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ChatStore) NextSession() int64 {
|
||||
s.nextSessionID++
|
||||
return s.nextSessionID
|
||||
}
|
||||
|
||||
func (s *ChatStore) NextMessage() int64 {
|
||||
s.nextMessageID++
|
||||
return s.nextMessageID
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"juwan-backend/app/chat/rpc/internal/config"
|
||||
"juwan-backend/app/chat/rpc/internal/server"
|
||||
"juwan-backend/app/chat/rpc/internal/svc"
|
||||
"juwan-backend/app/chat/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/core/service"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/reflection"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/pb.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
ctx := svc.NewServiceContext(c)
|
||||
|
||||
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||
pb.RegisterChatServiceServer(grpcServer, server.NewChatServiceServer(ctx))
|
||||
|
||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||
reflection.Register(grpcServer)
|
||||
}
|
||||
})
|
||||
defer s.Stop()
|
||||
|
||||
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
|
||||
s.Start()
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package pb
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type ChatServiceServer interface {
|
||||
AddChatSessions(context.Context, *AddChatSessionsReq) (*AddChatSessionsResp, error)
|
||||
UpdateChatSessions(context.Context, *UpdateChatSessionsReq) (*UpdateChatSessionsResp, error)
|
||||
DelChatSessions(context.Context, *DelChatSessionsReq) (*DelChatSessionsResp, error)
|
||||
GetChatSessionsById(context.Context, *GetChatSessionsByIdReq) (*GetChatSessionsByIdResp, error)
|
||||
SearchChatSessions(context.Context, *SearchChatSessionsReq) (*SearchChatSessionsResp, error)
|
||||
AddParticipant(context.Context, *AddParticipantReq) (*AddParticipantResp, error)
|
||||
RemoveParticipant(context.Context, *RemoveParticipantReq) (*RemoveParticipantResp, error)
|
||||
AddChatMessages(context.Context, *AddChatMessagesReq) (*AddChatMessagesResp, error)
|
||||
DelChatMessages(context.Context, *DelChatMessagesReq) (*DelChatMessagesResp, error)
|
||||
GetChatMessagesById(context.Context, *GetChatMessagesByIdReq) (*GetChatMessagesByIdResp, error)
|
||||
SearchChatMessages(context.Context, *SearchChatMessagesReq) (*SearchChatMessagesResp, error)
|
||||
mustEmbedUnimplementedChatServiceServer()
|
||||
}
|
||||
|
||||
type UnimplementedChatServiceServer struct{}
|
||||
|
||||
func (UnimplementedChatServiceServer) AddChatSessions(context.Context, *AddChatSessionsReq) (*AddChatSessionsResp, error) {
|
||||
return nil, grpc.Errorf(12, "method AddChatSessions not implemented")
|
||||
}
|
||||
func (UnimplementedChatServiceServer) UpdateChatSessions(context.Context, *UpdateChatSessionsReq) (*UpdateChatSessionsResp, error) {
|
||||
return nil, grpc.Errorf(12, "method UpdateChatSessions not implemented")
|
||||
}
|
||||
func (UnimplementedChatServiceServer) DelChatSessions(context.Context, *DelChatSessionsReq) (*DelChatSessionsResp, error) {
|
||||
return nil, grpc.Errorf(12, "method DelChatSessions not implemented")
|
||||
}
|
||||
func (UnimplementedChatServiceServer) GetChatSessionsById(context.Context, *GetChatSessionsByIdReq) (*GetChatSessionsByIdResp, error) {
|
||||
return nil, grpc.Errorf(12, "method GetChatSessionsById not implemented")
|
||||
}
|
||||
func (UnimplementedChatServiceServer) SearchChatSessions(context.Context, *SearchChatSessionsReq) (*SearchChatSessionsResp, error) {
|
||||
return nil, grpc.Errorf(12, "method SearchChatSessions not implemented")
|
||||
}
|
||||
func (UnimplementedChatServiceServer) AddParticipant(context.Context, *AddParticipantReq) (*AddParticipantResp, error) {
|
||||
return nil, grpc.Errorf(12, "method AddParticipant not implemented")
|
||||
}
|
||||
func (UnimplementedChatServiceServer) RemoveParticipant(context.Context, *RemoveParticipantReq) (*RemoveParticipantResp, error) {
|
||||
return nil, grpc.Errorf(12, "method RemoveParticipant not implemented")
|
||||
}
|
||||
func (UnimplementedChatServiceServer) AddChatMessages(context.Context, *AddChatMessagesReq) (*AddChatMessagesResp, error) {
|
||||
return nil, grpc.Errorf(12, "method AddChatMessages not implemented")
|
||||
}
|
||||
func (UnimplementedChatServiceServer) DelChatMessages(context.Context, *DelChatMessagesReq) (*DelChatMessagesResp, error) {
|
||||
return nil, grpc.Errorf(12, "method DelChatMessages not implemented")
|
||||
}
|
||||
func (UnimplementedChatServiceServer) GetChatMessagesById(context.Context, *GetChatMessagesByIdReq) (*GetChatMessagesByIdResp, error) {
|
||||
return nil, grpc.Errorf(12, "method GetChatMessagesById not implemented")
|
||||
}
|
||||
func (UnimplementedChatServiceServer) SearchChatMessages(context.Context, *SearchChatMessagesReq) (*SearchChatMessagesResp, error) {
|
||||
return nil, grpc.Errorf(12, "method SearchChatMessages not implemented")
|
||||
}
|
||||
func (UnimplementedChatServiceServer) mustEmbedUnimplementedChatServiceServer() {}
|
||||
|
||||
type UnsafeChatServiceServer interface {
|
||||
mustEmbedUnimplementedChatServiceServer()
|
||||
}
|
||||
|
||||
type ChatServiceClient interface {
|
||||
AddChatSessions(ctx context.Context, in *AddChatSessionsReq, opts ...grpc.CallOption) (*AddChatSessionsResp, error)
|
||||
UpdateChatSessions(ctx context.Context, in *UpdateChatSessionsReq, opts ...grpc.CallOption) (*UpdateChatSessionsResp, error)
|
||||
DelChatSessions(ctx context.Context, in *DelChatSessionsReq, opts ...grpc.CallOption) (*DelChatSessionsResp, error)
|
||||
GetChatSessionsById(ctx context.Context, in *GetChatSessionsByIdReq, opts ...grpc.CallOption) (*GetChatSessionsByIdResp, error)
|
||||
SearchChatSessions(ctx context.Context, in *SearchChatSessionsReq, opts ...grpc.CallOption) (*SearchChatSessionsResp, error)
|
||||
AddParticipant(ctx context.Context, in *AddParticipantReq, opts ...grpc.CallOption) (*AddParticipantResp, error)
|
||||
RemoveParticipant(ctx context.Context, in *RemoveParticipantReq, opts ...grpc.CallOption) (*RemoveParticipantResp, error)
|
||||
AddChatMessages(ctx context.Context, in *AddChatMessagesReq, opts ...grpc.CallOption) (*AddChatMessagesResp, error)
|
||||
DelChatMessages(ctx context.Context, in *DelChatMessagesReq, opts ...grpc.CallOption) (*DelChatMessagesResp, error)
|
||||
GetChatMessagesById(ctx context.Context, in *GetChatMessagesByIdReq, opts ...grpc.CallOption) (*GetChatMessagesByIdResp, error)
|
||||
SearchChatMessages(ctx context.Context, in *SearchChatMessagesReq, opts ...grpc.CallOption) (*SearchChatMessagesResp, error)
|
||||
}
|
||||
|
||||
type chatServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewChatServiceClient(cc grpc.ClientConnInterface) ChatServiceClient {
|
||||
return &chatServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *chatServiceClient) AddChatSessions(ctx context.Context, in *AddChatSessionsReq, opts ...grpc.CallOption) (*AddChatSessionsResp, error) {
|
||||
out := new(AddChatSessionsResp)
|
||||
err := c.cc.Invoke(ctx, "/pb.chatService/AddChatSessions", in, out, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *chatServiceClient) UpdateChatSessions(ctx context.Context, in *UpdateChatSessionsReq, opts ...grpc.CallOption) (*UpdateChatSessionsResp, error) {
|
||||
out := new(UpdateChatSessionsResp)
|
||||
err := c.cc.Invoke(ctx, "/pb.chatService/UpdateChatSessions", in, out, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *chatServiceClient) DelChatSessions(ctx context.Context, in *DelChatSessionsReq, opts ...grpc.CallOption) (*DelChatSessionsResp, error) {
|
||||
out := new(DelChatSessionsResp)
|
||||
err := c.cc.Invoke(ctx, "/pb.chatService/DelChatSessions", in, out, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *chatServiceClient) GetChatSessionsById(ctx context.Context, in *GetChatSessionsByIdReq, opts ...grpc.CallOption) (*GetChatSessionsByIdResp, error) {
|
||||
out := new(GetChatSessionsByIdResp)
|
||||
err := c.cc.Invoke(ctx, "/pb.chatService/GetChatSessionsById", in, out, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *chatServiceClient) SearchChatSessions(ctx context.Context, in *SearchChatSessionsReq, opts ...grpc.CallOption) (*SearchChatSessionsResp, error) {
|
||||
out := new(SearchChatSessionsResp)
|
||||
err := c.cc.Invoke(ctx, "/pb.chatService/SearchChatSessions", in, out, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *chatServiceClient) AddParticipant(ctx context.Context, in *AddParticipantReq, opts ...grpc.CallOption) (*AddParticipantResp, error) {
|
||||
out := new(AddParticipantResp)
|
||||
err := c.cc.Invoke(ctx, "/pb.chatService/AddParticipant", in, out, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *chatServiceClient) RemoveParticipant(ctx context.Context, in *RemoveParticipantReq, opts ...grpc.CallOption) (*RemoveParticipantResp, error) {
|
||||
out := new(RemoveParticipantResp)
|
||||
err := c.cc.Invoke(ctx, "/pb.chatService/RemoveParticipant", in, out, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *chatServiceClient) AddChatMessages(ctx context.Context, in *AddChatMessagesReq, opts ...grpc.CallOption) (*AddChatMessagesResp, error) {
|
||||
out := new(AddChatMessagesResp)
|
||||
err := c.cc.Invoke(ctx, "/pb.chatService/AddChatMessages", in, out, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *chatServiceClient) DelChatMessages(ctx context.Context, in *DelChatMessagesReq, opts ...grpc.CallOption) (*DelChatMessagesResp, error) {
|
||||
out := new(DelChatMessagesResp)
|
||||
err := c.cc.Invoke(ctx, "/pb.chatService/DelChatMessages", in, out, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *chatServiceClient) GetChatMessagesById(ctx context.Context, in *GetChatMessagesByIdReq, opts ...grpc.CallOption) (*GetChatMessagesByIdResp, error) {
|
||||
out := new(GetChatMessagesByIdResp)
|
||||
err := c.cc.Invoke(ctx, "/pb.chatService/GetChatMessagesById", in, out, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func (c *chatServiceClient) SearchChatMessages(ctx context.Context, in *SearchChatMessagesReq, opts ...grpc.CallOption) (*SearchChatMessagesResp, error) {
|
||||
out := new(SearchChatMessagesResp)
|
||||
err := c.cc.Invoke(ctx, "/pb.chatService/SearchChatMessages", in, out, opts...)
|
||||
return out, err
|
||||
}
|
||||
|
||||
var ChatService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "pb.chatService",
|
||||
HandlerType: (*ChatServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{MethodName: "AddChatSessions", Handler: _ChatService_AddChatSessions_Handler},
|
||||
{MethodName: "UpdateChatSessions", Handler: _ChatService_UpdateChatSessions_Handler},
|
||||
{MethodName: "DelChatSessions", Handler: _ChatService_DelChatSessions_Handler},
|
||||
{MethodName: "GetChatSessionsById", Handler: _ChatService_GetChatSessionsById_Handler},
|
||||
{MethodName: "SearchChatSessions", Handler: _ChatService_SearchChatSessions_Handler},
|
||||
{MethodName: "AddParticipant", Handler: _ChatService_AddParticipant_Handler},
|
||||
{MethodName: "RemoveParticipant", Handler: _ChatService_RemoveParticipant_Handler},
|
||||
{MethodName: "AddChatMessages", Handler: _ChatService_AddChatMessages_Handler},
|
||||
{MethodName: "DelChatMessages", Handler: _ChatService_DelChatMessages_Handler},
|
||||
{MethodName: "GetChatMessagesById", Handler: _ChatService_GetChatMessagesById_Handler},
|
||||
{MethodName: "SearchChatMessages", Handler: _ChatService_SearchChatMessages_Handler},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "chat.proto",
|
||||
}
|
||||
|
||||
func RegisterChatServiceServer(s grpc.ServiceRegistrar, srv ChatServiceServer) {
|
||||
s.RegisterService(&ChatService_ServiceDesc, srv)
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
package pb
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func _ChatService_AddChatSessions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AddChatSessionsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ChatServiceServer).AddChatSessions(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/pb.chatService/AddChatSessions"}
|
||||
return interceptor(ctx, in, info, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ChatServiceServer).AddChatSessions(ctx, req.(*AddChatSessionsReq))
|
||||
})
|
||||
}
|
||||
|
||||
func _ChatService_UpdateChatSessions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UpdateChatSessionsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ChatServiceServer).UpdateChatSessions(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/pb.chatService/UpdateChatSessions"}
|
||||
return interceptor(ctx, in, info, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ChatServiceServer).UpdateChatSessions(ctx, req.(*UpdateChatSessionsReq))
|
||||
})
|
||||
}
|
||||
|
||||
func _ChatService_DelChatSessions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DelChatSessionsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ChatServiceServer).DelChatSessions(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/pb.chatService/DelChatSessions"}
|
||||
return interceptor(ctx, in, info, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ChatServiceServer).DelChatSessions(ctx, req.(*DelChatSessionsReq))
|
||||
})
|
||||
}
|
||||
|
||||
func _ChatService_GetChatSessionsById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetChatSessionsByIdReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ChatServiceServer).GetChatSessionsById(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/pb.chatService/GetChatSessionsById"}
|
||||
return interceptor(ctx, in, info, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ChatServiceServer).GetChatSessionsById(ctx, req.(*GetChatSessionsByIdReq))
|
||||
})
|
||||
}
|
||||
|
||||
func _ChatService_SearchChatSessions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SearchChatSessionsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ChatServiceServer).SearchChatSessions(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/pb.chatService/SearchChatSessions"}
|
||||
return interceptor(ctx, in, info, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ChatServiceServer).SearchChatSessions(ctx, req.(*SearchChatSessionsReq))
|
||||
})
|
||||
}
|
||||
|
||||
func _ChatService_AddParticipant_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AddParticipantReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ChatServiceServer).AddParticipant(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/pb.chatService/AddParticipant"}
|
||||
return interceptor(ctx, in, info, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ChatServiceServer).AddParticipant(ctx, req.(*AddParticipantReq))
|
||||
})
|
||||
}
|
||||
|
||||
func _ChatService_RemoveParticipant_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(RemoveParticipantReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ChatServiceServer).RemoveParticipant(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/pb.chatService/RemoveParticipant"}
|
||||
return interceptor(ctx, in, info, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ChatServiceServer).RemoveParticipant(ctx, req.(*RemoveParticipantReq))
|
||||
})
|
||||
}
|
||||
|
||||
func _ChatService_AddChatMessages_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AddChatMessagesReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ChatServiceServer).AddChatMessages(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/pb.chatService/AddChatMessages"}
|
||||
return interceptor(ctx, in, info, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ChatServiceServer).AddChatMessages(ctx, req.(*AddChatMessagesReq))
|
||||
})
|
||||
}
|
||||
|
||||
func _ChatService_DelChatMessages_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DelChatMessagesReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ChatServiceServer).DelChatMessages(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/pb.chatService/DelChatMessages"}
|
||||
return interceptor(ctx, in, info, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ChatServiceServer).DelChatMessages(ctx, req.(*DelChatMessagesReq))
|
||||
})
|
||||
}
|
||||
|
||||
func _ChatService_GetChatMessagesById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetChatMessagesByIdReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ChatServiceServer).GetChatMessagesById(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/pb.chatService/GetChatMessagesById"}
|
||||
return interceptor(ctx, in, info, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ChatServiceServer).GetChatMessagesById(ctx, req.(*GetChatMessagesByIdReq))
|
||||
})
|
||||
}
|
||||
|
||||
func _ChatService_SearchChatMessages_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SearchChatMessagesReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ChatServiceServer).SearchChatMessages(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{Server: srv, FullMethod: "/pb.chatService/SearchChatMessages"}
|
||||
return interceptor(ctx, in, info, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ChatServiceServer).SearchChatMessages(ctx, req.(*SearchChatMessagesReq))
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package pb
|
||||
|
||||
type ChatMessages struct {
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
SessionId int64 `protobuf:"varint,2,opt,name=sessionId,proto3" json:"sessionId,omitempty"`
|
||||
SenderId int64 `protobuf:"varint,3,opt,name=senderId,proto3" json:"senderId,omitempty"`
|
||||
Type string `protobuf:"bytes,4,opt,name=type,proto3" json:"type,omitempty"`
|
||||
Content string `protobuf:"bytes,5,opt,name=content,proto3" json:"content,omitempty"`
|
||||
CreatedAt int64 `protobuf:"varint,6,opt,name=createdAt,proto3" json:"createdAt,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ChatMessages) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ChatMessages) GetSessionId() int64 {
|
||||
if x != nil {
|
||||
return x.SessionId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ChatMessages) GetSenderId() int64 {
|
||||
if x != nil {
|
||||
return x.SenderId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ChatMessages) GetType() string {
|
||||
if x != nil {
|
||||
return x.Type
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ChatMessages) GetContent() string {
|
||||
if x != nil {
|
||||
return x.Content
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ChatMessages) GetCreatedAt() int64 {
|
||||
if x != nil {
|
||||
return x.CreatedAt
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type AddChatMessagesReq struct {
|
||||
SessionId int64 `protobuf:"varint,1,opt,name=sessionId,proto3" json:"sessionId,omitempty"`
|
||||
SenderId int64 `protobuf:"varint,2,opt,name=senderId,proto3" json:"senderId,omitempty"`
|
||||
Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"`
|
||||
Content string `protobuf:"bytes,4,opt,name=content,proto3" json:"content,omitempty"`
|
||||
}
|
||||
|
||||
func (x *AddChatMessagesReq) GetSessionId() int64 {
|
||||
if x != nil {
|
||||
return x.SessionId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *AddChatMessagesReq) GetSenderId() int64 {
|
||||
if x != nil {
|
||||
return x.SenderId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *AddChatMessagesReq) GetType() string {
|
||||
if x != nil {
|
||||
return x.Type
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *AddChatMessagesReq) GetContent() string {
|
||||
if x != nil {
|
||||
return x.Content
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type AddChatMessagesResp struct {
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func (x *AddChatMessagesResp) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type DelChatMessagesReq struct {
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func (x *DelChatMessagesReq) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type DelChatMessagesResp struct{}
|
||||
|
||||
type GetChatMessagesByIdReq struct {
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func (x *GetChatMessagesByIdReq) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type GetChatMessagesByIdResp struct {
|
||||
ChatMessages *ChatMessages `protobuf:"bytes,1,opt,name=chatMessages,proto3" json:"chatMessages,omitempty"`
|
||||
}
|
||||
|
||||
func (x *GetChatMessagesByIdResp) GetChatMessages() *ChatMessages {
|
||||
if x != nil {
|
||||
return x.ChatMessages
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type SearchChatMessagesReq struct {
|
||||
Page int64 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"`
|
||||
Limit int64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"`
|
||||
SessionId int64 `protobuf:"varint,3,opt,name=sessionId,proto3" json:"sessionId,omitempty"`
|
||||
SenderId *int64 `protobuf:"varint,4,opt,name=senderId,proto3,oneof" json:"senderId,omitempty"`
|
||||
}
|
||||
|
||||
func (x *SearchChatMessagesReq) GetPage() int64 {
|
||||
if x != nil {
|
||||
return x.Page
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SearchChatMessagesReq) GetLimit() int64 {
|
||||
if x != nil {
|
||||
return x.Limit
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SearchChatMessagesReq) GetSessionId() int64 {
|
||||
if x != nil {
|
||||
return x.SessionId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SearchChatMessagesReq) GetSenderId() *int64 {
|
||||
if x != nil {
|
||||
return x.SenderId
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type SearchChatMessagesResp struct {
|
||||
ChatMessages []*ChatMessages `protobuf:"bytes,1,rep,name=chatMessages,proto3" json:"chatMessages,omitempty"`
|
||||
}
|
||||
|
||||
func (x *SearchChatMessagesResp) GetChatMessages() []*ChatMessages {
|
||||
if x != nil {
|
||||
return x.ChatMessages
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
package pb
|
||||
|
||||
type ChatSessions struct {
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
|
||||
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
|
||||
CreatorId int64 `protobuf:"varint,4,opt,name=creatorId,proto3" json:"creatorId,omitempty"`
|
||||
Participants []int64 `protobuf:"varint,5,rep,packed,name=participants,proto3" json:"participants,omitempty"`
|
||||
LastMessage string `protobuf:"bytes,6,opt,name=lastMessage,proto3" json:"lastMessage,omitempty"`
|
||||
LastMessageAt int64 `protobuf:"varint,7,opt,name=lastMessageAt,proto3" json:"lastMessageAt,omitempty"`
|
||||
CreatedAt int64 `protobuf:"varint,8,opt,name=createdAt,proto3" json:"createdAt,omitempty"`
|
||||
UpdatedAt int64 `protobuf:"varint,9,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ChatSessions) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ChatSessions) GetType() string {
|
||||
if x != nil {
|
||||
return x.Type
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ChatSessions) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ChatSessions) GetCreatorId() int64 {
|
||||
if x != nil {
|
||||
return x.CreatorId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ChatSessions) GetParticipants() []int64 {
|
||||
if x != nil {
|
||||
return x.Participants
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ChatSessions) GetLastMessage() string {
|
||||
if x != nil {
|
||||
return x.LastMessage
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ChatSessions) GetLastMessageAt() int64 {
|
||||
if x != nil {
|
||||
return x.LastMessageAt
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ChatSessions) GetCreatedAt() int64 {
|
||||
if x != nil {
|
||||
return x.CreatedAt
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *ChatSessions) GetUpdatedAt() int64 {
|
||||
if x != nil {
|
||||
return x.UpdatedAt
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type AddChatSessionsReq struct {
|
||||
Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
CreatorId int64 `protobuf:"varint,3,opt,name=creatorId,proto3" json:"creatorId,omitempty"`
|
||||
Participants []int64 `protobuf:"varint,4,rep,packed,name=participants,proto3" json:"participants,omitempty"`
|
||||
}
|
||||
|
||||
func (x *AddChatSessionsReq) GetType() string {
|
||||
if x != nil {
|
||||
return x.Type
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *AddChatSessionsReq) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *AddChatSessionsReq) GetCreatorId() int64 {
|
||||
if x != nil {
|
||||
return x.CreatorId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *AddChatSessionsReq) GetParticipants() []int64 {
|
||||
if x != nil {
|
||||
return x.Participants
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type AddChatSessionsResp struct {
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func (x *AddChatSessionsResp) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type UpdateChatSessionsReq struct {
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Name *string `protobuf:"bytes,2,opt,name=name,proto3,oneof" json:"name,omitempty"`
|
||||
LastMessage *string `protobuf:"bytes,3,opt,name=lastMessage,proto3,oneof" json:"lastMessage,omitempty"`
|
||||
LastMessageAt *int64 `protobuf:"varint,4,opt,name=lastMessageAt,proto3,oneof" json:"lastMessageAt,omitempty"`
|
||||
}
|
||||
|
||||
func (x *UpdateChatSessionsReq) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *UpdateChatSessionsReq) GetName() *string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *UpdateChatSessionsReq) GetLastMessage() *string {
|
||||
if x != nil {
|
||||
return x.LastMessage
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *UpdateChatSessionsReq) GetLastMessageAt() *int64 {
|
||||
if x != nil {
|
||||
return x.LastMessageAt
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type UpdateChatSessionsResp struct{}
|
||||
|
||||
type DelChatSessionsReq struct {
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func (x *DelChatSessionsReq) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type DelChatSessionsResp struct{}
|
||||
|
||||
type GetChatSessionsByIdReq struct {
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func (x *GetChatSessionsByIdReq) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type GetChatSessionsByIdResp struct {
|
||||
ChatSessions *ChatSessions `protobuf:"bytes,1,opt,name=chatSessions,proto3" json:"chatSessions,omitempty"`
|
||||
}
|
||||
|
||||
func (x *GetChatSessionsByIdResp) GetChatSessions() *ChatSessions {
|
||||
if x != nil {
|
||||
return x.ChatSessions
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type SearchChatSessionsReq struct {
|
||||
Page int64 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"`
|
||||
Limit int64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"`
|
||||
UserId *int64 `protobuf:"varint,3,opt,name=userId,proto3,oneof" json:"userId,omitempty"`
|
||||
Type *string `protobuf:"bytes,4,opt,name=type,proto3,oneof" json:"type,omitempty"`
|
||||
}
|
||||
|
||||
func (x *SearchChatSessionsReq) GetPage() int64 {
|
||||
if x != nil {
|
||||
return x.Page
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SearchChatSessionsReq) GetLimit() int64 {
|
||||
if x != nil {
|
||||
return x.Limit
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SearchChatSessionsReq) GetUserId() *int64 {
|
||||
if x != nil {
|
||||
return x.UserId
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *SearchChatSessionsReq) GetType() *string {
|
||||
if x != nil {
|
||||
return x.Type
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type SearchChatSessionsResp struct {
|
||||
ChatSessions []*ChatSessions `protobuf:"bytes,1,rep,name=chatSessions,proto3" json:"chatSessions,omitempty"`
|
||||
}
|
||||
|
||||
func (x *SearchChatSessionsResp) GetChatSessions() []*ChatSessions {
|
||||
if x != nil {
|
||||
return x.ChatSessions
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type AddParticipantReq struct {
|
||||
SessionId int64 `protobuf:"varint,1,opt,name=sessionId,proto3" json:"sessionId,omitempty"`
|
||||
UserId int64 `protobuf:"varint,2,opt,name=userId,proto3" json:"userId,omitempty"`
|
||||
}
|
||||
|
||||
func (x *AddParticipantReq) GetSessionId() int64 {
|
||||
if x != nil {
|
||||
return x.SessionId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *AddParticipantReq) GetUserId() int64 {
|
||||
if x != nil {
|
||||
return x.UserId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type AddParticipantResp struct{}
|
||||
|
||||
type RemoveParticipantReq struct {
|
||||
SessionId int64 `protobuf:"varint,1,opt,name=sessionId,proto3" json:"sessionId,omitempty"`
|
||||
UserId int64 `protobuf:"varint,2,opt,name=userId,proto3" json:"userId,omitempty"`
|
||||
}
|
||||
|
||||
func (x *RemoveParticipantReq) GetSessionId() int64 {
|
||||
if x != nil {
|
||||
return x.SessionId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *RemoveParticipantReq) GetUserId() int64 {
|
||||
if x != nil {
|
||||
return x.UserId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type RemoveParticipantResp struct{}
|
||||
Reference in New Issue
Block a user