mirror of
https://github.com/xaionaro-go/streamctl.git
synced 2025-09-26 19:41:17 +08:00
Fix parsing of messages store with undefined text formats
This commit is contained in:
@@ -319,7 +319,7 @@ func chatListen(cmd *cobra.Command, args []string) {
|
|||||||
assertNoError(ctx, err)
|
assertNoError(ctx, err)
|
||||||
|
|
||||||
fmt.Println("subscribing...")
|
fmt.Println("subscribing...")
|
||||||
ch, err := streamD.SubscribeToChatMessages(ctx, time.Now().Add(-time.Minute), 1000)
|
ch, err := streamD.SubscribeToChatMessages(ctx, time.Now().Add(-time.Hour*24*3), 1000)
|
||||||
assertNoError(ctx, err)
|
assertNoError(ctx, err)
|
||||||
|
|
||||||
fmt.Println("started listening...")
|
fmt.Println("started listening...")
|
||||||
|
@@ -24,9 +24,9 @@ func (s *ChatMessagesStorage) getMessagesSinceLocked(
|
|||||||
since time.Time,
|
since time.Time,
|
||||||
limit uint,
|
limit uint,
|
||||||
) (_ret []api.ChatMessage, _err error) {
|
) (_ret []api.ChatMessage, _err error) {
|
||||||
logger.Tracef(ctx, "getMessagesSinceLocked(ctx, %v, %d)", since, limit)
|
logger.Debugf(ctx, "getMessagesSinceLocked(ctx, %v, %d)", since, limit)
|
||||||
defer func() {
|
defer func() {
|
||||||
logger.Tracef(ctx, "/getMessagesSinceLocked(ctx, %v, %d): len:%d, %v", since, limit, len(_ret), _err)
|
logger.Debugf(ctx, "/getMessagesSinceLocked(ctx, %v, %d): len:%d, %v", since, limit, len(_ret), _err)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if len(s.Messages) == 0 {
|
if len(s.Messages) == 0 {
|
||||||
@@ -48,7 +48,7 @@ func (s *ChatMessagesStorage) getMessagesSinceLocked(
|
|||||||
if idx >= len(s.Messages) {
|
if idx >= len(s.Messages) {
|
||||||
lastMessage := s.Messages[len(s.Messages)-1]
|
lastMessage := s.Messages[len(s.Messages)-1]
|
||||||
if !since.Before(lastMessage.CreatedAt) {
|
if !since.Before(lastMessage.CreatedAt) {
|
||||||
logger.Tracef(ctx, "all messages are too old: %v < %v", lastMessage, since)
|
logger.Tracef(ctx, "all messages (%d) are too old: %v < %v; meanwhile the first message: %v", len(s.Messages), lastMessage, since, s.Messages[0])
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
idx = 0
|
idx = 0
|
||||||
|
@@ -12,6 +12,7 @@ const (
|
|||||||
TextFormatTypePlain
|
TextFormatTypePlain
|
||||||
TextFormatTypeMarkdown
|
TextFormatTypeMarkdown
|
||||||
TextFormatTypeHTML
|
TextFormatTypeHTML
|
||||||
|
EndOfTextFormatType
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t TextFormatType) String() string {
|
func (t TextFormatType) String() string {
|
||||||
@@ -34,7 +35,7 @@ func (t TextFormatType) MarshalJSON() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TextFormatTypeFromString(s string) (TextFormatType, error) {
|
func TextFormatTypeFromString(s string) (TextFormatType, error) {
|
||||||
for i := TextFormatTypeUndefined + 1; i < TextFormatTypeHTML; i++ {
|
for i := range EndOfTextFormatType {
|
||||||
if s == i.String() {
|
if s == i.String() {
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user