Tweak private share badges
This commit is contained in:
parent
2d7f8c0d87
commit
6b0246edad
|
@ -44,10 +44,20 @@ func Private() http.HandlerFunc {
|
|||
|
||||
log.Error("pager: %+v, len: %d", pager, len(users))
|
||||
|
||||
// Map reverse grantee statuses.
|
||||
var GranteeMap interface{}
|
||||
if isGrantee {
|
||||
// Shared With Me page: map whether we grant them shares back.
|
||||
GranteeMap = models.MapPrivatePhotoGranted(currentUser, users)
|
||||
} else {
|
||||
// My Shares page: map whether they share back with us.
|
||||
GranteeMap = models.MapPrivatePhotoGrantee(currentUser, users)
|
||||
}
|
||||
|
||||
var vars = map[string]interface{}{
|
||||
"IsGrantee": isGrantee,
|
||||
"CountGrantee": models.CountPrivateGrantee(currentUser.ID),
|
||||
"GranteeMap": models.MapPrivatePhotoGrantee(currentUser, users),
|
||||
"GranteeMap": GranteeMap,
|
||||
"Users": users,
|
||||
"Pager": pager,
|
||||
}
|
||||
|
|
|
@ -240,7 +240,7 @@ func (pb *PrivatePhoto) Save() error {
|
|||
// PrivateGranteeMap maps user IDs to whether they have granted you their private photos.
|
||||
type PrivateGranteeMap map[uint64]bool
|
||||
|
||||
// MapShyAccounts looks up a set of user IDs in bulk and returns a PrivateGranteeMap suitable for templates.
|
||||
// MapPrivatePhotoGrantee looks up a set of user IDs in bulk and returns a PrivateGranteeMap suitable for templates.
|
||||
func MapPrivatePhotoGrantee(currentUser *User, users []*User) PrivateGranteeMap {
|
||||
var (
|
||||
usermap = PrivateGranteeMap{}
|
||||
|
@ -277,3 +277,44 @@ func MapPrivatePhotoGrantee(currentUser *User, users []*User) PrivateGranteeMap
|
|||
func (um PrivateGranteeMap) Get(id uint64) bool {
|
||||
return um[id]
|
||||
}
|
||||
|
||||
// PrivateGrantedMap maps user IDs to whether we have granted our private pictures to them.
|
||||
type PrivateGrantedMap map[uint64]bool
|
||||
|
||||
// MapPrivatePhotoGranted looks up a set of user IDs in bulk and returns a PrivateGrantedMap suitable for templates.
|
||||
func MapPrivatePhotoGranted(currentUser *User, users []*User) PrivateGrantedMap {
|
||||
var (
|
||||
usermap = PrivateGrantedMap{}
|
||||
set = map[uint64]interface{}{}
|
||||
distinct = []uint64{}
|
||||
)
|
||||
|
||||
// Uniqueify users.
|
||||
for _, user := range users {
|
||||
if _, ok := set[user.ID]; ok {
|
||||
continue
|
||||
}
|
||||
set[user.ID] = nil
|
||||
distinct = append(distinct, user.ID)
|
||||
}
|
||||
|
||||
var (
|
||||
matched = []*PrivatePhoto{}
|
||||
result = DB.Model(&PrivatePhoto{}).
|
||||
Where("source_user_id = ? AND target_user_id IN ?", currentUser.ID, distinct).
|
||||
Find(&matched)
|
||||
)
|
||||
|
||||
if result.Error == nil {
|
||||
for _, row := range matched {
|
||||
usermap[row.TargetUserID] = true
|
||||
}
|
||||
}
|
||||
|
||||
return usermap
|
||||
}
|
||||
|
||||
// Get a user from the PrivateGrantedMap.
|
||||
func (um PrivateGrantedMap) Get(id uint64) bool {
|
||||
return um[id]
|
||||
}
|
||||
|
|
|
@ -110,19 +110,37 @@
|
|||
</p>
|
||||
|
||||
<!-- Indicator if they are sharing back -->
|
||||
<div>
|
||||
{{if $Root.GranteeMap.Get .ID}}
|
||||
<span class="has-text-success">
|
||||
<i class="fa fa-check mr-1"></i>
|
||||
Sharing with me too
|
||||
</span>
|
||||
{{else}}
|
||||
<span class="has-text-danger">
|
||||
<i class="fa fa-xmark mr-1"></i>
|
||||
Not sharing with me
|
||||
</span>
|
||||
{{end}}
|
||||
</div>
|
||||
{{if not $Root.IsGrantee}}
|
||||
<!-- "My Shares" tab - GranteeMap is whether they granted me back -->
|
||||
<div>
|
||||
{{if $Root.GranteeMap.Get .ID}}
|
||||
<span class="has-text-success">
|
||||
<i class="fa fa-check mr-1"></i>
|
||||
Sharing with me
|
||||
</span>
|
||||
{{else}}
|
||||
<span class="has-text-danger">
|
||||
<i class="fa fa-xmark mr-1"></i>
|
||||
Not sharing with me
|
||||
</span>
|
||||
{{end}}
|
||||
</div>
|
||||
{{else}}
|
||||
<!-- "Shared With Me" tab - GranteeMap is whether I granted them -->
|
||||
<div>
|
||||
{{if $Root.GranteeMap.Get .ID}}
|
||||
<span class="has-text-success">
|
||||
<i class="fa fa-check mr-1"></i>
|
||||
I share with them
|
||||
</span>
|
||||
{{else}}
|
||||
<span class="has-text-danger">
|
||||
<i class="fa fa-xmark mr-1"></i>
|
||||
I do not share with them
|
||||
</span>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue
Block a user