Skip to content

Commit

Permalink
feat: add friends discovering in legacy twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
guanbinrui committed Nov 27, 2019
1 parent 70d3360 commit 6c8c3a3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/database/helpers/group.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { GroupRecord, createUserGroupDatabase, updateUserGroupDatabase, queryUserGroupsDatabase } from '../group'
import { PersonIdentifier, GroupIdentifier, PreDefinedVirtualGroupNames } from '../type'
import { Person } from './person'
import { MessageCenter } from '../../utils/messages'

export interface Group extends GroupRecord {
avatar?: string
Expand Down
23 changes: 13 additions & 10 deletions src/social-network-provider/twitter.com/ui/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import { bioCardParser, postParser } from '../utils/fetch'
import { uploadToService } from '../utils/user'
import { isNil } from 'lodash-es'
import Services from '../../../extension/service'
import { twitterUrl } from '../utils/url'

const resolveLastRecognizedIdentity = (self: SocialNetworkUI) => {
const resolveLastRecognizedIdentity = async (self: SocialNetworkUI) => {
const selfSelector = selfInfoSelectors().handle
const assign = () => {
const ref = self.lastRecognizedIdentity
Expand All @@ -40,16 +41,18 @@ const resolveLastRecognizedIdentity = (self: SocialNetworkUI) => {
const registerUserCollector = () => {
new MutationObserverWatcher(bioCard())
.useForeach((cardNode: HTMLDivElement) => {
const resolve = () => {
const r = bioCardParser(cardNode)
uploadToService(r)
const theGroup = GroupIdentifier.getDefaultFriendsGroupIdentifier(
instanceOfTwitterUI.lastRecognizedIdentity.value.identifier,
)
if (r.isFollowing && r.isFollower) {
Services.People.addPersonToFriendsGroup(theGroup, [r.identifier]).then()
const resolve = async () => {
const bio = bioCardParser(cardNode)
uploadToService(bio)
const myIdentity =
(await Services.People.queryMyIdentity()).filter(
({ identifier }) => identifier.network === twitterUrl.hostIdentifier,
)[0] || PersonIdentifier.unknown
const theGroup = GroupIdentifier.getDefaultFriendsGroupIdentifier(myIdentity.identifier)
if (bio.isFollowing && bio.isFollower) {
Services.People.addPersonToFriendsGroup(theGroup, [bio.identifier]).then()
} else {
Services.People.removePersonFromFriendsGroup(theGroup, [r.identifier]).then()
Services.People.removePersonFromFriendsGroup(theGroup, [bio.identifier]).then()
}
}
resolve()
Expand Down
2 changes: 1 addition & 1 deletion src/social-network-provider/twitter.com/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const getPostUrl = (post: PostIdentifier<PersonIdentifier>, useMobile: bo
}

export const getProfileUrl = (self: PersonIdentifier, useMobile: boolean = false) => {
return `${hostLeadingUrlAuto(useMobile)}/${self.userId}`
return useMobile ? `${hostLeadingUrlAuto(useMobile)}/account` : `${hostLeadingUrlAuto(useMobile)}/${self.userId}`
}

export const topSites = [
Expand Down
7 changes: 4 additions & 3 deletions src/social-network-provider/twitter.com/worker/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PersonIdentifier, PostIdentifier } from '../../../database/type'
import { getPostUrl, getProfileUrl } from '../utils/url'
import tasks from '../../../extension/content-script/tasks'
import { isMobileTwitter } from '../utils/isMobile'

/**
* get things at server side with legacy twitter
Expand All @@ -9,10 +10,10 @@ import tasks from '../../../extension/content-script/tasks'
* resolve this problem when you can.
*/

export const fetchPostContent = async (post: PostIdentifier<PersonIdentifier>) => {
export const fetchPostContent = (post: PostIdentifier<PersonIdentifier>) => {
return tasks(getPostUrl(post)).getPostContent()
}

export const fetchProfile = async (self: PersonIdentifier) => {
return tasks(getProfileUrl(self), {}).getProfile(self)
export const fetchProfile = (self: PersonIdentifier) => {
return tasks(getProfileUrl(self, isMobileTwitter as boolean), {}).getProfile(self)
}

0 comments on commit 6c8c3a3

Please sign in to comment.