Changeset 435 in code for trunk/downstream.go
- Timestamp:
- Dec 14, 2020, 7:54:02 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/downstream.go
r431 r435 1158 1158 }) 1159 1159 1160 ch := &Channel{Name: upstreamName, Key: key, Detached: false} 1161 if current, ok := uc.network.channels[ch.Name]; ok && key == "" { 1160 var ch *Channel 1161 var ok bool 1162 if ch, ok = uc.network.channels[upstreamName]; ok { 1162 1163 // Don't clear the channel key if there's one set 1163 1164 // TODO: add a way to unset the channel key 1164 ch.Key = current.Key 1165 } 1166 if err := uc.network.createUpdateChannel(ch); err != nil { 1165 if key != "" { 1166 ch.Key = key 1167 } 1168 uc.network.attach(ch) 1169 } else { 1170 ch = &Channel{ 1171 Name: upstreamName, 1172 Key: key, 1173 } 1174 uc.network.channels[upstreamName] = ch 1175 } 1176 if err := dc.srv.db.StoreChannel(uc.network.ID, ch); err != nil { 1167 1177 dc.logger.Printf("failed to create or update channel %q: %v", upstreamName, err) 1168 1178 } … … 1186 1196 1187 1197 if strings.EqualFold(reason, "detach") { 1188 ch := &Channel{Name: upstreamName, Detached: true} 1189 if err := uc.network.createUpdateChannel(ch); err != nil { 1190 dc.logger.Printf("failed to detach channel %q: %v", upstreamName, err) 1198 var ch *Channel 1199 var ok bool 1200 if ch, ok = uc.network.channels[upstreamName]; ok { 1201 uc.network.detach(ch) 1202 } else { 1203 ch = &Channel{ 1204 Name: name, 1205 Detached: true, 1206 } 1207 uc.network.channels[upstreamName] = ch 1208 } 1209 if err := dc.srv.db.StoreChannel(uc.network.ID, ch); err != nil { 1210 dc.logger.Printf("failed to create or update channel %q: %v", upstreamName, err) 1191 1211 } 1192 1212 } else { … … 1614 1634 } 1615 1635 uc.produce(upstreamName, echoMsg, dc) 1636 1637 uc.updateChannelAutoDetach(upstreamName) 1616 1638 } 1617 1639 case "NOTICE": … … 1637 1659 Params: []string{upstreamName, unmarshaledText}, 1638 1660 }) 1661 1662 uc.updateChannelAutoDetach(upstreamName) 1639 1663 } 1640 1664 case "TAGMSG": … … 1659 1683 Params: []string{upstreamName}, 1660 1684 }) 1685 1686 uc.updateChannelAutoDetach(upstreamName) 1661 1687 } 1662 1688 case "INVITE":
Note:
See TracChangeset
for help on using the changeset viewer.