Changeset 516 in code for trunk/downstream.go


Ignore:
Timestamp:
May 18, 2021, 8:44:10 AM (4 years ago)
Author:
hubert
Message:

Implement CHATHISTORY BETWEEN

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r515 r516  
    18021802                        return err
    18031803                }
    1804                 var target, criteria, limitStr string
    1805                 if err := parseMessageParams(msg, nil, &target, &criteria, &limitStr); err != nil {
     1804                var target, limitStr string
     1805                var boundsStr [2]string
     1806                switch subcommand {
     1807                case "AFTER", "BEFORE":
     1808                        if err := parseMessageParams(msg, nil, &target, &boundsStr[0], &limitStr); err != nil {
     1809                                return err
     1810                        }
     1811                case "BETWEEN":
     1812                        if err := parseMessageParams(msg, nil, &target, &boundsStr[0], &boundsStr[1], &limitStr); err != nil {
     1813                                return err
     1814                        }
     1815                default:
     1816                        // TODO: support LATEST, AROUND
    18061817                        return ircError{&irc.Message{
    18071818                                Command: "FAIL",
    1808                                 Params:  []string{"CHATHISTORY", "NEED_MORE_PARAMS", subcommand, "Missing parameters"},
     1819                                Params:  []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, "Unknown command"},
    18091820                        }}
    18101821                }
     
    18251836
    18261837                // TODO: support msgid criteria
    1827                 criteriaParts := strings.SplitN(criteria, "=", 2)
    1828                 if len(criteriaParts) != 2 || criteriaParts[0] != "timestamp" {
     1838                var bounds [2]time.Time
     1839                bounds[0] = parseChatHistoryBound(boundsStr[0])
     1840                if bounds[0].IsZero() {
    18291841                        return ircError{&irc.Message{
    18301842                                Command: "FAIL",
    1831                                 Params:  []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, criteria, "Unknown criteria"},
     1843                                Params:  []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, boundsStr[0], "Invalid first bound"},
    18321844                        }}
    18331845                }
    18341846
    1835                 timestamp, err := time.Parse(serverTimeLayout, criteriaParts[1])
    1836                 if err != nil {
    1837                         return ircError{&irc.Message{
    1838                                 Command: "FAIL",
    1839                                 Params:  []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, criteria, "Invalid criteria"},
    1840                         }}
     1847                if boundsStr[1] != "" {
     1848                        bounds[1] = parseChatHistoryBound(boundsStr[1])
     1849                        if bounds[1].IsZero() {
     1850                                return ircError{&irc.Message{
     1851                                        Command: "FAIL",
     1852                                        Params:  []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, boundsStr[1], "Invalid second bound"},
     1853                                }}
     1854                        }
    18411855                }
    18421856
     
    18521866                switch subcommand {
    18531867                case "BEFORE":
    1854                         history, err = store.LoadBeforeTime(uc.network, entity, timestamp, limit)
     1868                        history, err = store.LoadBeforeTime(uc.network, entity, bounds[0], time.Time{}, limit)
    18551869                case "AFTER":
    1856                         history, err = store.LoadAfterTime(uc.network, entity, timestamp, limit)
    1857                 default:
    1858                         // TODO: support LATEST, BETWEEN
    1859                         return ircError{&irc.Message{
    1860                                 Command: "FAIL",
    1861                                 Params:  []string{"CHATHISTORY", "UNKNOWN_COMMAND", subcommand, "Unknown command"},
    1862                         }}
     1870                        history, err = store.LoadAfterTime(uc.network, entity, bounds[0], time.Now(), limit)
     1871                case "BETWEEN":
     1872                        if bounds[0].Before(bounds[1]) {
     1873                                history, err = store.LoadAfterTime(uc.network, entity, bounds[0], bounds[1], limit)
     1874                        } else {
     1875                                history, err = store.LoadBeforeTime(uc.network, entity, bounds[0], bounds[1], limit)
     1876                        }
    18631877                }
    18641878                if err != nil {
Note: See TracChangeset for help on using the changeset viewer.