-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-59: Add basic support for private messages
- Loading branch information
Showing
7 changed files
with
92 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { invoke } from "@tauri-apps/api"; | ||
import { TextMessage, addChatMessage } from "../store/features/users/chatMessageSlice"; | ||
import { UsersState } from "../store/features/users/userSlice"; | ||
import MessageParser from "./MessageParser"; | ||
import { Dispatch } from "react"; | ||
import { AnyAction } from "@reduxjs/toolkit"; | ||
|
||
export class ChatMessageHandler { | ||
|
||
constructor(private dispatch: Dispatch<AnyAction>, private setChatMessage: any) { | ||
|
||
} | ||
|
||
pushChatMessage(message: TextMessage) { | ||
this.dispatch(addChatMessage(message)); | ||
} | ||
|
||
public sendCustomChatMessage(data: string, userInfo: UsersState | undefined) { | ||
invoke('send_message', { chatMessage: data, channelId: userInfo?.channel_id }); | ||
console.log("customChatMessage", data); | ||
this.pushChatMessage({ | ||
actor: userInfo?.id || 0, | ||
sender: { | ||
user_id: userInfo?.id || 0, | ||
user_name: userInfo?.name || 'unknown' | ||
}, | ||
channel_id: [0], | ||
tree_id: [0], | ||
message: data, | ||
timestamp: Date.now() | ||
}) | ||
this.setChatMessage(""); | ||
} | ||
|
||
public sendPrivateMessage(data: string, userInfo: UsersState | undefined, reciever: number) { | ||
invoke('send_message', { chatMessage: data, reciever: reciever }); | ||
this.setChatMessage(""); | ||
} | ||
|
||
public sendChatMessage(chatMessage: string, userInfo: UsersState | undefined) { | ||
let message = new MessageParser(chatMessage) | ||
.parseLinks() | ||
.parseCommands() | ||
.parseMarkdown() | ||
.buildString(); | ||
this.sendCustomChatMessage(message, userInfo); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters