Commit dd85dee1 authored by Anthony Léonard's avatar Anthony Léonard Committed by Olivier SOLDANO

fix unread msg counter update + dock icon counter

2 problems were preventing the unread msg counter to work properly:
- Messages were not marked as read when displayed.
- Signals announcing status update were not listened to.

Moreover, the one present on dock icon was still listening to old LRC
mechanisms and is thus removed (until further improvements).

Finally, as the interactionStatusUpdated signal is triggered multiple
times when many messages are unread, some logic is added to debounce
it so only one refresh is triggered for a group of update.

Change-Id: Ieaa02d685bbd85d965de5315e8694ccdbd18eff1
Reviewed-by: default avatarOlivier Soldano <olivier.soldano@savoirfairelinux.com>
parent 48079dec
......@@ -144,16 +144,6 @@ static void ReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNet
}
});
QObject::connect(&Media::RecordingModel::instance(),
&Media::RecordingModel::unreadMessagesCountChanged,
[=](int unreadCount) {
NSDockTile *tile = [[NSApplication sharedApplication] dockTile];
NSString* label = unreadCount ? [NSString stringWithFormat:@"%d", unreadCount]: @"";
[tile setBadgeLabel:label];
[NSApp requestUserAttention:NSCriticalRequest];
});
QObject::connect(&Media::RecordingModel::instance(),
&Media::RecordingModel::newTextMessage,
[=](Media::TextRecording* t, ContactMethod* cm) {
......
......@@ -236,6 +236,8 @@
} else {
result = [tableView makeViewWithIdentifier:@"LeftMessageView" owner:self];
}
if (interaction.status == lrc::api::interaction::Status::UNREAD)
convModel_->setInteractionRead(convUid_, it->first);
break;
case lrc::api::interaction::Type::INCOMING_DATA_TRANSFER:
case lrc::api::interaction::Type::OUTGOING_DATA_TRANSFER:
......
......@@ -56,7 +56,8 @@
__strong IBOutlet NSSegmentedControl *listTypeSelector;
bool selectorIsPresent;
QMetaObject::Connection modelSortedConnection_, filterChangedConnection_, newConversationConnection_, conversationRemovedConnection_;
QMetaObject::Connection modelSortedConnection_, filterChangedConnection_, newConversationConnection_, conversationRemovedConnection_, interactionStatusUpdatedConnection_;
NSTimer* statusUpdateDebounceTimer;
lrc::api::ConversationModel* model_;
std::string selectedUid_;
......@@ -184,6 +185,7 @@ NSInteger const REQUEST_SEG = 1;
QObject::disconnect(filterChangedConnection_);
QObject::disconnect(newConversationConnection_);
QObject::disconnect(conversationRemovedConnection_);
QObject::disconnect(interactionStatusUpdatedConnection_);
[self reloadData];
if (model_ != nil) {
modelSortedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::modelSorted,
......@@ -202,6 +204,23 @@ NSInteger const REQUEST_SEG = 1;
[self] (){
[self reloadData];
});
interactionStatusUpdatedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::interactionStatusUpdated,
[self] (const std::string& convUid) {
if (convUid != selectedUid_)
return;
auto it = getConversationFromUid(selectedUid_, *model_);
if (it != model_->allFilteredConversations().end()) {
// The following mechanism is here to debounce the interactionStatusUpdated so
// we do not redraw the conversation list for each message status changing
if (statusUpdateDebounceTimer != nil) {
[statusUpdateDebounceTimer invalidate];
}
statusUpdateDebounceTimer = [NSTimer timerWithTimeInterval:1.0 repeats:NO block:^(NSTimer * _Nonnull timer) {
[self reloadData];
}];
[[NSRunLoop mainRunLoop] addTimer:statusUpdateDebounceTimer forMode:NSRunLoopCommonModes];
}
});
model_->setFilter(""); // Reset the filter
}
[searchField setStringValue:@""];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment