roster.go
author Chris Jones <chris@cjones.org>
Sat, 07 Jan 2012 22:22:18 -0700
changeset 61 16513974d273
parent 60 6d4f43f7dc19
child 72 53f15893a1a7
permissions -rw-r--r--
Stanzas can now contain multiple nested (extended) elements.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
     1
// Copyright 2011 The Go Authors.  All rights reserved.
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
     2
// Use of this source code is governed by a BSD-style
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
     3
// license that can be found in the LICENSE file.
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
     4
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
     5
package xmpp
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
     6
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
     7
import (
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
     8
	"fmt"
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
     9
	"os"
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    10
	"xml"
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    11
)
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    12
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    13
// This file contains support for roster management, RFC 3921, Section 7.
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    14
60
6d4f43f7dc19 Made a generic extension interface.
Chris Jones <chris@cjones.org>
parents: 58
diff changeset
    15
var rosterExt Extension = Extension{StanzaHandlers:
6d4f43f7dc19 Made a generic extension interface.
Chris Jones <chris@cjones.org>
parents: 58
diff changeset
    16
	map[string] func(*xml.Name) interface{}{NsRoster:
6d4f43f7dc19 Made a generic extension interface.
Chris Jones <chris@cjones.org>
parents: 58
diff changeset
    17
		newRosterQuery}, Start: startRosterFilter}
6d4f43f7dc19 Made a generic extension interface.
Chris Jones <chris@cjones.org>
parents: 58
diff changeset
    18
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    19
// Roster query/result
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    20
type RosterQuery struct {
39
4a06f7ccfa84 Use name tags for roster data structures.
Chris Jones <chris@cjones.org>
parents: 38
diff changeset
    21
	XMLName xml.Name `xml:"jabber:iq:roster query"`
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    22
	Item []RosterItem
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    23
}
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    24
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    25
// See RFC 3921, Section 7.1.
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    26
type RosterItem struct {
39
4a06f7ccfa84 Use name tags for roster data structures.
Chris Jones <chris@cjones.org>
parents: 38
diff changeset
    27
	XMLName xml.Name `xml:"item"`
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    28
	Jid string `xml:"attr"`
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    29
	Subscription string `xml:"attr"`
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    30
	Name string `xml:"attr"`
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    31
	Group []string
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    32
}
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    33
57
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    34
type rosterClient struct {
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    35
	rosterChan <-chan []RosterItem
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    36
	rosterUpdate chan<- RosterItem
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    37
}
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    38
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    39
var (
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    40
	rosterClients = make(map[string] rosterClient)
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    41
)
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    42
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    43
// Implicitly becomes part of NewClient's extStanza arg.
38
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
    44
func newRosterQuery(name *xml.Name) interface{} {
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
    45
	return &RosterQuery{}
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    46
}
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    47
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    48
// Synchronously fetch this entity's roster from the server and cache
57
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    49
// that information. This is called once from a fairly deep call stack
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    50
// as part of XMPP negotiation.
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    51
func fetchRoster(client *Client) os.Error {
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    52
	rosterUpdate := rosterClients[client.Uid].rosterUpdate
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    53
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    54
	iq := &Iq{From: client.Jid.String(), Id: <- Id, Type: "get",
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
    55
		Nested: []interface{}{RosterQuery{}}}
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    56
	ch := make(chan os.Error)
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    57
	f := func(st Stanza) bool {
57
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    58
		defer close(ch)
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    59
		if iq.Type == "error" {
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    60
			ch <- iq.Error
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    61
			return false
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    62
		}
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
    63
		var rq *RosterQuery
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
    64
		for _, ele := range(st.GetNested()) {
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
    65
			if q, ok := ele.(*RosterQuery) ; ok {
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
    66
				rq = q
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
    67
				break
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
    68
			}
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
    69
		}
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
    70
		if rq == nil {
38
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
    71
			ch <- os.NewError(fmt.Sprintf(
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
    72
				"Roster query result not query: %v", st))
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
    73
			return false
2839fece923e Extended stanzas work now.
Chris Jones <chris@cjones.org>
parents: 37
diff changeset
    74
		}
57
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    75
		for _, item := range(rq.Item) {
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    76
			rosterUpdate <- item
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    77
		}
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    78
		ch <- nil
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    79
		return false
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    80
	}
57
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    81
	client.HandleStanza(iq.Id, f)
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    82
	client.Out <- iq
36
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    83
	// Wait for f to complete.
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    84
	return <- ch
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    85
}
9fe022261dcc Added a capability to use extensions. There are still some bugs with
Chris Jones <chris@cjones.org>
parents:
diff changeset
    86
46
4a4530b8f622 Added roster updating.
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
    87
// The roster filter updates the Client's representation of the
57
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    88
// roster, but it lets the relevant stanzas through. This also starts
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    89
// the roster feeder, which is the goroutine that provides data on
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    90
// client.Roster.
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    91
func startRosterFilter(client *Client) {
46
4a4530b8f622 Added roster updating.
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
    92
	out := make(chan Stanza)
57
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    93
	in := client.AddFilter(out)
50
08d2b9deb710 Simplified the roster filter.
Chris Jones <chris@cjones.org>
parents: 47
diff changeset
    94
	go func(in <-chan Stanza, out chan<- Stanza) {
46
4a4530b8f622 Added roster updating.
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
    95
		defer close(out)
50
08d2b9deb710 Simplified the roster filter.
Chris Jones <chris@cjones.org>
parents: 47
diff changeset
    96
		for st := range(in) {
57
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
    97
			maybeUpdateRoster(client, st)
50
08d2b9deb710 Simplified the roster filter.
Chris Jones <chris@cjones.org>
parents: 47
diff changeset
    98
			out <- st
46
4a4530b8f622 Added roster updating.
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
    99
		}
4a4530b8f622 Added roster updating.
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
   100
	}(in, out)
57
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   101
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   102
	rosterCh := make(chan []RosterItem)
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   103
	rosterUpdate := make(chan RosterItem)
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   104
	rosterClients[client.Uid] = rosterClient{rosterChan: rosterCh,
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   105
		rosterUpdate: rosterUpdate}
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   106
	go feedRoster(rosterCh, rosterUpdate)
46
4a4530b8f622 Added roster updating.
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
   107
}
4a4530b8f622 Added roster updating.
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
   108
57
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   109
func maybeUpdateRoster(client *Client, st Stanza) {
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   110
	rosterUpdate := rosterClients[client.Uid].rosterUpdate
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   111
61
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   112
	var rq *RosterQuery
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   113
	for _, ele := range(st.GetNested()) {
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   114
		if q, ok := ele.(*RosterQuery) ; ok {
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   115
			rq = q
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   116
			break
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   117
		}
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   118
	}
16513974d273 Stanzas can now contain multiple nested (extended) elements.
Chris Jones <chris@cjones.org>
parents: 60
diff changeset
   119
	if st.GetName() == "iq" && st.GetType() == "set" && rq != nil {
57
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   120
		for _, item := range(rq.Item) {
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   121
			rosterUpdate <- item
46
4a4530b8f622 Added roster updating.
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
   122
		}
58
c0e8778bdb80 Sent acknowledgment when somebody sends us a roster iq.
Chris Jones <chris@cjones.org>
parents: 57
diff changeset
   123
		// Send a reply.
c0e8778bdb80 Sent acknowledgment when somebody sends us a roster iq.
Chris Jones <chris@cjones.org>
parents: 57
diff changeset
   124
		iq := &Iq{To: st.GetFrom(), Id: st.GetId(), Type:
c0e8778bdb80 Sent acknowledgment when somebody sends us a roster iq.
Chris Jones <chris@cjones.org>
parents: 57
diff changeset
   125
			"result"}
c0e8778bdb80 Sent acknowledgment when somebody sends us a roster iq.
Chris Jones <chris@cjones.org>
parents: 57
diff changeset
   126
		client.Out <- iq
46
4a4530b8f622 Added roster updating.
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
   127
	}
4a4530b8f622 Added roster updating.
Chris Jones <chris@cjones.org>
parents: 42
diff changeset
   128
}
57
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   129
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   130
func feedRoster(rosterCh chan<- []RosterItem, rosterUpdate <-chan RosterItem) {
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   131
	roster := make(map[string] RosterItem)
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   132
	snapshot := []RosterItem{}
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   133
	for {
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   134
		select {
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   135
		case newIt := <-rosterUpdate:
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   136
			if newIt.Subscription == "remove" {
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   137
				roster[newIt.Jid] = RosterItem{}, false
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   138
			} else {
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   139
				roster[newIt.Jid] = newIt
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   140
			}
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   141
		case rosterCh <- snapshot:
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   142
		}
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   143
		snapshot = make([]RosterItem, 0, len(roster))
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   144
		for _, v := range(roster) {
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   145
			snapshot = append(snapshot, v)
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   146
		}
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   147
	}
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   148
}
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   149
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   150
// Retrieve a snapshot of the roster for the given Client.
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   151
func Roster(client *Client) []RosterItem {
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   152
	rosterChan := rosterClients[client.Uid].rosterChan
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   153
	return <- rosterChan
e6cb3f049137 Revamped how the roster works. We're now using a channel to transmit snapshots
Chris Jones <chris@cjones.org>
parents: 55
diff changeset
   154
}