-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36701bc
commit cea89e1
Showing
8 changed files
with
217 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { MessageActionType, MessageType, TextMessageContent } from "./types" | ||
import { Message } from "./entities/message" | ||
|
||
export function defaultGetMessagePublishBody(messageBody: TextMessageContent) { | ||
return { | ||
type: messageBody.type, | ||
text: messageBody.text, | ||
files: messageBody.files, | ||
} | ||
} | ||
|
||
export function defaultGetMessageResponseBody<MessageBody extends object = TextMessageContent>( | ||
messageBody: MessageBody | ||
) { | ||
if ("type" in messageBody && "text" in messageBody && "files" in messageBody) { | ||
return { | ||
type: MessageType.TEXT, | ||
text: typeof messageBody.text === "string" ? messageBody.text : "UNKNOWN", | ||
files: Array.isArray(messageBody.files) ? messageBody.files : [], | ||
} | ||
} | ||
return { | ||
type: MessageType.TEXT, | ||
text: "UNKNOWN", | ||
files: [], | ||
} | ||
} | ||
|
||
export function defaultGetMessageDisplayContent(message: Message, editActionName: string) { | ||
const edits = message.actions?.[editActionName] | ||
if (!edits) return message.content.text || "" | ||
const flatEdits = Object.entries(edits).map(([k, v]) => ({ value: k, ...v[0] })) | ||
const lastEdit = flatEdits.reduce((a, b) => (a.actionTimetoken > b.actionTimetoken ? a : b)) | ||
|
||
return lastEdit.value | ||
} | ||
|
||
export const defaultEditActionName = MessageActionType.EDITED | ||
export const defaultDeleteActionName = MessageActionType.DELETED |
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
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
Oops, something went wrong.