Skip to content
This repository has been archived by the owner on Feb 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #73 from/feature/remove-frontend-misskey-verify
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Oct 10, 2021
2 parents f089360 + 9d78961 commit e0ccf0b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 141 deletions.
6 changes: 3 additions & 3 deletions src/common/content-providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface Content {
}

export default {
hub,
misskey,
twitter,
Hub: hub,
Misskey: misskey,
Twitter: twitter,
};
75 changes: 0 additions & 75 deletions src/common/content-providers/misskey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,83 +66,8 @@ interface File {
}

export default {
verify: async (account: string, rns: string, ethAddress: string): Promise<boolean> => {
const u = await getUser(account);
if (u) {
// Phase 1: in "name"
if ((rns && u.name?.includes(rns)) || u.name?.includes(ethAddress)) {
return true;
}

// Phase 2: in "description"
if ((rns && u.description?.includes(rns)) || u.description?.includes(ethAddress)) {
return true;
}

// Phase 3: in "fields"
if (u.fields?.length) {
for (const pair of u.fields) {
if ((rns && pair.value?.includes(rns)) || pair.value?.includes(ethAddress)) {
return true;
}
}
}

// Phase 4: in "pinnedNotes"
if (u.pinnedNotes?.length) {
for (const note of u.pinnedNotes) {
if ((rns && note.text?.includes(rns)) || note.text?.includes(ethAddress)) {
return true;
}
}
}
}

// Else: not verified
return false;
},
getAccountLink: (account: string) => {
const { username, instance } = spliceAccountString(account);
return `https://${instance}/@${username}`;
},
get: async (account: string, sinceOffset: number = 0, untilTimeStamp: number = 0xffffffff): Promise<Content[]> => {
const { instance } = spliceAccountString(account);
const u = await getUser(account);
if (u) {
try {
const reqData = {
userId: u.id,
includeReplies: false,
untilDate: untilTimeStamp * 1000,
limit: config.contentRequestLimit,
excludeNsfw: true,
};
const res = await axios.post(`https://${instance}/api/users/notes`, reqData);
if (res.data) {
const notes = <Note[]>res.data;
const contents: Content[] = [];
for (const note of notes) {
contents.push({
id: note.id,
identity: account,
platform: 'Misskey',
type: 'Misskey',
info: {
title: '',
pre_content: note.text,
timestamp: Math.floor(Number(new Date(note.createdAt)) / 1000),
txHash: `https://${instance}/notes/${note.id}`,
link: `https://${instance}/notes/${note.id}`,
},
});
}
return contents;
}
} catch (e) {
console.log(e);
}
}
// Else or fail
return [];
},
};
17 changes: 0 additions & 17 deletions src/common/content-providers/twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,7 @@ import config from '@/config';
import { Content } from './index';

export default {
verify: async (account: string, rns: string, ethAddress: string): Promise<boolean> => {
// Let hub to do the verify works
return true;
},
getAccountLink: (account: string) => {
return `https://twitter.com/${account}`;
},
// get: async (address: string, sinceOffset: number = 0, untilTimeStamp: number = 0xffffffff): Promise<Content[]> => {
// try {
// const res = await axios.get(
// `${config.hubEndpoint}/asset-profile/${address}/contents/?offset=${sinceOffset}&limit=${config.contentRequestLimit}&latest=${untilTimeStamp}`,
// );
// if (res.data?.status) {
// return res.data.assets;
// }
// } catch (e) {
// console.log(e);
// }
// return [];
// },
};
4 changes: 1 addition & 3 deletions src/views/Accounts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,8 @@ export default class Accounts extends Vue {
window.open(`https://etherscan.io/address/${address}`);
break;
case 'Misskey':
window.open(ContentProviders.misskey.getAccountLink(address));
break;
case 'Twitter':
window.open(ContentProviders.twitter.getAccountLink(address));
window.open(ContentProviders[platform].getAccountLink(address));
break;
}
}
Expand Down
21 changes: 9 additions & 12 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ export default class Home extends Vue {
this.isContentsHaveMoreEachProvider.push({
provider: {
platform: 'RSS3',
identity: 'hub',
identity: 'Hub',
signature: '',
},
more: true,
Expand Down Expand Up @@ -842,9 +842,13 @@ export default class Home extends Vue {
let isHavingMore: boolean = false;
const contentsMerge: Content[] = [];
for (const provider of this.isContentsHaveMoreEachProvider) {
if (provider.provider.platform === 'RSS3' && provider.provider.identity === 'hub') {
if (provider.provider.platform === 'RSS3' && provider.provider.identity === 'Hub') {
if (provider.more) {
const contents = await ContentProviders.hub.get(this.ethAddress, 0, provider.lastTS);
const contents = await ContentProviders[provider.provider.identity].get(
this.ethAddress,
0,
provider.lastTS,
);
if (contents.length < config.contentRequestLimit) {
// No more
provider.more = false;
Expand Down Expand Up @@ -1061,19 +1065,12 @@ export default class Home extends Vue {
}
public displayDialog(address: string, platform: string) {
if (platform === 'Misskey') {
if (platform === 'Misskey' || platform === 'Twitter') {
this.showingAccountDetails = {
address,
platform,
isLink: true,
link: ContentProviders.misskey.getAccountLink(address),
};
} else if (platform === 'Twitter') {
this.showingAccountDetails = {
address,
platform,
isLink: true,
link: ContentProviders.twitter.getAccountLink(address),
link: ContentProviders[platform].getAccountLink(address),
};
} else {
this.showingAccountDetails = {
Expand Down
39 changes: 8 additions & 31 deletions src/views/Setup/SetupAccounts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -425,37 +425,14 @@ export default class SetupAccounts extends Vue {
async addNoSignAccountConfirm() {
this.isShowingAddSpecifyAccountInput = false;
this.isLoading = true;
const ethAddres = (<IRSS3>this.rss3).account.address;
const rns = await RNS.addr2Name(ethAddres);
if (
this.specifyNoSignAccount.platform === 'Misskey' &&
(await ContentProviders.misskey.verify(this.specifyNoSignAccount.account, rns, ethAddres))
) {
// Pass
const newAccount = {
platform: this.specifyNoSignAccount.platform,
identity: this.specifyNoSignAccount.account,
signature: '',
};
this.show.push(newAccount);
this.toAdd.push(newAccount);
} else if (
this.specifyNoSignAccount.platform === 'Twitter' &&
(await ContentProviders.twitter.verify(this.specifyNoSignAccount.account, rns, ethAddres))
) {
// Pass
const newAccount = {
platform: this.specifyNoSignAccount.platform,
identity: this.specifyNoSignAccount.account,
signature: '',
};
this.show.push(newAccount);
this.toAdd.push(newAccount);
} else {
// Unverified
this.addAccountNotice = 'Sorry, but this account cannot be verified.';
this.isShowingAddAccountNotice = true;
}
const newAccount = {
platform: this.specifyNoSignAccount.platform,
identity: this.specifyNoSignAccount.account,
signature: '',
};
this.show.push(newAccount);
this.toAdd.push(newAccount);
this.specifyNoSignAccount.account = '';
this.isLoading = false;
Expand Down

0 comments on commit e0ccf0b

Please sign in to comment.