Changeset 676 in code for trunk/user.go


Ignore:
Timestamp:
Nov 8, 2021, 6:36:10 PM (4 years ago)
Author:
contact
Message:

Add context support to user and network mutations

References: https://todo.sr.ht/~emersion/soju/141

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user.go

    r666 r676  
    320320}
    321321
    322 func (net *network) deleteChannel(name string) error {
     322func (net *network) deleteChannel(ctx context.Context, name string) error {
    323323        ch := net.channels.Value(name)
    324324        if ch == nil {
     
    332332        }
    333333
    334         if err := net.user.srv.db.DeleteChannel(context.TODO(), ch.ID); err != nil {
     334        if err := net.user.srv.db.DeleteChannel(ctx, ch.ID); err != nil {
    335335                return err
    336336        }
     
    661661                        }
    662662
    663                         e.done <- u.updateUser(&record)
     663                        e.done <- u.updateUser(context.TODO(), &record)
    664664
    665665                        // If the password was updated, kill all downstream connections to
     
    767767}
    768768
    769 func (u *user) createNetwork(record *Network) (*network, error) {
     769func (u *user) createNetwork(ctx context.Context, record *Network) (*network, error) {
    770770        if record.ID != 0 {
    771771                panic("tried creating an already-existing network")
     
    781781
    782782        network := newNetwork(u, record, nil)
    783         err := u.srv.db.StoreNetwork(context.TODO(), u.ID, &network.Network)
     783        err := u.srv.db.StoreNetwork(ctx, u.ID, &network.Network)
    784784        if err != nil {
    785785                return nil, err
     
    803803}
    804804
    805 func (u *user) updateNetwork(record *Network) (*network, error) {
     805func (u *user) updateNetwork(ctx context.Context, record *Network) (*network, error) {
    806806        if record.ID == 0 {
    807807                panic("tried updating a new network")
     
    823823        }
    824824
    825         if err := u.srv.db.StoreNetwork(context.TODO(), u.ID, record); err != nil {
     825        if err := u.srv.db.StoreNetwork(ctx, u.ID, record); err != nil {
    826826                return nil, err
    827827        }
     
    884884}
    885885
    886 func (u *user) deleteNetwork(id int64) error {
     886func (u *user) deleteNetwork(ctx context.Context, id int64) error {
    887887        network := u.getNetworkByID(id)
    888888        if network == nil {
     
    890890        }
    891891
    892         if err := u.srv.db.DeleteNetwork(context.TODO(), network.ID); err != nil {
     892        if err := u.srv.db.DeleteNetwork(ctx, network.ID); err != nil {
    893893                return err
    894894        }
     
    910910}
    911911
    912 func (u *user) updateUser(record *User) error {
     912func (u *user) updateUser(ctx context.Context, record *User) error {
    913913        if u.ID != record.ID {
    914914                panic("ID mismatch when updating user")
     
    916916
    917917        realnameUpdated := u.Realname != record.Realname
    918         if err := u.srv.db.StoreUser(context.TODO(), record); err != nil {
     918        if err := u.srv.db.StoreUser(ctx, record); err != nil {
    919919                return fmt.Errorf("failed to update user %q: %v", u.Username, err)
    920920        }
     
    932932                var netErr error
    933933                for _, net := range needUpdate {
    934                         if _, err := u.updateNetwork(&net); err != nil {
     934                        if _, err := u.updateNetwork(ctx, &net); err != nil {
    935935                                netErr = err
    936936                        }
Note: See TracChangeset for help on using the changeset viewer.