source: code/trunk/msgstore.go@ 449

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

Make chat history operations optional in messageStore

Some stores may want not to implement chat history operations.

File size: 1.4 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 LoadLatestID(network *network, entity, id string, limit int) ([]*irc.Message, error)
20 Append(network *network, entity string, msg *irc.Message) (id string, err error)
21}
22
23// chatHistoryMessageStore is a message store that supports chat history
24// operations.
25type chatHistoryMessageStore interface {
26 messageStore
27
28 LoadBeforeTime(network *network, entity string, t time.Time, limit int) ([]*irc.Message, error)
29 LoadAfterTime(network *network, entity string, t time.Time, limit int) ([]*irc.Message, error)
30}
31
32func formatMsgID(netID int64, entity, extra string) string {
33 return fmt.Sprintf("%v %v %v", netID, entity, extra)
34}
35
36func parseMsgID(s string) (netID int64, entity, extra string, err error) {
37 l := strings.SplitN(s, " ", 3)
38 if len(l) != 3 {
39 return 0, "", "", fmt.Errorf("invalid message ID %q: expected 3 fields", s)
40 }
41 netID, err = strconv.ParseInt(l[0], 10, 64)
42 if err != nil {
43 return 0, "", "", fmt.Errorf("invalid message ID %q: %v", s, err)
44 }
45 return netID, l[1], l[2], nil
46}
Note: See TracBrowser for help on using the repository browser.