replySetSub is a response to new subscription request or an update to a subscription {set.sub}: update topic metadata cache, save/update subs, reply to the caller as {ctrl} message, generate a presence notification, if appropriate.
(sess *Session, pkt *ClientComMessage, asChan bool)
| 2716 | // update topic metadata cache, save/update subs, reply to the caller as {ctrl} message, |
| 2717 | // generate a presence notification, if appropriate. |
| 2718 | func (t *Topic) replySetSub(sess *Session, pkt *ClientComMessage, asChan bool) error { |
| 2719 | now := types.TimeNow() |
| 2720 | |
| 2721 | asUid := types.ParseUserId(pkt.AsUser) |
| 2722 | set := pkt.Set |
| 2723 | |
| 2724 | var target types.Uid |
| 2725 | if target = types.ParseUserId(set.Sub.User); target.IsZero() && set.Sub.User != "" { |
| 2726 | // Invalid user ID |
| 2727 | sess.queueOut(ErrMalformedReply(pkt, now)) |
| 2728 | return errors.New("invalid user id") |
| 2729 | } |
| 2730 | |
| 2731 | // if set.User is not set, request is for the current user |
| 2732 | if target.IsZero() { |
| 2733 | target = asUid |
| 2734 | } |
| 2735 | |
| 2736 | var err error |
| 2737 | var modeChanged *MsgAccessMode |
| 2738 | if target == asUid { |
| 2739 | // Request new subscription or modify own subscription |
| 2740 | modeChanged, err = t.thisUserSub(sess, pkt, asUid, asChan, set.Sub.Mode, nil) |
| 2741 | } else { |
| 2742 | // Request to approve/change someone's subscription |
| 2743 | modeChanged, err = t.anotherUserSub(sess, asUid, target, asChan, pkt) |
| 2744 | } |
| 2745 | if err != nil { |
| 2746 | return err |
| 2747 | } |
| 2748 | |
| 2749 | var resp *ServerComMessage |
| 2750 | if modeChanged != nil { |
| 2751 | // Report resulting access mode. |
| 2752 | params := map[string]any{"acs": modeChanged} |
| 2753 | if target != asUid { |
| 2754 | params["user"] = target.UserId() |
| 2755 | } |
| 2756 | resp = NoErrParamsReply(pkt, now, params) |
| 2757 | } else { |
| 2758 | resp = InfoNotModifiedReply(pkt, now) |
| 2759 | } |
| 2760 | |
| 2761 | sess.queueOut(resp) |
| 2762 | |
| 2763 | return nil |
| 2764 | } |
| 2765 | |
| 2766 | // replyGetData is a response to a get.data request - load a list of stored messages, send them to session as {data} |
| 2767 | // response goes to a single session rather than all sessions in a topic |
no test coverage detected