|
@@ -58,7 +58,8 @@ type User struct {
|
|
|
ConnectionErrors int
|
|
|
CommunityID string
|
|
|
|
|
|
- cleanDisconnection bool
|
|
|
+ cleanDisconnection bool
|
|
|
+ batteryWarningsSent int
|
|
|
|
|
|
chatListReceived chan struct{}
|
|
|
syncPortalsDone chan struct{}
|
|
@@ -672,6 +673,33 @@ func (user *User) putMessage(message PortalMessage) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (user *User) HandleNewContact(contact whatsapp.Contact) {
|
|
|
+ user.log.Debugfln("Contact message: %+v", contact)
|
|
|
+ go func() {
|
|
|
+ puppet := user.bridge.GetPuppetByJID(contact.Jid)
|
|
|
+ puppet.UpdateName(user, contact)
|
|
|
+ }()
|
|
|
+}
|
|
|
+
|
|
|
+func (user *User) HandleBatteryMessage(battery whatsapp.BatteryMessage) {
|
|
|
+ user.log.Debugfln("Battery message: %+v", battery)
|
|
|
+ var notice string
|
|
|
+ if !battery.Plugged && battery.Percentage < 15 && user.batteryWarningsSent < 1 {
|
|
|
+ notice = fmt.Sprintf("Phone battery low (%d remaining)", battery.Percentage)
|
|
|
+ user.batteryWarningsSent = 1
|
|
|
+ } else if !battery.Plugged && battery.Percentage < 5 && user.batteryWarningsSent < 1 {
|
|
|
+ notice = fmt.Sprintf("Phone battery very low (%d remaining)", battery.Percentage)
|
|
|
+ user.batteryWarningsSent = 2
|
|
|
+ } else {
|
|
|
+ user.batteryWarningsSent = 0
|
|
|
+ }
|
|
|
+ if notice != "" {
|
|
|
+ go func() {
|
|
|
+ _, _ = user.bridge.Bot.SendNotice(user.GetManagementRoom(), notice)
|
|
|
+ }()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (user *User) HandleTextMessage(message whatsapp.TextMessage) {
|
|
|
user.putMessage(PortalMessage{message.Info.RemoteJid, user, message, message.Info.Timestamp})
|
|
|
}
|