Skip to content

Commit

Permalink
fix(@desktop/notifications): nothing happens after clicking on any no…
Browse files Browse the repository at this point in the history
…tification

Fixes: #5935
  • Loading branch information
saledjenic committed Jun 21, 2022
1 parent a634df9 commit 46a2a61
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/app/core/notifications/details.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include ../../../app_service/common/json_utils

type
NotificationType* {.pure.} = enum
UnknownNotification,
TestNotification,
NewContactRequest,
AcceptedContactRequest,
Expand All @@ -18,7 +19,7 @@ type
IdentityVerificationRequest

NotificationDetails* = object
notificationType*: NotificationType
notificationType*: NotificationType # the default value is `UnknownNotification`
sectionId*: string
isCommunitySection*: bool
sectionActive*: bool
Expand All @@ -28,6 +29,9 @@ type
isGroupChat*: bool
messageId*: string

proc isEmpty*(self: NotificationDetails): bool =
return self.notificationType == NotificationType.UnknownNotification

proc toNotificationDetails*(jsonObj: JsonNode): NotificationDetails =
var notificationType: int
if (not (jsonObj.getProp("notificationType", notificationType) and
Expand Down
3 changes: 3 additions & 0 deletions src/app/core/notifications/notifications_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ QtObject:
app_makeItActive(singletonInstance.engine)

let details = toNotificationDetails(parseJson(identifier))
if(details.isEmpty()):
info "Notification details are empty"
return
if(details.notificationType == NotificationType.TestNotification):
info "Test notification was clicked"
return
Expand Down
10 changes: 9 additions & 1 deletion src/app/modules/main/ephemeral_notification_item.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ../../core/notifications/details

type
EphemeralNotificationType* {.pure.} = enum
Default = 0
Expand All @@ -13,6 +15,7 @@ type
loading: bool
ephNotifType: EphemeralNotificationType
url: string
details: NotificationDetails

proc initItem*(id: int64,
title: string,
Expand All @@ -21,7 +24,8 @@ proc initItem*(id: int64,
icon = "",
loading = false,
ephNotifType = EphemeralNotificationType.Default,
url = ""): Item =
url = "",
details: NotificationDetails): Item =
result = Item()
result.id = id
result.durationInMs = durationInMs
Expand All @@ -31,6 +35,7 @@ proc initItem*(id: int64,
result.loading = loading
result.ephNotifType = ephNotifType
result.url = url
result.details = details

proc id*(self: Item): int64 =
self.id
Expand All @@ -55,3 +60,6 @@ proc ephNotifType*(self: Item): EphemeralNotificationType =

proc url*(self: Item): string =
self.url

proc details*(self: Item): NotificationDetails =
self.details
6 changes: 6 additions & 0 deletions src/app/modules/main/ephemeral_notification_model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ QtObject:
if(self.items[i].id == id):
return i
return -1

proc getItemWithId*(self: Model, id: int64): Item =
let ind = self.findIndexById(id)
if(ind == -1):
return
return self.items[ind]

proc addItem*(self: Model, item: Item) =
let parentModelIndex = newQModelIndex()
Expand Down
5 changes: 4 additions & 1 deletion src/app/modules/main/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,15 @@ method displayEphemeralNotification*(self: AccessInterface, title: string, subTi
raise newException(ValueError, "No implementation available")

method displayEphemeralNotification*(self: AccessInterface, title: string, subTitle: string, icon: string, loading: bool,
ephNotifType: int, url: string) {.base.} =
ephNotifType: int, url: string, details = NotificationDetails()) {.base.} =
raise newException(ValueError, "No implementation available")

method removeEphemeralNotification*(self: AccessInterface, id: int64) {.base.} =
raise newException(ValueError, "No implementation available")

method ephemeralNotificationClicked*(self: AccessInterface, id: int64) {.base.} =
raise newException(ValueError, "No implementation available")

method newCommunityMembershipRequestReceived*(self: AccessInterface, membershipRequest: CommunityMembershipRequestDto)
{.base.} =
raise newException(ValueError, "No implementation available")
Expand Down
21 changes: 16 additions & 5 deletions src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -773,32 +773,43 @@ method meMentionedCountChanged*[T](self: Module[T], allMentions: int) =
singletonInstance.globalEvents.meMentionedIconBadgeNotification(allMentions)

method displayEphemeralNotification*[T](self: Module[T], title: string, subTitle: string, icon: string, loading: bool,
ephNotifType: int, url: string) =
ephNotifType: int, url: string, details = NotificationDetails()) =
let now = getTime()
let id = now.toUnix * 1000000000 + now.nanosecond
var finalEphNotifType = EphemeralNotificationType.Default
if(ephNotifType == EphemeralNotificationType.Success.int):
finalEphNotifType = EphemeralNotificationType.Success
let item = ephemeral_notification_item.initItem(id, title, TOAST_MESSAGE_VISIBILITY_DURATION_IN_MS, subTitle, icon,
loading, finalEphNotifType, url)
loading, finalEphNotifType, url, details)
self.view.ephemeralNotificationModel().addItem(item)

method displayEphemeralNotification*[T](self: Module[T], title: string, subTitle: string, details: NotificationDetails) =
if(details.notificationType == NotificationType.NewMessage or
details.notificationType == NotificationType.NewMessageWithPersonalMention or
details.notificationType == NotificationType.NewMessageWithGlobalMention):
self.displayEphemeralNotification(title, subTitle, "", false, EphemeralNotificationType.Default.int, "")
self.displayEphemeralNotification(title, subTitle, "", false, EphemeralNotificationType.Default.int, "", details)

elif(details.notificationType == NotificationType.NewContactRequest or
details.notificationType == NotificationType.IdentityVerificationRequest):
self.displayEphemeralNotification(title, subTitle, "contact", false, EphemeralNotificationType.Default.int, "")
self.displayEphemeralNotification(title, subTitle, "contact", false, EphemeralNotificationType.Default.int, "", details)

elif(details.notificationType == NotificationType.AcceptedContactRequest):
self.displayEphemeralNotification(title, subTitle, "checkmark-circle", false, EphemeralNotificationType.Success.int, "")
self.displayEphemeralNotification(title, subTitle, "checkmark-circle", false, EphemeralNotificationType.Success.int, "", details)

method removeEphemeralNotification*[T](self: Module[T], id: int64) =
self.view.ephemeralNotificationModel().removeItemWithId(id)

method ephemeralNotificationClicked*[T](self: Module[T], id: int64) =
let item = self.view.ephemeralNotificationModel().getItemWithId(id)
if(item.details.isEmpty()):
return
if(item.details.notificationType == NotificationType.NewMessage or
item.details.notificationType == NotificationType.NewMessageWithPersonalMention or
item.details.notificationType == NotificationType.NewMessageWithGlobalMention):
self.controller.switchTo(item.details.sectionId, item.details.chatId, item.details.messageId)
else:
self.osNotificationClicked(item.details)

method onStatusUrlRequested*[T](self: Module[T], action: StatusUrlAction, communityId: string, chatId: string,
url: string, userId: string, groupName: string, listOfUserIds: seq[string]) =

Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/main/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ QtObject:
proc removeEphemeralNotification*(self: View, id: string) {.slot.} =
self.delegate.removeEphemeralNotification(id.parseInt)

proc ephemeralNotificationClicked*(self: View, id: string) {.slot.} =
self.delegate.ephemeralNotificationClicked(id.parseInt)

proc openStoreToKeychainPopup*(self: View) {.signal.}

proc offerToStorePassword*(self: View) =
Expand Down
4 changes: 4 additions & 0 deletions ui/app/mainui/AppMain.qml
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,10 @@ Item {
type: model.ephNotifType
linkUrl: model.url
duration: model.durationInMs
onClicked: {
appMain.rootStore.mainModuleInst.ephemeralNotificationClicked(model.id)
this.open = false
}
onLinkActivated: {
Qt.openUrlExternally(link);
}
Expand Down

0 comments on commit 46a2a61

Please sign in to comment.