Skip to content

Commit

Permalink
return access mode for offline changes too
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Apr 5, 2019
1 parent fea8507 commit 7bb79ee
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
6 changes: 6 additions & 0 deletions server/datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,17 @@ type ServerComMessage struct {

// NoErr indicates successful completion (200)
func NoErr(id, topic string, ts time.Time) *ServerComMessage {
return NoErrParams(id, topic, ts, nil)
}

// NoErrParams indicates successful completion with additional parameters (200)
func NoErrParams(id, topic string, ts time.Time, params interface{}) *ServerComMessage {
return &ServerComMessage{Ctrl: &MsgServerCtrl{
Id: id,
Code: http.StatusOK, // 200
Text: "ok",
Topic: topic,
Params: params,
Timestamp: ts}}
}

Expand Down
2 changes: 1 addition & 1 deletion server/db/mysql/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ func (a *adapter) SubsDelForUser(user t.Uid, hard bool) error {

}

// Returns a list of users who match given tags, such as "email:jdoe@example.com" or "tel:18003287448".
// Returns a list of users who match given tags, such as "email:jdoe@example.com" or "tel:+18003287448".
// Searching the 'users.Tags' for the given tags using respective index.
func (a *adapter) FindUsers(uid t.Uid, req, opt []string) ([]t.Subscription, error) {
index := make(map[string]struct{})
Expand Down
2 changes: 1 addition & 1 deletion server/db/rethinkdb/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ func (a *adapter) SubsDelForUser(user t.Uid, hard bool) error {
return err
}

// Returns a list of users who match given tags, such as "email:jdoe@example.com" or "tel:18003287448".
// Returns a list of users who match given tags, such as "email:jdoe@example.com" or "tel:+18003287448".
// Searching the 'users.Tags' for the given tags using respective index.
func (a *adapter) FindUsers(uid t.Uid, req, opt []string) ([]t.Subscription, error) {
index := make(map[string]struct{})
Expand Down
4 changes: 1 addition & 3 deletions server/hdl_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ func largeFileUpload(wrt http.ResponseWriter, req *http.Request) {
return
}

resp := NoErr(msgID, "", now)
resp.Ctrl.Params = map[string]string{"url": url}
writeHttpResponse(resp, nil)
writeHttpResponse(NoErrParams(msgID, "", now, map[string]string{"url": url}), nil)
}

func largeFileRunGarbageCollection(period time.Duration, block int) chan<- bool {
Expand Down
11 changes: 10 additions & 1 deletion server/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,8 @@ func replyOfflineTopicSetSub(sess *Session, topic string, msg *ClientComMessage)

if modeWant != sub.ModeWant {
update["ModeWant"] = modeWant
// Cache it for later use
sub.ModeWant = modeWant
}
}

Expand All @@ -1239,7 +1241,14 @@ func replyOfflineTopicSetSub(sess *Session, topic string, msg *ClientComMessage)
log.Println("replyOfflineTopicSetSub update:", err)
sess.queueOut(decodeStoreError(err, msg.id, msg.topic, now, nil))
} else {
sess.queueOut(NoErr(msg.id, msg.topic, now))
var params interface{}
if update["ModeWant"] != nil {
params = map[string]interface{}{"acs": MsgAccessMode{
Given: sub.ModeGiven.String(),
Want: sub.ModeWant.String(),
Mode: (sub.ModeGiven & sub.ModeWant).String()}}
}
sess.queueOut(NoErrParams(msg.id, msg.topic, now, params))
}
} else {
sess.queueOut(InfoNotModified(msg.id, msg.topic, now))
Expand Down
26 changes: 7 additions & 19 deletions server/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,6 @@ func (t *Topic) subCommonReply(h *Hub, sreg *sessionJoin) error {

t.addSession(sreg.sess, asUid)

resp := NoErr(sreg.pkt.id, toriginal, now)
// Report back the assigned access mode.
params := map[string]interface{}{
"acs": &MsgAccessMode{
Expand All @@ -811,8 +810,7 @@ func (t *Topic) subCommonReply(h *Hub, sreg *sessionJoin) error {
if sreg.created && sreg.pkt.topic != toriginal {
params["tmpname"] = sreg.pkt.topic
}
resp.Ctrl.Params = params
sreg.sess.queueOut(resp)
sreg.sess.queueOut(NoErrParams(sreg.pkt.id, toriginal, now, params))

return nil
}
Expand Down Expand Up @@ -1703,7 +1701,6 @@ func (t *Topic) replySetSub(h *Hub, sess *Session, pkt *ClientComMessage) error

var resp *ServerComMessage
if changed {
resp = NoErr(pkt.id, toriginal, now)
// Report resulting access mode.
pud := t.perUser[target]
params := map[string]interface{}{"acs": MsgAccessMode{
Expand All @@ -1713,7 +1710,7 @@ func (t *Topic) replySetSub(h *Hub, sess *Session, pkt *ClientComMessage) error
if target != asUid {
params["user"] = target.UserId()
}
resp.Ctrl.Params = params
resp = NoErrParams(pkt.id, toriginal, now, params)
} else {
resp = InfoNotModified(pkt.id, toriginal, now)
}
Expand Down Expand Up @@ -1763,9 +1760,7 @@ func (t *Topic) replyGetData(sess *Session, asUid types.Uid, id string, req *Msg
}

// Inform the requester that all the data has been served.
reply := NoErr(id, toriginal, now)
reply.Ctrl.Params = map[string]interface{}{"what": "data", "count": count}
sess.queueOut(reply)
sess.queueOut(NoErrParams(id, toriginal, now, map[string]interface{}{"what": "data", "count": count}))

return nil
}
Expand All @@ -1790,9 +1785,7 @@ func (t *Topic) replyGetTags(sess *Session, asUid types.Uid, id string) error {
}

// Inform the requester that there are no tags.
reply := NoErr(id, t.original(asUid), now)
reply.Ctrl.Params = map[string]string{"what": "tags"}
sess.queueOut(reply)
sess.queueOut(NoErrParams(id, t.original(asUid), now, map[string]string{"what": "tags"}))

return nil
}
Expand Down Expand Up @@ -1831,15 +1824,14 @@ func (t *Topic) replySetTags(sess *Session, asUid types.Uid, set *MsgClientSet)
} else {
t.tags = tags

resp = NoErr(set.Id, t.original(asUid), now)
params := make(map[string]interface{})
if len(added) > 0 {
params["added"] = len(added)
}
if len(removed) > 0 {
params["removed"] = len(removed)
}
resp.Ctrl.Params = params
resp = NoErrParams(set.Id, t.original(asUid), now, params)
}
} else {
resp = InfoNotModified(set.Id, t.original(asUid), now)
Expand Down Expand Up @@ -1886,9 +1878,7 @@ func (t *Topic) replyGetDel(sess *Session, asUid types.Uid, id string, req *MsgG
}
}

reply := NoErr(id, toriginal, now)
reply.Ctrl.Params = map[string]string{"what": "del"}
sess.queueOut(reply)
sess.queueOut(NoErrParams(id, toriginal, now, map[string]string{"what": "del"}))

return nil
}
Expand Down Expand Up @@ -1992,9 +1982,7 @@ func (t *Topic) replyDelMsg(sess *Session, asUid types.Uid, del *MsgClientDel) e
t.presPubMessageDelete(asUid, t.delID, dr, sess.sid)
}

reply := NoErr(del.Id, t.original(asUid), now)
reply.Ctrl.Params = map[string]int{"del": t.delID}
sess.queueOut(reply)
sess.queueOut(NoErrParams(del.Id, t.original(asUid), now, map[string]int{"del": t.delID}))

return nil
}
Expand Down
4 changes: 1 addition & 3 deletions server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,7 @@ func replyUpdateUser(s *Session, msg *ClientComMessage, rec *auth.Rec) {
}
}

resp := NoErr(msg.id, "", msg.timestamp)
resp.Ctrl.Params = params
s.queueOut(resp)
s.queueOut(NoErrParams(msg.id, "", msg.timestamp, params))

// Call plugin with the account update
pluginAccount(user, plgActUpd)
Expand Down

0 comments on commit 7bb79ee

Please sign in to comment.