Skip to content

Commit

Permalink
Merge pull request #201 from Regynate/announcement-bugfix
Browse files Browse the repository at this point in the history
Bugfix & print system messages in italic
  • Loading branch information
gempir authored May 1, 2024
2 parents dd7fc40 + aa93239 commit c1fbfc1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
6 changes: 4 additions & 2 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type channelLogList struct {

type chatMessage struct {
Text string `json:"text"`
SystemText string `json:"systemText"`
Username string `json:"username"`
DisplayName string `json:"displayName"`
Channel string `json:"channel"`
Expand Down Expand Up @@ -457,7 +458,7 @@ func createChatMessage(parsedMessage twitch.Message) chatMessage {
Timestamp: timestamp{message.Time},
Username: message.TargetUsername,
DisplayName: message.TargetUsername,
Text: buildClearChatMessageText(*message),
SystemText: buildClearChatMessageText(*message),
Type: message.Type,
Channel: message.Channel,
Raw: message.Raw,
Expand All @@ -468,7 +469,8 @@ func createChatMessage(parsedMessage twitch.Message) chatMessage {
Timestamp: timestamp{message.Time},
Username: message.User.Name,
DisplayName: message.User.DisplayName,
Text: message.SystemMsg + " " + message.Message,
Text: message.Message,
SystemText: message.SystemMsg,
Type: message.Type,
Channel: message.Channel,
Raw: message.Raw,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
require (
github.com/gempir/go-twitch-irc/v3 v3.0.0
github.com/nicklaw5/helix v1.25.0
github.com/nursik/go-expire-map v1.1.0 // indirect
github.com/nursik/go-expire-map v1.2.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0 // indirect
)
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfE
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/nicklaw5/helix v1.25.0 h1:Mrz537izZVsGdM3I46uGAAlslj61frgkhS/9xQqyT/M=
github.com/nicklaw5/helix v1.25.0/go.mod h1:yvXZFapT6afIoxnAvlWiJiUMsYnoHl7tNs+t0bloAMw=
github.com/nursik/go-expire-map v1.1.0 h1:C+OJ81JtHDSPJXfuu0g3e8RRjHLd5of8dVzyfDOB9KY=
github.com/nursik/go-expire-map v1.1.0/go.mod h1:wdQsai5n32Uw1IuVXXZoopePGCFh5vb0Dka/TRcboHs=
github.com/nursik/go-ordered-set v0.0.0-20190626022851-0e8872c36517 h1:jau4pavdQo5lHeVTjZEGrm4+zvVGZj8SFQt4awsLLXE=
github.com/nursik/go-ordered-set v0.0.0-20190626022851-0e8872c36517/go.mod h1:qFI7Mmmx8i+Qz8a52FarvpgPQzylvD3w77JAwvnFtKg=
github.com/nursik/go-expire-map v1.2.0 h1:3yl3sVLSnfw4vbo6OVZWP1tFND4CBm4hrYCrrAT5jkU=
github.com/nursik/go-expire-map v1.2.0/go.mod h1:Mrqzxpk2G81At+TAlfImiNrKECj0gfVw7URv3p/eLzU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/ContentLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function ContentLog({ year, month }: { year: string, month: string }) {
const [searchText, setSearchText] = useState("");

const logs = useLog(state.currentChannel ?? "", state.currentUsername ?? "", year, month)
.filter(log => log.text.toLowerCase().includes(searchText.toLowerCase()));
.filter(log => (log.text + log.systemText).toLowerCase().includes(searchText.toLowerCase()));

const Row = ({ index, style }: { index: number, style: CSSProperties }) => (
<div style={style}><LogLine key={logs[index].id ? logs[index].id : index} message={logs[index]} /></div>
Expand Down
16 changes: 10 additions & 6 deletions web/src/components/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ThirdPartyEmote } from "../types/ThirdPartyEmote";
import runes from "runes";

const MessageContainer = styled.div`
a {
margin: 0 2px;
color: var(--theme2);
Expand All @@ -19,6 +18,10 @@ const MessageContainer = styled.div`
}
`;

const SystemMessageWrapper = styled.span`
font-style: italic;
`;

const Emote = styled.img`
max-height: 18px;
margin: 0 2px;
Expand All @@ -35,10 +38,8 @@ export function Message({ message, thirdPartyEmotes }: { message: LogMessage, th

let messageText = message.text;
let renderMessagePrefix = "";
if (message.tags['system-msg']) {
messageText = messageText.replace(message.tags['system-msg'] + " ", "");

renderMessagePrefix = `${message.tags['system-msg']} `;
if (message.systemText) {
renderMessagePrefix = `${message.systemText}`;
}

const messageTextEmoji = runes(messageText);
Expand Down Expand Up @@ -105,7 +106,10 @@ export function Message({ message, thirdPartyEmotes }: { message: LogMessage, th
}
}

const prefixElement = renderMessagePrefix ?
<SystemMessageWrapper>{renderMessagePrefix}</SystemMessageWrapper> : null;

return <MessageContainer className="message">
{renderMessagePrefix}{renderMessage}
{prefixElement}{renderMessagePrefix && renderMessage ? ' ' : ''}{renderMessage}
</MessageContainer>;
};
1 change: 1 addition & 0 deletions web/src/types/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface LogMessage extends Omit<RawLogMessage, "timestamp"> {

export interface RawLogMessage {
text: string,
systemText: string,
username: string,
displayName: string,
channel: string,
Expand Down

0 comments on commit c1fbfc1

Please sign in to comment.