本文整理汇总了Golang中github.com/janimo/textsecure.Message类的典型用法代码示例。如果您正苦于以下问题:Golang Message类的具体用法?Golang Message怎么用?Golang Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: saveAttachment
func saveAttachment(contact contactInfo, attachment io.Reader, name string, msg *textsecure.Message) (err error) {
var output *os.File
attachmentPath := contact.AttachmentDir
err = os.MkdirAll(attachmentPath, 0700)
if err != nil {
return
}
if name == "" {
output, err = ioutil.TempFile(attachmentPath, "attachment_")
} else {
outputPath := filepath.Join(attachmentPath, name)
output, err = os.OpenFile(outputPath, os.O_WRONLY|os.O_CREATE|os.O_EXCL|os.O_TRUNC, 0600)
}
if err != nil {
return
}
defer output.Close()
io.Copy(output, attachment)
status.Log(syslog.LOG_NOTICE, "saved attachment from %s %s\n", contact.Name, contact.Number)
name = relativePath(output.Name())
updateHistory(contact, "["+name+"]", "<", msg.Timestamp())
return
}
开发者ID:jmptrader,项目名称:interlock,代码行数:31,代码来源:textsecure.go
示例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())
}
开发者ID:fun-alex-alex2006hw,项目名称:textsecure,代码行数:7,代码来源:main.go
示例3: messageHandler
func messageHandler(msg *textsecure.Message) {
status.Log(syslog.LOG_NOTICE, "received message from %s\n", msg.Source())
go func() {
n := status.Notify(syslog.LOG_NOTICE, "received message from %s\n", msg.Source())
time.Sleep(30 * time.Second)
status.Remove(n)
}()
contact, err := getContact(msg.Source())
if err != nil {
status.Error(err)
return
}
if msg.Message() != "" {
updateHistory(contact, msg.Message(), "<", msg.Timestamp())
}
attachments := msg.Attachments()
attachmentPattern := regexp.MustCompile("\\[" + attachmentMsg + "(.*)\\]$")
m := attachmentPattern.FindStringSubmatch(msg.Message())
// assign random name by default, use name embedded in msg for
// attachment sent via INTERLOCK
name := ""
if len(attachments) == 1 && len(m) == 2 {
name = path.Base(m[1])
}
for _, a := range attachments {
err := saveAttachment(contact, a, name, msg)
if err != nil {
status.Error(err)
return
}
}
}
开发者ID:jmptrader,项目名称:interlock,代码行数:41,代码来源:textsecure.go
示例4: timestamp
func timestamp(msg *textsecure.Message) string {
t := time.Unix(0, int64(msg.Timestamp())*1000000)
return t.Format(timeFormat)
}
开发者ID:fun-alex-alex2006hw,项目名称:textsecure,代码行数:4,代码来源:main.go
示例5: 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)
}
}
开发者ID:fun-alex-alex2006hw,项目名称:textsecure,代码行数:33,代码来源:main.go
示例6: timestamp
func timestamp(msg *textsecure.Message) string {
t := msg.Timestamp()
return t.Format(timeFormat)
}
开发者ID:diagprov,项目名称:textsecure,代码行数:4,代码来源:main.go
示例7: 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)
}
开发者ID:janimo,项目名称:textsecure-qml,代码行数:88,代码来源:main.go
示例8: recieveMessage
func recieveMessage(msg *ts.Message) {
if msg.Message() != "" {
//fmt.Printf("\r %s%s : %s%s%s\n>", red, getName(msg.Source()), green, msg.Message(), blue)
if msg.Source() == currentContact {
var b bytes.Buffer
t := time.Now()
if t.Hour() < 10 {
b.WriteString("0")
}
b.WriteString(strconv.Itoa(t.Hour()))
b.WriteString(":")
if t.Minute() < 10 {
b.WriteString("0")
}
b.WriteString(strconv.Itoa(t.Minute()))
b.WriteString(": ")
b.WriteString(msg.Message())
printToMsgWindow(b.String(), globalMsgWin, false)
insertMessage(msg.Source(), "You", []byte(msg.Message()), nil)
}
insertMessage(msg.Source(), "You", []byte(msg.Message()), nil)
}
for _, a := range msg.Attachments() {
handleAttachment(msg.Source(), a)
}
}
开发者ID:AyaTech,项目名称:textsecure-client,代码行数:29,代码来源:recieve.go
注:本文中的github.com/janimo/textsecure.Message类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论