MCPcopy Create free account
hub / github.com/daodst/chat / leave

Method leave

server/session.go:242–272  ·  view source on GitHub ↗

Leave/Unsubscribe a topic

(msg *ClientComMessage)

Source from the content-addressed store, hash-verified

240
241// Leave/Unsubscribe a topic
242func (s *Session) leave(msg *ClientComMessage) {
243 var reply *ServerComMessage
244
245 if msg.Leave.Topic == "" {
246 s.QueueOut(ErrMalformed(msg.Leave.Id, "", msg.timestamp))
247 return
248 }
249
250 topic := msg.Leave.Topic
251 if msg.Leave.Topic == "me" {
252 topic = s.uid.UserId()
253 }
254
255 if sub, ok := s.subs[topic]; ok {
256 if msg.Leave.Topic == "me" && msg.Leave.Unsub {
257 // User should not unsubscribe from 'me'. Just leaving is fine
258 reply = ErrPermissionDenied(msg.Leave.Id, msg.Leave.Topic, msg.timestamp)
259 } else {
260 // unlink from topic
261 delete(s.subs, topic)
262
263 sub.done <- &sessionLeave{sess: s, unsub: msg.Leave.Unsub, pkt: msg}
264 reply = NoErr(msg.Leave.Id, msg.Leave.Topic, msg.timestamp)
265 }
266 } else {
267 // FIXME(gene): allow topic to unsubscribe to unsubscribe without joining first; send to hub to unsub
268 reply = ErrAttachFirst(msg.Leave.Id, msg.Leave.Topic, msg.timestamp)
269 }
270
271 s.QueueOut(reply)
272}
273
274// Broadcast a message to all topic subscribers
275func (s *Session) publish(msg *ClientComMessage) {

Callers 1

dispatchMethod · 0.95

Calls 5

QueueOutMethod · 0.95
ErrMalformedFunction · 0.85
ErrPermissionDeniedFunction · 0.85
NoErrFunction · 0.85
ErrAttachFirstFunction · 0.85

Tested by

no test coverage detected