MCPcopy Create free account
hub / github.com/daodst/chat / replySetInfo

Method replySetInfo

server/topic.go:690–807  ·  view source on GitHub ↗

replySetInfo updates topic metadata, saves it to DB, replies to the caller as {ctrl} message, generates {pres} update if necessary

(sess *Session, set *MsgClientSet)

Source from the content-addressed store, hash-verified

688// replySetInfo updates topic metadata, saves it to DB,
689// replies to the caller as {ctrl} message, generates {pres} update if necessary
690func (t *Topic) replySetInfo(sess *Session, set *MsgClientSet) error {
691 now := time.Now().UTC().Round(time.Millisecond)
692
693 assignAccess := func(upd map[string]interface{}, mode *MsgDefaultAcsMode) error {
694 if auth, anon, err := parseTopicAccess(mode, types.ModeInvalid, types.ModeInvalid); err != nil {
695 return err
696 } else if auth&types.ModeOwner != 0 || anon&types.ModeOwner != 0 {
697 return errors.New("default 'O' access is not permitted")
698 } else {
699 access := make(map[string]interface{})
700 if auth != types.ModeInvalid {
701 access["Auth"] = auth
702 }
703 if anon != types.ModeInvalid {
704 access["Anon"] = anon
705 }
706 if len(access) > 0 {
707 upd["Access"] = access
708 }
709 }
710 return nil
711 }
712
713 assignPubPriv := func(upd map[string]interface{}, what string, p interface{}) {
714 if isNullValue(p) {
715 upd[what] = nil
716 } else {
717 upd[what] = p
718 }
719 }
720
721 updateCached := func(upd map[string]interface{}) {
722 if tmp, ok := upd["Access"]; ok {
723 access := tmp.(map[string]interface{})
724 if auth, ok := access["Auth"]; ok {
725 t.accessAuth = auth.(types.AccessMode)
726 }
727 if anon, ok := access["Anon"]; ok {
728 t.accessAnon = anon.(types.AccessMode)
729 }
730 }
731 if public, ok := upd["Public"]; ok {
732 t.public = public
733 }
734 }
735
736 var err error
737
738 user := make(map[string]interface{})
739 topic := make(map[string]interface{})
740 sub := make(map[string]interface{})
741 if t.cat == TopicCat_Me {
742 // Update current user
743 if set.Info.DefaultAcs != nil {
744 err = assignAccess(user, set.Info.DefaultAcs)
745 }
746 if set.Info.Public != nil {
747 assignPubPriv(user, "Public", set.Info.Public)

Callers 1

runMethod · 0.95

Calls 7

parseTopicAccessFunction · 0.85
isNullValueFunction · 0.85
simpleByteSenderFunction · 0.85
ErrMalformedFunction · 0.85
ErrUnknownFunction · 0.85
NoErrFunction · 0.85
UpdateMethod · 0.45

Tested by

no test coverage detected