Changeset 516 in code for trunk/downstream.go
- Timestamp:
- May 18, 2021, 8:44:10 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/downstream.go
r515 r516 1802 1802 return err 1803 1803 } 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 1806 1817 return ircError{&irc.Message{ 1807 1818 Command: "FAIL", 1808 Params: []string{"CHATHISTORY", " NEED_MORE_PARAMS", subcommand, "Missing parameters"},1819 Params: []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, "Unknown command"}, 1809 1820 }} 1810 1821 } … … 1825 1836 1826 1837 // 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() { 1829 1841 return ircError{&irc.Message{ 1830 1842 Command: "FAIL", 1831 Params: []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, criteria, "Unknown criteria"},1843 Params: []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, boundsStr[0], "Invalid first bound"}, 1832 1844 }} 1833 1845 } 1834 1846 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 } 1841 1855 } 1842 1856 … … 1852 1866 switch subcommand { 1853 1867 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) 1855 1869 case "AFTER": 1856 history, err = store.LoadAfterTime(uc.network, entity, timestamp, limit)1857 default:1858 // TODO: support LATEST, BETWEEN1859 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 } 1863 1877 } 1864 1878 if err != nil {
Note:
See TracChangeset
for help on using the changeset viewer.