mirror of
https://github.com/litruv/lit.ruv.wtf.git
synced 2026-07-26 03:36:03 +10:00
feat: add MxjsClient for lightweight Matrix client functionality
- Implemented core methods for user authentication (register, login, logout). - Added room management features (createRoom, joinRoom, leaveRoom, inviteUser). - Included message handling capabilities (sendMessage, editMessage, redactEvent). - Introduced user moderation actions (kickUser, banUser, unbanUser). - Implemented profile management (getProfile, setDisplayName, setAvatarUrl). - Added support for media uploads and fetching messages from room timelines. - Included event handling with emit and on methods for custom event listeners. - Sanitization of HTML content and mention handling in messages.
This commit is contained in:
@@ -18,6 +18,7 @@ import samsayCmd from './scripts/commands/samsay.js';
|
||||
// Import Matrix client
|
||||
import {
|
||||
initMatrixClient,
|
||||
updateClientSession,
|
||||
chatMode,
|
||||
matrixApi,
|
||||
fetchPublicLastMessage,
|
||||
@@ -581,6 +582,14 @@ const commands = {
|
||||
};
|
||||
}
|
||||
|
||||
// Sync session to mxClient if exists
|
||||
if (window.matrixSession.accessToken && window.matrixSession.userId) {
|
||||
updateClientSession({
|
||||
accessToken: window.matrixSession.accessToken,
|
||||
userId: window.matrixSession.userId
|
||||
});
|
||||
}
|
||||
|
||||
// Register/login user if not logged in
|
||||
if (!window.matrixSession.accessToken) {
|
||||
try {
|
||||
@@ -627,6 +636,8 @@ const commands = {
|
||||
localStorage.setItem('matrix_username', username);
|
||||
localStorage.setItem('matrix_password', password);
|
||||
|
||||
updateClientSession({ accessToken: regData.access_token, userId: regData.user_id });
|
||||
|
||||
term.writeln(` Registered as: ${regData.user_id}\r\n`);
|
||||
} else if (regData.errcode === 'M_USER_IN_USE') {
|
||||
// Username exists, try to login
|
||||
@@ -653,6 +664,8 @@ const commands = {
|
||||
localStorage.setItem('matrix_username', username);
|
||||
localStorage.setItem('matrix_password', password);
|
||||
|
||||
updateClientSession({ accessToken: loginData.access_token, userId: loginData.user_id });
|
||||
|
||||
term.writeln(` Logged in as: ${loginData.user_id}\r\n`);
|
||||
} else {
|
||||
return ` Error: Failed to login - ${loginData.error || loginData.errcode || 'Unknown error'}`;
|
||||
|
||||
Reference in New Issue
Block a user