diff options
author | Simon Ser <contact@emersion.fr> | 2022-02-25 21:05:10 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-02-25 21:05:10 +0100 |
commit | dc58a7079463c12cd0901fe6d5d4df7d26df4bc1 (patch) | |
tree | c70dbb8317735dcf2e15bb032e6433d7d3191dd4 | |
parent | 379e07f7d8ac21d110c3f95b5512ed4f9457ce6e (diff) |
When fetching messages via draft/chathistory from a conversation
with another user, soju would send the following:
:sender PRIVMSG sender :hey
instead of
:sender PRIVMSG recipient :hey
because the file-system message store format doesn't contain the
original PRIVMSG target.
Fix this by doing some guesswork.
-rw-r--r-- | msgstore_fs.go | 19 | ||||
-rw-r--r-- | user.go | 2 |
2 files changed, 15 insertions, 6 deletions
diff --git a/msgstore_fs.go b/msgstore_fs.go index ebed557..b7bd850 100644 --- a/msgstore_fs.go +++ b/msgstore_fs.go @@ -80,6 +80,7 @@ type fsMessageStoreFile struct { // https://github.com/znc/znc/blob/master/modules/log.cpp type fsMessageStore struct { root string + user *User // Write-only files used by Append files map[string]*fsMessageStoreFile // indexed by entity @@ -88,9 +89,10 @@ type fsMessageStore struct { var _ messageStore = (*fsMessageStore)(nil) var _ chatHistoryMessageStore = (*fsMessageStore)(nil) -func newFSMessageStore(root, username string) *fsMessageStore { +func newFSMessageStore(root string, user *User) *fsMessageStore { return &fsMessageStore{ - root: filepath.Join(root, escapeFilename(username)), + root: filepath.Join(root, escapeFilename(user.Username)), + user: user, files: make(map[string]*fsMessageStoreFile), } } @@ -250,7 +252,7 @@ func formatMessage(msg *irc.Message) string { } } -func parseMessage(line, entity string, ref time.Time, events bool) (*irc.Message, time.Time, error) { +func (ms *fsMessageStore) parseMessage(line string, network *Network, entity string, ref time.Time, events bool) (*irc.Message, time.Time, error) { var hour, minute, second int _, err := fmt.Sscanf(line, "[%02d:%02d:%02d] ", &hour, &minute, &second) if err != nil { @@ -372,6 +374,13 @@ func parseMessage(line, entity string, ref time.Time, events bool) (*irc.Message } prefix = &irc.Prefix{Name: sender} + if entity == sender { + // This is a direct message from a user to us. We don't store own + // our nickname in the logs, so grab it from the network settings. + // Not very accurate since this may not match our nick at the time + // the message was received, but we can't do a lot better. + entity = GetNick(ms.user, network) + } params = []string{entity, text} } @@ -413,7 +422,7 @@ func (ms *fsMessageStore) parseMessagesBefore(network *Network, entity string, r } for sc.Scan() { - msg, t, err := parseMessage(sc.Text(), entity, ref, events) + msg, t, err := ms.parseMessage(sc.Text(), network, entity, ref, events) if err != nil { return nil, err } else if msg == nil || !t.After(end) { @@ -459,7 +468,7 @@ func (ms *fsMessageStore) parseMessagesAfter(network *Network, entity string, re var history []*irc.Message sc := bufio.NewScanner(f) for sc.Scan() && len(history) < limit { - msg, t, err := parseMessage(sc.Text(), entity, ref, events) + msg, t, err := ms.parseMessage(sc.Text(), network, entity, ref, events) if err != nil { return nil, err } else if msg == nil || !t.After(ref) { @@ -451,7 +451,7 @@ func newUser(srv *Server, record *User) *user { var msgStore messageStore if logPath := srv.Config().LogPath; logPath != "" { - msgStore = newFSMessageStore(logPath, record.Username) + msgStore = newFSMessageStore(logPath, record) } else { msgStore = newMemoryMessageStore() } |