This is a newly created topic (!me or generic), announce topic presence
()
| 960 | |
| 961 | // This is a newly created topic (!me or generic), announce topic presence |
| 962 | func (t *Topic) presPubTopicOnline() error { |
| 963 | |
| 964 | // Load the list of users interested in this topic |
| 965 | // Blocking call |
| 966 | subs, err := store.Topics.GetSubs(t.appid, t.name, nil) |
| 967 | if err != nil { |
| 968 | log.Println("Presence: topic: error loading topic sharing ", err) |
| 969 | return err |
| 970 | } |
| 971 | |
| 972 | var count = 0 |
| 973 | if len(subs) > 0 { |
| 974 | // Publish update to subscribers |
| 975 | t.pushTo = make(map[types.Uid]bool) |
| 976 | update := &MsgServerPres{Topic: "me", What: "on", User: t.name} |
| 977 | var uid types.Uid |
| 978 | |
| 979 | for _, sub := range subs { |
| 980 | if (sub.ModeGiven & sub.ModeWant & types.ModePres) != 0 { |
| 981 | uid.UnmarshalText([]byte(sub.User)) |
| 982 | t.pushTo[uid] = true |
| 983 | globals.hub.route <- &ServerComMessage{Pres: update, appid: t.appid, |
| 984 | rcptto: "usr" + sub.User} |
| 985 | count++ |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | log.Printf("Presence: topic '%s' came online, updated %d listeners", t.name, count) |
| 990 | |
| 991 | } else { |
| 992 | log.Println("Presence: orphaned topic:", t.name) |
| 993 | } |
| 994 | |
| 995 | return nil |
| 996 | } |
| 997 | |
| 998 | // Publish presence announcement |
| 999 | func (t *Topic) presPubChange(action string) { |
no test coverage detected