corrections in reading-writing tags

This commit is contained in:
or-else
2018-03-03 16:26:44 -08:00
parent df980eff4a
commit cc4df422c0
5 changed files with 51 additions and 2 deletions

View File

@ -1,5 +1,5 @@
#!/bin/bash
~/go/bin/gox -osarch="linux/amd64" -ldflags "-X main.buildstamp=`date -u '+%Y%m%dT%H:%M:%SZ'`" -tags rethinkdb ./server
~/go/bin/gox -osarch="linux/amd64" -ldflags "-X main.buildstamp=rdb.`date -u '+%Y%m%dT%H:%M:%SZ'`" -tags rethinkdb ./server
~/go/bin/gox -osarch="linux/amd64" -tags rethinkdb ./tinode-db
~/go/bin/gox -osarch="linux/amd64" ./keygen

View File

@ -49,5 +49,20 @@
"disabled": true
}
}
],
"plugins": [
{
"enabled": $PLUGIN_PYTHON_CHAT_BOT_ENABLED,
"name": "python_chat_bot",
"timeout": 20000,
"filters": {
"account": "C"
},
"failure_code": 0,
"failure_text": null,
"service_addr": "tcp://localhost:40051"
}
]
}

View File

@ -424,6 +424,8 @@ type MsgServerMeta struct {
Sub []MsgTopicSub `json:"sub,omitempty"`
// Delete ID and the ranges of IDs of deleted messages
Del *MsgDelValues `json:"del,omitempty"`
// User discovery tags
Tags []string `json:"tags,omitempty"`
}
// MsgServerInfo is the server-side copy of MsgClientNote with From added (non-authoritative).

View File

@ -295,6 +295,9 @@ func topicInit(sreg *sessionJoin, h *Hub) {
t.accessAuth = user.Access.Auth
t.accessAnon = user.Access.Anon
// Assign tags
t.tags = user.Tags
if err = t.loadSubscribers(); err != nil {
log.Println("hub: cannot load subscribers for '" + t.name + "' (" + err.Error() + ")")
sreg.sess.queueOut(ErrUnknown(sreg.pkt.Id, t.xoriginal, timestamp))
@ -691,6 +694,9 @@ func topicInit(sreg *sessionJoin, h *Hub) {
t.created = timestamp
t.updated = timestamp
// Assign tags
t.tags = tags
// t.lastId & t.clearId are not set for new topics
stopic := &types.Topic{
@ -738,6 +744,9 @@ func topicInit(sreg *sessionJoin, h *Hub) {
t.accessAuth = stopic.Access.Auth
t.accessAnon = stopic.Access.Anon
// Assign tags
t.tags = stopic.Tags
t.public = stopic.Public
t.created = stopic.CreatedAt

View File

@ -62,6 +62,9 @@ type Topic struct {
accessAuth types.AccessMode
accessAnon types.AccessMode
// Topic discovery tags
tags []string
// Topic's public data
public interface{}
@ -1685,6 +1688,23 @@ func (t *Topic) replyGetData(sess *Session, id string, req *MsgBrowseOpts) error
// replyGetTags returns topic's tags - tokens used for discovery.
func (t *Topic) replyGetTags(sess *Session, id string) error {
now := types.TimeNow()
if t.cat != types.TopicCatMe && t.cat != types.TopicCatGrp {
sess.queueOut(ErrOperationNotAllowed(id, t.original(sess.uid), now))
return errors.New("invalid topic category for getting tags")
}
if len(t.tags) > 0 {
sess.queueOut(&ServerComMessage{
Meta: &MsgServerMeta{Id: id, Topic: t.original(sess.uid), Timestamp: &now, Tags: t.tags}})
return nil
}
// Inform the requester that there are no tags.
reply := NoErr(id, t.original(sess.uid), now)
reply.Ctrl.Params = map[string]string{"what": "tags"}
sess.queueOut(reply)
return nil
}
@ -1696,8 +1716,11 @@ func (t *Topic) replySetTags(sess *Session, id string, set *MsgClientSet) error
now := types.TimeNow()
if t.cat != types.TopicCatMe && t.cat != types.TopicCatGrp {
sess.queueOut(ErrOperationNotAllowed(id, "", now))
sess.queueOut(ErrOperationNotAllowed(id, t.original(sess.uid), now))
return errors.New("invalid topic category assign tags")
} else if t.cat == types.TopicCatGrp && t.owner != sess.uid {
sess.queueOut(ErrPermissionDenied(id, t.original(sess.uid), now))
return errors.New("tags update by non-owner")
}
var tags []string