MCPcopy
hub / github.com/tinode/chat / replySetDesc

Method replySetDesc

server/topic.go:2204–2394  ·  view source on GitHub ↗

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

(sess *Session, asUid types.Uid, asChan bool,
	authLevel auth.Level, msg *ClientComMessage)

Source from the content-addressed store, hash-verified

2202// replySetDesc updates topic metadata, saves it to DB, replies to the caller as {ctrl} message,
2203// generates {pres} update if necessary.
2204func (t *Topic) replySetDesc(sess *Session, asUid types.Uid, asChan bool,
2205 authLevel auth.Level, msg *ClientComMessage) error {
2206 now := types.TimeNow()
2207
2208 assignAccess := func(upd map[string]any, mode *MsgDefaultAcsMode) error {
2209 if mode == nil {
2210 return nil
2211 }
2212 if auth, anon, err := parseTopicAccess(mode, types.ModeUnset, types.ModeUnset); err != nil {
2213 return err
2214 } else if auth.IsOwner() || anon.IsOwner() {
2215 return errors.New("default 'owner' access is not permitted")
2216 } else {
2217 access := types.DefaultAccess{Auth: t.accessAuth, Anon: t.accessAnon}
2218 if auth != types.ModeUnset {
2219 if t.cat == types.TopicCatMe {
2220 auth &= types.ModeCAuth
2221 if auth != types.ModeNone {
2222 // This is the default access mode for P2P topics.
2223 // It must be either an N or must include an A permission.
2224 auth |= types.ModeApprove
2225 }
2226 }
2227 access.Auth = auth
2228 }
2229 if anon != types.ModeUnset {
2230 if t.cat == types.TopicCatMe {
2231 anon &= globals.typesModeCP2P
2232 if anon != types.ModeNone {
2233 anon |= types.ModeApprove
2234 }
2235 }
2236 access.Anon = anon
2237 }
2238 if access.Auth != t.accessAuth || access.Anon != t.accessAnon {
2239 upd["Access"] = access
2240 }
2241 }
2242 return nil
2243 }
2244
2245 assignGenericValues := func(upd map[string]any, what string, dst, src any) (changed bool) {
2246 if dst, changed = mergeInterfaces(dst, src); changed {
2247 upd[what] = dst
2248 }
2249 return
2250 }
2251
2252 // DefaultAccess and/or Public have chanegd
2253 var sendCommon bool
2254 // Private has changed
2255 var sendPriv bool
2256 var err error
2257
2258 // Change to the main object (user or topic).
2259 core := make(map[string]any)
2260 // Change to subscription.
2261 sub := make(map[string]any)

Callers 1

handleMetaSetMethod · 0.95

Calls 15

fndGetPublicMethod · 0.95
fndSetPublicMethod · 0.95
presUsersOfInterestMethod · 0.95
presSubsOfflineMethod · 0.95
presSingleUserOfflineMethod · 0.95
TimeNowFunction · 0.92
GrpToChnFunction · 0.92
parseTopicAccessFunction · 0.85
mergeInterfacesFunction · 0.85
ErrPermissionDeniedReplyFunction · 0.85
ErrMalformedReplyFunction · 0.85
InfoNotModifiedReplyFunction · 0.85

Tested by

no test coverage detected