feat: added support for the new get message function
This commit is contained in:
parent
21f87d049a
commit
79873bdd8c
@ -18,14 +18,16 @@ type server struct {
|
|||||||
database database.OtterSpace
|
database database.OtterSpace
|
||||||
taskExecutionFunction TaskExecution
|
taskExecutionFunction TaskExecution
|
||||||
sendMessageExecution SendMessageExecution
|
sendMessageExecution SendMessageExecution
|
||||||
|
getMessageExecution GetMessageExecution
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGrpcServer(database database.OtterSpace, taskExecutionFunction TaskExecution, sendMessageExecution SendMessageExecution) gRPC.PlugConnectorServer {
|
func NewGrpcServer(database database.OtterSpace, taskExecutionFunction TaskExecution, sendMessageExecution SendMessageExecution, getMessageExecution GetMessageExecution) gRPC.PlugConnectorServer {
|
||||||
return &server{
|
return &server{
|
||||||
ctx: make(map[string]context.CancelFunc),
|
ctx: make(map[string]context.CancelFunc),
|
||||||
database: database,
|
database: database,
|
||||||
taskExecutionFunction: taskExecutionFunction,
|
taskExecutionFunction: taskExecutionFunction,
|
||||||
sendMessageExecution: sendMessageExecution,
|
sendMessageExecution: sendMessageExecution,
|
||||||
|
getMessageExecution: getMessageExecution,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,3 +117,24 @@ func (s *server) SendMessage(ctx context.Context, request *gRPC.SendMessageReque
|
|||||||
|
|
||||||
return &messageResponse, nil
|
return &messageResponse, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *server) GetUserMessages(ctx context.Context, request *gRPC.GetMessagesRequest) (*gRPC.GetMessagesResponse, error) {
|
||||||
|
messageResponse := gRPC.GetMessagesResponse{}
|
||||||
|
|
||||||
|
messages, err := s.getMessageExecution(ctx, request.UserId, request.UserName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, message := range messages {
|
||||||
|
messageResponse.Messages = append(messageResponse.Messages, &gRPC.Message{
|
||||||
|
FromUserId: request.UserId,
|
||||||
|
FromUserName: request.UserName,
|
||||||
|
CreatedAt: message.createdAt,
|
||||||
|
Body: message.body,
|
||||||
|
Title: message.title,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return &messageResponse, nil
|
||||||
|
}
|
||||||
|
@ -4,19 +4,26 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.dragse.it/anthrove/otter-space-sdk/v2/pkg/database"
|
||||||
otterError "git.dragse.it/anthrove/otter-space-sdk/v2/pkg/error"
|
otterError "git.dragse.it/anthrove/otter-space-sdk/v2/pkg/error"
|
||||||
|
"git.dragse.it/anthrove/otter-space-sdk/v2/pkg/models"
|
||||||
|
"github.com/golang/protobuf/ptypes/timestamp"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/v2/pkg/database"
|
|
||||||
"git.dragse.it/anthrove/otter-space-sdk/v2/pkg/models"
|
|
||||||
|
|
||||||
pb "git.dragse.it/anthrove/plug-sdk/v2/pkg/grpc"
|
pb "git.dragse.it/anthrove/plug-sdk/v2/pkg/grpc"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Message struct {
|
||||||
|
title string
|
||||||
|
body string
|
||||||
|
createdAt *timestamp.Timestamp
|
||||||
|
}
|
||||||
|
|
||||||
type TaskExecution func(ctx context.Context, database database.OtterSpace, sourceUsername string, anthroveUser models.User, deepScrape bool, apiKey string, cancelFunction func()) error
|
type TaskExecution func(ctx context.Context, database database.OtterSpace, sourceUsername string, anthroveUser models.User, deepScrape bool, apiKey string, cancelFunction func()) error
|
||||||
type SendMessageExecution func(ctx context.Context, userSourceID string, message string) error
|
type SendMessageExecution func(ctx context.Context, userSourceID string, message string) error
|
||||||
|
type GetMessageExecution func(ctx context.Context, userSourceID string, userSourceUsername string) ([]Message, error)
|
||||||
|
|
||||||
type Plug struct {
|
type Plug struct {
|
||||||
address string
|
address string
|
||||||
@ -25,6 +32,7 @@ type Plug struct {
|
|||||||
database database.OtterSpace
|
database database.OtterSpace
|
||||||
taskExecutionFunction TaskExecution
|
taskExecutionFunction TaskExecution
|
||||||
sendMessageExecution SendMessageExecution
|
sendMessageExecution SendMessageExecution
|
||||||
|
getMessageExecution GetMessageExecution
|
||||||
source models.Source
|
source models.Source
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +63,7 @@ func (p *Plug) Listen() error {
|
|||||||
|
|
||||||
grpcServer := grpc.NewServer()
|
grpcServer := grpc.NewServer()
|
||||||
|
|
||||||
pb.RegisterPlugConnectorServer(grpcServer, NewGrpcServer(p.database, p.taskExecutionFunction, p.sendMessageExecution))
|
pb.RegisterPlugConnectorServer(grpcServer, NewGrpcServer(p.database, p.taskExecutionFunction, p.sendMessageExecution, p.getMessageExecution))
|
||||||
|
|
||||||
err = grpcServer.Serve(lis)
|
err = grpcServer.Serve(lis)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -76,3 +84,7 @@ func (p *Plug) TaskExecutionFunction(function TaskExecution) {
|
|||||||
func (p *Plug) SendMessageExecution(function SendMessageExecution) {
|
func (p *Plug) SendMessageExecution(function SendMessageExecution) {
|
||||||
p.sendMessageExecution = function
|
p.sendMessageExecution = function
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Plug) GetMessageExecution(function GetMessageExecution) {
|
||||||
|
p.getMessageExecution = function
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user