Skip to content

Commit e9024b7

Browse files
committed
Fix parsing of messages store with undefined text formats
1 parent 293fb40 commit e9024b7

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

cmd/streamcli/commands/commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func chatListen(cmd *cobra.Command, args []string) {
319319
assertNoError(ctx, err)
320320

321321
fmt.Println("subscribing...")
322-
ch, err := streamD.SubscribeToChatMessages(ctx, time.Now().Add(-time.Minute), 1000)
322+
ch, err := streamD.SubscribeToChatMessages(ctx, time.Now().Add(-time.Hour*24*3), 1000)
323323
assertNoError(ctx, err)
324324

325325
fmt.Println("started listening...")

pkg/chatmessagesstorage/get_messages_since.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ func (s *ChatMessagesStorage) getMessagesSinceLocked(
2424
since time.Time,
2525
limit uint,
2626
) (_ret []api.ChatMessage, _err error) {
27-
logger.Tracef(ctx, "getMessagesSinceLocked(ctx, %v, %d)", since, limit)
27+
logger.Debugf(ctx, "getMessagesSinceLocked(ctx, %v, %d)", since, limit)
2828
defer func() {
29-
logger.Tracef(ctx, "/getMessagesSinceLocked(ctx, %v, %d): len:%d, %v", since, limit, len(_ret), _err)
29+
logger.Debugf(ctx, "/getMessagesSinceLocked(ctx, %v, %d): len:%d, %v", since, limit, len(_ret), _err)
3030
}()
3131

3232
if len(s.Messages) == 0 {
@@ -48,7 +48,7 @@ func (s *ChatMessagesStorage) getMessagesSinceLocked(
4848
if idx >= len(s.Messages) {
4949
lastMessage := s.Messages[len(s.Messages)-1]
5050
if !since.Before(lastMessage.CreatedAt) {
51-
logger.Tracef(ctx, "all messages are too old: %v < %v", lastMessage, since)
51+
logger.Tracef(ctx, "all messages (%d) are too old: %v < %v; meanwhile the first message: %v", len(s.Messages), lastMessage, since, s.Messages[0])
5252
return nil, nil
5353
}
5454
idx = 0

pkg/streamcontrol/text_format_type.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const (
1212
TextFormatTypePlain
1313
TextFormatTypeMarkdown
1414
TextFormatTypeHTML
15+
EndOfTextFormatType
1516
)
1617

1718
func (t TextFormatType) String() string {
@@ -34,7 +35,7 @@ func (t TextFormatType) MarshalJSON() ([]byte, error) {
3435
}
3536

3637
func TextFormatTypeFromString(s string) (TextFormatType, error) {
37-
for i := TextFormatTypeUndefined + 1; i < TextFormatTypeHTML; i++ {
38+
for i := range EndOfTextFormatType {
3839
if s == i.String() {
3940
return i, nil
4041
}

0 commit comments

Comments
 (0)