Skip to content

Commit

Permalink
[AsteroidOS] notifications service - increment id, show phone call
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlich committed Dec 25, 2023
1 parent 2a11367 commit 69bf006
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
3 changes: 1 addition & 2 deletions daemon/src/devices/asteroidosdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ void AsteroidOSDevice::incomingCall(const QString &caller)

AsteroidNotificationService *notification = qobject_cast<AsteroidNotificationService*>(service(AsteroidNotificationService::UUID_SERVICE_NOTIFICATION));
if (notification) {
qDebug() << "Have an notification service";
// notification->incomingCall(QByteArray::fromHex("030100"), caller);
notification->incomingCall(caller);
}

}
Expand Down
46 changes: 34 additions & 12 deletions daemon/src/services/asteroidnotificationservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,32 @@ AsteroidNotificationService::AsteroidNotificationService(const QString &path, QO

void AsteroidNotificationService::sendAlert(const QString &sender, const QString &subject, const QString &message)
{
// qDebug() << Q_FUNC_INFO << sender << subject << message;

unsigned int id = 0;
QString icon = sender;
QString icon = mapSenderToIcon(sender);

// for vibrate, valid options are { "ringtone", "strong", "normal", "none" }
QString vibrate = "normal";

QByteArray data = QString("<insert><pn>%1</pn><id>%2</id><an>%3</an><ai>%4</ai><su>%5</su><bo>%6</bo><vb>%7</vb></insert>")
.arg(sender, QString::number(id), sender, icon, subject, message, vibrate).toUtf8();
.arg(sender, QString::number(m_lastNotificationId), sender, icon, subject, message, vibrate).toUtf8();


qDebug() << Q_FUNC_INFO << sender << subject << message << data;
m_lastNotificationId++;

writeValue(UUID_CHARACTERISTIC_NOTIFICATION_UPDATE, data);
}

//void AlertNotificationService::incomingCall(const QByteArray header, const QString &caller)
//{
// qDebug() << Q_FUNC_INFO << caller;
// QByteArray send = header + caller.toUtf8();
// writeValue(UUID_CHARACTERISTIC_ALERT_NOTIFICATION_NEW_ALERT, send);
//}

void AsteroidNotificationService::incomingCall(const QString &caller)
{
qDebug() << Q_FUNC_INFO << caller;
m_lastVoiceCallNotification = m_lastNotificationId;
sendAlert("incoming-call", caller, "");
}

void AsteroidNotificationService::incomingCallEnded()
{
removeNotification(m_lastVoiceCallNotification);
}

void AsteroidNotificationService::removeNotification(unsigned int id)
{
Expand All @@ -50,3 +52,23 @@ void AsteroidNotificationService::characteristicChanged(const QString &c, const
qDebug() << Q_FUNC_INFO << c << value;
emit serviceEvent(c, value[0]);
}

QString AsteroidNotificationService::mapSenderToIcon(const QString &sender) {

// see https://github.com/AsteroidOS/asteroid-icons-ion
const QMap<QString, QString> iconMapping = {
{"Dekko", "ios-mail"},
{"TELEports", "ios-paper-plane"},
{"Cinny", "ios-paper-plane"},
{"indicator-datetime", "ios-alarm"},
{"incoming-call", "ios-call"},
};

for (auto it = iconMapping.begin(); it != iconMapping.end(); ++it) {
if (sender == it.key()) {
return it.value();
}
}

return "ios-mail-open-outline";
}
8 changes: 5 additions & 3 deletions daemon/src/services/asteroidnotificationservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ class AsteroidNotificationService : public QBLEService

Q_INVOKABLE void sendAlert(const QString &sender, const QString &subject, const QString &message);
Q_INVOKABLE void removeNotification(unsigned int id);
// Q_INVOKABLE void incomingCall(const QByteArray header, const QString &caller);
// static int mapSenderToIcon(const QString &sender);
Q_INVOKABLE void incomingCall(const QString &caller);
Q_INVOKABLE void incomingCallEnded();
static QString mapSenderToIcon(const QString &sender);

Q_SIGNAL void serviceEvent(const QString &c, uint8_t event);

private:
void characteristicChanged(const QString &c, const QByteArray &value);
// uint8_t m_seperatorChar = 0x00;
unsigned int m_lastNotificationId = 0;
unsigned int m_lastVoiceCallNotification = 0;
};

#endif // ASTEROIDNOTIFICATIONSERVICE_H

0 comments on commit 69bf006

Please sign in to comment.