conversation.go 940 B

12345678910111213141516171819202122232425262728293031323334
  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. func ConversationEntry(aimID, displayID, message, msgID, sender string, sent bool, unread int) map[string]interface{} {
  15. entry := map[string]interface{}{
  16. "aimId": aimID,
  17. "displayId": displayID,
  18. "active": 0,
  19. "unreadCount": unread,
  20. }
  21. if message != "" {
  22. entry["lastIM"] = map[string]interface{}{
  23. "message": message,
  24. "msgId": msgID,
  25. "sender": sender,
  26. "sent": sent,
  27. "timestamp": float64(time.Now().Unix()),
  28. }
  29. }
  30. return entry
  31. }