mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-15 11:40:29 +03:00
(chore) remove outdated code (#1765)
* optimize room typing members hook * remove unused code - WIP * remove old code from initMatrix * remove twemojify function * remove old sanitize util * delete old markdown util * delete Math atom component * uninstall unused dependencies * remove old notification system * decrypt message in inbox notification center and fix refresh in background * improve notification --------- Co-authored-by: Krishan <33421343+kfiven@users.noreply.github.com>
This commit is contained in:
parent
60e022035f
commit
4f09e6bbb5
147 changed files with 1164 additions and 15330 deletions
|
|
@ -1,41 +0,0 @@
|
|||
import appDispatcher from '../dispatcher';
|
||||
import cons from '../state/cons';
|
||||
|
||||
/**
|
||||
* @param {string | string[]} roomId - room id or array of them to add into shortcuts
|
||||
*/
|
||||
export function createSpaceShortcut(roomId) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.accountData.CREATE_SPACE_SHORTCUT,
|
||||
roomId,
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteSpaceShortcut(roomId) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.accountData.DELETE_SPACE_SHORTCUT,
|
||||
roomId,
|
||||
});
|
||||
}
|
||||
|
||||
export function moveSpaceShortcut(roomId, toIndex) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.accountData.MOVE_SPACE_SHORTCUTS,
|
||||
roomId,
|
||||
toIndex,
|
||||
});
|
||||
}
|
||||
|
||||
export function categorizeSpace(roomId) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.accountData.CATEGORIZE_SPACE,
|
||||
roomId,
|
||||
});
|
||||
}
|
||||
|
||||
export function unCategorizeSpace(roomId) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.accountData.UNCATEGORIZE_SPACE,
|
||||
roomId,
|
||||
});
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
import * as sdk from 'matrix-js-sdk';
|
||||
import cons from '../state/cons';
|
||||
|
||||
function updateLocalStore(accessToken, deviceId, userId, baseUrl) {
|
||||
localStorage.setItem(cons.secretKey.ACCESS_TOKEN, accessToken);
|
||||
localStorage.setItem(cons.secretKey.DEVICE_ID, deviceId);
|
||||
localStorage.setItem(cons.secretKey.USER_ID, userId);
|
||||
localStorage.setItem(cons.secretKey.BASE_URL, baseUrl);
|
||||
}
|
||||
|
||||
function createTemporaryClient(baseUrl) {
|
||||
return sdk.createClient({ baseUrl });
|
||||
}
|
||||
|
||||
async function startSsoLogin(baseUrl, type, idpId) {
|
||||
const client = createTemporaryClient(baseUrl);
|
||||
localStorage.setItem(cons.secretKey.BASE_URL, client.baseUrl);
|
||||
window.location.href = client.getSsoLoginUrl(window.location.href, type, idpId);
|
||||
}
|
||||
|
||||
async function login(baseUrl, username, email, password) {
|
||||
const identifier = {};
|
||||
if (username) {
|
||||
identifier.type = 'm.id.user';
|
||||
identifier.user = username;
|
||||
} else if (email) {
|
||||
identifier.type = 'm.id.thirdparty';
|
||||
identifier.medium = 'email';
|
||||
identifier.address = email;
|
||||
} else throw new Error('Bad Input');
|
||||
|
||||
const client = createTemporaryClient(baseUrl);
|
||||
const res = await client.login('m.login.password', {
|
||||
identifier,
|
||||
password,
|
||||
initial_device_display_name: cons.DEVICE_DISPLAY_NAME,
|
||||
});
|
||||
|
||||
const myBaseUrl = res?.well_known?.['m.homeserver']?.base_url || client.baseUrl;
|
||||
updateLocalStore(res.access_token, res.device_id, res.user_id, myBaseUrl);
|
||||
}
|
||||
|
||||
async function loginWithToken(baseUrl, token) {
|
||||
const client = createTemporaryClient(baseUrl);
|
||||
|
||||
const res = await client.login('m.login.token', {
|
||||
token,
|
||||
initial_device_display_name: cons.DEVICE_DISPLAY_NAME,
|
||||
});
|
||||
|
||||
const myBaseUrl = res?.well_known?.['m.homeserver']?.base_url || client.baseUrl;
|
||||
updateLocalStore(res.access_token, res.device_id, res.user_id, myBaseUrl);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
async function verifyEmail(baseUrl, email, client_secret, send_attempt, next_link) {
|
||||
const res = await fetch(`${baseUrl}/_matrix/client/r0/register/email/requestToken`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
email, client_secret, send_attempt, next_link,
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
},
|
||||
credentials: 'same-origin',
|
||||
});
|
||||
const data = await res.json();
|
||||
return data;
|
||||
}
|
||||
|
||||
async function completeRegisterStage(
|
||||
baseUrl, username, password, auth,
|
||||
) {
|
||||
const tempClient = createTemporaryClient(baseUrl);
|
||||
|
||||
try {
|
||||
const result = await tempClient.registerRequest({
|
||||
username,
|
||||
password,
|
||||
auth,
|
||||
initial_device_display_name: cons.DEVICE_DISPLAY_NAME,
|
||||
});
|
||||
const data = { completed: result.completed || [] };
|
||||
if (result.access_token) {
|
||||
data.done = true;
|
||||
updateLocalStore(result.access_token, result.device_id, result.user_id, baseUrl);
|
||||
}
|
||||
return data;
|
||||
} catch (e) {
|
||||
const result = e.data;
|
||||
const data = { completed: result.completed || [] };
|
||||
if (result.access_token) {
|
||||
data.done = true;
|
||||
updateLocalStore(result.access_token, result.device_id, result.user_id, baseUrl);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
updateLocalStore, createTemporaryClient, login, verifyEmail,
|
||||
loginWithToken, startSsoLogin,
|
||||
completeRegisterStage,
|
||||
};
|
||||
13
src/client/action/auth.ts
Normal file
13
src/client/action/auth.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import cons from '../state/cons';
|
||||
|
||||
export function updateLocalStore(
|
||||
accessToken: string,
|
||||
deviceId: string,
|
||||
userId: string,
|
||||
baseUrl: string
|
||||
) {
|
||||
localStorage.setItem(cons.secretKey.ACCESS_TOKEN, accessToken);
|
||||
localStorage.setItem(cons.secretKey.DEVICE_ID, deviceId);
|
||||
localStorage.setItem(cons.secretKey.USER_ID, userId);
|
||||
localStorage.setItem(cons.secretKey.BASE_URL, baseUrl);
|
||||
}
|
||||
|
|
@ -1,35 +1,6 @@
|
|||
import appDispatcher from '../dispatcher';
|
||||
import cons from '../state/cons';
|
||||
|
||||
export function selectTab(tabId) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.SELECT_TAB,
|
||||
tabId,
|
||||
});
|
||||
}
|
||||
|
||||
export function selectSpace(roomId) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.SELECT_SPACE,
|
||||
roomId,
|
||||
});
|
||||
}
|
||||
|
||||
export function selectRoom(roomId, eventId) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.SELECT_ROOM,
|
||||
roomId,
|
||||
eventId,
|
||||
});
|
||||
}
|
||||
|
||||
// Open navigation on compact screen sizes
|
||||
export function openNavigation() {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.OPEN_NAVIGATION,
|
||||
});
|
||||
}
|
||||
|
||||
export function openSpaceSettings(roomId, tabText) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.OPEN_SPACE_SETTINGS,
|
||||
|
|
@ -38,13 +9,6 @@ export function openSpaceSettings(roomId, tabText) {
|
|||
});
|
||||
}
|
||||
|
||||
export function openSpaceManage(roomId) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.OPEN_SPACE_MANAGE,
|
||||
roomId,
|
||||
});
|
||||
}
|
||||
|
||||
export function openSpaceAddExisting(roomId, spaces = false) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.OPEN_SPACE_ADDEXISTING,
|
||||
|
|
@ -61,24 +25,6 @@ export function toggleRoomSettings(roomId, tabText) {
|
|||
});
|
||||
}
|
||||
|
||||
export function openShortcutSpaces() {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.OPEN_SHORTCUT_SPACES,
|
||||
});
|
||||
}
|
||||
|
||||
export function openInviteList() {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.OPEN_INVITE_LIST,
|
||||
});
|
||||
}
|
||||
|
||||
export function openPublicRooms(searchTerm) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.OPEN_PUBLIC_ROOMS,
|
||||
searchTerm,
|
||||
});
|
||||
}
|
||||
|
||||
export function openCreateRoom(isSpace = false, parentId = null) {
|
||||
appDispatcher.dispatch({
|
||||
|
|
@ -118,39 +64,6 @@ export function openSettings(tabText) {
|
|||
});
|
||||
}
|
||||
|
||||
export function openEmojiBoard(cords, requestEmojiCallback) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.OPEN_EMOJIBOARD,
|
||||
cords,
|
||||
requestEmojiCallback,
|
||||
});
|
||||
}
|
||||
|
||||
export function openReadReceipts(roomId, userIds) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.OPEN_READRECEIPTS,
|
||||
roomId,
|
||||
userIds,
|
||||
});
|
||||
}
|
||||
|
||||
export function openViewSource(event) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.OPEN_VIEWSOURCE,
|
||||
event,
|
||||
});
|
||||
}
|
||||
|
||||
export function replyTo(userId, eventId, body, formattedBody) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.CLICK_REPLY_TO,
|
||||
userId,
|
||||
eventId,
|
||||
body,
|
||||
formattedBody,
|
||||
});
|
||||
}
|
||||
|
||||
export function openSearch(term) {
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.navigation.OPEN_SEARCH,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ export async function markAsRead(roomId) {
|
|||
const mx = initMatrix.matrixClient;
|
||||
const room = mx.getRoom(roomId);
|
||||
if (!room) return;
|
||||
initMatrix.notifications.deleteNoti(roomId);
|
||||
|
||||
const timeline = room.getLiveTimeline().getEvents();
|
||||
const readEventId = room.getEventReadUpTo(mx.getUserId());
|
||||
|
|
|
|||
|
|
@ -107,37 +107,12 @@ async function join(roomIdOrAlias, isDM = false, via = undefined) {
|
|||
const targetUserId = guessDMRoomTargetId(mx.getRoom(resultRoom.roomId), mx.getUserId());
|
||||
await addRoomToMDirect(resultRoom.roomId, targetUserId);
|
||||
}
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.room.JOIN,
|
||||
roomId: resultRoom.roomId,
|
||||
isDM,
|
||||
});
|
||||
return resultRoom.roomId;
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} roomId
|
||||
* @param {boolean} isDM
|
||||
*/
|
||||
async function leave(roomId) {
|
||||
const mx = initMatrix.matrixClient;
|
||||
const isDM = initMatrix.roomList.directs.has(roomId);
|
||||
try {
|
||||
await mx.leave(roomId);
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.room.LEAVE,
|
||||
roomId,
|
||||
isDM,
|
||||
});
|
||||
} catch {
|
||||
console.error('Unable to leave room.');
|
||||
}
|
||||
}
|
||||
|
||||
async function create(options, isDM = false) {
|
||||
const mx = initMatrix.matrixClient;
|
||||
try {
|
||||
|
|
@ -145,11 +120,6 @@ async function create(options, isDM = false) {
|
|||
if (isDM && typeof options.invite?.[0] === 'string') {
|
||||
await addRoomToMDirect(result.room_id, options.invite[0]);
|
||||
}
|
||||
appDispatcher.dispatch({
|
||||
type: cons.actions.room.CREATE,
|
||||
roomId: result.room_id,
|
||||
isDM,
|
||||
});
|
||||
return result;
|
||||
} catch (e) {
|
||||
const errcodes = ['M_UNKNOWN', 'M_BAD_JSON', 'M_ROOM_IN_USE', 'M_INVALID_ROOM_STATE', 'M_UNSUPPORTED_ROOM_VERSION'];
|
||||
|
|
@ -348,7 +318,7 @@ async function setMyRoomAvatar(roomId, mxc) {
|
|||
export {
|
||||
convertToDm,
|
||||
convertToRoom,
|
||||
join, leave,
|
||||
join,
|
||||
createDM, createRoom,
|
||||
invite, kick, ban, unban,
|
||||
ignore, unignore,
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
import initMatrix from '../initMatrix';
|
||||
|
||||
async function redactEvent(roomId, eventId, reason) {
|
||||
const mx = initMatrix.matrixClient;
|
||||
|
||||
try {
|
||||
await mx.redactEvent(roomId, eventId, undefined, typeof reason === 'undefined' ? undefined : { reason });
|
||||
return true;
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function sendReaction(roomId, toEventId, reaction, shortcode) {
|
||||
const mx = initMatrix.matrixClient;
|
||||
const content = {
|
||||
'm.relates_to': {
|
||||
event_id: toEventId,
|
||||
key: reaction,
|
||||
rel_type: 'm.annotation',
|
||||
},
|
||||
};
|
||||
if (typeof shortcode === 'string') content.shortcode = shortcode;
|
||||
try {
|
||||
await mx.sendEvent(roomId, 'm.reaction', content);
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
redactEvent,
|
||||
sendReaction,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue