Skip to content

Commit

Permalink
Merge pull request #686 from csmith/master
Browse files Browse the repository at this point in the history
Add formatting action highlights.
  • Loading branch information
greboid committed Mar 12, 2016
2 parents d69ce00 + 1c60f29 commit abf98ac
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
8 changes: 8 additions & 0 deletions res/com/dmdirc/ui/messages/format.yml
Expand Up @@ -121,6 +121,10 @@ ChannelQuitEvent:
ChannelActionEvent:
format: "* {{client.modePrefixedNickname}} {{message}}"
colour: 6
ChannelActionHighlightEvent:
format: "* {{client.modePrefixedNickname}} {{message}}"
colour: 6
background: F9C4BB
ChannelSelfActionEvent:
format: "* {{client.modePrefixedNickname}} {{message}}"
colour: 6
Expand Down Expand Up @@ -195,6 +199,10 @@ channelUserBackEvent:
QueryActionEvent:
format: "* {{user.nickname}} {{message}}"
colour: 6
QueryActionHighlightEvent:
format: "* {{user.nickname}} {{message}}"
colour: 6
background: F9C4BB
QuerySelfActionEvent:
format: "* {{user.nickname}} {{message}}"
colour: 6
Expand Down
45 changes: 45 additions & 0 deletions src/com/dmdirc/events/ChannelActionHighlightEvent.java
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2006-2015 DMDirc Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.dmdirc.events;

import com.dmdirc.interfaces.GroupChat;
import com.dmdirc.interfaces.GroupChatUser;

import java.time.LocalDateTime;

/**
* Event raised when a highlight is detected in an action in a channel.
*/
public class ChannelActionHighlightEvent extends ChannelActionEvent {

public ChannelActionHighlightEvent(final LocalDateTime timestamp, final GroupChat channel,
final GroupChatUser client, final String message) {
super(timestamp, channel, client, message);
}

public ChannelActionHighlightEvent(final GroupChat channel, final GroupChatUser client,
final String message) {
super(channel, client, message);
}

}
44 changes: 44 additions & 0 deletions src/com/dmdirc/events/QueryActionHighlightEvent.java
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2006-2015 DMDirc Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.dmdirc.events;

import com.dmdirc.Query;
import com.dmdirc.interfaces.User;

import java.time.LocalDateTime;

/**
* Event raised when a highlight is detected in an action query.
*/
public class QueryActionHighlightEvent extends QueryActionEvent {

public QueryActionHighlightEvent(final LocalDateTime timestamp, final Query query,
final User user, final String message) {
super(timestamp, query, user, message);
}

public QueryActionHighlightEvent(final Query query, final User user, final String message) {
super(query, user, message);
}

}
28 changes: 28 additions & 0 deletions src/com/dmdirc/ui/messages/HighlightManager.java
Expand Up @@ -22,9 +22,13 @@

package com.dmdirc.ui.messages;

import com.dmdirc.events.ChannelActionEvent;
import com.dmdirc.events.ChannelActionHighlightEvent;
import com.dmdirc.events.ChannelHighlightEvent;
import com.dmdirc.events.ChannelMessageEvent;
import com.dmdirc.events.DisplayProperty;
import com.dmdirc.events.QueryActionEvent;
import com.dmdirc.events.QueryActionHighlightEvent;
import com.dmdirc.events.QueryHighlightEvent;
import com.dmdirc.events.QueryMessageEvent;
import com.dmdirc.events.ServerConnectedEvent;
Expand Down Expand Up @@ -68,6 +72,18 @@ void handleChannelMessage(final ChannelMessageEvent event) {
}
}

@Handler(rejectSubtypes = true)
void handleChannelAction(final ChannelActionEvent event) {
if (event.getChannel().getConnection().get().getWindowModel().equals(serverWindow)
&& patterns.stream().anyMatch(p -> p.matcher(event.getMessage()).matches())) {
event.setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
event.getChannel().getEventBus().publish(
new ChannelActionHighlightEvent(
event.getTimestamp(), event.getChannel(), event.getClient(),
event.getMessage()));
}
}

@Handler(rejectSubtypes = true)
void handleQueryMessage(final QueryMessageEvent event) {
if (event.getUser().getConnection().getWindowModel().equals(serverWindow)
Expand All @@ -80,6 +96,18 @@ void handleQueryMessage(final QueryMessageEvent event) {
}
}

@Handler(rejectSubtypes = true)
void handleQueryMessage(final QueryActionEvent event) {
if (event.getUser().getConnection().getWindowModel().equals(serverWindow)
&& patterns.stream().anyMatch(p -> p.matcher(event.getMessage()).matches())) {
event.setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
event.getQuery().getEventBus().publish(
new QueryActionHighlightEvent(
event.getTimestamp(), event.getQuery(), event.getUser(),
event.getMessage()));
}
}

@Handler
void handleNickChange(final ServerNickChangeEvent event) {
if (event.getConnection().getWindowModel().equals(serverWindow)) {
Expand Down

0 comments on commit abf98ac

Please sign in to comment.