Skip to content

Commit e24e0cf

Browse files
authored
Merge pull request tinode#710 from tinode/next
Fixing {get sub ims=...} for subscriptions with new messages
2 parents 96711cb + e5eaf2d commit e24e0cf

File tree

15 files changed

+173
-127
lines changed

15 files changed

+173
-127
lines changed

INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ A bash script [run-cluster.sh](./server/run-cluster.sh) may be found useful.
173173

174174
### Enabling Push Notifications
175175

176-
Follow [instructions](./docs/faq.md#q-how-to-setup-fcm-push-notifications).
176+
Follow [instructions](./docs/faq.md#q-how-to-setup-push-notifications-with-google-fcm).
177177

178178
### Note on Running the Server in Background
179179

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,15 @@ More translations are [welcome](docs/translations.md). Particularly interested i
144144
* Demo avatars and some other graphics are from https://www.pexels.com/ under [CC0 license](https://www.pexels.com/photo-license/) and https://pixabay.com/ under their [license](https://pixabay.com/service/license/).
145145
* Web and Android background patterns are from http://subtlepatterns.com/ under [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) license.
146146
* Android icons are from https://material.io/tools/icons/ under [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0.html) license.
147-
* Some iOS icons are from https://icons8.com/ under [CC BY-ND 3.0](https://icons8.com/license) license.
148147

149148
## Screenshots
150149

151150
### [Android](https://github.com/tinode/tindroid/)
152151

153152
<p align="center">
154-
<img src="docs/android-contacts.png" alt="Android screenshot: list of chats" width=270 />
155-
<img src="docs/android-chat.png" alt="Android screenshot: one conversation" width=270 />
156-
<img src="docs/android-account.png" alt="Android screenshot: account settings" width=270 />
153+
<img src="docs/android-contacts.png" alt="Android screenshot: list of chats" width=250 />
154+
<img src="docs/android-chat.png" alt="Android screenshot: one conversation" width=250 />
155+
<img src="docs/android-account.png" alt="Android screenshot: account settings" width=250 />
157156
</p>
158157

159158
### [iOS](https://github.com/tinode/ios)

docs/android-account.png

2.39 KB
Loading

docs/android-chat.png

-23.6 KB
Loading

docs/android-contacts.png

-10.2 KB
Loading

docs/web-desktop.jpg

-80.1 KB
Loading

docs/web-mob-chat.png

-118 KB
Loading

docs/web-mob-contacts.png

-4.28 KB
Loading

docs/web-mob-info.png

-15.5 KB
Loading

server/db/common/common.go

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,38 @@ func SelectEarliestUpdatedSubs(subs []t.Subscription, opts *t.QueryOpt, maxResul
2323
}
2424
}
2525

26-
if !ims.IsZero() || len(subs) > limit {
27-
// Now that we fetched potentially more subscriptions than needed, we got to take those with the oldest modifications.
28-
// Sorting in ascending order by modification time.
29-
sort.Slice(subs, func(i, j int) bool {
30-
return subs[i].UpdatedAt.Before(subs[j].UpdatedAt)
26+
// No cache management and the number of results is below the limit: return all.
27+
if ims.IsZero() && len(subs) <= limit {
28+
return subs
29+
}
30+
31+
// Now that we fetched potentially more subscriptions than needed, we got to take those with the oldest modifications.
32+
// Sorting in ascending order by modification time.
33+
sort.Slice(subs, func(i, j int) bool {
34+
return subs[i].LastModified().Before(subs[j].LastModified())
35+
})
36+
37+
if !ims.IsZero() {
38+
// Keep only those subscriptions which are newer than ims.
39+
at := sort.Search(len(subs), func(i int) bool {
40+
return subs[i].LastModified().After(ims)
3141
})
32-
if !ims.IsZero() {
33-
// Keep only those subscriptions which are newer than ims.
34-
at := sort.Search(len(subs), func(i int) bool { return subs[i].UpdatedAt.After(ims) })
35-
subs = subs[at:]
36-
}
37-
// Trim slice at the limit.
38-
if len(subs) > limit {
39-
subs = subs[:limit]
40-
}
42+
subs = subs[at:]
43+
}
44+
// Trim slice at the limit.
45+
if len(subs) > limit {
46+
subs = subs[:limit]
4147
}
4248

4349
return subs
4450
}
4551

46-
// SelectEarliestUpdatedAt picks the oldest timestamp which is still newer than the threshold ims.
47-
// The 'old' can be less than 'ims', the 'curr' must be greater than 'ims'.
48-
func SelectEarliestUpdatedAt(old, curr, ims time.Time) time.Time {
49-
if old.Before(ims) {
52+
// SelectLatestTime picks the latest update timestamp out of the two.
53+
func SelectLatestTime(t1, t2 time.Time) time.Time {
54+
if t1.Before(t2) {
5055
// Subscription has not changed recently, use user's update timestamp.
51-
return curr
52-
} else if old.After(curr) {
53-
if !ims.IsZero() {
54-
// Subscription changed after the user and cache management: using earlier timestamp.
55-
return curr
56-
}
57-
} else if ims.IsZero() {
58-
// Subscription changed before the user and NO cache management: using later timestamp.
59-
return curr
56+
return t2
6057
}
6158

62-
return old
59+
return t1
6360
}

0 commit comments

Comments
 (0)