Changeset 153 in code for trunk/upstream.go


Ignore:
Timestamp:
Mar 25, 2020, 10:16:53 PM (5 years ago)
Author:
delthas
Message:

Add upstream batch capability support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/upstream.go

    r152 r153  
    5050        channels   map[string]*upstreamChannel
    5151        caps       map[string]string
     52        batches    map[string]batch
    5253
    5354        tagsSupported bool
     
    8485                channels:              make(map[string]*upstreamChannel),
    8586                caps:                  make(map[string]string),
     87                batches:               make(map[string]batch),
    8688                availableChannelTypes: stdChannelTypes,
    8789                availableChannelModes: stdChannelModes,
     
    151153
    152154func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
     155        var msgBatch *batch
     156        if batchName, ok := msg.GetTag("batch"); ok {
     157                b, ok := uc.batches[batchName]
     158                if !ok {
     159                        return fmt.Errorf("unexpected batch reference: batch was not defined: %q", batchName)
     160                }
     161                msgBatch = &b
     162        }
     163
    153164        switch msg.Command {
    154165        case "PING":
     
    194205
    195206                        requestCaps := make([]string, 0, 16)
    196                         for _, c := range []string{"message-tags"} {
     207                        for _, c := range []string{"message-tags", "batch"} {
    197208                                if _, ok := uc.caps[c]; ok {
    198209                                        requestCaps = append(requestCaps, c)
     
    406417                        }
    407418                }
     419        case "BATCH":
     420                var tag string
     421                if err := parseMessageParams(msg, &tag); err != nil {
     422                        return err
     423                }
     424
     425                if strings.HasPrefix(tag, "+") {
     426                        tag = tag[1:]
     427                        if _, ok := uc.batches[tag]; ok {
     428                                return fmt.Errorf("unexpected BATCH reference tag: batch was already defined: %q", tag)
     429                        }
     430                        var batchType string
     431                        if err := parseMessageParams(msg, nil, &batchType); err != nil {
     432                                return err
     433                        }
     434                        uc.batches[tag] = batch{
     435                                Type:   batchType,
     436                                Params: msg.Params[2:],
     437                                Outer:  msgBatch,
     438                        }
     439                } else if strings.HasPrefix(tag, "-") {
     440                        tag = tag[1:]
     441                        if _, ok := uc.batches[tag]; !ok {
     442                                return fmt.Errorf("unknown BATCH reference tag: %q", tag)
     443                        }
     444                        delete(uc.batches, tag)
     445                } else {
     446                        return fmt.Errorf("unexpected BATCH reference tag: missing +/- prefix: %q", tag)
     447                }
    408448        case "NICK":
    409449                if msg.Prefix == nil {
Note: See TracChangeset for help on using the changeset viewer.