Only send call notification for incoming calls

This commit is contained in:
Elara 2023-04-25 16:13:38 -07:00
parent 9998915959
commit 858edb0f55

View File

@ -71,6 +71,17 @@ func initCallNotifs(ctx context.Context, wg WaitGroup, dev *infinitime.Device) e
continue continue
} }
// Get direction of call object using method call connection
direction, err := getDirection(conn, callObj)
if err != nil {
log.Error("Error getting call direction").Err(err).Send()
continue
}
if direction != MMCallDirectionIncoming {
continue
}
// Send call notification to InfiniTime // Send call notification to InfiniTime
resCh, err := dev.NotifyCall(phoneNum) resCh, err := dev.NotifyCall(phoneNum)
if err != nil { if err != nil {
@ -131,6 +142,25 @@ func getPhoneNum(conn *dbus.Conn, callObj dbus.BusObject) (string, error) {
return out, nil return out, nil
} }
type MMCallDirection int
const (
MMCallDirectionUnknown MMCallDirection = iota
MMCallDirectionIncoming
MMCallDirectionOutgoing
)
// getDirection gets the direction of a call object using a DBus connection
func getDirection(conn *dbus.Conn, callObj dbus.BusObject) (MMCallDirection, error) {
var out MMCallDirection
// Get number property on DBus object and store return value in out
err := callObj.StoreProperty("org.freedesktop.ModemManager1.Call.Direction", &out)
if err != nil {
return 0, err
}
return out, nil
}
// getPhoneNum accepts a call using a DBus connection // getPhoneNum accepts a call using a DBus connection
func acceptCall(ctx context.Context, conn *dbus.Conn, callObj dbus.BusObject) error { func acceptCall(ctx context.Context, conn *dbus.Conn, callObj dbus.BusObject) error {
// Call Accept() method on DBus object // Call Accept() method on DBus object