Archived
1
0

Merge branch 'master' of ssh://github.com/majestrate/nntpchan

This commit is contained in:
Jeff Becker 2017-04-22 09:36:30 -04:00
commit 872c5d3757
2 changed files with 21 additions and 10 deletions

View File

@ -51,7 +51,7 @@ type ModUI interface {
type ModAction string type ModAction string
const ModInetBan = ModAction("overchan-inet-ban") const ModInetBan = ModAction("overchan-inet-ban")
const ModDelete = ModAction("overchan-delete") const ModDelete = ModAction("delete")
const ModRemoveAttachment = ModAction("overchan-del-attachment") const ModRemoveAttachment = ModAction("overchan-del-attachment")
const ModStick = ModAction("overchan-stick") const ModStick = ModAction("overchan-stick")
const ModLock = ModAction("overchan-lock") const ModLock = ModAction("overchan-lock")
@ -81,7 +81,13 @@ func (self simpleModEvent) String() string {
} }
func (self simpleModEvent) Action() ModAction { func (self simpleModEvent) Action() ModAction {
return ModAction(strings.Split(string(self), " ")[0]) switch strings.Split(string(self), " ")[0] {
case "delete":
return ModDelete
case "overchan-inet-ban":
return ModInetBan
}
return ""
} }
func (self simpleModEvent) Reason() string { func (self simpleModEvent) Reason() string {
@ -89,7 +95,11 @@ func (self simpleModEvent) Reason() string {
} }
func (self simpleModEvent) Target() string { func (self simpleModEvent) Target() string {
return strings.Split(string(self), " ")[1] parts := strings.Split(string(self), " ")
if len(parts) > 1 {
return parts[1]
}
return ""
} }
func (self simpleModEvent) Scope() string { func (self simpleModEvent) Scope() string {
@ -311,8 +321,10 @@ func (mod *modEngine) HandleMessage(msgid string) {
pubkey := nntp.Pubkey() pubkey := nntp.Pubkey()
for _, line := range strings.Split(nntp.Message(), "\n") { for _, line := range strings.Split(nntp.Message(), "\n") {
line = strings.Trim(line, "\r\t\n ") line = strings.Trim(line, "\r\t\n ")
ev := ParseModEvent(line) if len(line) > 0 {
mod.Execute(ev, pubkey) ev := ParseModEvent(line)
mod.Execute(ev, pubkey)
}
} }
} }
} }
@ -321,7 +333,7 @@ func (mod *modEngine) Do(ev ModEvent) {
action := ev.Action() action := ev.Action()
target := ev.Target() target := ev.Target()
if action == ModDelete || action == ModDeleteAlt { if action == ModDelete || action == ModDeleteAlt {
msgid := ev.Target() msgid := target
if !ValidMessageID(msgid) { if !ValidMessageID(msgid) {
// invalid message-id // invalid message-id
log.Println("invalid message-id", msgid) log.Println("invalid message-id", msgid)
@ -412,7 +424,6 @@ func (mod *modEngine) Execute(ev ModEvent, pubkey string) {
action := ev.Action() action := ev.Action()
target := ev.Target() target := ev.Target()
switch action { switch action {
case ModDeleteAlt:
case ModDelete: case ModDelete:
if mod.AllowDelete(pubkey, target) { if mod.AllowDelete(pubkey, target) {
mod.Do(ev) mod.Do(ev)

View File

@ -469,11 +469,11 @@ func (self *articleStore) GetMessage(msgid string) (nntp NNTPMessage) {
R: msg.Body, R: msg.Body,
N: MaxMessageSize, N: MaxMessageSize,
} }
err = read_message_body(body, hdr, nil, nil, true, func(nntp NNTPMessage) { err = read_message_body(body, hdr, nil, nil, true, func(n NNTPMessage) {
c := chnl c := chnl
// inject pubkey for mod // inject pubkey for mod
nntp.Headers().Set("X-PubKey-Ed25519", hdr.Get("X-PubKey-Ed25519")) n.Headers().Set("X-PubKey-Ed25519", hdr.Get("X-PubKey-Ed25519"))
c <- nntp c <- n
close(c) close(c)
}) })
if err == nil { if err == nil {