almost done with chat interceptor. Implement message registories mechanism

This commit is contained in:
harshabose
2025-05-23 11:02:30 +05:30
parent 3bc71a1627
commit c1b249bc1f
67 changed files with 923 additions and 521 deletions

View File

@@ -5,41 +5,34 @@ import (
"fmt"
"time"
"github.com/harshabose/socket-comm/pkg/middleware/chat/errors"
"github.com/harshabose/socket-comm/pkg/middleware/chat/interfaces"
"github.com/harshabose/socket-comm/pkg/middleware/chat/state"
"github.com/harshabose/socket-comm/pkg/interceptor"
"github.com/harshabose/socket-comm/pkg/middleware/chat/types"
)
// DeleteRoomWaiter is a process that waits until TTL to delete a room.
// NOTE: THIS IS A PURE PROCESS; AND IS NOT ADVISED TO BE TAGGED IN A MESSAGE
type DeleteRoomWaiter struct {
TTL time.Duration `json:"ttl"`
RoomID types.RoomID `json:"room_id"`
TTL time.Duration `json:"ttl"`
DeleteRoom
AsyncProcess
}
func NewDeleteRoomWaiter(ctx context.Context, roomid types.RoomID, ttl time.Duration) *DeleteRoomWaiter {
return &DeleteRoomWaiter{
AsyncProcess: ManualAsyncProcessInitialisation(context.WithTimeout(ctx, ttl)),
RoomID: roomid,
DeleteRoom: DeleteRoom{RoomID: roomid},
TTL: ttl,
}
}
func (p *DeleteRoomWaiter) Process(ctx context.Context, processor interfaces.Processor, _ *state.State) error {
d, ok := processor.(interfaces.CanDeleteRoom)
if !ok {
return errors.ErrInterfaceMisMatch
}
func (p *DeleteRoomWaiter) Process(ctx context.Context, processor interceptor.CanProcess, _ interceptor.State) error {
timer := time.NewTimer(p.TTL)
defer timer.Stop()
for {
select {
case <-timer.C:
if err := p.process(d); err != nil {
if err := p.DeleteRoom.Process(ctx, processor, nil); err != nil {
return fmt.Errorf("error while processing DeleteRoomWaiter process; err: %s", err.Error())
}
return nil
@@ -48,11 +41,3 @@ func (p *DeleteRoomWaiter) Process(ctx context.Context, processor interfaces.Pro
}
}
}
func (p *DeleteRoomWaiter) process(d interfaces.CanDeleteRoom) error {
if err := d.DeleteRoom(p.RoomID); err != nil {
return err
}
return nil
}