Skip to content

Commit

Permalink
add default access to {get} response, fix for a crash when reporting …
Browse files Browse the repository at this point in the history
…a topic
  • Loading branch information
or-else committed Mar 19, 2022
1 parent 1903052 commit 363bb0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 15 additions & 0 deletions server/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,13 @@ func replyOfflineTopicGetDesc(sess *Session, msg *ClientComMessage) {
Anon: stopic.Access.Anon.String(),
}
}
// Report appropriate access level. Could be overriden below if subscription exists.
desc.Acs = &MsgAccessMode{}
if sess.authLvl == auth.LevelAuth || sess.authLvl == auth.LevelRoot {
desc.Acs.Mode = stopic.Access.Auth.String()
} else if sess.authLvl == auth.LevelAnon {
desc.Acs.Mode = stopic.Access.Anon.String()
}
} else {
// 'me' and p2p topics
uid := types.ZeroUid
Expand Down Expand Up @@ -632,6 +639,14 @@ func replyOfflineTopicGetDesc(sess *Session, msg *ClientComMessage) {
if sess.authLvl == auth.LevelRoot {
desc.State = suser.State.String()
}

// Report appropriate access level. Could be overriden below if subscription exists.
desc.Acs = &MsgAccessMode{}
if sess.authLvl == auth.LevelAuth || sess.authLvl == auth.LevelRoot {
desc.Acs.Mode = suser.Access.Auth.String()
} else if sess.authLvl == auth.LevelAnon {
desc.Acs.Mode = suser.Access.Anon.String()
}
}

sub, err := store.Subs.Get(topic, asUid, false)
Expand Down
7 changes: 4 additions & 3 deletions server/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,8 +1007,9 @@ func (t *Topic) handlePubBroadcast(msg *ClientComMessage) {
t.broadcastToSessions(data)

// usersPush will update unread message count and send push notification.
pushRcpt := t.pushForData(asUid, data.Data)
usersPush(pushRcpt)
if pushRcpt := t.pushForData(asUid, data.Data); pushRcpt != nil {
usersPush(pushRcpt)
}
}

// handleNoteBroadcast fans out {note} -> {info} messages to recipients in a master topic.
Expand Down Expand Up @@ -1957,7 +1958,7 @@ func (t *Topic) replyGetDesc(sess *Session, asUid types.Uid, asChan bool, opts *
// Give subscriber a fuller description than to a stranger/channel reader.
if full {
if t.cat == types.TopicCatP2P {
// For p2p topics default access mode makes no sense.
// For p2p topics default access mode makes no sense: only participants have access to topic.
// Don't report it.
} else if t.cat == types.TopicCatMe || (pud.modeGiven & pud.modeWant).IsSharer() {
desc.DefaultAcs = &MsgDefaultAcsMode{
Expand Down

0 comments on commit 363bb0f

Please sign in to comment.