Skip to content

Commit

Permalink
notify on private messages
Browse files Browse the repository at this point in the history
  • Loading branch information
zlatinb committed Aug 29, 2022
1 parent 6a46126 commit f05d2c7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gui/griffon-app/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ NEW_MESSAGE=New MuWire Message
NEW_MESSAGE_FROM=New message from {0}
NEW_CHAT_MENTION=Mentioned in chat
NEW_CHAT_MENTION_DETAILS=You were mentioned in room {0} on server {1}
NEW_PRIVATE_CHAT=New private chat
NEW_PRIVATE_CHAT_DETAILS=New private chat from {0} on server {1}

# Startup general
MUWIRE_WILL_EXIT=MuWire will now exit.
Expand Down Expand Up @@ -412,7 +414,7 @@ OPTIONS_START_CHAT_SERVER_STARTUP=Start chat server on startup
OPTIONS_MAX_CHAT_CONNECTIONS=Maximum chat connections (-1 means unlimited)
OPTIONS_ADVERTISE_CHAT=Advertise chat ability in search results
OPTIONS_MAX_CHAT_SCROLLBACK=Maximum lines of scrollback (-1 means unlimited)
OPTIONS_CHAT_NOTIFY_MENTIONS=Notify when mentioned
OPTIONS_CHAT_NOTIFY_MENTIONS=Notify on mentions or private messages
OPTIONS_CHAT_WELCOME_FILE=Welcome message file
OPTIONS_CHAT_JOIN_DEFAULT_ROOM=Automatically join default room on servers
OPTIONS_CHAT_DEFAULT_ROOM=Default chat room (empty for none)
Expand Down
13 changes: 13 additions & 0 deletions gui/griffon-app/models/com/muwire/gui/ChatServerModel.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.muwire.gui
import com.muwire.core.chat.ChatDisconnectionEvent
import griffon.core.GriffonApplication

import javax.inject.Inject
import java.util.logging.Level

import javax.annotation.Nonnull
Expand Down Expand Up @@ -30,9 +31,13 @@ class ChatServerModel {
ChatServerView view
@MVCMember @Nonnull
ChatServerController controller
@Inject
GriffonApplication application

Persona host
Core core
UISettings settings
NotifyService notifyService

@Observable boolean disconnectActionEnabled
@Observable String buttonText = "DISCONNECT"
Expand All @@ -44,6 +49,10 @@ class ChatServerModel {
volatile boolean running

void mvcGroupInit(Map<String, String> params) {

settings = application.context.get("ui-settings")
notifyService = application.context.get("notify-service")

disconnectActionEnabled = host != core.me // can't disconnect from myself
core.eventBus.register(ChatConnectionEvent.class, this)
core.eventBus.register(ChatDisconnectionEvent.class, this)
Expand Down Expand Up @@ -154,6 +163,10 @@ class ChatServerModel {
room == core.me.toBase64()) {
String groupId = host.getHumanReadableName()+"-"+e.sender.getHumanReadableName() + "-private-chat"
if (!mvcGroup.childrenGroups.containsKey(groupId)) {

if (settings.chatNotifyMentions)
notifyService.notifyPrivateChat(e.sender.getHumanReadableName(), host.getHumanReadableName())

def params = [:]
params['core'] = core
params['tabName'] = host.getHumanReadableName() + "-chat-rooms"
Expand Down
10 changes: 10 additions & 0 deletions gui/src/main/groovy/com/muwire/gui/NotifyService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ class NotifyService {
this.trayIcon = trayIcon
}

void notifyPrivateChat(String from, String server) {
String caption = trans("NEW_PRIVATE_CHAT")
String body = trans("NEW_PRIVATE_CHAT_DETAILS", from, server)
if (!SystemVersion.isWindows() && !SystemVersion.isMac()) {
DBUSNotifyService.notify(caption, body, DBUSNotifyService.SOUND_CHAT)
} else {
trayIcon.displayMessage(caption, body, TrayIcon.MessageType.INFO)
}
}

void notifyChatMention(String room, String server) {
String caption = trans("NEW_CHAT_MENTION")
String body = trans("NEW_CHAT_MENTION_DETAILS", room , server)
Expand Down

0 comments on commit f05d2c7

Please sign in to comment.