topicInit reads an existing topic from database or creates a new topic
(sreg *sessionJoin, h *Hub)
| 244 | |
| 245 | // topicInit reads an existing topic from database or creates a new topic |
| 246 | func topicInit(sreg *sessionJoin, h *Hub) { |
| 247 | var t *Topic |
| 248 | |
| 249 | timestamp := time.Now().UTC().Round(time.Millisecond) |
| 250 | |
| 251 | t = &Topic{name: sreg.topic, |
| 252 | original: sreg.pkt.Topic, |
| 253 | appid: sreg.sess.appid, |
| 254 | sessions: make(map[*Session]bool), |
| 255 | broadcast: make(chan *ServerComMessage, 256), |
| 256 | reg: make(chan *sessionJoin, 32), |
| 257 | unreg: make(chan *sessionLeave, 32), |
| 258 | meta: make(chan *metaReq, 32), |
| 259 | perUser: make(map[types.Uid]perUserData), |
| 260 | } |
| 261 | |
| 262 | // Request to load a me topic. The topic must exist |
| 263 | if t.original == "me" { |
| 264 | log.Println("hub: loading me topic") |
| 265 | |
| 266 | t.cat = TopicCat_Me |
| 267 | |
| 268 | user, err := store.Users.Get(t.appid, sreg.sess.uid) |
| 269 | if err != nil { |
| 270 | log.Println("hub: cannot load user object for 'me'='" + t.name + "' (" + err.Error() + ")") |
| 271 | sreg.sess.QueueOut(ErrUnknown(sreg.pkt.Id, t.original, timestamp)) |
| 272 | return |
| 273 | } |
| 274 | |
| 275 | if err = t.loadSubscriptions(); err != nil { |
| 276 | log.Println("hub: cannot load subscritions for '" + t.name + "' (" + err.Error() + ")") |
| 277 | sreg.sess.QueueOut(ErrUnknown(sreg.pkt.Id, t.original, timestamp)) |
| 278 | return |
| 279 | } |
| 280 | |
| 281 | // 'me' has no owner |
| 282 | // t.owner = sreg.sess.uid |
| 283 | |
| 284 | // Ensure all requests to subscribe are automatically rejected |
| 285 | t.accessAuth = types.ModeBanned |
| 286 | t.accessAnon = types.ModeBanned |
| 287 | |
| 288 | t.public = user.Public |
| 289 | |
| 290 | t.created = user.CreatedAt |
| 291 | t.updated = user.UpdatedAt |
| 292 | //t.lastMessage = time.Time{} |
| 293 | |
| 294 | // Request to create a new p2p topic, then attach to it |
| 295 | } else if strings.HasPrefix(t.original, "usr") { |
| 296 | log.Println("hub: new p2p topic") |
| 297 | |
| 298 | t.cat = TopicCat_P2P |
| 299 | |
| 300 | // t.owner is blank for p2p topics |
| 301 | |
| 302 | // Ensure that other users are automatically rejected |
| 303 | t.accessAuth = types.ModeBanned |
no test coverage detected