64
64
QStringList recipients;
65
65
recipients << notificationData->participantIds;
66
66
recipients.removeDuplicates();
67
notificationData->observer->sendMessage(recipients, notificationData->messageText, accountId);
67
notificationData->observer->sendMessage(*notificationData);
70
70
notify_notification_close(notification, &error);
90
90
History::TextEvent textEvent(notificationData->accountId,
92
notificationData->eventId,
92
QString(QByteArray::fromHex(notificationData->encodedEventId.toUtf8())),
93
93
notificationData->senderId,
94
94
notificationData->timestamp,
146
146
connect(MessagingMenu::instance(),
147
SIGNAL(replyReceived(QStringList,QString,QString)),
148
SLOT(onReplyReceived(QStringList,QString,QString)));
147
SIGNAL(replyReceived(NotificationData)),
148
SLOT(onReplyReceived(NotificationData)));
149
149
connect(MessagingMenu::instance(),
150
SIGNAL(messageRead(QStringList,QString,QString)),
151
SLOT(onMessageRead(QStringList,QString,QString)));
150
SIGNAL(messageRead(NotificationData)),
151
SLOT(onMessageRead(NotificationData)));
153
153
if (GreeterContacts::isGreeterMode()) {
154
154
connect(GreeterContacts::instance(), SIGNAL(contactUpdated(QtContacts::QContact)),
169
169
mNotifications.clear();
172
void TextChannelObserver::sendMessage(const QStringList &recipients, const QString &text, const QString &accountId)
172
void TextChannelObserver::sendMessage(NotificationData notificationData)
174
AccountEntry *account = TelepathyHelper::instance()->accountForId(accountId);
175
if (!account || accountId.isEmpty()) {
174
AccountEntry *account = TelepathyHelper::instance()->accountForId(notificationData.accountId);
175
if (!account || notificationData.accountId.isEmpty()) {
176
176
// fallback to the default account
177
177
if (TelepathyHelper::instance()->defaultMessagingAccount() && TelepathyHelper::instance()->defaultMessagingAccount()->active()) {
178
178
account = TelepathyHelper::instance()->defaultMessagingAccount();
191
191
bool phoneNumberBased = account->type() == AccountEntry::PhoneAccount || account->type() == AccountEntry::MultimediaAccount;
192
192
History::Thread thread = History::Manager::instance()->threadForParticipants(account->accountId(),
193
193
History::EventTypeText,
194
notificationData.participantIds,
195
195
phoneNumberBased ? History::MatchPhoneNumber :
196
196
History::MatchCaseSensitive,
231
231
g_object_unref(icon);
232
232
g_free(iconPath);
233
233
NotificationData *data = new NotificationData();
234
data->participantIds = recipients;
235
data->accountId = account->accountId();
236
data->messageText = text;
234
*data = notificationData;
237
235
data->notificationList = &mNotifications;
238
236
mNotifications.insert(notification, data);
263
261
QVariantMap properties;
264
properties["participantIds"] = recipients;
265
ChatManager::instance()->sendMessage(account->accountId(), text, QVariantMap(), properties);
262
properties["participantIds"] = notificationData.participantIds;
263
properties["chatType"] = notificationData.targetType;
264
if (notificationData.targetId.isEmpty()) {
265
properties["threadId"] = notificationData.targetId;
267
ChatManager::instance()->sendMessage(account->accountId(), notificationData.messageReply, QVariantMap(), properties);
268
270
void TextChannelObserver::clearNotifications()
278
void TextChannelObserver::showNotificationForNewGroup(const QString &accountId, const Tp::TextChannelPtr channel)
280
// show the notification
282
NotificationData *data = new NotificationData();
283
data->accountId = accountId;
284
data->timestamp = QDateTime::currentDateTime();
285
data->targetId = channel->targetId();
286
data->targetType = channel->targetHandleType();
287
data->notificationTitle = QString::fromUtf8(C::gettext("New Group"));
288
data->encodedEventId = QByteArray(QDateTime::currentDateTime().toString("yyyy-MM-ddTHH:mm:ss.zzz").toUtf8()).toHex();
289
data->icon = QUrl::fromLocalFile(telephonyServiceDir() + "/assets/contact-group.svg").toString();
291
Tp::Client::ChannelInterfaceRoomInterface *roomInterface = channel->optionalInterface<Tp::Client::ChannelInterfaceRoomInterface>();
292
Tp::Client::ChannelInterfaceRoomConfigInterface *roomConfigInterface = channel->optionalInterface<Tp::Client::ChannelInterfaceRoomConfigInterface>();
293
QVariantMap roomInterfaceProps = getInterfaceProperties(roomInterface);
294
QVariantMap roomConfigInterfaceProps = getInterfaceProperties(roomConfigInterface);
295
if (roomConfigInterfaceProps.contains("Title") && !roomConfigInterfaceProps["Title"].toString().isEmpty()) {
296
// TRANSLATORS : %1 is the group name
297
data->messageText = QString::fromUtf8(C::gettext("You joined group %1 ")).arg(roomConfigInterfaceProps["Title"].toString());
298
data->roomName = roomConfigInterfaceProps["Title"].toString();
299
} else if (roomInterfaceProps.contains("RoomName") && !roomInterfaceProps["RoomName"].toString().isEmpty()) {
300
// TRANSLATORS : %1 is the group name
301
data->messageText = QString::fromUtf8(C::gettext("You joined group %1")).arg(roomInterfaceProps["RoomName"].toString());
302
data->roomName = roomInterfaceProps["RoomName"].toString();
304
data->messageText = QString::fromUtf8(C::gettext("You joined a new group"));
307
if (roomInterfaceProps["CreationTimestamp"].toDateTime().isValid()) {
308
data->timestamp = roomInterfaceProps["CreationTimestamp"].toDateTime();
311
NotificationData messagingMenuData = *data;
313
MessagingMenu::instance()->addNotification(messagingMenuData);
315
NotifyNotification *notification = notify_notification_new(data->notificationTitle.toStdString().c_str(),
316
data->messageText.toStdString().c_str(),
317
data->icon.toStdString().c_str());
319
mNotifications.insert(notification, data);
321
notify_notification_add_action (notification,
322
"notification_action",
323
C::gettext("View Group"),
327
g_signal_connect(notification, "closed", G_CALLBACK(notification_closed), &mNotifications);
329
GError *error = NULL;
330
if (!notify_notification_show(notification, &error)) {
331
qWarning() << "Failed to show message notification:" << error->message;
332
g_error_free (error);
335
Ringtone::instance()->playIncomingMessageSound();
276
338
void TextChannelObserver::showNotificationForFlashMessage(const Tp::ReceivedMessage &message, const QString &accountId)
278
340
Tp::ContactPtr contact = message.sender();
287
349
data->accountId = accountId;
288
350
data->timestamp = message.received();
289
351
data->messageText = message.text();
290
data->eventId = message.messageToken().toUtf8();
352
data->encodedEventId = token.toHex();
292
354
NotificationData messagingMenuData = *data;
293
messagingMenuData.eventId = token.toHex();
295
356
MessagingMenu::instance()->addFlashMessage(messagingMenuData);
471
532
messagingMenuData.alias = telepathyContact->alias();
472
533
messagingMenuData.participantIds = participantIds;
473
534
messagingMenuData.accountId = accountId;
474
messagingMenuData.eventId = token.toHex();
535
messagingMenuData.encodedEventId = token.toHex();
475
536
messagingMenuData.timestamp = message.received();
476
537
messagingMenuData.messageText = messageText;
477
538
messagingMenuData.targetId = channel->targetId();
524
585
data->participantIds = participantIds;
525
586
data->alias = alias;
526
587
data->messageText = messageText;
588
data->targetId = channel->targetId();
589
data->targetType = channel->targetHandleType();
527
590
data->notificationList = &mNotifications;
528
data->targetId = channel->targetId();
529
data->targetType = channel->targetHandleType();
530
591
mNotifications.insert(notification, data);
532
593
// add the callback action
606
667
SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
607
668
SLOT(onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString)));
670
AccountEntry *account = TelepathyHelper::instance()->accountForConnection(textChannel->connection());
675
if (textChannel->targetHandleType() == Tp::HandleTypeRoom && !textChannel->isRequested()) {
676
QVariantMap properties;
677
properties["accountId"] = account->accountId();
678
properties["threadId"] = textChannel->targetId();
679
properties["chatType"] = Tp::HandleTypeRoom;
680
History::Thread thread = History::Manager::instance()->threadForProperties(account->accountId(),
681
History::EventTypeText,
683
if (thread.isNull()) {
684
// notify that we got added to a new group
685
showNotificationForNewGroup(account->accountId(), textChannel);
610
689
if (textChannel->immutableProperties().contains(TP_QT_IFACE_CHANNEL_INTERFACE_SMS + QLatin1String(".Flash")) &&
611
690
textChannel->immutableProperties()[TP_QT_IFACE_CHANNEL_INTERFACE_SMS + QLatin1String(".Flash")].toBool()) {
694
773
MessagingMenu::instance()->removeMessage(token.toHex());
697
void TextChannelObserver::onReplyReceived(const QStringList &recipients, const QString &accountId, const QString &reply)
776
void TextChannelObserver::onReplyReceived(NotificationData notificationData)
699
AccountEntry *account = TelepathyHelper::instance()->accountForId(accountId);
778
AccountEntry *account = TelepathyHelper::instance()->accountForId(notificationData.accountId);
704
783
// FIXME - we need to find a better way to deal with dual sim in the messaging-menu
705
if (!TelepathyHelper::instance()->defaultMessagingAccount()
706
&& TelepathyHelper::instance()->activeAccounts().size() > 1
707
&& account->type() != AccountEntry::GenericAccount) {
784
if (account->type() == AccountEntry::PhoneAccount
785
&& !TelepathyHelper::instance()->defaultMessagingAccount()
786
&& TelepathyHelper::instance()->activeAccounts().size() > 1) {
708
787
NotifyNotification *notification = notify_notification_new(C::gettext("Please, select a SIM card:"),
709
reply.toStdString().c_str(),
788
notificationData.messageReply.toStdString().c_str(),
711
790
NotificationData *data = new NotificationData();
712
data->participantIds = recipients;
713
data->accountId = accountId;
714
data->messageText = reply;
791
*data = notificationData;
715
792
data->observer = this;
716
793
mNotifications.insert(notification, data);
740
if (account->type() == AccountEntry::GenericAccount) {
741
sendMessage(recipients, reply, accountId);
743
// FIXME: for now we dont specify any accountId
744
sendMessage(recipients, reply, "");
817
sendMessage(notificationData);
748
void TextChannelObserver::onMessageRead(const QStringList &recipients, const QString &accountId, const QString &encodedMessageId)
820
void TextChannelObserver::onMessageRead(NotificationData notificationData)
750
QString messageId(QByteArray::fromHex(encodedMessageId.toUtf8()));
822
QString messageId(QByteArray::fromHex(notificationData.encodedEventId.toUtf8()));
751
823
QVariantMap properties;
752
properties["accountId"] = accountId;
753
properties["participantIds"] = recipients;
754
properties["messageId"] = encodedMessageId;
824
properties["accountId"] = notificationData.accountId;
825
properties["participantIds"] = notificationData.participantIds;
826
properties["messageId"] = notificationData.encodedEventId;
755
827
ChatManager::instance()->acknowledgeMessage(properties);