source: code/trunk/msgstore.go@ 440

Last change on this file since 440 was 440, checked in by contact, 4 years ago

Add store-agnostic message ID format

Allow to query the network ID and entity from the message ID regardless
of the underlying store used.

File size: 1.3 KB
Line 
1package soju
2
3import (
4 "fmt"
5 "strconv"
6 "strings"
7 "time"
8
9 "gopkg.in/irc.v3"
10)
11
12// messageStore is a per-user store for IRC messages.
13type messageStore interface {
14 Close() error
15 // LastMsgID queries the last message ID for the given network, entity and
16 // date. The message ID returned may not refer to a valid message, but can be
17 // used in history queries.
18 LastMsgID(network *network, entity string, t time.Time) (string, error)
19 LoadBeforeTime(network *network, entity string, t time.Time, limit int) ([]*irc.Message, error)
20 LoadAfterTime(network *network, entity string, t time.Time, limit int) ([]*irc.Message, error)
21 LoadLatestID(network *network, entity, id string, limit int) ([]*irc.Message, error)
22 Append(network *network, entity string, msg *irc.Message) (id string, err error)
23}
24
25func formatMsgID(netID int64, entity, extra string) string {
26 return fmt.Sprintf("%v %v %v", netID, entity, extra)
27}
28
29func parseMsgID(s string) (netID int64, entity, extra string, err error) {
30 l := strings.SplitN(s, " ", 3)
31 if len(l) != 3 {
32 return 0, "", "", fmt.Errorf("invalid message ID %q: expected 3 fields", s)
33 }
34 netID, err = strconv.ParseInt(l[0], 10, 64)
35 if err != nil {
36 return 0, "", "", fmt.Errorf("invalid message ID %q: %v", s, err)
37 }
38 return netID, l[1], l[2], nil
39}
Note: See TracBrowser for help on using the repository browser.