차단 목록 관리 완료
This commit is contained in:
@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
type blockDoc struct {
|
||||
Id primitive.ObjectID `bson:"_id,omitempty" json:"id"`
|
||||
Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
|
||||
From primitive.ObjectID `bson:"from,omitempty" json:"-"`
|
||||
To primitive.ObjectID `bson:"to,omitempty" json:"-"`
|
||||
ToAlias string `bson:"talias" json:"to"`
|
||||
@ -53,13 +53,14 @@ func (bl *blocklist) Block(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
block.Timestamp = time.Now().UTC().Unix()
|
||||
_, newid, err := bl.mongoClient.Update(block_collection_name, bson.M{
|
||||
"_id": combineObjectID(block.From, block.To),
|
||||
}, bson.M{
|
||||
"$set": block,
|
||||
}, options.Update().SetUpsert(true))
|
||||
|
||||
if err != nil || newid != block.Id {
|
||||
if err != nil || newid == nil {
|
||||
// 이미 있다고 봐야지
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
@ -67,7 +68,7 @@ func (bl *blocklist) Block(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
block.Id = newid.(primitive.ObjectID)
|
||||
bl.wsh.SendUpstreamMessage(&wshandler.UpstreamMessage{
|
||||
Target: block.To.Hex(),
|
||||
Target: block.From.Hex(),
|
||||
Body: []blockDoc{block},
|
||||
Tag: blocks_tag,
|
||||
})
|
||||
@ -92,9 +93,8 @@ func (bl *blocklist) Unblock(ctx wshandler.ApiCallContext) {
|
||||
|
||||
if updated {
|
||||
bl.conns.writeMessage(ctx.CallBy.Accid, &wshandler.DownstreamMessage{
|
||||
Alias: ctx.CallBy.Alias,
|
||||
Body: []blockDoc{{Id: id, Deleted: true, Timestamp: now}},
|
||||
Tag: blocks_tag,
|
||||
Body: []blockDoc{{Id: id, Deleted: true, Timestamp: now}},
|
||||
Tag: blocks_tag,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -122,3 +122,23 @@ func (bl *blocklist) QueryBlock(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusGone)
|
||||
}
|
||||
}
|
||||
|
||||
func (bl *blocklist) QueryBlocks(ctx wshandler.ApiCallContext) {
|
||||
queryfrom := int64(ctx.Arguments[0].(float64))
|
||||
|
||||
var myblocks []blockDoc
|
||||
err := bl.mongoClient.FindAllAs(block_collection_name, bson.M{
|
||||
"from": ctx.CallBy.Accid,
|
||||
"ts": bson.M{"$gt": queryfrom},
|
||||
}, &myblocks)
|
||||
if err != nil {
|
||||
logger.Println("QueryBlocks failed. FindAllAs err :", err)
|
||||
}
|
||||
|
||||
if len(myblocks) > 0 {
|
||||
bl.conns.writeMessage(ctx.CallBy.Accid, &wshandler.DownstreamMessage{
|
||||
Body: myblocks,
|
||||
Tag: blocks_tag,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user