app/src/main/java/org/andstatus/app/net/social/Audience.java
/** TODO: Audience should belong to an Activity, not to a Note.
     *        As audience currently belongs to a Note, we actually use noteAuthor instead of activityActor here.
     * @return true if data changed */
Audience should belong to an Activity, not to a Note.
As audience currently belongs to a Note, we actually use noteAuthor instead of activityActor here.
@return true if data changed
Audience should belong to an Activity not to a Note . As audience currently belongs to a Note we actually use noteAuthor instead of activityActor here . @return true if data changed
public boolean save(Actor actorOfAudience, long noteId, Visibility visibility, boolean countOnly) {
        if (this == EMPTY || !actorOfAudience.origin.isValid() || noteId == 0 || actorOfAudience.actorId == 0 || !origin.myContext.isReady()) {
            return false;
        }
        Audience prevAudience = Audience.loadIds(actorOfAudience.origin, noteId, Optional.of(visibility));
        List<Actor> actorsToSave = evaluateAndGetActorsToSave(actorOfAudience);
        Set<Actor> toDelete = new HashSet<>();
        Set<Actor> toAdd = new HashSet<>();
        for (Actor actor : prevAudience.evaluateAndGetActorsToSave(actorOfAudience)) {
            findSame(actor).onFailure(e -> toDelete.add(actor));
        }
        for (Actor actor : actorsToSave) {
            if (actor.actorId == 0) {
                MyLog.w(TAG, "No actorId for " + actor);
                continue;
            }
            prevAudience.findSame(actor).onFailure( e -> toAdd.add(actor));
        }
        if (!toDelete.isEmpty() || !toAdd.isEmpty()) {
            MyLog.d(TAG, "Audience differs, noteId:" + noteId + "," +
                    "\nprev: " + prevAudience +
                    "\nnew: " + this +
                    (!toDelete.isEmpty() ? "\ntoDelete: " + toDelete : "") +
                    (!toAdd.isEmpty() ? "\ntoAdd: " + toAdd : "")
            );
        }
        if (!countOnly) try {
            if (!toDelete.isEmpty()) {
                MyProvider.delete(origin.myContext, AudienceTable.TABLE_NAME, AudienceTable.NOTE_ID + "=" + noteId
                        + " AND " + AudienceTable.ACTOR_ID + SqlIds.actorIdsOf(toDelete).getSql());
            }
            toAdd.forEach(actor -> MyProvider.insert(origin.myContext, AudienceTable.TABLE_NAME, toContentValues(noteId, actor)));
        } catch (Exception e) {
            MyLog.w(this, "save, noteId:" + noteId + "; " + actors, e);
        }
        return  !toDelete.isEmpty() || !toAdd.isEmpty();
    }
public boolean save ( Actor actorOfAudience , long noteId , Visibility visibility , boolean countOnly ) { if ( this == EMPTY || ! actorOfAudience . origin . isValid ( ) || noteId == 0 || actorOfAudience . actorId == 0 || ! origin . myContext . isReady ( ) ) { return false ; } Audience prevAudience = Audience . loadIds ( actorOfAudience . origin , noteId , Optional . of ( visibility ) ) ; List < Actor > actorsToSave = evaluateAndGetActorsToSave ( actorOfAudience ) ; Set < Actor > toDelete = new HashSet < > ( ) ; Set < Actor > toAdd = new HashSet < > ( ) ; for ( Actor actor : prevAudience . evaluateAndGetActorsToSave ( actorOfAudience ) ) { findSame ( actor ) . onFailure ( e -> toDelete . add ( actor ) ) ; } for ( Actor actor : actorsToSave ) { if ( actor . actorId == 0 ) { MyLog . w ( TAG , "No actorId for " + actor ) ; continue ; } prevAudience . findSame ( actor ) . onFailure ( e -> toAdd . add ( actor ) ) ; } if ( ! toDelete . isEmpty ( ) || ! toAdd . isEmpty ( ) ) { MyLog . d ( TAG , "Audience differs, noteId:" + noteId + "," + "\nprev: " + prevAudience + "\nnew: " + this + ( ! toDelete . isEmpty ( ) ? "\ntoDelete: " + toDelete : "" ) + ( ! toAdd . isEmpty ( ) ? "\ntoAdd: " + toAdd : "" ) ) ; } if ( ! countOnly ) try { if ( ! toDelete . isEmpty ( ) ) { MyProvider . delete ( origin . myContext , AudienceTable . TABLE_NAME , AudienceTable . NOTE_ID + "=" + noteId + " AND " + AudienceTable . ACTOR_ID + SqlIds . actorIdsOf ( toDelete ) . getSql ( ) ) ; } toAdd . forEach ( actor -> MyProvider . insert ( origin . myContext , AudienceTable . TABLE_NAME , toContentValues ( noteId , actor ) ) ) ; } catch ( Exception e ) { MyLog . w ( this , "save, noteId:" + noteId + "; " + actors , e ) ; } return ! toDelete . isEmpty ( ) || ! toAdd . isEmpty ( ) ; }
TODO: Audience should belong to an Activity, not to a Note.
TODO : Audience should belong to an Activity not to a Note .