@@ -14,52 +14,42 @@ const { Types, Creators } = createActions({
1414 getBlacklist : ( ) => {
1515 return ( dispatch , getState ) => {
1616 WebIM . conn . getBlocklist ( ) . then ( res => {
17- dispatch ( Creators . updateBlacklist ( res . data ) )
17+ res . data && dispatch ( Creators . updateBlacklist ( res . data ) )
1818 } )
1919 }
2020 } ,
2121 // add to black list
2222 doAddBlacklist : id => {
2323 return ( dispatch , getState ) => {
2424 dispatch ( CommonActions . fetching ( ) )
25+ try {
26+ WebIM . conn . addUsersToBlocklist ( { name :id } ) ;
27+ let blacklist = getState ( ) . entities . blacklist . byName . asMutable ( )
28+ let index = blacklist . findIndex ( i => blacklist [ i ] == id )
29+ if ( index > - 1 ) return
30+ blacklist . push ( id ) ;
31+ dispatch ( Creators . updateBlacklist ( blacklist ) )
32+ } catch ( e ) {
2533
26- let blacklist = getState ( ) . entities . blacklist . byName . asMutable ( )
27- let roster = getState ( ) . entities . roster . byName
28- if ( blacklist [ id ] ) return
29- blacklist [ id ] = roster [ id ]
30- WebIM . conn . addToBlackList ( {
31- // list: blacklist,
32- // type: "jid",
33- name : id ,
34- success : function ( ) {
35- // TODO: add to black list directly , shouldn't re-pull
36- dispatch ( CommonActions . fetched ( ) )
37- } ,
38- error : function ( ) {
39- dispatch ( CommonActions . fetched ( ) )
40- }
41- } )
34+ } finally {
35+ dispatch ( CommonActions . fetched ( ) )
36+ }
4237 }
4338 } ,
4439 // delete from blacklist
4540 doRemoveBlacklist : id => {
4641 return ( dispatch , getState ) => {
4742 dispatch ( CommonActions . fetching ( ) )
48-
49- let blacklist = getState ( ) . entities . blacklist . byName . asMutable ( )
50- delete blacklist [ id ]
51- WebIM . conn . removeFromBlackList ( {
52- // list: blacklist,
53- // type: "jid",
54- name : id ,
55- success : function ( ) {
56- // TODO: delete from black list directly , shouldn't re-pull
57- dispatch ( CommonActions . fetched ( ) )
58- } ,
59- error : function ( ) {
60- dispatch ( CommonActions . fetched ( ) )
61- }
62- } )
43+ try {
44+ let blacklist = getState ( ) . entities . blacklist . byName . asMutable ( )
45+ WebIM . conn . removeUserFromBlackList ( { name :blacklist [ id ] } )
46+ blacklist . splice ( id , 1 )
47+ dispatch ( Creators . updateBlacklist ( blacklist ) )
48+ dispatch ( CommonActions . fetched ( ) )
49+ // delete blacklist[id]
50+ } catch ( e ) {
51+ dispatch ( CommonActions . fetched ( ) )
52+ }
6353 }
6454 }
6555} )
0 commit comments