attach sender ID to messages
This commit is contained in:
+19
-18
@@ -180,9 +180,9 @@ export default class ChatModel {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
readonly getNameAndChannel = (): [string, string] | false => {
|
readonly getSendingData = (): [string, string, string] => {
|
||||||
const senderName: string = this.settingsModel.username;
|
const senderName: string = this.settingsModel.username || "?";
|
||||||
if (senderName == "") return false;
|
const id: string = this.settingsModel.userid;
|
||||||
|
|
||||||
const allChannels: string[] = [this.id];
|
const allChannels: string[] = [this.id];
|
||||||
for (const secondaryChannel of this.info.secondaryChannels) {
|
for (const secondaryChannel of this.info.secondaryChannels) {
|
||||||
@@ -191,7 +191,7 @@ export default class ChatModel {
|
|||||||
|
|
||||||
const combinedChannel: string = allChannels.join("/");
|
const combinedChannel: string = allChannels.join("/");
|
||||||
|
|
||||||
return [senderName, combinedChannel];
|
return [id, senderName, combinedChannel];
|
||||||
};
|
};
|
||||||
|
|
||||||
readonly sendMessage = async (
|
readonly sendMessage = async (
|
||||||
@@ -199,12 +199,11 @@ export default class ChatModel {
|
|||||||
inlineReplyId?: string,
|
inlineReplyId?: string,
|
||||||
fileContent?: FileContent<string>,
|
fileContent?: FileContent<string>,
|
||||||
): Promise<string | false> => {
|
): Promise<string | false> => {
|
||||||
const nameAndChannel = this.getNameAndChannel();
|
const [senderId, senderName, combinedChannel] = this.getSendingData();
|
||||||
if (nameAndChannel == false) return false;
|
|
||||||
const [senderName, combinedChannel] = nameAndChannel;
|
|
||||||
|
|
||||||
const chatMessage: ChatMessage = await ChatModel.createChatMessage(
|
const chatMessage: ChatMessage = await ChatModel.createChatMessage(
|
||||||
combinedChannel,
|
combinedChannel,
|
||||||
|
senderId,
|
||||||
senderName,
|
senderName,
|
||||||
this.info.encryptionKey,
|
this.info.encryptionKey,
|
||||||
body,
|
body,
|
||||||
@@ -237,13 +236,11 @@ export default class ChatModel {
|
|||||||
content: ReactionSymbols,
|
content: ReactionSymbols,
|
||||||
isDeleting: boolean = false,
|
isDeleting: boolean = false,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const nameAndChannel = this.getNameAndChannel();
|
const [senderId, senderName, combinedChannel] = this.getSendingData();
|
||||||
if (nameAndChannel == false) return;
|
|
||||||
const [senderName] = nameAndChannel;
|
|
||||||
|
|
||||||
const reaction = ChatModel.createMessageReaction(
|
const reaction = ChatModel.createMessageReaction(
|
||||||
messageId,
|
messageId,
|
||||||
senderName,
|
senderId,
|
||||||
content,
|
content,
|
||||||
isDeleting,
|
isDeleting,
|
||||||
);
|
);
|
||||||
@@ -399,6 +396,7 @@ export default class ChatModel {
|
|||||||
static createChatMessage = async (
|
static createChatMessage = async (
|
||||||
channel: string,
|
channel: string,
|
||||||
sender: string,
|
sender: string,
|
||||||
|
senderId: string,
|
||||||
encryptionKey: string,
|
encryptionKey: string,
|
||||||
body: string,
|
body: string,
|
||||||
inlineReplyId?: string,
|
inlineReplyId?: string,
|
||||||
@@ -411,6 +409,7 @@ export default class ChatModel {
|
|||||||
|
|
||||||
channel,
|
channel,
|
||||||
sender,
|
sender,
|
||||||
|
senderId,
|
||||||
body,
|
body,
|
||||||
dateSent: createTimestamp(),
|
dateSent: createTimestamp(),
|
||||||
inlineReplyId,
|
inlineReplyId,
|
||||||
@@ -439,7 +438,7 @@ export default class ChatModel {
|
|||||||
|
|
||||||
static createMessageReaction = (
|
static createMessageReaction = (
|
||||||
messageId: string,
|
messageId: string,
|
||||||
sender: string,
|
senderId: string,
|
||||||
content: ReactionSymbols,
|
content: ReactionSymbols,
|
||||||
isDeleting: boolean,
|
isDeleting: boolean,
|
||||||
): ChatMessageReaction => {
|
): ChatMessageReaction => {
|
||||||
@@ -447,10 +446,10 @@ export default class ChatModel {
|
|||||||
FileModel.createFileContent(v4(), "reaction");
|
FileModel.createFileContent(v4(), "reaction");
|
||||||
const reaction: ChatMessageReaction = {
|
const reaction: ChatMessageReaction = {
|
||||||
...fileContent,
|
...fileContent,
|
||||||
fileId: ChatModel.createMessageReactionId(messageId, sender),
|
fileId: ChatModel.createMessageReactionId(messageId, senderId),
|
||||||
|
|
||||||
messageId,
|
messageId,
|
||||||
sender,
|
senderId,
|
||||||
content,
|
content,
|
||||||
isDeleting,
|
isDeleting,
|
||||||
};
|
};
|
||||||
@@ -459,9 +458,9 @@ export default class ChatModel {
|
|||||||
|
|
||||||
static createMessageReactionId = (
|
static createMessageReactionId = (
|
||||||
messageId: string,
|
messageId: string,
|
||||||
sender: string,
|
senderId: string,
|
||||||
): string => {
|
): string => {
|
||||||
return messageId + sender;
|
return messageId + senderId;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,6 +496,7 @@ export interface ChatMessage extends ValidObject {
|
|||||||
|
|
||||||
readonly channel: string;
|
readonly channel: string;
|
||||||
readonly sender: string;
|
readonly sender: string;
|
||||||
|
readonly senderId: string;
|
||||||
body: string;
|
body: string;
|
||||||
readonly dateSent: string;
|
readonly dateSent: string;
|
||||||
readonly inlineReplyId?: string;
|
readonly inlineReplyId?: string;
|
||||||
@@ -509,7 +509,7 @@ export interface ChatMessage extends ValidObject {
|
|||||||
export interface ChatMessageReaction
|
export interface ChatMessageReaction
|
||||||
extends ValidObject, FileContent<"reaction"> {
|
extends ValidObject, FileContent<"reaction"> {
|
||||||
readonly messageId: string;
|
readonly messageId: string;
|
||||||
readonly sender: string;
|
readonly senderId: string;
|
||||||
readonly content: ReactionSymbols | string;
|
readonly content: ReactionSymbols | string;
|
||||||
isDeleting: boolean;
|
isDeleting: boolean;
|
||||||
}
|
}
|
||||||
@@ -540,6 +540,7 @@ export const ChatMessageReference: ChatMessage = {
|
|||||||
|
|
||||||
channel: "",
|
channel: "",
|
||||||
sender: "",
|
sender: "",
|
||||||
|
senderId: "",
|
||||||
body: "",
|
body: "",
|
||||||
dateSent: "",
|
dateSent: "",
|
||||||
|
|
||||||
@@ -557,7 +558,7 @@ export const ChatMessageReactionReference: ChatMessageReaction = {
|
|||||||
type: "reaction",
|
type: "reaction",
|
||||||
|
|
||||||
messageId: "",
|
messageId: "",
|
||||||
sender: "",
|
senderId: "",
|
||||||
content: "",
|
content: "",
|
||||||
|
|
||||||
isDeleting: false,
|
isDeleting: false,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { ChatMessageReaction } from "../../Model/Chat/chatModel";
|
|||||||
export function MessageReactionEntry(reaction: ChatMessageReaction) {
|
export function MessageReactionEntry(reaction: ChatMessageReaction) {
|
||||||
return (
|
return (
|
||||||
<div class="tile flex-row">
|
<div class="tile flex-row">
|
||||||
<span class="flex width-100">{reaction.sender}</span>
|
<span class="flex width-100">{reaction.senderId}</span>
|
||||||
<span>{reaction.content}</span>
|
<span>{reaction.content}</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -160,12 +160,12 @@ export default class ChatMessageViewModel {
|
|||||||
// reactions
|
// reactions
|
||||||
handleReaction = (reaction: ChatMessageReaction): void => {
|
handleReaction = (reaction: ChatMessageReaction): void => {
|
||||||
if (reaction.isDeleting) {
|
if (reaction.isDeleting) {
|
||||||
this.allReactions.remove(reaction.sender);
|
this.allReactions.remove(reaction.senderId);
|
||||||
} else {
|
} else {
|
||||||
this.allReactions.set(reaction.sender, reaction);
|
this.allReactions.set(reaction.senderId, reaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reaction.sender != this.coreViewModel.settingsModel.username)
|
if (reaction.senderId != this.coreViewModel.settingsModel.username)
|
||||||
return;
|
return;
|
||||||
this.userReaction.value = reaction.isDeleting
|
this.userReaction.value = reaction.isDeleting
|
||||||
? undefined
|
? undefined
|
||||||
|
|||||||
Reference in New Issue
Block a user