-
Notifications
You must be signed in to change notification settings - Fork 80
/
notifications.go
84 lines (66 loc) · 2.01 KB
/
notifications.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package gui
import (
"fmt"
"log"
"time"
"github.com/coyim/coyim/xmpp/jid"
"github.com/coyim/gotk3adapter/gtki"
)
const mergeNotificationsThreshold = 7
func (u *gtkUI) lastActionTimeFor(f string) time.Time {
return u.actionTimes[f]
}
func (u *gtkUI) registerLastActionTimeFor(f string, t time.Time) {
u.actionTimes[f] = t
}
func (u *gtkUI) maybeNotify(timestamp time.Time, account *account, peer jid.WithoutResource, message string) {
if u.deNotify == nil {
return
}
dname := u.displayNameFor(account, peer)
if timestamp.Before(u.lastActionTimeFor(peer.String()).Add(time.Duration(mergeNotificationsThreshold) * time.Second)) {
fmt.Println("Decided to not show notification, since the time is not ready")
return
}
u.registerLastActionTimeFor(peer.String(), timestamp)
err := u.deNotify.show(peer.String(), dname, message)
if err != nil {
log.Println(err)
}
}
func (u *gtkUI) showConnectAccountNotification(account *account) func() {
var notification gtki.InfoBar
doInUIThread(func() {
notification = account.buildConnectionNotification()
account.setCurrentNotification(notification, u.notificationArea)
})
return func() {
doInUIThread(func() {
account.removeCurrentNotificationIf(notification)
})
}
}
func (u *gtkUI) notifyTorIsNotRunning(account *account, moreInfo func()) {
doInUIThread(func() {
notification := account.buildTorNotRunningNotification(moreInfo)
account.setCurrentNotification(notification, u.notificationArea)
})
}
func (u *gtkUI) notifyConnectionFailure(account *account, moreInfo func()) {
doInUIThread(func() {
notification := account.buildConnectionFailureNotification(moreInfo)
account.setCurrentNotification(notification, u.notificationArea)
})
}
func (u *gtkUI) notify(title, message string) {
builder := newBuilder("SimpleNotification")
obj := builder.getObj("dialog")
dlg := obj.(gtki.MessageDialog)
dlg.SetProperty("title", title)
dlg.SetProperty("text", message)
dlg.SetTransientFor(u.window)
doInUIThread(func() {
dlg.Run()
dlg.Destroy()
})
}