Skip to content

Commit

Permalink
incognito mode works as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Apr 2, 2020
1 parent a093d40 commit 00cdd35
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 0 additions & 2 deletions server/hdl_longpoll.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func (sess *Session) readOnce(wrt http.ResponseWriter, req *http.Request) (int,
// - if payload exists, process it and close
// - if sid is not empty but there is no session, report an error
func serveLongPoll(wrt http.ResponseWriter, req *http.Request) {

now := time.Now().UTC().Round(time.Millisecond)

// Use the lowest common denominator - this is a legacy handler after all (otherwise would use application/json)
Expand Down Expand Up @@ -138,7 +137,6 @@ func serveLongPoll(wrt http.ResponseWriter, req *http.Request) {
enc.Encode(pkt)

return

}

// Existing session
Expand Down
20 changes: 17 additions & 3 deletions server/pres.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (t *Topic) presProcReq(fromUserID, what string, wantReply bool) string {
}
}

// log.Println("in-what:", debugWhat, "out-what", what, "from:", fromUserID, "to:", t.name, "reply:", replyAs)
// log.Println("out-what", what, "from:", fromUserID, "to:", t.name, "reply:", replyAs)

// If requester's online status has not changed, do not reply, otherwise an endless loop will happen.
// wantReply is needed to ensure unnecessary {pres} is not sent:
Expand All @@ -222,11 +222,25 @@ func (t *Topic) presProcReq(fromUserID, what string, wantReply bool) string {
// Case C: user agent change, "ua", ua
// Case D: User updated 'public', "upd"
func (t *Topic) presUsersOfInterest(what, ua string) {
parts := strings.Split(what, "+")
wantReply := parts[0] == "on"
goOffline := len(parts) > 1 && parts[1] == "dis"

// Push update to subscriptions
for topic := range t.perSubs {
for topic, psd := range t.perSubs {
globals.hub.route <- &ServerComMessage{
Pres: &MsgServerPres{Topic: "me", What: what, Src: t.name, UserAgent: ua, WantReply: (what == "on")},
Pres: &MsgServerPres{
Topic: "me",
What: what,
Src: t.name,
UserAgent: ua,
WantReply: wantReply},
rcptto: topic}

if psd.online && goOffline {
psd.online = false
t.perSubs[topic] = psd
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions server/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2531,12 +2531,12 @@ func (t *Topic) notifySubChange(uid, actor types.Uid, oldWant, oldGiven,
} else if (newWant & newGiven).IsPresencer() && !(oldWant & oldGiven).IsPresencer() {
// Subscription un-muted.

if t.cat == types.TopicCatMe {
// Notify subscriber of topic's online status.
if t.cat == types.TopicCatGrp {
t.presSingleUserOffline(uid, "?unkn+en", nilPresParams, "", false)
} else if t.cat == types.TopicCatMe {
// User is visible online now, notify subscribers.
t.presUsersOfInterest("on+en", t.userAgent)
} else {
// Notify subscriber of topic's online status.
t.presSingleUserOffline(uid, "?unkn+en", nilPresParams, "", false)
}
}

Expand Down

0 comments on commit 00cdd35

Please sign in to comment.