Skip to content

Commit

Permalink
feat: auto add user to friend group
Browse files Browse the repository at this point in the history
  • Loading branch information
Misaka-0x447f committed Oct 28, 2019
1 parent 511dc81 commit d00c57a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/social-network-provider/twitter.com/ui/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bioCard, postsSelector, selfInfoSelectors } from '../utils/selector'
import { MutationObserverWatcher } from '@holoflows/kit'
import { PersonIdentifier } from '../../../database/type'
import { GroupIdentifier, PersonIdentifier } from '../../../database/type'
import {
getEmptyPostInfoByElement,
SocialNetworkUI,
Expand All @@ -11,6 +11,7 @@ import { instanceOfTwitterUI } from './index'
import { bioCardParser, postParser } from '../utils/fetch'
import { uploadToService } from '../utils/user'
import { isNil } from 'lodash-es'
import Services from '../../../extension/service'

const resolveLastRecognizedIdentity = (self: SocialNetworkUI) => {
const selfSelector = selfInfoSelectors().handle
Expand Down Expand Up @@ -43,6 +44,14 @@ const registerUserCollector = () => {
const resolve = () => {
const r = bioCardParser()
uploadToService(r)
const theGroup = GroupIdentifier.getDefaultFriendsGroupIdentifier(
instanceOfTwitterUI.lastRecognizedIdentity.value.identifier,
)
if (r.isFollowing && r.isFollower) {
Services.People.addPersonToFriendsGroup(theGroup, [r.identifier]).then()
} else {
Services.People.removePersonFromFriendsGroup(theGroup, [r.identifier]).then()
}
}
resolve()
return {
Expand Down
2 changes: 1 addition & 1 deletion src/social-network-provider/twitter.com/ui/inject.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AdditionalPostBox } from '../../../components/InjectedComponents/AdditionalPostBox'
import React from 'react'
import { AdditionalPostBox } from '../../../components/InjectedComponents/AdditionalPostBox'
import { LiveSelector, MutationObserverWatcher as MOW } from '@holoflows/kit'
import { hasDraftEditor, newPostEditorBelow, postPopupInjectPointSelector } from '../utils/selector'
import { renderInShadowRoot } from '../../../utils/jss/renderInShadowRoot'
Expand Down
3 changes: 3 additions & 0 deletions src/social-network-provider/twitter.com/utils/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { regexMatch } from '../../../utils/utils'
import { notNullable } from '../../../utils/assert'
import { defaultTo, isUndefined, join } from 'lodash-es'
import { nthChild } from '../../../utils/dom'
import { PersonIdentifier } from '../../../database/type'
import { host } from '../index'

/**
* @example
Expand Down Expand Up @@ -53,6 +55,7 @@ export const bioCardParser = () => {
avatar,
name: nameArea.name,
handle: nameArea.handle,
identifier: new PersonIdentifier(host, nameArea.handle),
bio,
isFollower,
isFollowing,
Expand Down

0 comments on commit d00c57a

Please sign in to comment.