mirror of
https://github.com/irislib/iris-messenger.git
synced 2024-09-19 17:46:33 +00:00
copy link
This commit is contained in:
parent
93d4033f9c
commit
06d6822a0f
@ -50,10 +50,6 @@ Session.init({ autologin: false, autofollow: false });
|
||||
|
||||
class Main extends Component<Props, ReactState> {
|
||||
componentDidMount() {
|
||||
// if location contains a hash #, redirect to the same url without the hash. For example #/profile -> /profile
|
||||
if (window.location.hash.length) {
|
||||
window.location.href = window.location.origin + window.location.hash.replace('#', '');
|
||||
}
|
||||
window.onload = () => {
|
||||
// this makes sure that window.nostr is there
|
||||
localState.get('loggedIn').on(this.inject());
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { PaperAirplaneIcon } from '@heroicons/react/24/solid';
|
||||
|
||||
import Key from '../../nostr/Key';
|
||||
import { translate as t } from '../../translations/Translation.mjs';
|
||||
import View from '../View';
|
||||
|
||||
import ChatList from './ChatList';
|
||||
import ChatMessages from './ChatMessages';
|
||||
import NewChat from './NewChat';
|
||||
import NewChat, { addChatWithInputKey } from './NewChat';
|
||||
|
||||
class Chat extends View {
|
||||
id: string;
|
||||
@ -16,6 +17,18 @@ class Chat extends View {
|
||||
this.hideSideBar = true;
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
super.componentDidMount();
|
||||
const id = window.location.hash.substr(1);
|
||||
if (id && id.startsWith('nsec')) {
|
||||
window.history.replaceState({}, document.title, window.location.pathname);
|
||||
if (!Key.getPubKey()) {
|
||||
Key.loginAsNewUser();
|
||||
}
|
||||
addChatWithInputKey(id);
|
||||
}
|
||||
}
|
||||
|
||||
renderContent = (id) => {
|
||||
if (id === 'new') {
|
||||
return <NewChat />;
|
||||
|
@ -165,6 +165,11 @@ function ChatMessages({ id }) {
|
||||
copyStr={formatPrivateKey()}
|
||||
text="Copy nsec"
|
||||
/>
|
||||
<Copy
|
||||
className="btn btn-neutral btn-sm"
|
||||
copyStr={`https://beta.iris.to/chat/#${formatPrivateKey()}`}
|
||||
text="Copy link"
|
||||
/>
|
||||
</div>
|
||||
<Show when={showQr}>
|
||||
<QrCode data={'nostr:' + formatPrivateKey()} />
|
||||
|
@ -6,15 +6,23 @@ import localState from '../../LocalState';
|
||||
import Key from '../../nostr/Key';
|
||||
import { translate as t } from '../../translations/Translation.mjs';
|
||||
|
||||
export const createNewGroup = (key) => {
|
||||
const randomChatID = Math.floor(Math.random() * 1000000000);
|
||||
localState.get('groups').get(randomChatID).put({ key });
|
||||
console.log('create new group', key);
|
||||
route(`/chat/${randomChatID}`);
|
||||
};
|
||||
|
||||
export const addChatWithInputKey = (inputKey) => {
|
||||
if (inputKey.startsWith('nsec')) {
|
||||
const hexPriv = Key.toNostrHexAddress(inputKey);
|
||||
hexPriv && createNewGroup(hexPriv);
|
||||
}
|
||||
};
|
||||
|
||||
export default function NewChat() {
|
||||
const [inputKey, setInputKey] = useState('');
|
||||
|
||||
const createNewGroup = (key) => {
|
||||
const randomChatID = Math.floor(Math.random() * 1000000000);
|
||||
localState.get('groups').get(randomChatID).put({ key });
|
||||
route(`/chat/${randomChatID}`);
|
||||
};
|
||||
|
||||
const startNewGroup = () => {
|
||||
const newNostrKey = generatePrivateKey();
|
||||
createNewGroup(newNostrKey);
|
||||
@ -22,14 +30,7 @@ export default function NewChat() {
|
||||
|
||||
const handleInput = (e) => {
|
||||
setInputKey(e.target.value);
|
||||
addChatWithInputKey();
|
||||
};
|
||||
|
||||
const addChatWithInputKey = () => {
|
||||
if (inputKey.startsWith('nsec')) {
|
||||
const hexPriv = Key.toNostrHexAddress(inputKey);
|
||||
hexPriv && createNewGroup(hexPriv);
|
||||
}
|
||||
addChatWithInputKey(e.target.value);
|
||||
};
|
||||
|
||||
return (
|
||||
@ -44,7 +45,7 @@ export default function NewChat() {
|
||||
type="password"
|
||||
id="pasteLink"
|
||||
className="text-center input border border-gray-400 rounded-full p-2"
|
||||
onInput={handleInput}
|
||||
onChange={handleInput}
|
||||
value={inputKey}
|
||||
/>
|
||||
{/*<button id="scanQR" className="btn btn-neutral" onClick={}>
|
||||
|
Loading…
Reference in New Issue
Block a user