commit bbc5b26a15792a399de5ac0428d22b01832f196f
parent cf091623138fb7ae91a0e735f0b751670845ed76
Author: Peter Kosyh <p.kosyh@gmail.com>
Date: Sat, 12 Sep 2020 14:19:07 +0300
Edit and Offs fix
Diffstat:
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/ii-node/web.go b/ii-node/web.go
@@ -363,7 +363,7 @@ func www_query(ctx *WebContext, w http.ResponseWriter, r *http.Request, q ii.Que
ii.Trace.Printf("www query")
sort.SliceStable(mis, func(i, j int) bool {
- return mis[i].Off > mis[j].Off
+ return mis[i].Num > mis[j].Num
})
count := len(mis)
start := makePager(ctx, count, page)
@@ -440,7 +440,7 @@ func www_topics(ctx *WebContext, w http.ResponseWriter, r *http.Request, page in
}
sort.SliceStable(topics, func(i, j int) bool {
- return topics[i].Last.Off > topics[j].Last.Off
+ return topics[i].Last.Num > topics[j].Last.Num
})
ctx.BasePath = echo
tcount := len(topics)
@@ -615,6 +615,7 @@ func www_new(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
ii.Error.Printf("Access denied")
return errors.New("Access denied")
}
+ m.Date = om.Date
m.MsgId = id
m.From = om.From
m.Addr = om.Addr
diff --git a/ii/db.go b/ii/db.go
@@ -18,6 +18,7 @@ import (
)
type MsgInfo struct {
+ Num int
Id string
Echo string
To string
@@ -220,6 +221,7 @@ func (db *DB) LoadIndex() error {
}
var err2 error
linenr := 0
+ nr := len(Idx.List)
err = f_lines(file, func(line string) bool {
linenr++
info := strings.Split(line, ":")
@@ -227,14 +229,17 @@ func (db *DB) LoadIndex() error {
err2 = errors.New("Wrong format on line:" + fmt.Sprintf("%d", linenr))
return false
}
- mi := MsgInfo{Id: info[0], Echo: info[1], To: info[3], From: info[4]}
+ mi := MsgInfo{Num: nr, Id: info[0], Echo: info[1], To: info[3], From: info[4]}
if _, err := fmt.Sscanf(info[2], "%d", &mi.Off); err != nil {
err2 = errors.New("Wrong offset on line: " + fmt.Sprintf("%d", linenr))
return false
}
mi.Repto = info[5]
- if _, ok := Idx.Hash[mi.Id]; !ok { // new msg
+ if mm, ok := Idx.Hash[mi.Id]; !ok { // new msg
Idx.List = append(Idx.List, mi.Id)
+ nr ++
+ } else {
+ mi.Num = mm.Num
}
Idx.Hash[mi.Id] = mi
// Trace.Printf("Adding %s to index", mi.Id)
@@ -578,7 +583,7 @@ func (db *DB) GetTopics(mi []*MsgInfo) map[string][]string {
topics[t.Id] = append(topics[t.Id], t.Id)
}
sort.SliceStable(l, func(i int, j int) bool {
- return l[i].Off < l[j].Off
+ return l[i].Num < l[j].Num
})
for _, i := range l {
if i.Id == t.Id {