Skip to content

Commit

Permalink
corner case: all messages deleted but pill counter not cleared
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Jul 20, 2018
1 parent e58a7c0 commit e8b5930
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
20 changes: 13 additions & 7 deletions server/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -1716,21 +1716,27 @@ func (t *Topic) replyGetData(sess *Session, id string, req *MsgGetOpts) error {
count = len(messages)
for i := count - 1; i >= 0; i-- {
mm := messages[i]

from := types.ParseUid(mm.From)
msg := &ServerComMessage{Data: &MsgServerData{
sess.queueOut(&ServerComMessage{Data: &MsgServerData{
Topic: t.original(sess.uid),
Head: mm.Head,
SeqId: mm.SeqId,
From: from.UserId(),
From: types.ParseUid(mm.From).UserId(),
Timestamp: mm.CreatedAt,
Content: mm.Content}}

sess.queueOut(msg)
Content: mm.Content}})
}
}
}

// Request for all available data returned no results while the client expects results
// because t.lastID > 0. Generate an empty data message to indicate that all messages
// have been deleted.
if count == 0 && t.lastID > 0 && (req == nil || (req.BeforeId == 0 && req.SinceId == 0)) {
sess.queueOut(&ServerComMessage{Data: &MsgServerData{
Topic: t.original(sess.uid),
SeqId: t.lastID,
Timestamp: now}})
}

// Inform the requester that all the data has been served.
reply := NoErr(id, t.original(sess.uid), now)
reply.Ctrl.Params = map[string]interface{}{"what": "data", "count": count}
Expand Down
7 changes: 6 additions & 1 deletion tinode-db/gendb.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ func genDb(reset bool, dbSource string, data *Data) {

seqIds := map[string]int{}

// Shuffle messages
rand.Shuffle(len(data.Messages), func(i, j int) {
data.Messages[i], data.Messages[j] = data.Messages[j], data.Messages[i]
})

now := time.Now().UTC().Add(-time.Minute).Round(time.Millisecond)
// Starting 4 days ago.
timestamp := now.Add(time.Hour * time.Duration(-24*4))
Expand Down Expand Up @@ -275,7 +280,7 @@ func genDb(reset bool, dbSource string, data *Data) {

seqIds[topic]++
seqId := seqIds[topic]
str := data.Messages[rand.Intn(len(data.Messages))]
str := data.Messages[i%len(data.Messages)]
// Max time between messages is 2 hours, averate - 1 hour, time is increasing as seqId increases
timestamp = timestamp.Add(time.Microsecond * time.Duration(rand.Intn(increment)))
if err = store.Messages.Save(&types.Message{
Expand Down

0 comments on commit e8b5930

Please sign in to comment.