diff --git a/world/net/place/threads.c b/world/net/place/threads.c index c161668..35338b7 100644 --- a/world/net/place/threads.c +++ b/world/net/place/threads.c @@ -267,17 +267,15 @@ setSubject(id, thread) { // TODO: topic uebergeben addEntry(text, unick, thread) { - mapping* entries; + int id = sizeof(_thread); mapping newentry = ([ - "text" : text, - "author" : unick, - "date" : time(), - "thread" : thread || "", + "id": id, + "text": text, + "author": unick, + "date": time(), + "thread": thread || "", ]); - entries = _thread || ({ }); - entries += ({ newentry }); - int id = sizeof(entries) - 1; - _thread = entries; + _thread += ({ newentry }); save(); castmsg(ME, "_notice_thread_entry", thread ? @@ -528,23 +526,18 @@ displayMain(last) { } #endif -htmlEntries(array(mapping) entries, int last, int js, string chan, string submit) { - P3((">> threads:htmlentries(%O, %O)\n", entries, last)) - string t; - string ht = ""; +htmlEntries(array(mapping) entries, int js, string chan, string submit) { + P3((">> threads:htmlentries(%O, %O, %O, %O)\n", entries, js, chan, submit)) + string t, ht = ""; + string id_prefix = chan ? chan + "-" : ""; if (js) ht += "\n"; - string id_prefix = chan ? chan + "-" : ""; - mapping item; - int n = 0; - int id; - // reverse order - for (id = sizeof(entries) - 1; id >= 0; id--) { - P3((">>> entries[%O]: %O\n", id, entries[id])) - unless (item = entries[id]) continue; + foreach (mapping item : entries) { + P3((">>> item: %O\n", item)) + unless (item) continue; t = htquote(item["text"]); t = replace(t, "\n", "
\n"); @@ -559,48 +552,45 @@ htmlEntries(array(mapping) entries, int last, int js, string chan, string submit ht += "
\n" "
\n" - "#" + id + " - \n" + "#" + item["id"] + " - \n" "" + item["author"] + "\n" + (item["thread"] && strlen(item["thread"]) ? " - " : "") + "" + htquote(item["thread"]) + "\n" "
\n" "
\n" "
" + t + "
\n" - "\n" "\n" "
\n"; - if (last && ++n >= last) break; } P3((">>> ht: %O\n", ht)) return "
" + ht + "
"; } htMain(int last) { - return htmlEntries(_thread, last, 1); + return htmlEntries(entries(last), 1); } entries(int last) { array(mapping) entries = ({ }); - int n = 0; - int id; - // reverse order - for (id = sizeof(_thread) - 1; id >= 0; id--) { - P3((">>> _thread[%O]: %O\n", id, _thread[id])) - unless (_thread[id]) continue; - entries += ({ _thread[id] }); + int i, n = 0; + for (i = sizeof(_thread) - 1; i >= 0; i--) { + P3((">>> _thread[%O]: %O\n", i, _thread[i])) + unless (_thread[i]) continue; + entries += ({ _thread[i] }); if (++n >= last) break; }