Fixed for data storage and support for messages with nil username.

This commit is contained in:
Igor Mandrigin 2018-02-22 17:53:19 +01:00
parent 06a952bdca
commit 1fd64db523
2 changed files with 4 additions and 2 deletions

View File

@ -12,7 +12,7 @@ import (
)
const (
messageRegexString = `{:message-id "(?P<ID>.+)",\s+:group-id "(?P<GroupID>.+)",\s+:content "(?P<Content>.+)",\s+:username "(?P<Username>.+)",\s+:type :public-group-message.+:timestamp (?P<Timestamp>\d+)}`
messageRegexString = `{:message-id "(?P<ID>.+)",\s+:group-id "(?P<GroupID>.+)",\s+:content "(?P<Content>.+)",\s+:username ["]?(?P<Username>.+)["]?,\s+:type :public-group-message.+:timestamp (?P<Timestamp>\d+)}`
)
var messageRegex *regexp.Regexp = regexp.MustCompile(messageRegexString)

View File

@ -69,7 +69,9 @@ func (ms *messagesStore) Add(message bots.StatusMessage) error {
}
func (ms *messagesStore) Messages(channel string) []bots.StatusMessage {
return messagesFromIterator(ms.db.NewIterator(util.BytesPrefix([]byte(channel)), nil))
messages := messagesFromIterator(ms.db.NewIterator(util.BytesPrefix([]byte(channel)), nil))
sort.Sort(ByTimestamp(messages))
return messages
}
func (ms *messagesStore) Close() {