31
33
notifications *[]plugins.Notification
37
SERVICENAME_GMAIL = "google-gmail"
38
SERVICENAME_TWITTER = "twitter-microblog"
39
SERVICENAME_FACEBOOK = "facebook-microblog"
35
46
// TODO NewAccount called here is just for playing purposes.
36
a := NewAccount("sergiusens@gmail.com", "gmail")
38
47
postWatch := make(chan *PostWatch)
40
49
if bus, err := dbus.Connect(dbus.SessionBus); err != nil {
43
52
go postOffice(bus, postWatch)
55
go monitorAccounts(postWatch)
48
57
done := make(chan bool)
61
func monitorAccounts(postWatch chan *PostWatch) {
62
mgr := make(map[uint]*AccountManager)
64
for data := range accounts.WatchForService(SERVICENAME_GMAIL, SERVICENAME_FACEBOOK, SERVICENAME_TWITTER) {
65
if account, ok := mgr[data.AccountId]; ok {
66
log.Printf("New account data for %d - was %#v, now is %#v", data.AccountId, account.authData, data)
68
account.authData = data
71
delete(mgr, data.AccountId)
73
} else if data.Enabled {
74
var plugin plugins.Plugin
75
switch data.ServiceName {
76
case SERVICENAME_GMAIL:
77
log.Println("Creating account with id", data.AccountId, "for", data.ServiceName)
79
case SERVICENAME_FACEBOOK:
80
// This is just stubbed until the plugin exists.
81
log.Println("Unhandled account with id", data.AccountId, "for", data.ServiceName)
83
case SERVICENAME_TWITTER:
84
// This is just stubbed until the plugin exists.
85
log.Println("Unhandled account with id", data.AccountId, "for", data.ServiceName)
88
log.Println("Unhandled account with id", data.AccountId, "for", data.ServiceName)
91
mgr[data.AccountId] = NewAccountManager(data, plugin)
92
go mgr[data.AccountId].Loop(postWatch)
52
97
func postOffice(bus *dbus.Connection, postWatch chan *PostWatch) {
53
98
for post := range postWatch {
54
99
for _, n := range *post.notifications {
55
fmt.Println("Should be dispathing", n, "to the post office using", bus.UniqueName, "for", post.appId)
100
fmt.Println("Should be dispatching", n, "to the post office using", bus.UniqueName, "for", post.appId)