本文整理汇总了Golang中github.com/janimo/textsecure.Message.Group方法的典型用法代码示例。如果您正苦于以下问题:Golang Message.Group方法的具体用法?Golang Message.Group怎么用?Golang Message.Group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/janimo/textsecure.Message
的用法示例。
在下文中一共展示了Message.Group方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: messageHandler
func messageHandler(msg *textsecure.Message) {
if echo {
to := msg.Source()
if msg.Group() != nil {
to = msg.Group().Name
}
err := sendMessage(msg.Group() != nil, to, msg.Message())
if err != nil {
log.Println(err)
}
return
}
if msg.Message() != "" {
fmt.Printf("\r %s%s\n>", pretty(msg), blue)
}
for _, a := range msg.Attachments() {
handleAttachment(msg.Source(), a.R)
}
// if no peer was specified on the command line, start a conversation with the first one contacting us
if to == "" {
to = msg.Source()
isGroup := false
if msg.Group() != nil {
isGroup = true
to = msg.Group().Name
}
go conversationLoop(isGroup)
}
}
示例2: pretty
func pretty(msg *textsecure.Message) string {
src := getName(msg.Source())
if msg.Group() != nil {
src = src + "[" + msg.Group().Name + "]"
}
return fmt.Sprintf("%s%s %s%s %s%s", yellow, timestamp(msg), red, src, green, msg.Message())
}
示例3: messageHandler
func messageHandler(msg *textsecure.Message) {
var err error
f := ""
mt := ""
if len(msg.Attachments()) > 0 {
mt = msg.Attachments()[0].MimeType
f, err = saveAttachment(msg.Attachments()[0])
if err != nil {
log.Printf("Error saving %s\n", err.Error())
}
}
msgFlags := 0
text := msg.Message()
if msg.Flags() == textsecure.EndSessionFlag {
text = sessionReset
msgFlags = msgFlagResetSession
}
gr := msg.Group()
if gr != nil && gr.Flags != 0 {
_, ok := groups[gr.Hexid]
members := ""
if ok {
members = groups[gr.Hexid].Members
}
av := []byte{}
if gr.Avatar != nil {
av, err = ioutil.ReadAll(gr.Avatar)
if err != nil {
log.Println(err)
return
}
}
groups[gr.Hexid] = &GroupRecord{
GroupID: gr.Hexid,
Members: strings.Join(gr.Members, ","),
Name: gr.Name,
Avatar: av,
Active: true,
}
if ok {
updateGroup(groups[gr.Hexid])
} else {
saveGroup(groups[gr.Hexid])
}
if gr.Flags == textsecure.GroupUpdateFlag {
dm, _ := membersDiffAndUnion(members, strings.Join(gr.Members, ","))
text = groupUpdateMsg(dm, gr.Name)
msgFlags = msgFlagGroupUpdate
}
if gr.Flags == textsecure.GroupLeaveFlag {
text = telToName(msg.Source()) + " has left the group."
msgFlags = msgFlagGroupLeave
}
}
s := msg.Source()
if gr != nil {
s = gr.Hexid
}
session := sessionsModel.Get(s)
m := session.Add(text, msg.Source(), f, mt, false)
m.ReceivedAt = uint64(time.Now().UnixNano() / 1000000)
m.SentAt = msg.Timestamp()
m.HTime = humanizeTimestamp(m.SentAt)
qml.Changed(m, &m.HTime)
session.Timestamp = m.SentAt
session.When = m.HTime
qml.Changed(session, &session.When)
if gr != nil && gr.Flags == textsecure.GroupUpdateFlag {
session.Name = gr.Name
qml.Changed(session, &session.Name)
}
if msgFlags != 0 {
m.Flags = msgFlags
qml.Changed(m, &m.Flags)
}
saveMessage(m)
updateSession(session)
}