Skip to content
Snippets Groups Projects
Commit 2f97d4ed authored by Nicolas Vengeon's avatar Nicolas Vengeon Committed by Sébastien Blin
Browse files

LocationSharing: handle timers per conversation

Timers are now set per conversation to fit
the new design

Change-Id: I76411c68b12020ef18dc8f915bfb6cbefa8c5d7f
parent f6acfd39
No related branches found
No related tags found
No related merge requests found
...@@ -80,8 +80,8 @@ ItemDelegate { ...@@ -80,8 +80,8 @@ ItemDelegate {
imageId: UID imageId: UID
showPresenceIndicator: Presence !== undefined ? Presence : false showPresenceIndicator: Presence !== undefined ? Presence : false
showSharePositionIndicator: PositionManager.isPositionSharedToConv(accountId, UID) showSharePositionIndicator: PositionManager.isPositionSharedToConv(CurrentAccount.id, UID)
showSharedPositionIndicator: PositionManager.isConvSharingPosition(accountId, UID) showSharedPositionIndicator: PositionManager.isConvSharingPosition(CurrentAccount.id, UID)
Layout.preferredWidth: JamiTheme.smartListAvatarSize Layout.preferredWidth: JamiTheme.smartListAvatarSize
Layout.preferredHeight: JamiTheme.smartListAvatarSize Layout.preferredHeight: JamiTheme.smartListAvatarSize
...@@ -89,10 +89,10 @@ ItemDelegate { ...@@ -89,10 +89,10 @@ ItemDelegate {
Connections { Connections {
target: PositionManager target: PositionManager
function onPositionShareConvIdsCountChanged () { function onPositionShareConvIdsCountChanged () {
avatar.showSharePositionIndicator = PositionManager.isPositionSharedToConv(accountId, UID) avatar.showSharePositionIndicator = PositionManager.isPositionSharedToConv(CurrentAccount.id, UID)
} }
function onSharingUrisCountChanged () { function onSharingUrisCountChanged () {
avatar.showSharedPositionIndicator = PositionManager.isConvSharingPosition(accountId, UID) avatar.showSharedPositionIndicator = PositionManager.isConvSharingPosition(CurrentAccount.id, UID)
} }
} }
......
...@@ -199,6 +199,7 @@ void ...@@ -199,6 +199,7 @@ void
PositionManager::stopSharingPosition(QString accountId, const QString convId) PositionManager::stopSharingPosition(QString accountId, const QString convId)
{ {
QString stopMsg; QString stopMsg;
PositionKey key = qMakePair(accountId, convId);
stopMsg = "{\"type\":\"Stop\"}"; stopMsg = "{\"type\":\"Stop\"}";
if (accountId == "") { if (accountId == "") {
sendPosition(stopMsg, false); sendPosition(stopMsg, false);
...@@ -206,15 +207,17 @@ PositionManager::stopSharingPosition(QString accountId, const QString convId) ...@@ -206,15 +207,17 @@ PositionManager::stopSharingPosition(QString accountId, const QString convId)
positionShareConvIds_.clear(); positionShareConvIds_.clear();
} else { } else {
if (convId == "") { if (convId == "") {
stopPositionTimers(accountId);
for (auto it = positionShareConvIds_.begin(); it != positionShareConvIds_.end();) { for (auto it = positionShareConvIds_.begin(); it != positionShareConvIds_.end();) {
if (it->first == accountId) { if (it->first == accountId) {
key = qMakePair(accountId, it->second);
stopPositionTimers(key);
sendStopMessage(accountId, it->second); sendStopMessage(accountId, it->second);
it = positionShareConvIds_.erase(it); it = positionShareConvIds_.erase(it);
} else } else
++it; ++it;
} }
} else { } else {
stopPositionTimers(key);
sendStopMessage(accountId, convId); sendStopMessage(accountId, convId);
auto iter = std::find(positionShareConvIds_.begin(), auto iter = std::find(positionShareConvIds_.begin(),
positionShareConvIds_.end(), positionShareConvIds_.end(),
...@@ -356,19 +359,22 @@ PositionManager::parseJsonPosition(const QString& accountId, ...@@ -356,19 +359,22 @@ PositionManager::parseJsonPosition(const QString& accountId,
void void
PositionManager::startPositionTimers(int timeSharing) PositionManager::startPositionTimers(int timeSharing)
{ {
mapTimerCountDown_[lrcInstance_->get_currentAccountId()] = timeSharing; PositionKey key;
key.first = lrcInstance_->get_currentAccountId();
key.second = lrcInstance_->get_selectedConvUid();
mapTimerCountDown_[key] = timeSharing;
countdownUpdate(); countdownUpdate();
countdownTimer_->start(1000); countdownTimer_->start(1000);
} }
void void
PositionManager::stopPositionTimers(QString accountId) PositionManager::stopPositionTimers(PositionKey key)
{ {
// reset all timers // reset all timers
if (accountId == nullptr) { if (key == PositionKey()) {
mapTimerCountDown_.clear(); mapTimerCountDown_.clear();
} else { } else {
auto it = mapTimerCountDown_.find(accountId); auto it = mapTimerCountDown_.find(key);
if (it != mapTimerCountDown_.end()) { if (it != mapTimerCountDown_.end()) {
mapTimerCountDown_.erase(it); mapTimerCountDown_.erase(it);
} }
...@@ -457,13 +463,13 @@ PositionManager::countdownUpdate() ...@@ -457,13 +463,13 @@ PositionManager::countdownUpdate()
mapTimerCountDown_.end(), mapTimerCountDown_.end(),
[](const auto& end) { return end == 0; }); [](const auto& end) { return end == 0; });
if (end != mapTimerCountDown_.end()) { if (end != mapTimerCountDown_.end()) {
Q_EMIT sendCountdownUpdate(end.key(), end.value()); Q_EMIT sendCountdownUpdate(end.key().first + "_" + end.key().second, end.value());
stopSharingPosition(end.key()); stopSharingPosition(end.key().first, end.key().second);
} }
// When removals are done, countdown can be updated // When removals are done, countdown can be updated
for (auto it = mapTimerCountDown_.begin(); it != mapTimerCountDown_.end(); it++) { for (auto it = mapTimerCountDown_.begin(); it != mapTimerCountDown_.end(); it++) {
if (it.value() != 0) { if (it.value() != 0) {
Q_EMIT sendCountdownUpdate(it.key(), it.value()); Q_EMIT sendCountdownUpdate(it.key().first + "_" + it.key().second, it.value());
it.value() -= 1000; it.value() -= 1000;
} }
} }
......
...@@ -54,7 +54,7 @@ Q_SIGNALS: ...@@ -54,7 +54,7 @@ Q_SIGNALS:
void unPinMapSignal(const QString& key); void unPinMapSignal(const QString& key);
void localPositionReceived(const QString& accountId, const QString& peerId, const QString& body); void localPositionReceived(const QString& accountId, const QString& peerId, const QString& body);
void makeVisibleSharingButton(const QString& accountId); void makeVisibleSharingButton(const QString& accountId);
void sendCountdownUpdate(const QString& accountId, const int remainingTime); void sendCountdownUpdate(const QString key, const int remainingTime);
protected: protected:
QString getAvatar(const QString& accountId, const QString& peerId); QString getAvatar(const QString& accountId, const QString& peerId);
...@@ -67,7 +67,7 @@ protected: ...@@ -67,7 +67,7 @@ protected:
void removePositionFromMemory(PositionKey key, QVariantMap positionReceived); void removePositionFromMemory(PositionKey key, QVariantMap positionReceived);
void positionWatchDog(); void positionWatchDog();
void startPositionTimers(int timeSharing); void startPositionTimers(int timeSharing);
void stopPositionTimers(QString accountId = {}); void stopPositionTimers(PositionKey key = {});
bool isNewMessageTriggersMap(bool endSharing, const QString& uri, const QString& accountId); bool isNewMessageTriggersMap(bool endSharing, const QString& uri, const QString& accountId);
void countdownUpdate(); void countdownUpdate();
void sendStopMessage(QString accountId = "", const QString convId = ""); void sendStopMessage(QString accountId = "", const QString convId = "");
...@@ -105,7 +105,7 @@ private Q_SLOTS: ...@@ -105,7 +105,7 @@ private Q_SLOTS:
private: private:
SystemTray* systemTray_; SystemTray* systemTray_;
std::unique_ptr<Positioning> localPositioning_; std::unique_ptr<Positioning> localPositioning_;
QMap<QString, int> mapTimerCountDown_; QMap<PositionKey, int> mapTimerCountDown_;
QTimer* countdownTimer_ = nullptr; QTimer* countdownTimer_ = nullptr;
// map of all shared position by peers // map of all shared position by peers
QMap<PositionKey, PositionObject*> objectListSharingUris_; QMap<PositionKey, PositionObject*> objectListSharingUris_;
......
...@@ -39,11 +39,7 @@ ColumnLayout { ...@@ -39,11 +39,7 @@ ColumnLayout {
Layout.preferredWidth: textTimer.width + 15 Layout.preferredWidth: textTimer.width + 15
Layout.preferredHeight: textTimer.height + 15 Layout.preferredHeight: textTimer.height + 15
color: JamiTheme.mapButtonsOverlayColor color: JamiTheme.mapButtonsOverlayColor
visible: textTimer.remainingTimeMs === 0 visible: textTimer.remainingTimeMs !== 0 && !isUnpin && webView.isLoaded && isSharingToCurrentConversation
? false
: isUnpin
? isSharing
: isSharingToCurrentConversation
Text { Text {
id: textTimer id: textTimer
...@@ -76,8 +72,8 @@ ColumnLayout { ...@@ -76,8 +72,8 @@ ColumnLayout {
property int remainingTimeMs: 0 property int remainingTimeMs: 0
Connections { Connections {
target: PositionManager target: PositionManager
function onSendCountdownUpdate(accountId, remainingTime) { function onSendCountdownUpdate(key, remainingTime) {
if (accountId === attachedAccountId) { if (key === attachedAccountId + "_" + currentConvId) {
textTimer.remainingTimeMs = remainingTime textTimer.remainingTimeMs = remainingTime
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment