|
@@ -10,6 +10,7 @@ import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
|
|
import { Storage } from "@ionic/storage";
|
|
import { Storage } from "@ionic/storage";
|
|
import { P2pStorageIpfsProvider } from "../../providers/p2p-storage-ipfs/p2p-storage-ipfs";
|
|
import { P2pStorageIpfsProvider } from "../../providers/p2p-storage-ipfs/p2p-storage-ipfs";
|
|
import { P2pDatabaseGunProvider } from "../../providers/p2p-database-gun/p2p-database-gun";
|
|
import { P2pDatabaseGunProvider } from "../../providers/p2p-database-gun/p2p-database-gun";
|
|
|
|
+import twittertext from "twitter-text";
|
|
|
|
|
|
@IonicPage()
|
|
@IonicPage()
|
|
@Component({
|
|
@Component({
|
|
@@ -84,13 +85,51 @@ export class WriteTweetPage {
|
|
|
|
|
|
private async buildPrivateTweet() {
|
|
private async buildPrivateTweet() {
|
|
const status = this.tweet.value["text"].trim();
|
|
const status = this.tweet.value["text"].trim();
|
|
|
|
+ const entities = await this.getEntities(status);
|
|
|
|
+
|
|
return {
|
|
return {
|
|
full_text: status,
|
|
full_text: status,
|
|
user_id: await this.storage.get("userId"),
|
|
user_id: await this.storage.get("userId"),
|
|
created_at: Date.now(),
|
|
created_at: Date.now(),
|
|
private_tweet: true,
|
|
private_tweet: true,
|
|
display_text_range: [0, status.length],
|
|
display_text_range: [0, status.length],
|
|
- entities: {}
|
|
|
|
|
|
+ entities: entities
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private async getEntities(status: string) {
|
|
|
|
+ return {
|
|
|
|
+ hashtags: twittertext.extractHashtagsWithIndices(status),
|
|
|
|
+ urls: twittertext.extractUrlsWithIndices(status),
|
|
|
|
+ user_mentions: await this.getMentions(status)
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private async getMentions(status: string) {
|
|
|
|
+ // extract mentions
|
|
|
|
+ const entities = twittertext.extractMentionsWithIndices(status);
|
|
|
|
+
|
|
|
|
+ // add user_id
|
|
|
|
+ const entitiesWithPromises = entities.map(async mention => {
|
|
|
|
+ try {
|
|
|
|
+ const user = await this.twitter.fetchUserFromScreenName(
|
|
|
|
+ mention.screenName
|
|
|
|
+ );
|
|
|
|
+ mention["id_str"] = user[0]["id_str"];
|
|
|
|
+ mention["screen_name"] = mention.screenName;
|
|
|
|
+ delete mention.screenName;
|
|
|
|
+ } catch (err) {
|
|
|
|
+ console.error(
|
|
|
|
+ "There is no user signed up to twitter with username: " +
|
|
|
|
+ mention.screenName
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ return mention;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // filter for valid users and return
|
|
|
|
+ return (await Promise.all(entitiesWithPromises)).filter(el =>
|
|
|
|
+ el.hasOwnProperty("id_str")
|
|
|
|
+ );
|
|
|
|
+ }
|
|
}
|
|
}
|