Changeset 549 in code for trunk/downstream.go


Ignore:
Timestamp:
Jun 2, 2021, 6:32:11 PM (4 years ago)
Author:
contact
Message:

Implement CHATHISTORY TARGETS

References: https://github.com/ircv3/ircv3-specifications/pull/450

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r547 r549  
    20312031                                return err
    20322032                        }
     2033                case "TARGETS":
     2034                        if err := parseMessageParams(msg, nil, &boundsStr[0], &boundsStr[1], &limitStr); err != nil {
     2035                                return err
     2036                        }
    20332037                default:
    20342038                        // TODO: support LATEST, AROUND
     
    20932097                                history, err = store.LoadBeforeTime(uc.network, entity, bounds[0], bounds[1], limit)
    20942098                        }
     2099                case "TARGETS":
     2100                        // TODO: support TARGETS in multi-upstream mode
     2101                        targets, err := store.ListTargets(uc.network, bounds[0], bounds[1], limit)
     2102                        if err != nil {
     2103                                dc.logger.Printf("failed fetching targets for chathistory: %v", target, err)
     2104                                return ircError{&irc.Message{
     2105                                        Command: "FAIL",
     2106                                        Params:  []string{"CHATHISTORY", "MESSAGE_ERROR", subcommand, "Failed to retrieve targets"},
     2107                                }}
     2108                        }
     2109
     2110                        batchRef := "history-targets"
     2111                        dc.SendMessage(&irc.Message{
     2112                                Prefix:  dc.srv.prefix(),
     2113                                Command: "BATCH",
     2114                                Params:  []string{"+" + batchRef, "draft/chathistory-targets"},
     2115                        })
     2116
     2117                        for _, target := range targets {
     2118                                dc.SendMessage(&irc.Message{
     2119                                        Tags:    irc.Tags{"batch": irc.TagValue(batchRef)},
     2120                                        Prefix:  dc.srv.prefix(),
     2121                                        Command: "CHATHISTORY",
     2122                                        Params:  []string{"TARGETS", target.Name, target.LatestMessage.UTC().Format(serverTimeLayout)},
     2123                                })
     2124                        }
     2125
     2126                        dc.SendMessage(&irc.Message{
     2127                                Prefix:  dc.srv.prefix(),
     2128                                Command: "BATCH",
     2129                                Params:  []string{"-" + batchRef},
     2130                        })
     2131
     2132                        return nil
    20952133                }
    20962134                if err != nil {
Note: See TracChangeset for help on using the changeset viewer.