conversation.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package types
  2. import "time"
  3. // ConversationEventData builds a conversation fetchEvents payload.
  4. func ConversationEventData(operation string, conversations []map[string]interface{}) map[string]interface{} {
  5. if conversations == nil {
  6. conversations = []map[string]interface{}{}
  7. }
  8. return map[string]interface{}{
  9. "operation": operation,
  10. "conversations": conversations,
  11. }
  12. }
  13. // ConversationEntry builds one conversation object for the Web AIM client.
  14. //
  15. // An empty displayID is omitted rather than sent blank: the client falls back to
  16. // the name it already has for aimID, whereas any value present here replaces it.
  17. func ConversationEntry(aimID, displayID, message, msgID, sender string, sent bool, unread int) map[string]interface{} {
  18. entry := map[string]interface{}{
  19. "aimId": aimID,
  20. "active": 0,
  21. "unreadCount": unread,
  22. }
  23. if displayID != "" {
  24. entry["displayId"] = displayID
  25. }
  26. if message != "" {
  27. entry["lastIM"] = map[string]interface{}{
  28. "message": message,
  29. "msgId": msgID,
  30. "sender": sender,
  31. "sent": sent,
  32. "timestamp": float64(time.Now().Unix()),
  33. }
  34. }
  35. return entry
  36. }