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))
|
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{}{
|
var vars = map[string]interface{}{
|
||||||
"IsGrantee": isGrantee,
|
"IsGrantee": isGrantee,
|
||||||
"CountGrantee": models.CountPrivateGrantee(currentUser.ID),
|
"CountGrantee": models.CountPrivateGrantee(currentUser.ID),
|
||||||
"GranteeMap": models.MapPrivatePhotoGrantee(currentUser, users),
|
"GranteeMap": GranteeMap,
|
||||||
"Users": users,
|
"Users": users,
|
||||||
"Pager": pager,
|
"Pager": pager,
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,7 +240,7 @@ func (pb *PrivatePhoto) Save() error {
|
||||||
// PrivateGranteeMap maps user IDs to whether they have granted you their private photos.
|
// PrivateGranteeMap maps user IDs to whether they have granted you their private photos.
|
||||||
type PrivateGranteeMap map[uint64]bool
|
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 {
|
func MapPrivatePhotoGrantee(currentUser *User, users []*User) PrivateGranteeMap {
|
||||||
var (
|
var (
|
||||||
usermap = PrivateGranteeMap{}
|
usermap = PrivateGranteeMap{}
|
||||||
|
@ -277,3 +277,44 @@ func MapPrivatePhotoGrantee(currentUser *User, users []*User) PrivateGranteeMap
|
||||||
func (um PrivateGranteeMap) Get(id uint64) bool {
|
func (um PrivateGranteeMap) Get(id uint64) bool {
|
||||||
return um[id]
|
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>
|
</p>
|
||||||
|
|
||||||
<!-- Indicator if they are sharing back -->
|
<!-- Indicator if they are sharing back -->
|
||||||
<div>
|
{{if not $Root.IsGrantee}}
|
||||||
{{if $Root.GranteeMap.Get .ID}}
|
<!-- "My Shares" tab - GranteeMap is whether they granted me back -->
|
||||||
<span class="has-text-success">
|
<div>
|
||||||
<i class="fa fa-check mr-1"></i>
|
{{if $Root.GranteeMap.Get .ID}}
|
||||||
Sharing with me too
|
<span class="has-text-success">
|
||||||
</span>
|
<i class="fa fa-check mr-1"></i>
|
||||||
{{else}}
|
Sharing with me
|
||||||
<span class="has-text-danger">
|
</span>
|
||||||
<i class="fa fa-xmark mr-1"></i>
|
{{else}}
|
||||||
Not sharing with me
|
<span class="has-text-danger">
|
||||||
</span>
|
<i class="fa fa-xmark mr-1"></i>
|
||||||
{{end}}
|
Not sharing with me
|
||||||
</div>
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user