Skip to content

Commit

Permalink
notify plugins on subscription change, #757
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed May 17, 2022
1 parent 7a6842c commit f888679
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions server/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -1613,26 +1613,38 @@ func (t *Topic) thisUserSub(sess *Session, pkt *ClientComMessage, asUid types.Ui
userData.modeWant = modeWant
}

// Create a subscription object to notify plugins.
sub := types.Subscription{
User: asUid.String(),
Topic: t.name,
}

// Save changes to DB
update := map[string]interface{}{}
if isNullValue(private) {
update["Private"] = nil
userData.private = nil
sub.Private = private
} else if private != nil {
update["Private"] = private
userData.private = private
sub.Private = private
}
if userData.modeWant != oldWant {
update["ModeWant"] = userData.modeWant
sub.ModeWant = userData.modeWant
}
if userData.modeGiven != oldGiven {
update["ModeGiven"] = userData.modeGiven
sub.ModeGiven = userData.modeGiven
}

if len(update) > 0 {
if err := store.Subs.Update(t.name, asUid, update); err != nil {
sess.queueOut(ErrUnknownReply(pkt, now))
return nil, err
}
pluginSubscription(&sub, plgActUpd)
}

// No transactions in RethinkDB, but two owners are better than none
Expand Down

0 comments on commit f888679

Please sign in to comment.