MCPcopy
hub / github.com/tinode/chat / handleTopicTermination

Method handleTopicTermination

server/topic.go:524–566  ·  view source on GitHub ↗
(sd *shutDown)

Source from the content-addressed store, hash-verified

522}
523
524func (t *Topic) handleTopicTermination(sd *shutDown) {
525 // Handle four cases:
526 // 1. Topic is shutting down by timer due to inactivity (reason == StopNone)
527 // 2. Topic is being deleted (reason == StopDeleted)
528 // 3. System shutdown (reason == StopShutdown, done != nil).
529 // 4. Cluster rehashing (reason == StopRehashing)
530
531 switch sd.reason {
532 case StopDeleted:
533 if t.cat == types.TopicCatGrp {
534 t.presSubsOffline("gone", nilPresParams, nilPresFilters, nilPresFilters, "", false)
535 }
536 // P2P users get "off+remove" earlier in the process
537
538 // Inform plugins that the topic is deleted
539 pluginTopic(t, plgActDel)
540
541 case StopRehashing:
542 // Must send individual messages to sessions because normal sending through the topic's
543 // broadcast channel won't work - it will be shut down too soon.
544 t.presSubsOnlineDirect("term", nilPresParams, nilPresFilters, "")
545 }
546 // In case of a system shutdown don't bother with notifications. They won't be delivered anyway.
547
548 // Tell sessions to remove the topic
549 for s := range t.sessions {
550 s.detachSession(t.name)
551 }
552
553 if t.cat == types.TopicCatGrp {
554 // Update topic subscriber count.
555 if err := store.Topics.UpdateSubCnt(t.name); err != nil {
556 logs.Warn.Println("topic update sub cnt:", err)
557 }
558 }
559
560 usersRegisterTopic(t, false)
561
562 // Report completion back to sender, if 'done' is not nil.
563 if sd.done != nil {
564 sd.done <- true
565 }
566}
567
568func (t *Topic) runLocal(hub *Hub) {
569 // Kills topic after a period of inactivity.

Callers 2

runLocalMethod · 0.95

Calls 7

presSubsOfflineMethod · 0.95
presSubsOnlineDirectMethod · 0.95
pluginTopicFunction · 0.85
usersRegisterTopicFunction · 0.85
detachSessionMethod · 0.80
PrintlnMethod · 0.80
UpdateSubCntMethod · 0.65

Tested by 1