narrow

package
v0.1.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2025 License: Unlicense Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter []Narrow

Filter is a collection of narrow items to be applied when searching for messages or filtering events

Example
package main

import (
	"fmt"

	"github.com/wakumaku/go-zulip/narrow"
)

func main() {
	// Create a new filter with a search, topic, and stream narrow
	narrow := narrow.NewFilter().
		Add(narrow.New(narrow.Channel, "general")).
		Add(narrow.New(narrow.Topic, "greetings")).
		Add(narrow.New(narrow.Search, "hello narrow"))

	narrowString := narrow.String()

	fmt.Println(narrowString)
}
Output:

channel:general topic:greetings search:hello narrow

func NewFilter

func NewFilter() Filter

NewFilter creates a new Filter

func (Filter) Add

func (nf Filter) Add(narrow Narrow) Filter

Add adds a new narrow item to the filter and returns the updated filter

func (Filter) MarshalEvent

func (n Filter) MarshalEvent() ([]byte, error)

MarshalEvent returns the JSON encoding of the Filter for events

func (Filter) MarshalJSON

func (n Filter) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the Filter

func (*Filter) String

func (nf *Filter) String() string

String returns a string representation of the Filter

type Narrow

type Narrow struct {
	Operator Operator `json:"operator"`
	Operand  Operand  `json:"operand"`
	Negated  bool     `json:"negated"`
}

Narrow is a struct that represents a single narrow item to be applied when searching for messages or filtering events

var (
	IsUnread      Narrow = New(Is, Unread)
	IsFollowed    Narrow = New(Is, Followed)
	IsDm          Narrow = New(Is, Operand("dm"))
	IsMentioned   Narrow = New(Is, Mentioned)
	IsStarred     Narrow = New(Is, Starred)
	IsRead        Narrow = New(Is, Read)
	IsAlerted     Narrow = New(Is, Alerted)
	HasAttachment Narrow = New(Is, Attachment)
	HasImage      Narrow = New(Is, Image)
	HasLink       Narrow = New(Has, Link)
	HasReaction   Narrow = New(Has, Reaction)
)

Operators with Operands

func Negate

func Negate(n Narrow) Narrow

Negate returns a new Negated Narrow

func New

func New(op Operator, val Operand) Narrow

New creates a new Narrow

func NewFromString

func NewFromString(s string) Narrow

NewFromString creates a new Narrow from a string

func NewNegated

func NewNegated(op Operator, val Operand) Narrow

NewNegated creates a new Negated Narrow

func (*Narrow) String

func (n *Narrow) String() string

String returns a string representation of the Narrow

type Operand

type Operand any

Operand is a type that represents the concrete operands that can be used in the narrow parameter.

var (
	Unread   Operand = "unread"
	Followed Operand = "followed"
	// Dm         Operand = "dm" // clashes with Dm Operator
	Mentioned  Operand = "mentioned"
	Starred    Operand = "starred"
	Read       Operand = "read"
	Alerted    Operand = "alerted"
	Attachment Operand = "attachment"
	Image      Operand = "image"
	Link       Operand = "link"
	Reaction   Operand = "reaction"
)

Operands List

type Operator

type Operator string

Operator is a type that represents the concrete operators that can be used in the narrow parameter.

const (
	// Search for only the message with ID 12345
	Id Operator = "id"
	// Search for the conversation that contains the message with ID 12345.
	With     Operator = "with"
	Near     Operator = "near"
	Channel  Operator = "channel"
	Channels Operator = "channels"
	// stream is a legacy alias for "channel"
	Stream Operator = "stream"
	// streams is a legacy alias for "channels"
	Streams Operator = "streams"
	Topic   Operator = "topic"
	Sender  Operator = "sender"
	Search  Operator = "search"
	// Search the direct message conversation between you and user ID 1234
	Dm Operator = "dm"
	// Search all direct messages (1-on-1 and group) that include you and user ID 1234.
	DmIncluding Operator = "dm-including"

	Is  Operator = "is"
	Has Operator = "has"
)

Operators List

func (Operator) String

func (n Operator) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL