Skip to content

Commit

Permalink
Change Topic.maybeFixTopicName() to account for sub type.
Browse files Browse the repository at this point in the history
Channel subs vs regular subs.
  • Loading branch information
aforge committed Aug 19, 2022
1 parent efc0071 commit 29279f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/pres.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (t *Topic) presSubsOnlineDirect(what string, params *presParams, filter *pr
// For p2p topics topic name is dependent on receiver.
// It's OK to change the pointer here because the message will be serialized in queueOut
// before being placed into the channel.
t.maybeFixTopicName(msg, pssd.uid)
t.maybeFixTopicName(msg, pssd.uid, pssd.isChanSub)
}
s.queueOut(msg)
}
Expand Down
22 changes: 16 additions & 6 deletions server/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,33 @@ func (t *Topic) userIsReader(uid types.Uid) bool {
return (modeGiven & modeWant).IsReader()
}

// maybeFixTopicName sets the topic field in `msg` depending on the uid.
func (t *Topic) maybeFixTopicName(msg *ServerComMessage, uid types.Uid) {
// maybeFixTopicName sets the topic field in `msg` depending on the uid and subscription type.
func (t *Topic) maybeFixTopicName(msg *ServerComMessage, uid types.Uid, isChanSub bool) {
// For zero uids we don't know the proper topic name.
if uid.IsZero() {
return
}
// We are only interested in broadcastable messages.
if msg.Data == nil && msg.Pres == nil && msg.Info == nil {
return
}

if t.cat == types.TopicCatP2P || (t.cat == types.TopicCatGrp && t.isChan) {
// For p2p topics topic name is dependent on receiver.
// Channel topics may be presented as grpXXX or chnXXX.
var topicName string
if isChanSub {
topicName = types.GrpToChn(t.xoriginal)
} else {
topicName = t.original(uid)
}
switch {
case msg.Data != nil:
msg.Data.Topic = t.original(uid)
msg.Data.Topic = topicName
case msg.Pres != nil:
msg.Pres.Topic = t.original(uid)
msg.Pres.Topic = topicName
case msg.Info != nil:
msg.Info.Topic = t.original(uid)
msg.Info.Topic = topicName
}
}
}
Expand Down Expand Up @@ -1272,7 +1282,7 @@ func (t *Topic) broadcastToSessions(msg *ServerComMessage) {
}

// Topic name may be different depending on the user to which the `sess` belongs.
t.maybeFixTopicName(msg, pssd.uid)
t.maybeFixTopicName(msg, pssd.uid, pssd.isChanSub)

// Send channel messages anonymously.
if pssd.isChanSub && msg.Data != nil {
Expand Down

0 comments on commit 29279f3

Please sign in to comment.